0

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>"
  )
Jazzwave06
  • 1,883
  • 1
  • 11
  • 19
  • please provide a [mre] (something I can copy and paste and try out myself). Ex. You haven't shown the definition of `target` or example include directories. – starball Apr 06 '23 at 19:25
  • "_when `MY_INCLUDE_DIRECTORIES` evaluates to an empty list,_" How are you certain that it's evaluating to an empty list? – starball Apr 06 '23 at 19:26
  • What do you see when you make your COMMAND `echo $`? – starball Apr 06 '23 at 19:32
  • If it was not an empty list, say `MY_INCLUDE_DIRECTORIES="include"`, it would print `binary 1 include`. If it had multiple values, say `MY_INCLUDE_DIRECTORIES=include1;include2`, it would print `binary 1 include1;include2`. If it's printing `binary 1`, it means it's both empty but evaluates to true. Also, I've fixed it, I needed to have both generator expression in list append in the same double quote scope. – Jazzwave06 Apr 06 '23 at 19:32
  • Your fix doesn't look like a fix. What does your "fix" do when those target properties are both NOT empty? You haven't separated the generator expressions in `"$$"` with a semicolon... I'm betting the actual answer has to do with the order of `add_custom_target(... COMMAND_EXPAND_LISTS)` handling semicolons. That's why wrote my third comment (please see my third comment) – starball Apr 06 '23 at 19:35
  • 1
    if `COMMAND echo $` echoes a semicolon, then the list is not really empty- it would be a list with two empty values, and the solution would probably to make your `$` filter out empty list values using `$`. – starball Apr 06 '23 at 19:39

0 Answers0