Skip to content

Commit

Permalink
add target pulsarStaticNossl for static lib not include ssl
Browse files Browse the repository at this point in the history
  • Loading branch information
jiazhai committed Mar 5, 2020
1 parent c3672a2 commit 26c5427
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pulsar-client-cpp/docker/build-client-lib-within-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ cmake . -DBUILD_TESTS=OFF -DLINK_STATIC=ON \
-DPYTHON_INCLUDE_DIR=/opt/python/$PYTHON_SPEC/include/python$PYTHON_VERSION \
-DPYTHON_LIBRARY=/opt/python/$PYTHON_SPEC/lib \

make pulsarShared pulsarStatic -j4
make pulsarShared pulsarStatic pulsarStaticNossl -j4
41 changes: 38 additions & 3 deletions pulsar-client-cpp/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,23 @@ if (WIN32)
string(APPEND LIB_NAME_SHARED dll)
endif()

add_library(pulsarShared SHARED ${PULSAR_SOURCES})
set_target_properties(pulsarShared PROPERTIES OUTPUT_NAME ${LIB_NAME_SHARED} VERSION ${LIBRARY_VERSION})
target_link_libraries(pulsarShared ${COMMON_LIBS} ${CMAKE_DL_LIBS})
set(LIB_NAME_NOSSL ${LIB_NAME}nossl)

add_library(pulsarStatic STATIC ${PULSAR_SOURCES})
set_target_properties(pulsarStatic PROPERTIES OUTPUT_NAME ${LIB_NAME} VERSION ${LIBRARY_VERSION})
target_compile_definitions(pulsarStatic PRIVATE PULSAR_STATIC)

add_library(pulsarStaticNossl STATIC ${PULSAR_SOURCES})
set_target_properties(pulsarStaticNossl PROPERTIES OUTPUT_NAME ${LIB_NAME_NOSSL} VERSION ${LIBRARY_VERSION})
target_compile_definitions(pulsarStaticNossl PRIVATE PULSAR_STATIC)

add_library(pulsarShared SHARED ${PULSAR_SOURCES})
set_target_properties(pulsarShared PROPERTIES OUTPUT_NAME ${LIB_NAME_SHARED} VERSION ${LIBRARY_VERSION})
target_link_libraries(pulsarShared ${COMMON_LIBS} ${CMAKE_DL_LIBS})

if (MSVC)
target_include_directories(pulsarStatic PRIVATE ${dlfcn-win32_INCLUDE_DIRS})
target_include_directories(pulsarStaticNossl PRIVATE ${dlfcn-win32_INCLUDE_DIRS})
target_include_directories(pulsarShared PRIVATE ${dlfcn-win32_INCLUDE_DIRS})
target_link_options(pulsarShared PRIVATE $<$<CONFIG:DEBUG>:/NODEFAULTLIB:MSVCRT>)
endif()
Expand Down Expand Up @@ -97,6 +104,13 @@ if (LINK_STATIC)
remove_libtype("${COMMON_LIBS}" "debug" STATIC_LIBS)
set_target_properties(pulsarStaticWithDeps PROPERTIES STATIC_LIBRARY_FLAGS_DEBUG ${DEBUG_STATIC_LIBS} STATIC_LIBRARY_FLAGS_RELEASE ${STATIC_LIBS} OUTPUT_NAME ${LIB_NAME}WithDeps VERSION ${LIBRARY_VERSION})
install(TARGETS pulsarStaticWithDeps DESTINATION lib)

add_library(pulsarStaticWithDepsNossl STATIC ${PULSAR_SOURCES})
target_include_directories(pulsarStaticWithDepsNossl PRIVATE ${dlfcn-win32_INCLUDE_DIRS})
remove_libtype("${COMMON_LIBS}" "optimized" DEBUG_STATIC_LIBS)
remove_libtype("${COMMON_LIBS}" "debug" STATIC_LIBS)
set_target_properties(pulsarStaticWithDepsNossl PROPERTIES STATIC_LIBRARY_FLAGS_DEBUG ${DEBUG_STATIC_LIBS} STATIC_LIBRARY_FLAGS_RELEASE ${STATIC_LIBS} OUTPUT_NAME ${LIB_NAME}WithDepsNossl VERSION ${LIBRARY_VERSION})
install(TARGETS pulsarStaticWithDeps DESTINATION lib)
else()
# Build a list of the requird .a libs to merge
SET(STATIC_LIBS "")
Expand All @@ -113,6 +127,26 @@ if (LINK_STATIC)
DEPENDS pulsarStatic
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
install(FILES ../merged-library/libpulsar.a DESTINATION lib)

