You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2021/02/12 05:15:35 UTC
[pulsar] branch master updated: [C++] Allow to disable static or
dynamic lib at build time (#9570)
This is an automated email from the ASF dual-hosted git repository.
mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 7ab6249 [C++] Allow to disable static or dynamic lib at build time (#9570)
7ab6249 is described below
commit 7ab6249bae0fecabfb07850152d0841f2449f735
Author: Matteo Merli <mm...@apache.org>
AuthorDate: Thu Feb 11 21:14:51 2021 -0800
[C++] Allow to disable static or dynamic lib at build time (#9570)
* [C++] Allow to disable static or dynamic lib at build time
* Small improvement
---
pulsar-client-cpp/CMakeLists.txt | 11 +++++++-
pulsar-client-cpp/lib/CMakeLists.txt | 49 +++++++++++++++++++++++-------------
2 files changed, 42 insertions(+), 18 deletions(-)
diff --git a/pulsar-client-cpp/CMakeLists.txt b/pulsar-client-cpp/CMakeLists.txt
index 733c2c3..580bf74 100644
--- a/pulsar-client-cpp/CMakeLists.txt
+++ b/pulsar-client-cpp/CMakeLists.txt
@@ -29,6 +29,12 @@ endif(CCACHE_PROGRAM)
MESSAGE(STATUS "ARCHITECTURE: ${CMAKE_SYSTEM_PROCESSOR}")
+option(BUILD_DYNAMIC_LIB "Build dynamic lib" ON)
+MESSAGE(STATUS "BUILD_DYNAMIC_LIB: " ${BUILD_DYNAMIC_LIB})
+
+option(BUILD_STATIC_LIB "Build static lib" ON)
+MESSAGE(STATUS "BUILD_STATIC_LIB: " ${BUILD_STATIC_LIB})
+
option(BUILD_TESTS "Build tests" ON)
MESSAGE(STATUS "BUILD_TESTS: " ${BUILD_TESTS})
@@ -348,7 +354,10 @@ add_subdirectory(lib)
if(BUILD_PERF_TOOLS)
add_subdirectory(perf)
endif(BUILD_PERF_TOOLS)
-add_subdirectory(examples)
+
+if (BUILD_DYNAMIC_LIB)
+ add_subdirectory(examples)
+endif()
if (BUILD_TESTS)
add_subdirectory(tests)
diff --git a/pulsar-client-cpp/lib/CMakeLists.txt b/pulsar-client-cpp/lib/CMakeLists.txt
index 1ca2bd4..e81cdd8 100644
--- a/pulsar-client-cpp/lib/CMakeLists.txt
+++ b/pulsar-client-cpp/lib/CMakeLists.txt
@@ -57,10 +57,12 @@ if (WIN32)
string(APPEND LIB_NAME_SHARED dll)
endif()
-add_library(pulsarShared SHARED ${PULSAR_SOURCES})
-set_property(TARGET pulsarShared PROPERTY OUTPUT_NAME ${LIB_NAME_SHARED})
-set_property(TARGET pulsarShared PROPERTY VERSION ${LIBRARY_VERSION})
-target_link_libraries(pulsarShared ${COMMON_LIBS} ${CMAKE_DL_LIBS})
+if (BUILD_DYNAMIC_LIB)
+ add_library(pulsarShared SHARED ${PULSAR_SOURCES})
+ set_property(TARGET pulsarShared PROPERTY OUTPUT_NAME ${LIB_NAME_SHARED})
+ set_property(TARGET pulsarShared PROPERTY VERSION ${LIBRARY_VERSION})
+ target_link_libraries(pulsarShared ${COMMON_LIBS} ${CMAKE_DL_LIBS})
+endif()
### pulsarSharedNossl not static link ssl, it could avoid rebuild libpulsar when ssl lib need update.
@@ -75,15 +77,19 @@ if (NOT ${RECORD_OPENSSL_CRYPTO_LIBRARY} MATCHES ".+\\.a$")
LIST(APPEND COMMON_LIBS_NOSSL ${RECORD_OPENSSL_CRYPTO_LIBRARY})
endif ()
-add_library(pulsarSharedNossl SHARED ${PULSAR_SOURCES})
-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})
+if (BUILD_DYNAMIC_LIB AND LINK_STATIC)
+ add_library(pulsarSharedNossl SHARED ${PULSAR_SOURCES})
+ 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()
-add_library(pulsarStatic STATIC ${PULSAR_SOURCES})
-set_property(TARGET pulsarStatic PROPERTY OUTPUT_NAME ${LIB_NAME})
-set_property(TARGET pulsarStatic PROPERTY VERSION ${LIBRARY_VERSION})
-target_compile_definitions(pulsarStatic PRIVATE PULSAR_STATIC)
+if (BUILD_STATIC_LIB)
+ add_library(pulsarStatic STATIC ${PULSAR_SOURCES})
+ set_property(TARGET pulsarStatic PROPERTY OUTPUT_NAME ${LIB_NAME})
+ set_property(TARGET pulsarStatic PROPERTY VERSION ${LIBRARY_VERSION})
+ target_compile_definitions(pulsarStatic PRIVATE PULSAR_STATIC)
+endif()
if (MSVC)
target_include_directories(pulsarStatic PRIVATE ${dlfcn-win32_INCLUDE_DIRS})
@@ -93,7 +99,7 @@ endif()
# When linking statically, install a libpulsar.a that contains all the
# required dependencies except ssl
-if (LINK_STATIC)
+if (LINK_STATIC AND BUILD_STATIC_LIB)
if (MSVC)
# This function is to remove either "debug" or "optimized" library names
@@ -136,13 +142,22 @@ if (LINK_STATIC)
DEPENDS pulsarStatic
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
endif(MSVC)
-else()
+elseif(BUILD_STATIC_LIB)
# Install regular libpulsar.a
target_link_libraries(pulsarStatic ${COMMON_LIBS})
install(TARGETS pulsarStatic DESTINATION lib)
endif(LINK_STATIC)
-install(TARGETS pulsarStatic DESTINATION lib)
-install(TARGETS pulsarShared RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
-install(TARGETS pulsarSharedNossl RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
+if (BUILD_STATIC_LIB)
+ install(TARGETS pulsarStatic DESTINATION lib)
+endif()
+
+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)