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.
Does ${WAT}
contain a genex? If not, you could use this as an alternative to the genex:
if(WAT)
target_sources(your_target_name PRIVATE ${CMAKE__SOURCE_DIR}/src/wat.c ${CMAKE_SOURCE_DIR}/src/modules/mod_wat.c)
endif()
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 :).
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.