From c58928cc890f62b27f49f50e92783589300667ce Mon Sep 17 00:00:00 2001 From: iphydf Date: Tue, 26 Dec 2023 00:04:07 +0000 Subject: [PATCH] chore: Add `IMPORTED_TARGET` to pkg-config packages. Also use `PRIVATE` for `target_link_libraries`. This helps avoid implicit transitive dependencies. --- CMakeLists.txt | 2 +- cmake/ModulePackage.cmake | 8 ++++---- other/fun/CMakeLists.txt | 2 +- testing/fuzzing/CMakeLists.txt | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d902c5f7..42f11310 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -423,7 +423,7 @@ install_module(toxcore DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tox) function(unit_test subdir target) add_executable(unit_${target}_test ${subdir}/${target}_test.cc) target_link_modules(unit_${target}_test toxcore) - target_link_libraries(unit_${target}_test GTest::GTest GTest::Main) + target_link_libraries(unit_${target}_test PRIVATE GTest::GTest GTest::Main) set_target_properties(unit_${target}_test PROPERTIES COMPILE_FLAGS "${TEST_CXX_FLAGS}") add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} unit_${target}_test) set_property(TEST ${target} PROPERTY ENVIRONMENT "LLVM_PROFILE_FILE=${target}.profraw") diff --git a/cmake/ModulePackage.cmake b/cmake/ModulePackage.cmake index 04dbf16d..b6787893 100644 --- a/cmake/ModulePackage.cmake +++ b/cmake/ModulePackage.cmake @@ -24,7 +24,7 @@ find_package(PkgConfig) function(pkg_use_module mod pkgs) foreach(pkg IN ITEMS ${pkgs}) if(PKG_CONFIG_FOUND) - pkg_search_module(${mod} ${pkg}) + pkg_search_module(${mod} ${pkg} IMPORTED_TARGET) endif() if(NOT ${mod}_FOUND) find_package(${pkg} QUIET) @@ -151,9 +151,9 @@ function(target_link_modules target) foreach(dep ${ARGN}) foreach(_target ${_targets}) if(TARGET ${dep}_${${_target}_primary}) - target_link_libraries(${_target} ${dep}_${${_target}_primary}) + target_link_libraries(${_target} PRIVATE ${dep}_${${_target}_primary}) elseif(TARGET ${dep}_${${_target}_secondary}) - target_link_libraries(${_target} ${dep}_${${_target}_secondary}) + target_link_libraries(${_target} PRIVATE ${dep}_${${_target}_secondary}) else() # We record the modules linked to this target, so that we can collect # them later when linking a composed module. @@ -162,7 +162,7 @@ function(target_link_modules target) set(LINK_MODULES ${LINK_MODULES} ${dep}) endif() - target_link_libraries(${_target} ${dep}) + target_link_libraries(${_target} PRIVATE ${dep}) endif() endforeach() endforeach() diff --git a/other/fun/CMakeLists.txt b/other/fun/CMakeLists.txt index 52129409..343afdbb 100644 --- a/other/fun/CMakeLists.txt +++ b/other/fun/CMakeLists.txt @@ -25,6 +25,6 @@ if(NOT MSVC) if(OpenMP_C_FOUND) add_executable(cracker cracker.c) target_link_modules(cracker ${LIBSODIUM_LIBRARIES}) - target_link_libraries(cracker OpenMP::OpenMP_C) + target_link_libraries(cracker PRIVATE OpenMP::OpenMP_C) endif() endif() diff --git a/testing/fuzzing/CMakeLists.txt b/testing/fuzzing/CMakeLists.txt index a000ccb0..c2b88c72 100644 --- a/testing/fuzzing/CMakeLists.txt +++ b/testing/fuzzing/CMakeLists.txt @@ -13,14 +13,14 @@ endif() # Fuzzes the toxsave API add_executable(toxsave_fuzzer toxsave_harness.cc) -target_link_libraries(toxsave_fuzzer toxcore_static fuzz_support ${LIBFUZZER_LINKER_FLAGS}) +target_link_libraries(toxsave_fuzzer PRIVATE toxcore_static fuzz_support ${LIBFUZZER_LINKER_FLAGS}) # Fuzzes the bootstrap process add_executable(bootstrap_fuzzer bootstrap_harness.cc) -target_link_libraries(bootstrap_fuzzer toxcore_static fuzz_support ${LIBFUZZER_LINKER_FLAGS}) +target_link_libraries(bootstrap_fuzzer PRIVATE toxcore_static fuzz_support ${LIBFUZZER_LINKER_FLAGS}) add_executable(DHT_fuzz_test ../../toxcore/DHT_fuzz_test.cc) -target_link_libraries(DHT_fuzz_test toxcore_static fuzz_support ${LIBFUZZER_LINKER_FLAGS}) +target_link_libraries(DHT_fuzz_test PRIVATE toxcore_static fuzz_support ${LIBFUZZER_LINKER_FLAGS}) add_executable(tox_events_fuzz_test ../../toxcore/tox_events_fuzz_test.cc) -target_link_libraries(tox_events_fuzz_test toxcore_static fuzz_support ${LIBFUZZER_LINKER_FLAGS}) +target_link_libraries(tox_events_fuzz_test PRIVATE toxcore_static fuzz_support ${LIBFUZZER_LINKER_FLAGS})