Skip to content

Commit

Permalink
Remove unused direct shared object dependencies
Browse files Browse the repository at this point in the history
Adds a scope specification to all `target_link_libraries`.
Lots of scopes are set to `PRIVATE`. Due to this many unused direct
shared object dependencies were removed.
  • Loading branch information
jrohel authored and Conan-Kudo committed Aug 31, 2023
1 parent b755cc7 commit 1c39410
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 30 deletions.
2 changes: 1 addition & 1 deletion common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ add_library(common OBJECT ${COMMON_SOURCES})
set_property(TARGET common PROPERTY POSITION_INDEPENDENT_CODE ON)

# required by clang
target_link_libraries(common stdc++)
target_link_libraries(common PUBLIC stdc++)
2 changes: 1 addition & 1 deletion dnf5/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ add_executable(dnf5 ${DNF5_SOURCES})
# Enable symbol export. Needed for loadable modules (dnf5 plugins).
set_property(TARGET dnf5 PROPERTY ENABLE_EXPORTS 1)

target_link_libraries(dnf5 PUBLIC common libdnf5 libdnf5-cli Threads::Threads)
target_link_libraries(dnf5 PRIVATE common libdnf5 libdnf5-cli Threads::Threads)
install(TARGETS dnf5 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})


Expand Down
2 changes: 1 addition & 1 deletion dnf5daemon-client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ add_executable(${DNF5DAEMON_CLIENT_BIN} ${DNF5DAEMON_CLIENT_SOURCES})

target_link_libraries(
${DNF5DAEMON_CLIENT_BIN}
PUBLIC
PRIVATE
common
libdnf5
libdnf5-cli
Expand Down
2 changes: 1 addition & 1 deletion dnf5daemon-server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ add_executable(${DNF5DAEMON_SERVER_BIN} ${DNF5DAEMON_SERVER_SOURCES})

target_link_libraries(
${DNF5DAEMON_SERVER_BIN}
PUBLIC
PRIVATE
common
libdnf5
libdnf5-cli
Expand Down
8 changes: 4 additions & 4 deletions libdnf5-cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ set(DNF_CLI_SO_VERSION 1)
set_target_properties(libdnf5-cli PROPERTIES OUTPUT_NAME "dnf5-cli")
set_target_properties(libdnf5-cli PROPERTIES SOVERSION ${DNF_CLI_SO_VERSION})
# required by clang
target_link_libraries(libdnf5-cli stdc++)
target_link_libraries(libdnf5-cli PUBLIC stdc++)

# install libdnf5-cli.so
install(TARGETS libdnf5-cli LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR})


# link libraries and set pkg-config requires

target_link_libraries(libdnf5-cli common libdnf5)
target_link_libraries(libdnf5-cli PUBLIC libdnf5)

pkg_check_modules(LIBFMT REQUIRED fmt)
list(APPEND LIBDNF5_CLI_PC_REQUIRES "${LIBFMT_MODULE_NAME}")
target_link_libraries(libdnf5-cli ${LIBFMT_LIBRARIES})
target_link_libraries(libdnf5-cli PUBLIC ${LIBFMT_LIBRARIES})

pkg_check_modules(SMARTCOLS REQUIRED smartcols)
list(APPEND LIBDNF5_CLI_PC_REQUIRES_PRIVATE "${SMARTCOLS_MODULE_NAME}")
target_link_libraries(libdnf5-cli ${SMARTCOLS_LIBRARIES})
target_link_libraries(libdnf5-cli PUBLIC ${SMARTCOLS_LIBRARIES})


# sort the pkg-config requires and concatenate them into a string
Expand Down
28 changes: 14 additions & 14 deletions libdnf5/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,49 +25,49 @@ set(DNF_SO_VERSION 1)
set_target_properties(libdnf5 PROPERTIES OUTPUT_NAME "dnf5")
set_target_properties(libdnf5 PROPERTIES SOVERSION ${DNF_SO_VERSION})
# required to have dlopen symbol
target_link_libraries(libdnf5 ${CMAKE_DL_LIBS})
target_link_libraries(libdnf5 PUBLIC ${CMAKE_DL_LIBS})

# required by clang
target_link_libraries(libdnf5 stdc++)
target_link_libraries(libdnf5 PUBLIC stdc++)

# install libdnf5.so
install(TARGETS libdnf5 LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR})

