Skip to content

Commit

Permalink
Fixed static linking on C++ lib on MacOS (apache#5581)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
merlimat authored Feb 7, 2020
1 parent 4018d0b commit 125a588
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
37 changes: 19 additions & 18 deletions pulsar-client-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,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)
Expand Down Expand Up @@ -104,6 +110,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)
Expand All @@ -116,24 +135,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})
Expand Down
3 changes: 2 additions & 1 deletion pulsar-client-cpp/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 125a588

Please sign in to comment.