adaldev
December 11, 2025, 3:34pm
1
Hi,
I’ve got a static library target L where I do:
target_compile_definitions(L PUBLIC SOMESYMBOL)
In an application A, I’m linking against L:
target_link_library(A PRIVATE L)
I’m then expecting A to inherit SOMESYMBOL but:
get_target_property(ouputvar A <INTERFACE_>COMPILE_DEFINITIONS)
message(${ouputvar})
displays only
outputvar-NOTFOUND
What is happening?
Regards
A.
Andrej730
(Andrej)
December 11, 2025, 7:59pm
2
They do propagate, you can see it when running the build.
cmake_minimum_required(VERSION 3.15)
project(mypkg CXX)
add_library(L src/mypkg.cpp)
target_compile_definitions(L PUBLIC SOMESYMBOL)
add_library(A src/mypkg.cpp)
target_link_libraries(A PRIVATE L)
Output (note SOMESYMBOL present in both commands):
# ninja -v -n
[1/4] L:\Software\MICROS~2\2022\COMMUN~1\VC\Tools\MSVC\1444~1.352\bin\Hostx64\x64\cl.exe /nologo /TP -DSOMESYMBOL /DWIN32 /D_WINDOWS /GR /EHsc /Zi /Ob0 /Od /RTC1 -MDd /showIncludes /FoCMakeFiles\L.dir\src\mypkg.cpp.obj /FdCMakeFiles\L.dir\L.pdb /FS -c L:\oblivion\conan-test\src\mypkg.cpp
[2/4] L:\Software\MICROS~2\2022\COMMUN~1\VC\Tools\MSVC\1444~1.352\bin\Hostx64\x64\cl.exe /nologo /TP -DSOMESYMBOL /DWIN32 /D_WINDOWS /GR /EHsc /Zi /Ob0 /Od /RTC1 -MDd /showIncludes /FoCMakeFiles\A.dir\src\mypkg.cpp.obj /FdCMakeFiles\A.dir\A.pdb /FS -c L:\oblivion\conan-test\src\mypkg.cpp
When you do target_link_library you don’t copy properties of all linked targets to another, you just reference the target as linked to another and it’s properties then inherited later during project build files generation.
adaldev
December 12, 2025, 5:21pm
3
Thanks Andrej,
There is no way to test for the symbol from A CMakeLists.txt at configuration time?
At worse, can I display a message at build time, based on the existence of the symbol?
Regards,
A.