target_link_libraries(libdnf5 common)
target_link_libraries(libdnf5 PRIVATE common)

# link libraries and set pkg-config requires

find_package(toml11 REQUIRED)

pkg_check_modules(LIBFMT REQUIRED fmt)
list(APPEND LIBDNF5_PC_REQUIRES "${LIBFMT_MODULE_NAME}")
target_link_libraries(libdnf5 ${LIBFMT_LIBRARIES})
target_link_libraries(libdnf5 PUBLIC ${LIBFMT_LIBRARIES})

pkg_check_modules(JSONC REQUIRED json-c)
include_directories(${JSONC_INCLUDE_DIRS})
target_link_libraries(libdnf5 ${JSONC_LIBRARIES})
target_link_libraries(libdnf5 PRIVATE ${JSONC_LIBRARIES})

pkg_check_modules(LIBMODULEMD REQUIRED modulemd-2.0>=2.11.2)
list(APPEND LIBDNF5_PC_REQUIRES "${LIBMODULEMD_MODULE_NAME}")
target_link_libraries(libdnf5 ${LIBMODULEMD_LIBRARIES})
target_link_libraries(libdnf5 PRIVATE ${LIBMODULEMD_LIBRARIES})

pkg_check_modules(LIBSOLV REQUIRED libsolv>=0.7.21)
list(APPEND LIBDNF5_PC_REQUIRES "${LIBSOLV_MODULE_NAME}")
target_link_libraries(libdnf5 ${LIBSOLV_LIBRARIES})
target_link_libraries(libdnf5 PRIVATE ${LIBSOLV_LIBRARIES})

pkg_check_modules(LIBSOLVEXT REQUIRED libsolvext>=0.7.7)
list(APPEND LIBDNF5_PC_REQUIRES_PRIVATE "${LIBSOLVEXT_MODULE_NAME}")
target_link_libraries(libdnf5 ${LIBSOLVEXT_LIBRARIES})
target_link_libraries(libdnf5 PRIVATE ${LIBSOLVEXT_LIBRARIES})

pkg_check_modules(RPM REQUIRED rpm>=4.17.0)
list(APPEND LIBDNF5_PC_REQUIRES "${RPM_MODULE_NAME}")
target_link_libraries(libdnf5 ${RPM_LIBRARIES})
target_link_libraries(libdnf5 PRIVATE ${RPM_LIBRARIES})

if(WITH_COMPS)
pkg_check_modules(LIBXML2 REQUIRED libxml-2.0)
list(APPEND LIBDNF5_PC_REQUIRES_PRIVATE "${LIBXML2_MODULE_NAME}")
include_directories(${LIBXML2_INCLUDE_DIRS})
target_link_libraries(libdnf5 ${LIBXML2_LIBRARIES})
target_link_libraries(libdnf5 PRIVATE ${LIBXML2_LIBRARIES})
endif()

if (WITH_ZCHUNK)
Expand All @@ -78,17 +78,17 @@ endif()
# GLIB librepo and libmodulemd uses glib2 in API :(
pkg_check_modules (GLIB2 glib-2.0>=2.46.0)
include_directories(${GLIB2_INCLUDE_DIRS})
target_link_libraries(libdnf5 ${GLIB2_LIBRARIES})
target_link_libraries(libdnf5 PRIVATE ${GLIB2_LIBRARIES})

pkg_check_modules(LIBREPO REQUIRED librepo>=1.15.0)
list(APPEND LIBDNF5_PC_REQUIRES "${LIBREPO_MODULE_NAME}")
target_include_directories(libdnf5 PRIVATE ${LIBREPO_INCLUDE_DIRS})
target_link_libraries(libdnf5 ${LIBREPO_LDFLAGS})
target_include_directories(libdnf5 PUBLIC PRIVATE ${LIBREPO_INCLUDE_DIRS})
target_link_libraries(libdnf5 PRIVATE ${LIBREPO_LDFLAGS})

