# Detecting scope of added sources

**URL:** https://discourse.cmake.org/t/detecting-scope-of-added-sources/8634
**Category:** Code
**Created:** [July 29, 2023, 6:07pm UTC](https://discourse.cmake.org/t/detecting-scope-of-added-sources/8634 "2023-07-29T18:07:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mbee](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@mbee](https://discourse.cmake.org/u/mbee)
#### Post date: [July 29, 2023, 6:07pm UTC](https://discourse.cmake.org/t/detecting-scope-of-added-sources/8634/1 "2023-07-29T18:07:28Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [July 29, 2023, 8:54pm UTC](https://discourse.cmake.org/t/detecting-scope-of-added-sources/8634/2 "2023-07-29T20:54:20Z")

</div>

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

> [@Generation expression based on dependee?](https://discourse.cmake.org/t/generation-expression-based-on-dependee/7220/2):
>
> This is what I call “intersectional usage requirements” (or “I use A and B therefore C” kind of logic). CMake doesn’t have support for this. What you can do is something like: target\_link\_libraries(input INTERFACE "$\<$\<BOOL:$\<TARGET\_PROPERTY:USES\_MOUSE\>\>:widgets\>") add\_executable(app) target\_link\_libraries(app PUBLIC input mouse) set\_property(TARGET app PROPERTY USES\_MOUSE 1) There’s also no support for $\<INHERITED\_PROPERTY\> because it can cause undecidable builds (a “later” target coul…

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [July 29, 2023, 9:00pm UTC](https://discourse.cmake.org/t/detecting-scope-of-added-sources/8634/3 "2023-07-29T21:00:35Z")

</div>

> [@mbee](#):
>
> Checking Lib’s SOURCE property for being empty or -NOFOUND is not sufficient

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.
