From a46b6d14fa2f9327c69c92d5687dcc72b2954a15 Mon Sep 17 00:00:00 2001 From: Jaroslav Rohel Date: Tue, 21 May 2024 07:15:47 +0200 Subject: [PATCH] Do not export symbols from private common utils Symbols from internal object files (from /common/utils) were exported by all binaries (libdnf5.so, libdnf5-cli.so, dnf5, ...). An archive of these object files is now created. And symbols from all archive libraries are excluded from the automatic export. --- CMakeLists.txt | 4 ++++ common/CMakeLists.txt | 2 +- libdnf5-cli/CMakeLists.txt | 2 ++ test/shared/CMakeLists.txt | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2267e3d65..a184e038b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,6 +77,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # Give inline methods hidden visibility by default set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) +# Excludes symbols in all archive libraries from automatic export +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--exclude-libs,ALL") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--exclude-libs,ALL") + # remove PROJECT_SOURCE_DIR prefix from __FILE__ macro used in asserts (available since GCC 8 and Clang 10) add_compile_options("-fmacro-prefix-map=${PROJECT_SOURCE_DIR}/=") diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index a3f0de058..d918f92c0 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -2,7 +2,7 @@ file(GLOB_RECURSE COMMON_SOURCES *.cpp *.c) include_directories(.) -add_library(common OBJECT ${COMMON_SOURCES}) +add_library(common STATIC ${COMMON_SOURCES}) set_property(TARGET common PROPERTY POSITION_INDEPENDENT_CODE ON) # required by clang diff --git a/libdnf5-cli/CMakeLists.txt b/libdnf5-cli/CMakeLists.txt index dd3d721e6..47d9bee01 100644 --- a/libdnf5-cli/CMakeLists.txt +++ b/libdnf5-cli/CMakeLists.txt @@ -33,6 +33,8 @@ install(TARGETS libdnf5-cli LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}) # link libraries and set pkg-config requires +target_link_libraries(libdnf5-cli PRIVATE common) + target_link_libraries(libdnf5-cli PUBLIC libdnf5) pkg_check_modules(LIBFMT REQUIRED fmt) diff --git a/test/shared/CMakeLists.txt b/test/shared/CMakeLists.txt index ab81e83b7..fa698ac46 100644 --- a/test/shared/CMakeLists.txt +++ b/test/shared/CMakeLists.txt @@ -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 PUBLIC stdc++ libdnf5 cppunit) +target_link_libraries(test_shared PUBLIC stdc++ common libdnf5 cppunit)