This is an automated email from the ASF dual-hosted git repository.

guangning pushed a commit to branch branch-2.5
in repository https://gitbox.apache.org/repos/asf/pulsar.git

commit 92b0c75c3cd0ff321c1670a5cc244dcb506a0373
Author: Matteo Merli <[email protected]>
AuthorDate: Thu Feb 6 21:24:20 2020 -0800

    Fixed static linking on C++ lib on MacOS (#5581)
    
    * Fixed static linking on C++ lib on MacOS
    
    * Use `-undefined dynamic_lookup` when linking on Mac to not include 
python's own runtime
    
    * Fixed searching for protobuf
---
 pulsar-client-cpp/CMakeLists.txt        | 37 +++++++++++++++++----------------
 pulsar-client-cpp/python/CMakeLists.txt |  3 ++-
 2 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/pulsar-client-cpp/CMakeLists.txt b/pulsar-client-cpp/CMakeLists.txt
index 55740b2..56144b2 100644
--- a/pulsar-client-cpp/CMakeLists.txt
+++ b/pulsar-client-cpp/CMakeLists.txt
@@ -68,6 +68,12 @@ endif(NOT LOG_CATEGORY_NAME)
 add_definitions(-DLOG_CATEGORY_NAME=${LOG_CATEGORY_NAME} -DBUILDING_PULSAR 
-DBOOST_ALL_NO_LIB -DBOOST_ALLOW_DEPRECATED_HEADERS)
 
 if (LINK_STATIC)
+    find_library(ZLIB_LIBRARIES REQUIRED NAMES libz.a z)
+    find_library(Protobuf_LITE_LIBRARIES NAMES libprotobuf-lite.a)
+    find_library(CURL_LIBRARIES NAMES libcurl.a curl curl_a)
+    find_library(LIB_ZSTD NAMES libzstd.a)
+    find_library(LIB_SNAPPY NAMES libsnappy.a)
+
     if (USE_LOG4CXX)
         if (LOG4CXX_USE_DYNAMIC_LIBS)
             find_library(LOG4CXX_LIBRARY_PATH log4cxx)
@@ -98,6 +104,19 @@ if (LINK_STATIC)
     SET(OPENSSL_USE_STATIC_LIBS TRUE)
 else()
     # Link to shared libraries
+    find_package(ZLIB REQUIRED)
+    set(ZLIB_LIBRARIES ${ZLIB_LIBRARIES})
+    if (NOT PROTOBUF_LIBRARIES)
+        find_package(ProtoBuf QUIET)
+        if (NOT Protobuf_FOUND OR NOT Protobuf_LITE_LIBRARIES)
+            find_library(Protobuf_LITE_LIBRARIES protobuf-lite 
libprotobuf-lite)
+            find_path(Protobuf_INCLUDE_DIRS google/protobuf/stubs/common.h)
+        endif()
+    endif (NOT PROTOBUF_LIBRARIES)
+
+    find_library(LIB_ZSTD zstd)
+    find_library(LIB_SNAPPY snappy libsnappy)
+    find_library(CURL_LIBRARIES curl)
     if (USE_LOG4CXX)
         find_library(LOG4CXX_LIBRARY_PATH log4cxx)
         find_path(LOG4CXX_INCLUDE_PATH log4cxx/logger.h)
@@ -110,24 +129,6 @@ else()
   find_package(Boost REQUIRED COMPONENTS program_options regex system)
 endif()
 
-find_package(ZLIB REQUIRED)
-
-find_package(Protobuf QUIET)
-if (NOT Protobuf_FOUND OR NOT Protobuf_LITE_LIBRARIES)
-    find_library(Protobuf_LITE_LIBRARIES protobuf-lite libprotobuf-lite)
-    find_path(Protobuf_INCLUDE_DIRS google/protobuf/stubs/common.h)
-endif()
-
-find_package(CURL QUIET)
-if (NOT CURL_FOUND)
-    find_library(CURL_LIBRARIES NAMES curl libcurl_a)
-    find_path(CURL_INCLUDE_DIRS curl/curl.h)
-endif()
-
-find_library(LIB_ZSTD zstd libzstd)
-
-find_library(LIB_SNAPPY snappy libsnappy)
-
 if (BUILD_PYTHON_WRAPPER)
     find_package(PythonLibs REQUIRED)
     MESSAGE(STATUS "PYTHON: " ${PYTHONLIBS_VERSION_STRING})
diff --git a/pulsar-client-cpp/python/CMakeLists.txt 
b/pulsar-client-cpp/python/CMakeLists.txt
index 5421cbc..1cbc972 100644
--- a/pulsar-client-cpp/python/CMakeLists.txt
+++ b/pulsar-client-cpp/python/CMakeLists.txt
@@ -51,7 +51,7 @@ set(PYTHON_WRAPPER_LIBS ${Boost_PYTHON_LIBRARY} 
${Boost_PYTHON3_LIBRARY}
                         ${Boost_PYTHON36_LIBRARY})
 
 if (APPLE)
-    set(PYTHON_WRAPPER_LIBS ${PYTHON_LIBRARIES} ${PYTHON_WRAPPER_LIBS}
+    set(PYTHON_WRAPPER_LIBS ${PYTHON_WRAPPER_LIBS}
                          ${Boost_PYTHON27-MT_LIBRARY_RELEASE} 
${Boost_PYTHON37-MT_LIBRARY_RELEASE})
 
     if (LINK_STATIC)
@@ -71,6 +71,7 @@ if (NOT PYTHON_WRAPPER_LIBS)
 endif ()
 
 if (APPLE)
+    set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS 
"${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS} -undefined dynamic_lookup")
     target_link_libraries(_pulsar -Wl,-all_load pulsarStatic 
${PYTHON_WRAPPER_LIBS} ${COMMON_LIBS} ${ICU_LIBS})
 else ()
     if (NOT MSVC)

Reply via email to