Ambiguous documentation of TARGET_GENEX_EVAL
The documentation says of TARGET_GENEX_EVAL
$<TARGET_GENEX_EVAL:tgt,expr>
Content of expr evaluated as a generator expression in the context of tgt target. This enables consumption of custom target properties that themselves contain generator expressions.
Consider the following project which wraps a target-less $<TARGET_PROPERTY:prop>
genex into a $<TARGET_GENEX_EVAL:tgt, prop>
, so that the genex can be evaluated in file(GENERATE)
without having to specify the target directly to file(GENERATE)
or having to modify the original genex from $<TARGET_PROPERTY:prop>
to $<TARGET_PROPERTY:tgt,prop>
because there might be many of them.
One would expect this to work.
cmake_minimum_required(VERSION 3.18)
project(test_proj CXX)
set(source_file "${CMAKE_CURRENT_BINARY_DIR}/app.cpp")
file(WRITE "${source_file}" "int main(int argc, char** argv) {return 0;}")
add_executable(app "${source_file}")
set(prop "_my_prop")
set_target_properties(app PROPERTIES ${prop} 1)
set(genex "$<TARGET_PROPERTY:${prop}>")
set(genex_wrap "$<TARGET_GENEX_EVAL:app,$<TARGET_PROPERTY:${prop}>>")
file(GENERATE OUTPUT "out.txt" CONTENT "${genex_wrap}")
CMake Error at CMakeLists.txt:14 (file):
Error evaluating generator expression:
$<TARGET_PROPERTY:_my_prop>
$<TARGET_PROPERTY:prop> may only be used with binary targets. It may not
be used with add_custom_command or add_custom_target. Specify the target
to read a property from using the $<TARGET_PROPERTY:tgt,prop> signature
instead.
Is the documentation ambiguous? Is my interpretation wrong? Is this a bug that should be fixed?