But this does not work because CMake escapes whitespace between flags. The obvious alternative would be getting rid of the quotes around the generator expression but that causes it to not be expanded at all in build.ninja (or similar)!
Is there really no way to achieve this without “manual” string operations?
There is an example showing precisely this in the genex documentation. The example builds it up in several steps, but here are the two final forms it offers:
Using $<JOIN>:
# The $<BOOL:...> check prevents adding anything if the property is empty,
# assuming the property value cannot be one of CMake's false constants.
set(prop "$<TARGET_PROPERTY:tgt,INCLUDE_DIRECTORIES>")
add_custom_target(run_some_tool
COMMAND some_tool "$<$<BOOL:${prop}>:-I$<JOIN:${prop},;-I>>"
COMMAND_EXPAND_LISTS
VERBATIM
)
I have a question about this. If tgt’s INCLUDE_DIRECTORIES has $<BUILD_INTERFACE:...> and $<INSTALL_INTERFACE:...> generator expressions as suggested here, then
with one empty -I flag for each $<INSTALL_INTERFACE:...>. The empty -I flags cause gcc to complain it can’t find headers! Is there a way to filter these out?
Edit: the form with $<JOIN>: doesn’t produce the empty -I flags and works as expected! It seems these two solutions are not equivalent. It would be a good idea to update the documentation accordingly (or fix the bug, if it’s a bug).