Querying target properties with generator expressions - LINK_LIBRARIES incosistency
I wanted to dump various CMake target properties to a file. These properties can contain generator expressions, which I expected to be resolved to actual values. I used file(GENERATE)
command.
cmake_minimum_required(VERSION 3.10.0)
project(Test)
add_executable(Exec main.cpp)
target_link_libraries(Exec PRIVATE Lib0 $<IF:$<CONFIG:Debug>,Lib1,Lib2>)
target_include_directories(Exec PRIVATE /Dir0 $<IF:$<CONFIG:Debug>,/Dir1,/Dir2>)
target_compile_definitions(Exec PRIVATE -DVALUE=Val0 -DVALUE=$<IF:$<CONFIG:Debug>,Val1,Val2>)
target_compile_options(Exec PRIVATE Opt0 $<IF:$<CONFIG:Debug>,Opt1,Opt2>)
set(EXPR "\
$<TARGET_PROPERTY:Exec,LINK_LIBRARIES>
$<TARGET_PROPERTY:Exec,INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:Exec,COMPILE_DEFINITIONS>
$<TARGET_PROPERTY:Exec,COMPILE_OPTIONS>
")
file(GENERATE OUTPUT output$<CONFIG>.txt CONTENT "${EXPR}")
This works great for all properties I tried except for LINK_LIBRARIES
- generator expressions are not resolved. See output for debug config:
Lib0;$<IF:$<CONFIG:Debug>,Lib1,Lib2>
/Dir0;/Dir1
VALUE=Val0;VALUE=Val1
Opt0;Opt1
The behaviour is incosistent. After adding $<GENEX_EVAL>
around $<TARGET_PROPERTY:Exec,LINK_LIBRARIES>
it starts to work as expected. Why is it different for LINK_LIBRARIES
(and INTERFACE_LINK_LIBRARIES
)? Is this behaviour documented? I cannot find anything about it, looks like a bug.
I am using current cmake from Arch repositories, which is 3.27.7.
Edited by Maciej Dziuban