From 7dbebbb194cb868a7980808455431f1ebbc4ef22 Mon Sep 17 00:00:00 2001 From: Yunze Xu Date: Sat, 8 Feb 2025 11:33:13 +0800 Subject: [PATCH 1/2] Make it optional to link statically to libgcc and libstdc++ --- lib/CMakeLists.txt | 3 ++- pkg/deb/build-deb.sh | 2 +- pkg/rpm/SPECS/pulsar-client.spec | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index f578c29a..c750539e 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -76,6 +76,7 @@ target_include_directories(PULSAR_OBJECT_LIB PUBLIC "${CMAKE_SOURCE_DIR}/include" "${CMAKE_BINARY_DIR}/include") +option(LINK_STATIC_GCC_CXX "Link statically to libgcc and libstdc++" OFF) include(CheckCXXSymbolExists) if (BUILD_DYNAMIC_LIB) add_library(pulsarShared SHARED $) @@ -94,7 +95,7 @@ if (BUILD_DYNAMIC_LIB) target_link_options(pulsarShared PRIVATE -Wl,-Bsymbolic) endif () check_cxx_symbol_exists(__GLIBCXX__ iostream GLIBCXX) - if (GLIBCXX) + if (GLIBCXX and LINK_STATIC_GCC_CXX) target_link_libraries(pulsarShared PUBLIC -static-libgcc -static-libstdc++) endif () endif() diff --git a/pkg/deb/build-deb.sh b/pkg/deb/build-deb.sh index 8415056c..1dabb9f9 100755 --- a/pkg/deb/build-deb.sh +++ b/pkg/deb/build-deb.sh @@ -41,7 +41,7 @@ pushd $CPP_DIR export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH chmod +x $(find . -name "*.sh") -cmake . -DBUILD_TESTS=OFF -DBUILD_PERF_TOOLS=OFF -DLINK_STATIC=ON +cmake . -DBUILD_TESTS=OFF -DBUILD_PERF_TOOLS=OFF -DLINK_STATIC=ON -DLINK_STATIC_GCC_CXX=ON make -j 3 popd diff --git a/pkg/rpm/SPECS/pulsar-client.spec b/pkg/rpm/SPECS/pulsar-client.spec index 425eec5f..41a2e581 100644 --- a/pkg/rpm/SPECS/pulsar-client.spec +++ b/pkg/rpm/SPECS/pulsar-client.spec @@ -55,6 +55,7 @@ static library. %build git clone https://github.com/microsoft/vcpkg.git cmake -B build -DINTEGRATE_VCPKG=ON -DCMAKE_BUILD_TYPE=Release \ + -DLINK_STATIC_GCC_CXX=ON \ -DBUILD_TESTS=OFF -DBUILD_DYNAMIC_LIB=ON -DBUILD_STATIC_LIB=ON cmake --build build -j8 ./build-support/merge_archives_vcpkg.sh $PWD/build From 98fa23cc7825bff95ddc51d3962531d8a48d55b4 Mon Sep 17 00:00:00 2001 From: Yunze Xu Date: Sat, 8 Feb 2025 11:48:41 +0800 Subject: [PATCH 2/2] Fix CMakeLists.txt --- lib/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index c750539e..21b308c8 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -95,7 +95,7 @@ if (BUILD_DYNAMIC_LIB) target_link_options(pulsarShared PRIVATE -Wl,-Bsymbolic) endif () check_cxx_symbol_exists(__GLIBCXX__ iostream GLIBCXX) - if (GLIBCXX and LINK_STATIC_GCC_CXX) + if (GLIBCXX AND LINK_STATIC_GCC_CXX) target_link_libraries(pulsarShared PUBLIC -static-libgcc -static-libstdc++) endif () endif()