chore: Add IMPORTED_TARGET to pkg-config packages.

Also use `PRIVATE` for `target_link_libraries`. This helps avoid
implicit transitive dependencies.
This commit is contained in:
iphydf 2023-12-26 00:04:07 +00:00
parent 895a6af122
commit c58928cc89
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
4 changed files with 10 additions and 10 deletions

View File

@ -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")

View File

@ -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()

View File

@ -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()

View File

@ -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})