# SQLite3
pkg_check_modules(SQLite3 REQUIRED sqlite3>=3.35.0)
list(APPEND LIBDNF5_PC_REQUIRES "${SQLite3_MODULE_NAME}")
target_link_libraries(libdnf5 ${SQLite3_LIBRARIES})
target_link_libraries(libdnf5 PRIVATE ${SQLite3_LIBRARIES})


# sort the pkg-config requires and concatenate them into a string
Expand Down
6 changes: 5 additions & 1 deletion test/dnf5-plugins/copr_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ include_directories(${PROJECT_SOURCE_DIR}/libdnf5)
include_directories(${JSONC_INCLUDE_DIRS})

add_executable(run_tests_copr ${TEST_COPR_SOURCES})
target_link_libraries(run_tests_copr stdc++ libdnf5 libdnf5-cli test_shared)
target_link_libraries(run_tests_copr PRIVATE stdc++ libdnf5 libdnf5-cli test_shared)

pkg_check_modules(JSONC REQUIRED json-c)
include_directories(${JSONC_INCLUDE_DIRS})
target_link_libraries(run_tests_copr PRIVATE ${JSONC_LIBRARIES})

add_compile_definitions(TEST_DATADIR="${CMAKE_CURRENT_SOURCE_DIR}/data")

Expand Down
4 changes: 2 additions & 2 deletions test/libdnf5-cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ include_directories(${PROJECT_SOURCE_DIR}/libdnf5)


add_executable(run_tests_cli ${TEST_LIBDNF5_CLI_SOURCES})
target_link_directories(run_tests_cli PUBLIC ${CMAKE_BINARY_DIR}/libdnf5)
target_link_libraries(run_tests_cli stdc++ libdnf5 libdnf5-cli cppunit test_shared)
target_link_directories(run_tests_cli PRIVATE ${CMAKE_BINARY_DIR}/libdnf5)
target_link_libraries(run_tests_cli PRIVATE stdc++ libdnf5 libdnf5-cli cppunit test_shared)


add_test(NAME test_libdnf_cli COMMAND run_tests_cli)
9 changes: 6 additions & 3 deletions test/libdnf5/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ target_compile_options(run_tests PRIVATE "-Wno-unused-value")
target_compile_options(run_tests PRIVATE "-Wno-self-assign-overloaded")
target_compile_options(run_tests PRIVATE "-Wno-self-move")

target_link_directories(run_tests PUBLIC ${CMAKE_BINARY_DIR}/libdnf5)
target_link_libraries(run_tests stdc++ libdnf5 cppunit test_shared)
target_link_directories(run_tests PRIVATE ${CMAKE_BINARY_DIR}/libdnf5)
target_link_libraries(run_tests PRIVATE stdc++ libdnf5 cppunit test_shared)

pkg_check_modules(JSONC REQUIRED json-c)
include_directories(${JSONC_INCLUDE_DIRS})
target_link_libraries(run_tests ${JSONC_LIBRARIES})
target_link_libraries(run_tests PRIVATE ${JSONC_LIBRARIES})

pkg_check_modules(LIBSOLV REQUIRED libsolv>=0.7.21)
target_link_libraries(run_tests PRIVATE ${LIBSOLV_LIBRARIES})


if(WITH_PERFORMANCE_TESTS)
Expand Down
2 changes: 1 addition & 1 deletion test/shared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ include_directories(${PROJECT_SOURCE_DIR}/libdnf5)
add_library(test_shared OBJECT ${TEST_SHARED_SOURCES})

target_link_directories(test_shared PUBLIC ${CMAKE_BINARY_DIR}/libdnf5)
target_link_libraries(test_shared stdc++ libdnf5 cppunit)
target_link_libraries(test_shared PUBLIC stdc++ libdnf5 cppunit)
2 changes: 1 addition & 1 deletion test/tutorial/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include_directories(${PROJECT_SOURCE_DIR}/libdnf5)


add_executable(run_tests_tutorial ${TEST_TUTORIAL_SOURCES})
target_link_libraries(run_tests_tutorial stdc++ libdnf5 libdnf5-cli cppunit)
target_link_libraries(run_tests_tutorial PRIVATE stdc++ libdnf5 libdnf5-cli cppunit)


add_test(NAME test_tutorial COMMAND run_tests_tutorial)
Expand Down

0 comments on commit 1c39410

Please sign in to comment.