I am working on a project that use cmake
build. I have my cmake
files like this:
dirA/CMakeLists.txt :
add_library(A STATIC ${SRC_FILES})
target_compile_definitions(A public -DABC)
dirB/CMakeLists.txt :
add_library(B STATIC ${SRC_FILES})
target_link_libraries(B PRIVATE A) //-DABC is passed to B
dirC/CMakeLists.txt :
add_library(C STATIC ${SRC_FILES})
target_link_libraries(C B) ////-DABC is not passed to C
I observe that flag -DABC
is being passed to library B
but not to library C
. Is there a way to pass the compile definitions in cmake
transitively?
Sure. Link A to B publicly.
target_link_libraries(B PUBLIC A)
Private linkage explicitly halts transitive propagation of properties.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.