This is an automated email from the ASF dual-hosted git repository. mmerli pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/pulsar-client-cpp.git
The following commit(s) were added to refs/heads/main by this push: new d72924f Link to OpenSSL statically when LINK_STATIC is ON (#31) d72924f is described below commit d72924f6131e0ba53dea25fd19dfa69fd45c0ce1 Author: Yunze Xu <xyzinfern...@163.com> AuthorDate: Mon Oct 10 23:23:47 2022 +0800 Link to OpenSSL statically when LINK_STATIC is ON (#31) * Link to OpenSSL statically when LINK_STATIC is ON ### Motivation See discussions here: https://github.com/apache/pulsar-client-cpp/pull/28#issuecomment-1272588627 The original purpose to not include static OpenSSL library in `libpulsarwithnossl.so` and `libpulsarwithdeps.a` is https://github.com/apache/pulsar/pull/6458. However, the ABI compatibility of OpenSSL is not good. If the Pulsar C++ library links dynamically to OpenSSL and the user only changes the OpenSSL dynamic library, some symbols might not be found. ### Modifications Use `LINK_STATIC` option to determine whether to link to OpenSSL library statically. After that, there are only 3 libraries generated when `LINK_STATIC` is ON. - `libpulsar.so`: the dynamic pulsar-client-cpp library. - `libpulsar.a`: the static pulsar-client-cpp library. When it's used, users must link to all 3rd party dependencies (OpenSSL, curl, etc.) - `libpulsarwithdeps.a`: the static pulsar-client-cpp library. * Remove unnecessary code * Remove libpulsarnossl.so build --- CMakeLists.txt | 41 ++++++++-------------------------------- lib/CMakeLists.txt | 25 +----------------------- pkg/deb/build-deb.sh | 3 +-- pkg/rpm/SPECS/pulsar-client.spec | 4 +--- 4 files changed, 11 insertions(+), 62 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f882043..6e4d7f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,36 +122,6 @@ endif(NOT LOG_CATEGORY_NAME) add_definitions(-DLOG_CATEGORY_NAME=${LOG_CATEGORY_NAME} -DBUILDING_PULSAR -DBOOST_ALL_NO_LIB -DBOOST_ALLOW_DEPRECATED_HEADERS) -set(OPENSSL_ROOT_DIR ${OPENSSL_ROOT_DIR} /usr/lib64/) - -### This part is to find and keep SSL dynamic libs in RECORD_OPENSSL_SSL_LIBRARY and RECORD_OPENSSL_CRYPTO_LIBRARY -### After find the libs, will unset related cache, and will not affect another same call to find_package. -if (APPLE) - set(OPENSSL_INCLUDE_DIR /usr/local/opt/openssl/include/ /opt/homebrew/opt/openssl/include) - set(OPENSSL_ROOT_DIR ${OPENSSL_ROOT_DIR} /usr/local/opt/openssl/ /opt/homebrew/opt/openssl) -endif () - -set(OPENSSL_USE_STATIC_LIBS FALSE) -find_package(OpenSSL REQUIRED) -set(RECORD_OPENSSL_SSL_LIBRARY ${OPENSSL_SSL_LIBRARY}) -set(RECORD_OPENSSL_CRYPTO_LIBRARY ${OPENSSL_CRYPTO_LIBRARY}) -message("RECORD_OPENSSL_SSL_LIBRARY: " ${RECORD_OPENSSL_SSL_LIBRARY}) -message("RECORD_OPENSSL_CRYPTO_LIBRARY: " ${RECORD_OPENSSL_CRYPTO_LIBRARY}) - -unset(OPENSSL_FOUND CACHE) -unset(OPENSSL_INCLUDE_DIR CACHE) -unset(OPENSSL_CRYPTO_LIBRARY CACHE) -unset(OPENSSL_CRYPTO_LIBRARIES CACHE) -unset(OPENSSL_SSL_LIBRARY CACHE) -unset(OPENSSL_SSL_LIBRARIES CACHE) -unset(OPENSSL_LIBRARIES CACHE) -unset(OPENSSL_VERSION CACHE) - -find_package(OpenSSL REQUIRED) -message("OPENSSL_INCLUDE_DIR: " ${OPENSSL_INCLUDE_DIR}) -message("OPENSSL_SSL_LIBRARY: " ${OPENSSL_SSL_LIBRARY}) -message("OPENSSL_CRYPTO_LIBRARY: " ${OPENSSL_CRYPTO_LIBRARY}) - # For dependencies other than OpenSSL, dynamic libraries are forbidden to link when LINK_STATIC is ON if (LINK_STATIC) if (NOT MSVC) @@ -162,6 +132,14 @@ endif () find_package(Boost REQUIRED) message("Boost_INCLUDE_DIRS: " ${Boost_INCLUDE_DIRS}) +set(OPENSSL_ROOT_DIR ${OPENSSL_ROOT_DIR} /usr/lib64/) +if (APPLE) + set(OPENSSL_ROOT_DIR ${OPENSSL_ROOT_DIR} /usr/local/opt/openssl/ /opt/homebrew/opt/openssl) +endif () +find_package(OpenSSL REQUIRED) +message("OPENSSL_INCLUDE_DIR: " ${OPENSSL_INCLUDE_DIR}) +message("OPENSSL_LIBRARIES: " ${OPENSSL_LIBRARIES}) + find_package(Protobuf REQUIRED) message("Protobuf_INCLUDE_DIRS: " ${Protobuf_INCLUDE_DIRS}) message("Protobuf_LIBRARIES: " ${Protobuf_LIBRARIES}) @@ -217,9 +195,6 @@ if (LINK_STATIC) if (MSVC) add_definitions(-DCURL_STATICLIB) endif() - - SET(Boost_USE_STATIC_LIBS ON) - SET(OPENSSL_USE_STATIC_LIBS TRUE) else() if (MSVC AND (${CMAKE_BUILD_TYPE} STREQUAL Debug)) find_library(LIB_ZSTD zstdd HINTS "${VCPKG_DEBUG_ROOT}/lib") diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index a4a354d..fb89a23 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -72,25 +72,6 @@ if(HAVE_AUXV_GETAUXVAL) add_definitions(-DPULSAR_AUXV_GETAUXVAL_PRESENT) endif() -### pulsarSharedNossl not static link ssl, it could avoid rebuild libpulsar when ssl lib need update. -### pulsarSharedNossl is build under condition LINK_STATIC=ON, we should replace static ssl libs with dynamic libs. -SET(COMMON_LIBS_NOSSL ${COMMON_LIBS}) -if (NOT ${RECORD_OPENSSL_SSL_LIBRARY} MATCHES ".+\\.a$") - LIST(REMOVE_ITEM COMMON_LIBS_NOSSL ${OPENSSL_SSL_LIBRARY}) - LIST(APPEND COMMON_LIBS_NOSSL ${RECORD_OPENSSL_SSL_LIBRARY}) -endif () -if (NOT ${RECORD_OPENSSL_CRYPTO_LIBRARY} MATCHES ".+\\.a$") - LIST(REMOVE_ITEM COMMON_LIBS_NOSSL ${OPENSSL_CRYPTO_LIBRARY}) - LIST(APPEND COMMON_LIBS_NOSSL ${RECORD_OPENSSL_CRYPTO_LIBRARY}) -endif () - -if (BUILD_DYNAMIC_LIB AND LINK_STATIC) - add_library(pulsarSharedNossl SHARED $<TARGET_OBJECTS:PULSAR_OBJECT_LIB>) - set_property(TARGET pulsarSharedNossl PROPERTY OUTPUT_NAME ${LIB_NAME_SHARED}nossl) - set_property(TARGET pulsarSharedNossl PROPERTY VERSION ${LIBRARY_VERSION}) - target_link_libraries(pulsarSharedNossl ${COMMON_LIBS_NOSSL} ${CMAKE_DL_LIBS}) -endif() - if (BUILD_STATIC_LIB) add_library(pulsarStatic STATIC $<TARGET_OBJECTS:PULSAR_OBJECT_LIB>) if (MSVC) @@ -136,7 +117,7 @@ if (LINK_STATIC AND BUILD_STATIC_LIB) # Build a list of the requird .a libs (except ssl) to merge SET(STATIC_LIBS "") foreach (LIB IN LISTS COMMON_LIBS) - if (${LIB} MATCHES ".+\\.a$" AND NOT ${LIB} MATCHES ${OPENSSL_SSL_LIBRARY} AND NOT ${LIB} MATCHES ${OPENSSL_CRYPTO_LIBRARY}) + if (${LIB} MATCHES ".+\\.a$") set(STATIC_LIBS "${STATIC_LIBS} ${LIB}") endif() endforeach() @@ -164,8 +145,4 @@ if (BUILD_DYNAMIC_LIB) install(TARGETS pulsarShared RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) endif() -if (BUILD_DYNAMIC_LIB AND LINK_STATIC) - install(TARGETS pulsarSharedNossl RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) -endif() - install(DIRECTORY "../include/pulsar" DESTINATION include) diff --git a/pkg/deb/build-deb.sh b/pkg/deb/build-deb.sh index b1d30ec..8415056 100755 --- a/pkg/deb/build-deb.sh +++ b/pkg/deb/build-deb.sh @@ -42,7 +42,7 @@ 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 -make pulsarShared pulsarSharedNossl pulsarStatic pulsarStaticWithDeps -j 3 +make -j 3 popd DEST_DIR=apache-pulsar-client @@ -78,7 +78,6 @@ cp -ar $CPP_DIR/include/pulsar $DEVEL_DEST_DIR/usr/include/ cp $CPP_DIR/lib/libpulsar.a $DEVEL_DEST_DIR/usr/lib cp $CPP_DIR/lib/libpulsarwithdeps.a $DEVEL_DEST_DIR/usr/lib cp $CPP_DIR/lib/libpulsar.so $DEST_DIR/usr/lib -cp $CPP_DIR/lib/libpulsarnossl.so $DEST_DIR/usr/lib cp $ROOT_DIR/NOTICE $DEST_DIR/usr/share/doc/pulsar-client-$VERSION cp $CPP_DIR/pkg/licenses/* $DEST_DIR/usr/share/doc/pulsar-client-$VERSION diff --git a/pkg/rpm/SPECS/pulsar-client.spec b/pkg/rpm/SPECS/pulsar-client.spec index b4ae946..c978258 100644 --- a/pkg/rpm/SPECS/pulsar-client.spec +++ b/pkg/rpm/SPECS/pulsar-client.spec @@ -53,7 +53,7 @@ static library. %build cmake . -DBUILD_TESTS=OFF -DLINK_STATIC=ON -make pulsarShared pulsarSharedNossl pulsarStatic pulsarStaticWithDeps -j 3 +make -j 3 %install INCLUDE_DIR=$RPM_BUILD_ROOT/usr/include @@ -66,7 +66,6 @@ cp -ar include/pulsar $INCLUDE_DIR cp lib/libpulsar.a $LIB_DIR cp lib/libpulsarwithdeps.a $LIB_DIR cp lib/libpulsar.so $LIB_DIR -cp lib/libpulsarnossl.so $LIB_DIR # Copy LICENSE files cp NOTICE $DOC_DIR @@ -77,7 +76,6 @@ cp $DOC_DIR/* $DOC_DEVEL_DIR/ %files %defattr(-,root,root) /usr/lib/libpulsar.so -/usr/lib/libpulsarnossl.so /usr/share/doc/pulsar-client-%{version} %files devel