I'm trying to add a custom command target to my build, and I'm trying to append a list of arguments based on a variable which contains itself a generator expression. My code looks like this:
list(
APPEND MY_INCLUDE_DIRECTORIES
$<TARGET_PROPERTY:target,INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:target,INTERFACE_INCLUDE_DIRECTORIES>
)
add_custom_target(
custom_target
COMMAND binary
"$<$<BOOL:$<GENEX_EVAL:${MY_INCLUDE_DIRECTORIES}>>:--includes;$<JOIN:${MY_INCLUDE_DIRECTORIES},;--includes;>>"
COMMAND_EXPAND_LISTS
VERBATIM
)
However, when MY_INCLUDE_DIRECTORIES
evaluates to an empty list, it tries to execute binary --includes
and I don't understand why. I've modified part of the custom target to debug the output of each generator expression as such.
add_custom_target(
custom_target
COMMAND binary
"$<BOOL:$<GENEX_EVAL:${MY_INCLUDE_DIRECTORIES}>>"
"$<GENEX_EVAL:${MY_INCLUDE_DIRECTORIES}>"
COMMAND_EXPAND_LISTS
VERBATIM
)
But it prints the command binary 1
, which implies that the boolean expression is true, but the list is empty. Am I doing something wrong?
EDIT: I've found a fix, although I still don't understand what was happening. I had to append the generator expressions as such:
list(
APPEND MY_INCLUDE_DIRECTORIES
"$<TARGET_PROPERTY:target,INCLUDE_DIRECTORIES>$<TARGET_PROPERTY:target,INTERFACE_INCLUDE_DIRECTORIES>"
)