transitive usage requirements passed through `PRIVATE` dependencies
reading the 'transitive usage requirements' section there is the example:
add_library(archive archive.cpp)
target_compile_definitions(archive INTERFACE USING_ARCHIVE_LIB)
add_library(serialization serialization.cpp)
target_compile_definitions(serialization INTERFACE USING_SERIALIZATION_LIB)
add_library(archiveExtras extras.cpp)
target_link_libraries(archiveExtras PUBLIC archive)
target_link_libraries(archiveExtras PRIVATE serialization)
# archiveExtras is compiled with -DUSING_ARCHIVE_LIB
# and -DUSING_SERIALIZATION_LIB
add_executable(consumer consumer.cpp)
# consumer is compiled with -DUSING_ARCHIVE_LIB
target_link_libraries(consumer archiveExtras)
this comes with the following explanation:
Because archive is a PUBLIC dependency of archiveExtras, the usage requirements of it are propagated to consumer too. Because serialization is a PRIVATE dependency of archiveExtras, the usage requirements of it are not propagated to consumer.
https://cmake.org/cmake/help/git-stage/manual/cmake-buildsystem.7.html#transitive-usage-requirements
compiling this example gives me the following:
➜ b ninja -v
[1/8] /usr/bin/c++ -DUSING_ARCHIVE_LIB -DUSING_SERIALIZATION_LIB -MD -MT CMakeFiles/archiveExtras.dir/extras.o -MF CMakeFiles/archiveExtras.dir/extras.o.d -o CMakeFiles/archiveExtras.dir/extras.o -c ../extras.cpp
[2/8] /usr/bin/c++ -DUSING_ARCHIVE_LIB -DUSING_SERIALIZATION_LIB -MD -MT CMakeFiles/consumer.dir/consumer.o -MF CMakeFiles/consumer.dir/consumer.o.d -o CMakeFiles/consumer.dir/consumer.o -c ../consumer.cpp
[3/8] /usr/bin/c++ -MD -MT CMakeFiles/archive.dir/archive.o -MF CMakeFiles/archive.dir/archive.o.d -o CMakeFiles/archive.dir/archive.o -c ../archive.cpp
[4/8] /usr/bin/c++ -MD -MT CMakeFiles/serialization.dir/serialization.o -MF CMakeFiles/serialization.dir/serialization.o.d -o CMakeFiles/serialization.dir/serialization.o -c ../serialization.cpp
[5/8] : && /snap/cmake/846/bin/cmake -E rm -f libserialization.a && /usr/bin/ar qc libserialization.a CMakeFiles/serialization.dir/serialization.o && /usr/bin/ranlib libserialization.a && :
[6/8] : && /snap/cmake/846/bin/cmake -E rm -f libarchive.a && /usr/bin/ar qc libarchive.a CMakeFiles/archive.dir/archive.o && /usr/bin/ranlib libarchive.a && :
[7/8] : && /snap/cmake/846/bin/cmake -E rm -f libarchiveExtras.a && /usr/bin/ar qc libarchiveExtras.a CMakeFiles/archiveExtras.dir/extras.o && /usr/bin/ranlib libarchiveExtras.a && :
[8/8] : && /usr/bin/c++ -rdynamic CMakeFiles/consumer.dir/consumer.o -o consumer libarchiveExtras.a libarchive.a libserialization.a && :
most notably consumer.cpp
is compiled with both -DUSING_ARCHIVE_LIB
and with -DUSING_SERIALIZATION_LIB
.
this seems to contradict the statement:
Because serialization is a PRIVATE dependency of archiveExtras, the usage requirements of it are not propagated to consumer.
which would imply that consumer.cpp
is compiled with -DUSING_ARCHIVE_LIB
, but not with -DUSING_SERIALIZATION_LIB