Detecting scope of added sources

I have the following lines of code:

add_executable( MyExecutable)
add_library(Lib EXCLUDE_FROM_ALL)

# … much later, conditionally, in deeply nested code and at multiple locations

target_sources(Lib PRIVATE some.cpp)

# After Surfacing

target_link_libraries(MyExecutable Lib)

This will not work of course, because the lib doesn’t propagate its usage requirements (using PUBLIC for example) and the relevant error is thrown (“No SOURCES given to target: MyExecutable”).

How can I check if Lib has any propagated PUBLIC sources in order to take measures, if not? Creating some dummy file as PUBLIC source of Lib would be enough then to make the executable target valid, but I would like to avoid this, if not necessary.

Checking Lib’s SOURCE property for being empty or -NOFOUND is not sufficient, because it also shows all of its PRIVATE sources and I don’t know how to further differentiate their scope.

It’s not possible and will not be supported. See this post:

Oh, if you want to do configure-time querying, I think INTERFACE_SOURCES is the property you want to ask. You just can’t express it as a generator expression.