Consider a target with compile options and include files:
target_compile_options(Tutorial PRIVATE /DC=1)
target_compile_options(Tutorial PRIVATE /DD=2)
target_include_directories(Tutorial PRIVATE "include files/a")
target_include_directories(Tutorial PRIVATE "include files/b")
And a custom command that wants to do something special:
add_custom_command(
OUTPUT Tutorial.i
COMMAND "${CMAKE_C_COMPILER}" -I"$<JOIN:$<TARGET_PROPERTY:Tutorial,INCLUDE_DIRECTORIES>,\" -I\">" "$<JOIN:$<TARGET_PROPERTY:Tutorial,COMPILE_OPTIONS>,\" \">" /P ${CMAKE_CURRENT_SOURCE_DIR}/Tutorial.cxx
MAIN_DEPENDENCY "Tutorial.cxx"
COMMENT "Preprocessing Tutorial.cxx"
)
This correctly quotes the include folders:
-I"include files/a" -I"include files/b"
Note the "
marks immediately before and after the $<JOIN...>
expression show up in the output.
However, the compile options come out without the leading and trailing "
like this:
/DC=1" "/DD=2
On the other hand, if the generator expression for the compile options is this:
"$<JOIN:$<TARGET_PROPERTY:Tutorial,COMPILE_OPTIONS>, >"
Then, the result is this where the outer quotes are retained.
"/DC=1 /DD=2"
Neither are what I need - which is each option quoted separately. This can be fixed by expressly including first and last quotes:
"\"$<JOIN:$<TARGET_PROPERTY:Tutorial,COMPILE_OPTIONS>, >\""
What I don't understand is why the two JOIN
expressions behave differently about retaining or dropping the surrounding double quotes?
P.S> And if the $<JOIN
isn't surrounded in quotes at all, then it doesn't seem to be processed $<JOIN...>
actually shows up in the command line.
This can be reproduced starting with the CMake Tutorial step 4 and adding the option and custom command lines above.