I was attempting to validate my understanding of the inheritance of PROPERTY
s through target link libraries. That is, I thought that if target1
was given a property and target2
linked that target, it would inherit that property, such that $<TARGET_PROPERTY:target2,property_name>
would reveal that value.
Is this wrong, or is my test case simply wrong?
cmake_minimum_required (VERSION 3.17)
project (test LANGUAGES C)
add_library (l1 STATIC f1.c)
set_property (TARGET l1 PROPERTY FOO "FOO property from l1")
target_compile_definitions (l1 PUBLIC -DBAR="public Dbar from l1")
target_compile_definitions (l1 PRIVATE -DBAR="Dbar from l1")
add_library (l2 STATIC f2.c)
target_link_libraries (l2 PUBLIC l1)
target_compile_definitions (l2 PRIVATE -DFOO_L1="$<TARGET_PROPERTY:l1,FOO>")
target_compile_definitions (l2 PRIVATE -DFOO_L2="$<TARGET_PROPERTY:l2,FOO>")
add_executable (test main.c)
target_link_libraries (test l2)
what this finds is that l1,FOO
resolves to a value, but l2,FOO
is empty in this scenario.
f1BAR:[Dbar from l1] f2bar:[public Dbar from l1] f2foo1:[FOO property from l1] f2foo2:[]
Is this a limitation of target_compile definitions
or a misunderstanding of properties?