I'm working with a CMake body of code that wants to set certain variables with generator expressions, e.g., the second entry in
target_sources( date-tz
PUBLIC
include/date/tz.h
$<$<BOOL:${IOS}>:include/date/ios.h>
)
The idea here is: if ${IOS}
is TRUE
, then the second line expands to
include/date/ios.h
and otherwise to nothing (""
).
This however is not true: The output target files will contain something like
$<$<BOOL:TRUE>:include/date/ios.h>
I gather from here that generator expressions are for things that are not known at configure time, and hence are probably not what we actually want.
One alternative would be to set
if (${IOS})
set(ios_h include/date/ios.h)
else()
set(ios_h "")
endif()
target_sources( date-tz
PUBLIC
include/date/tz.h
${ios_h}
)
which sure enough is evaluated at configure time. Is this the correct approach? Is there a shorter (inline) form of the latter?
This is with CMake 3.16.3.