# libpulsarnossl.a is similar as build libpulsar.a, except no OPENSSL_SSL_LIBRARY and OPENSSL_CRYPTO_LIBRARY
message("Modified libraries list, remove ${OPENSSL_SSL_LIBRARY} and ${OPENSSL_CRYPTO_LIBRARY}")
LIST(REMOVE_ITEM COMMON_LIBS ${OPENSSL_SSL_LIBRARY})
LIST(REMOVE_ITEM COMMON_LIBS ${OPENSSL_CRYPTO_LIBRARY})
SET(STATIC_LIBS_NOSSL "")
foreach (LIB IN LISTS COMMON_LIBS)
if (${LIB} MATCHES ".+\\.a$")
set(STATIC_LIBS_NOSSL "${STATIC_LIBS_NOSSL} ${LIB}")
endif()
endforeach()
message(${STATIC_LIBS_NOSSL})
add_custom_target(pulsarStaticWithDepsNossl
ALL
BYPRODUCTS merged-library
COMMAND ./build-support/merge_archives.sh libpulsarnossl.a $<TARGET_FILE:pulsarStaticNossl> ${STATIC_LIBS_NOSSL}
DEPENDS pulsarStaticNossl
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
install(FILES ../merged-library/libpulsarnossl.a DESTINATION lib)

endif(MSVC)
else()
# Install regular libpulsar.a
Expand All @@ -121,5 +155,6 @@ else()
endif(LINK_STATIC)

install(TARGETS pulsarStatic DESTINATION lib)
install(TARGETS pulsarStaticNossl DESTINATION lib)
install(TARGETS pulsarShared RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
install(DIRECTORY "../include/pulsar" DESTINATION include)
3 changes: 2 additions & 1 deletion pulsar-client-cpp/pkg/deb/build-deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ tar xfz $SRC_ROOT_DIR/distribution/server/target/apache-pulsar-$POM_VERSION-src.
pushd $CPP_DIR

cmake . -DBUILD_TESTS=OFF -DLINK_STATIC=ON
make pulsarShared pulsarStatic -j 3
make pulsarShared pulsarStatic pulsarStaticNossl -j 3
popd

DEST_DIR=apache-pulsar-client
Expand Down Expand Up @@ -70,6 +70,7 @@ mkdir -p $DEVEL_DEST_DIR/usr/share/doc/pulsar-client-dev-$VERSION

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/libpulsarnossl.a $DEVEL_DEST_DIR/usr/lib
cp $CPP_DIR/lib/libpulsar.so.$POM_VERSION $DEST_DIR/usr/lib
pushd $DEST_DIR/usr/lib
ln -s libpulsar.so.$POM_VERSION libpulsar.so
Expand Down
9 changes: 8 additions & 1 deletion pulsar-client-cpp/pkg/rpm/SPECS/pulsar-client.spec
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static library.
%build
cd pulsar-client-cpp
cmake . -DBUILD_TESTS=OFF -DLINK_STATIC=ON -DBUILD_PYTHON_WRAPPER=OFF
make pulsarShared pulsarStatic -j 3
make pulsarShared pulsarStatic pulsarStaticNossl -j 3

%install
cd pulsar-client-cpp
Expand All @@ -65,6 +65,7 @@ mkdir -p $INCLUDE_DIR $LIB_DIR $DOC_DIR $DOC_DEVEL_DIR

cp -ar include/pulsar $INCLUDE_DIR
cp lib/libpulsar.a $LIB_DIR
cp lib/libpulsarnossl.a $LIB_DIR
cp lib/libpulsar.so.%{pom_version} $LIB_DIR

# Copy LICENSE files
Expand All @@ -87,3 +88,9 @@ ln -s libpulsar.so.%{pom_version} libpulsar.so
/usr/lib/libpulsar.a
/usr/include/pulsar
/usr/share/doc/pulsar-client-devel-%{version}

%files devel-nossl
%defattr(-,root,root)
/usr/lib/libpulsarnossl.a
/usr/include/pulsar
/usr/share/doc/pulsar-client-devel-nossl-%{version}

0 comments on commit 26c5427

Please sign in to comment.