# Target sources contains empty entries

**URL:** https://discourse.cmake.org/t/target-sources-contains-empty-entries/9392
**Category:** Code
**Created:** [November 8, 2023, 3:08pm UTC](https://discourse.cmake.org/t/target-sources-contains-empty-entries/9392 "2023-11-08T15:08:30Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![eriols](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eriols/32/945_2.png) [@eriols](https://discourse.cmake.org/u/eriols)
#### Post date: [November 8, 2023, 3:08pm UTC](https://discourse.cmake.org/t/target-sources-contains-empty-entries/9392/1 "2023-11-08T15:08:30Z")

</div>

I’m using `target_sources` and noticed that when I need to retrieve those sources using `$<TARGET_PROPERTY:my_target,SOURCES>` I’d get a few empty entries here and there which breaks a bit of my build.  
Eg the list starts with a few emtpy entries `;;;/some/file.c;/another/file.c`.  
I’m using a few genexes on the target\_sources command which seems to be a likely culprit as the empty entries happen near them. Example:  
` $<$<BOOL:${WAT}>:${CMAKE_SOURCE_DIR}/src/wat.c ${CMAKE_SOURCE_DIR}/src/modules/mod_wat.c>`  
Are the false booleans expanding to an empty entry? Is there a good way to avoid this? Alas I’m not on such a recent version that I can use the genex version of remove duplicates if that is one workaround.

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [November 9, 2023, 10:11am UTC](https://discourse.cmake.org/t/target-sources-contains-empty-entries/9392/2 "2023-11-09T10:11:17Z")

</div>

Does `${WAT}` contain a genex? If not, you could use this as an alternative to the genex:

```auto
if(WAT)
  target_sources(your_target_name PRIVATE ${CMAKE__SOURCE_DIR}/src/wat.c ${CMAKE_SOURCE_DIR}/src/modules/mod_wat.c)
endif()

```

---

<div class="post-metadata">

### Author: ![eriols](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eriols/32/945_2.png) [@eriols](https://discourse.cmake.org/u/eriols)
#### Post date: [November 9, 2023, 10:33am UTC](https://discourse.cmake.org/t/target-sources-contains-empty-entries/9392/3 "2023-11-09T10:33:11Z")

</div>

Thanks, no WAT just a build option so your suggestion is indeed a workaround.  
I’ve since realized that the empty entries are probably not the issue so I might create another topic :).

---

<div class="post-metadata">

### Author: ![eriols](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eriols/32/945_2.png) [@eriols](https://discourse.cmake.org/u/eriols)
#### Post date: [November 13, 2023, 10:24am UTC](https://discourse.cmake.org/t/target-sources-contains-empty-entries/9392/4 "2023-11-13T10:24:21Z")

</div>

I got what I wanted by using `get_target_property(res my_target INTERFACE_SOURCES)` instead of the `$<TARGET_PROPERTY...` construct; then I get the entries looking like they do if they were just a normal list.
