Genex: $<TARGET_PROPERTY:...> contents is not genex expanded
When value of a target property is retrieved through genex $<TARGET_PROPERTY...>
, the contents is not expanded if it contains generator expressions.
Here is small example showing the problem:
add_library (example SHARED example.cxx)
set_property (TARGET example PROPERTY CUSTOM_CONFIG $<$<CONFIG:DEBUG>:MY_DEBUG>)
add_custom_target (custom
COMMAND echo "$<TARGET_PROPERTY:example,CUSTOM_CONFIG>"
DEPENDS example)
In case of debug configuration (cmake -DCMAKE_BUILD_TYPE=Debug ...
), building custom
target, expected result is MY_DEBUG
displayed in the console.
But, because generator-expression is not expanded, expression $<$<CONFIG:DEBUG>:MY_DEBUG>
is stored in the build script rather than MY_DEBUG
, so we get the following error:
/bin/sh: -c: line 0: syntax error near unexpected token 'newline'
/bin/sh: -c: line 0: 'echo libexample.dyliblibexample.dylibCONFIG:DEBUG>:MY_DEBUG>'
Curious error message comes from the fact that $<
is a special variable in make
tool.