From d2f40357ba6eeae8c9635f94b213c642125fbc65 Mon Sep 17 00:00:00 2001 From: Yunze Xu Date: Thu, 7 Dec 2023 16:05:54 +0800 Subject: [PATCH 01/12] [pulsar-client-cpp] New port --- .../0001-use-find-package.patch | 167 ++++++++++++++++++ ports/pulsar-client-cpp/portfile.cmake | 35 ++++ .../unofficial-pulsar-config.cmake | 38 ++++ ports/pulsar-client-cpp/usage | 8 + ports/pulsar-client-cpp/vcpkg.json | 48 +++++ versions/baseline.json | 4 + versions/p-/pulsar-client-cpp.json | 9 + 7 files changed, 309 insertions(+) create mode 100644 ports/pulsar-client-cpp/0001-use-find-package.patch create mode 100644 ports/pulsar-client-cpp/portfile.cmake create mode 100644 ports/pulsar-client-cpp/unofficial-pulsar-config.cmake create mode 100644 ports/pulsar-client-cpp/usage create mode 100644 ports/pulsar-client-cpp/vcpkg.json create mode 100644 versions/p-/pulsar-client-cpp.json diff --git a/ports/pulsar-client-cpp/0001-use-find-package.patch b/ports/pulsar-client-cpp/0001-use-find-package.patch new file mode 100644 index 00000000000000..a20f93bc82622f --- /dev/null +++ b/ports/pulsar-client-cpp/0001-use-find-package.patch @@ -0,0 +1,167 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index fb4f1b1..84b8b1a 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -98,11 +98,7 @@ else () + endif () + + if (NOT CMAKE_CXX_STANDARD) +- if (LATEST_PROTOBUF) +- set(CMAKE_CXX_STANDARD 17) +- else () +- set(CMAKE_CXX_STANDARD 11) +- endif () ++ set(CMAKE_CXX_STANDARD 11) + endif () + set(CMAKE_C_STANDARD 11) + +@@ -148,43 +144,21 @@ if (APPLE) + set(OPENSSL_ROOT_DIR ${OPENSSL_ROOT_DIR} /usr/local/opt/openssl/ /opt/homebrew/opt/openssl) + endif () + find_package(OpenSSL REQUIRED) ++set(COMMON_LIBS ${COMMON_LIBS} OpenSSL::SSL OpenSSL::Crypto) + message("OPENSSL_INCLUDE_DIR: " ${OPENSSL_INCLUDE_DIR}) + message("OPENSSL_LIBRARIES: " ${OPENSSL_LIBRARIES}) + +-if (LATEST_PROTOBUF) +- # See https://github.com/apache/arrow/issues/35987 +- add_definitions(-DPROTOBUF_USE_DLLS) +- # Use Config mode to avoid FindProtobuf.cmake does not find the Abseil library +- find_package(Protobuf REQUIRED CONFIG) +-else () +- find_package(Protobuf REQUIRED) +-endif () ++find_package(protobuf REQUIRED CONFIG) ++set(COMMON_LIBS ${COMMON_LIBS} protobuf::libprotobuf) + message("Protobuf_INCLUDE_DIRS: " ${Protobuf_INCLUDE_DIRS}) + message("Protobuf_LIBRARIES: " ${Protobuf_LIBRARIES}) + +-# NOTE: CMake might not find curl and zlib on some platforms like Ubuntu, in this case, find them manually + set(CURL_NO_CURL_CMAKE ON) +-find_package(curl QUIET) +-if (NOT CURL_FOUND) +- find_path(CURL_INCLUDE_DIRS NAMES curl/curl.h) +- find_library(CURL_LIBRARIES NAMES curl curllib libcurl_imp curllib_static libcurl) +-endif () +-message("CURL_INCLUDE_DIRS: " ${CURL_INCLUDE_DIRS}) +-message("CURL_LIBRARIES: " ${CURL_LIBRARIES}) +-if (NOT CURL_INCLUDE_DIRS OR NOT CURL_LIBRARIES) +- message(FATAL_ERROR "Could not find libcurl") +-endif () ++find_package(CURL REQUIRED) ++set(COMMON_LIBS ${COMMON_LIBS} CURL::libcurl) + +-find_package(zlib QUIET) +-if (NOT ZLIB_FOUND) +- find_path(ZLIB_INCLUDE_DIRS NAMES zlib.h) +- find_library(ZLIB_LIBRARIES NAMES z zlib zdll zlib1 zlibstatic) +-endif () +-message("ZLIB_INCLUDE_DIRS: " ${ZLIB_INCLUDE_DIRS}) +-message("ZLIB_LIBRARIES: " ${ZLIB_LIBRARIES}) +-if (NOT ZLIB_INCLUDE_DIRS OR NOT ZLIB_LIBRARIES) +- message(FATAL_ERROR "Could not find zlib") +-endif () ++find_package(ZLIB REQUIRED) ++set(COMMON_LIBS ${COMMON_LIBS} ZLIB::ZLIB) + + if (LINK_STATIC AND NOT VCPKG_TRIPLET) + find_library(LIB_ZSTD NAMES libzstd.a) +@@ -227,15 +201,15 @@ elseif (LINK_STATIC AND VCPKG_TRIPLET) + message(STATUS "Found Snappy library: ${LIB_SNAPPY}") + endif () + else() +- if (MSVC AND (${CMAKE_BUILD_TYPE} STREQUAL Debug)) +- find_library(LIB_ZSTD zstdd HINTS "${VCPKG_DEBUG_ROOT}/lib") +- else () +- find_library(LIB_ZSTD zstd) +- endif () +- if (MSVC AND (${CMAKE_BUILD_TYPE} STREQUAL Debug)) +- find_library(LIB_SNAPPY NAMES snappyd HINTS "${VCPKG_DEBUG_ROOT}/lib") +- else () +- find_library(LIB_SNAPPY NAMES snappy libsnappy) ++ find_package(zstd CONFIG REQUIRED) ++ set(HAS_ZSTD 1) ++ set(LIB_ZSTD ++ $,zstd::libzstd_shared,zstd::libzstd_static>) ++ find_package(Snappy CONFIG REQUIRED) ++ set(HAS_SNAPPY 1) ++ set(LIB_SNAPPY Snappy::snappy) ++ if (MSVC) ++ find_package(dlfcn-win32 CONFIG REQUIRED) + endif () + endif () + +@@ -319,20 +293,10 @@ set(COMMON_LIBS + ${Boost_REGEX_LIBRARY} + ${Boost_SYSTEM_LIBRARY} + ${Boost_DATE_TIME_LIBRARY} +- ${CURL_LIBRARIES} +- ${OPENSSL_LIBRARIES} +- ${ZLIB_LIBRARIES} + ${ADDITIONAL_LIBRARIES} + ${CMAKE_DL_LIBS} + ) + +-if (LATEST_PROTOBUF) +- # Protobuf_LIBRARIES is empty when finding Protobuf in Config mode +- set(COMMON_LIBS ${COMMON_LIBS} protobuf::libprotobuf) +-else () +- set(COMMON_LIBS ${COMMON_LIBS} ${Protobuf_LIBRARIES}) +-endif () +- + if (MSVC) + set(COMMON_LIBS + ${COMMON_LIBS} +@@ -377,10 +341,6 @@ endif () + + add_definitions(-DHAS_SNAPPY=${HAS_SNAPPY}) + +-if(NOT APPLE AND NOT MSVC) +- set(COMMON_LIBS ${COMMON_LIBS} rt) +-endif () +- + link_directories(${PROJECT_BINARY_DIR}/lib) + + set(LIB_NAME $ENV{PULSAR_LIBRARY_NAME}) +diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt +index 8bd9749..e5ee8dd 100644 +--- a/lib/CMakeLists.txt ++++ b/lib/CMakeLists.txt +@@ -27,16 +27,16 @@ set(LIB_AUTOGEN_DIR ${AUTOGEN_DIR}/lib) + file(MAKE_DIRECTORY ${LIB_AUTOGEN_DIR}) + include_directories(${LIB_AUTOGEN_DIR}) + +-# Protobuf generation is only supported natively starting from CMake 3.8 +-# Using custom command for now ++add_library(proto-objects OBJECT "${CMAKE_SOURCE_DIR}/proto/PulsarApi.proto") ++target_link_libraries(proto-objects PUBLIC protobuf::libprotobuf) ++target_include_directories(proto-objects PUBLIC "${LIB_AUTOGEN_DIR}") ++protobuf_generate( ++ TARGET proto-objects ++ IMPORT_DIRS "${CMAKE_SOURCE_DIR}/proto" ++ PROTOC_OUT_DIR "${LIB_AUTOGEN_DIR}") ++ + set(PROTO_SOURCES ${LIB_AUTOGEN_DIR}/PulsarApi.pb.cc ${LIB_AUTOGEN_DIR}/PulsarApi.pb.h) + set(PULSAR_SOURCES ${PULSAR_SOURCES} ${PROTO_SOURCES}) +-ADD_CUSTOM_COMMAND( +- OUTPUT ${PROTO_SOURCES} +- COMMAND ${PROTOC_PATH} -I ../proto ../proto/PulsarApi.proto --cpp_out=${LIB_AUTOGEN_DIR} +- DEPENDS +- ../proto/PulsarApi.proto +- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + + set(LIBRARY_VERSION $ENV{PULSAR_LIBRARY_VERSION}) + if (NOT LIBRARY_VERSION) +@@ -70,6 +70,12 @@ if (BUILD_DYNAMIC_LIB) + target_include_directories(pulsarShared PRIVATE ${dlfcn-win32_INCLUDE_DIRS}) + target_link_options(pulsarShared PRIVATE $<$:/NODEFAULTLIB:MSVCRT>) + endif() ++ if (APPLE) ++ target_link_libraries(pulsarShared stdc++ "-framework Security" ++ "-framework CoreFoundation" ++ "-framework CoreServices" ++ "-framework SystemConfiguration") ++ endif () + endif() + + include(CheckCXXSymbolExists) diff --git a/ports/pulsar-client-cpp/portfile.cmake b/ports/pulsar-client-cpp/portfile.cmake new file mode 100644 index 00000000000000..9d1a5034f96517 --- /dev/null +++ b/ports/pulsar-client-cpp/portfile.cmake @@ -0,0 +1,35 @@ +vcpkg_check_linkage(ONLY_STATIC_LIBRARY) + +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO apache/pulsar-client-cpp + REF "v${VERSION}" + SHA512 ab257f5e82d3815a232dd73297c6ff032536de3d9e5adec6c53fa0276fc02efb1a84e153278f21881de1d3a786e26c4d4d2aff78c1d3fbf932f4d5b6e8cae9dc + HEAD_REF main + PATCHES + 0001-use-find-package.patch +) + +string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" PULSAR_BUILD_STATIC) + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" + OPTIONS + -DBUILD_TESTS=OFF + -DBUILD_PERF_TOOLS=OFF + -DBUILD_STATIC_LIB=${PULSAR_BUILD_STATIC} +) + +vcpkg_cmake_install() + +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") +if(VCPKG_LIBRARY_LINKAGE STREQUAL "static") + file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" "${CURRENT_PACKAGES_DIR}/debug/bin") +endif() + +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") +configure_file("${CMAKE_CURRENT_LIST_DIR}/usage" "${CURRENT_PACKAGES_DIR}/share/${PORT}/usage" COPYONLY) + +file(COPY "${CURRENT_PORT_DIR}/unofficial-pulsar-config.cmake" DESTINATION "${CURRENT_PACKAGES_DIR}/share/unofficial-pulsar/") + +vcpkg_copy_pdbs() diff --git a/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake b/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake new file mode 100644 index 00000000000000..d077b5aff853a1 --- /dev/null +++ b/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake @@ -0,0 +1,38 @@ +if (NOT TARGET unofficial::pulsar::pulsar) + get_filename_component(VCPKG_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH) + get_filename_component(VCPKG_IMPORT_PREFIX "${VCPKG_IMPORT_PREFIX}" PATH) + get_filename_component(VCPKG_IMPORT_PREFIX "${VCPKG_IMPORT_PREFIX}" PATH) + + find_path(_pulsar_include_dir NAMES "pulsar/Client.h" PATH ${VCPKG_IMPORT_PREFIX}) + if (CMAKE_BUILD_TYPE STREQUAL "Debug") + set(VCPKG_IMPORT_PREFIX "${VCPKG_IMPORT_PREFIX}/debug") + endif () + if ("@VCPKG_LIBRARY_LINKAGE" STREQUAL "dynamic" OR PULSAR_FORCE_DYNAMIC_LIBRARY) + find_library(_pulsar_library NAMES libpulsar.so libpulsar.dylib pulsar.lib PATH ${VCPKG_IMPORT_PREFIX}) + else () + find_library(_pulsar_library NAMES libpulsar.a pulsar-static.lib PATH ${VCPKG_IMPORT_PREFIX}) + endif () + if (NOT _pulsar_include_dir OR NOT _pulsar_library) + message(FATAL_ERROR "Broken installation of vcpkg port pulsar-client-cpp") + endif () + + # Find 3rd party dependencies + find_package(protobuf CONFIG REQUIRED) + find_package(CURL CONFIG REQUIRED) + find_package(zstd CONFIG REQUIRED) + find_package(snappy CONFIG REQUIRED) + + add_library(unofficial::pulsar::pulsar INTERFACE IMPORTED) + set_target_properties(unofficial::pulsar::pulsar PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${_pulsar_include_dir}" + IMPORTED_LOCATION "${_pulsar_library}") + target_link_libraries(unofficial::pulsar::pulsar INTERFACE + ${_pulsar_library} + protobuf::libprotobuf + CURL::libcurl + $,zstd::libzstd_shared,zstd::libzstd_static> + Snappy::snappy + ) + unset(_pulsar_library) +endif () +unset(_pulsar_include_dir) diff --git a/ports/pulsar-client-cpp/usage b/ports/pulsar-client-cpp/usage new file mode 100644 index 00000000000000..ac7bb627fa8b09 --- /dev/null +++ b/ports/pulsar-client-cpp/usage @@ -0,0 +1,8 @@ +pulsar-client-cpp provides CMake targets: + + find_package(unofficial-pulsar CONFIG REQUIRED) + target_link_libraries(main PRIVATE unofficial::pulsar::pulsar) + + # When VCPKG_LIBRARY_LINKAGE is static, both static and dynamic libraries will be generated + # and the static library will be found. To link the dynamic library, set + # PULSAR_FORCE_DYNAMIC_LIBRARY to ON. diff --git a/ports/pulsar-client-cpp/vcpkg.json b/ports/pulsar-client-cpp/vcpkg.json new file mode 100644 index 00000000000000..99916831fad862 --- /dev/null +++ b/ports/pulsar-client-cpp/vcpkg.json @@ -0,0 +1,48 @@ +{ + "name": "pulsar-client-cpp", + "version": "3.4.1", + "description": "The Apache Pulsar C++ library", + "homepage": "https://github.com/apache/pulsar-client-cpp", + "license": "Apache-2.0", + "supports": "!(arm & windows) & !android", + "dependencies": [ + "boost-accumulators", + "boost-algorithm", + "boost-any", + "boost-asio", + "boost-circular-buffer", + "boost-date-time", + "boost-predef", + "boost-property-tree", + "boost-random", + "boost-serialization", + "boost-xpressive", + { + "name": "curl", + "default-features": false, + "features": [ + "openssl" + ] + }, + { + "name": "dlfcn-win32", + "platform": "windows" + }, + "openssl", + { + "name": "protobuf", + "version>=": "3.21.12" + }, + "snappy", + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + }, + "zlib", + "zstd" + ] +} diff --git a/versions/baseline.json b/versions/baseline.json index e796a857b30356..54558a6da3614a 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -6844,6 +6844,10 @@ "baseline": "1.14", "port-version": 0 }, + "pulsar-client-cpp": { + "baseline": "3.4.1", + "port-version": 0 + }, "pulzed-mini": { "baseline": "0.9.14", "port-version": 0 diff --git a/versions/p-/pulsar-client-cpp.json b/versions/p-/pulsar-client-cpp.json new file mode 100644 index 00000000000000..e5ddae6335e135 --- /dev/null +++ b/versions/p-/pulsar-client-cpp.json @@ -0,0 +1,9 @@ +{ + "versions": [ + { + "git-tree": "2f3d3adb380413ccf4567d24382b7b00c13698d7", + "version": "3.4.1", + "port-version": 0 + } + ] +} From c8bd4090a3333a73c1047f5a4f7161bc0e3b18f0 Mon Sep 17 00:00:00 2001 From: Yunze Xu Date: Tue, 12 Dec 2023 01:53:48 +0800 Subject: [PATCH 02/12] Remove unnecessary link options --- .../pulsar-client-cpp/0001-use-find-package.patch | 15 +-------------- .../unofficial-pulsar-config.cmake | 3 +-- versions/p-/pulsar-client-cpp.json | 2 +- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/ports/pulsar-client-cpp/0001-use-find-package.patch b/ports/pulsar-client-cpp/0001-use-find-package.patch index a20f93bc82622f..5ca7255e13d3da 100644 --- a/ports/pulsar-client-cpp/0001-use-find-package.patch +++ b/ports/pulsar-client-cpp/0001-use-find-package.patch @@ -124,7 +124,7 @@ index fb4f1b1..84b8b1a 100644 set(LIB_NAME $ENV{PULSAR_LIBRARY_NAME}) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt -index 8bd9749..e5ee8dd 100644 +index 8bd9749..007df90 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -27,16 +27,16 @@ set(LIB_AUTOGEN_DIR ${AUTOGEN_DIR}/lib) @@ -152,16 +152,3 @@ index 8bd9749..e5ee8dd 100644 set(LIBRARY_VERSION $ENV{PULSAR_LIBRARY_VERSION}) if (NOT LIBRARY_VERSION) -@@ -70,6 +70,12 @@ if (BUILD_DYNAMIC_LIB) - target_include_directories(pulsarShared PRIVATE ${dlfcn-win32_INCLUDE_DIRS}) - target_link_options(pulsarShared PRIVATE $<$:/NODEFAULTLIB:MSVCRT>) - endif() -+ if (APPLE) -+ target_link_libraries(pulsarShared stdc++ "-framework Security" -+ "-framework CoreFoundation" -+ "-framework CoreServices" -+ "-framework SystemConfiguration") -+ endif () - endif() - - include(CheckCXXSymbolExists) diff --git a/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake b/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake index d077b5aff853a1..98b2fefe317a1e 100644 --- a/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake +++ b/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake @@ -16,7 +16,6 @@ if (NOT TARGET unofficial::pulsar::pulsar) message(FATAL_ERROR "Broken installation of vcpkg port pulsar-client-cpp") endif () - # Find 3rd party dependencies find_package(protobuf CONFIG REQUIRED) find_package(CURL CONFIG REQUIRED) find_package(zstd CONFIG REQUIRED) @@ -34,5 +33,5 @@ if (NOT TARGET unofficial::pulsar::pulsar) Snappy::snappy ) unset(_pulsar_library) + unset(_pulsar_include_dir) endif () -unset(_pulsar_include_dir) diff --git a/versions/p-/pulsar-client-cpp.json b/versions/p-/pulsar-client-cpp.json index e5ddae6335e135..dd7a59f7189316 100644 --- a/versions/p-/pulsar-client-cpp.json +++ b/versions/p-/pulsar-client-cpp.json @@ -1,7 +1,7 @@ { "versions": [ { - "git-tree": "2f3d3adb380413ccf4567d24382b7b00c13698d7", + "git-tree": "9362c70d01cdba78a286aa2ff40934ec275d69d6", "version": "3.4.1", "port-version": 0 } From 57717c93491b356d3e0403ac0473a4e592bbe02a Mon Sep 17 00:00:00 2001 From: Yunze Xu Date: Thu, 14 Dec 2023 16:33:31 +0800 Subject: [PATCH 03/12] Address review comments - Use find_dependency instead of find_package - Specify BUILD_DYNAMIC_LIB explicitly --- ports/pulsar-client-cpp/portfile.cmake | 5 +++-- ports/pulsar-client-cpp/unofficial-pulsar-config.cmake | 9 +++++---- versions/p-/pulsar-client-cpp.json | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ports/pulsar-client-cpp/portfile.cmake b/ports/pulsar-client-cpp/portfile.cmake index 9d1a5034f96517..db232f40e04730 100644 --- a/ports/pulsar-client-cpp/portfile.cmake +++ b/ports/pulsar-client-cpp/portfile.cmake @@ -10,14 +10,15 @@ vcpkg_from_github( 0001-use-find-package.patch ) -string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" PULSAR_BUILD_STATIC) +string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" BUILD_STATIC_LIB) vcpkg_cmake_configure( SOURCE_PATH "${SOURCE_PATH}" OPTIONS -DBUILD_TESTS=OFF -DBUILD_PERF_TOOLS=OFF - -DBUILD_STATIC_LIB=${PULSAR_BUILD_STATIC} + -DBUILD_DYNAMIC_LIB=ON + -DBUILD_STATIC_LIB=${BUILD_STATIC_LIB} ) vcpkg_cmake_install() diff --git a/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake b/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake index 98b2fefe317a1e..7e1f46621eeea3 100644 --- a/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake +++ b/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake @@ -16,10 +16,11 @@ if (NOT TARGET unofficial::pulsar::pulsar) message(FATAL_ERROR "Broken installation of vcpkg port pulsar-client-cpp") endif () - find_package(protobuf CONFIG REQUIRED) - find_package(CURL CONFIG REQUIRED) - find_package(zstd CONFIG REQUIRED) - find_package(snappy CONFIG REQUIRED) + include(CMakeFindDependencyMacro) + find_dependency(protobuf CONFIG) + find_dependency(CURL CONFIG) + find_dependency(zstd CONFIG) + find_dependency(snappy CONFIG) add_library(unofficial::pulsar::pulsar INTERFACE IMPORTED) set_target_properties(unofficial::pulsar::pulsar PROPERTIES diff --git a/versions/p-/pulsar-client-cpp.json b/versions/p-/pulsar-client-cpp.json index dd7a59f7189316..65ad47e63b9439 100644 --- a/versions/p-/pulsar-client-cpp.json +++ b/versions/p-/pulsar-client-cpp.json @@ -1,7 +1,7 @@ { "versions": [ { - "git-tree": "9362c70d01cdba78a286aa2ff40934ec275d69d6", + "git-tree": "d8d761157af00807d6c8310d671e3908e5b8ce43", "version": "3.4.1", "port-version": 0 } From 3374c426d1352907324aa096deff8a8f44ebff54 Mon Sep 17 00:00:00 2001 From: Yunze Xu Date: Sat, 16 Dec 2023 20:07:13 +0800 Subject: [PATCH 04/12] Fix the Windows build and linkage --- ports/pulsar-client-cpp/portfile.cmake | 8 ++++--- .../unofficial-pulsar-config.cmake | 24 +++++++++++++++++-- ports/pulsar-client-cpp/usage | 6 ++--- versions/p-/pulsar-client-cpp.json | 2 +- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/ports/pulsar-client-cpp/portfile.cmake b/ports/pulsar-client-cpp/portfile.cmake index db232f40e04730..32bcedd871f1ca 100644 --- a/ports/pulsar-client-cpp/portfile.cmake +++ b/ports/pulsar-client-cpp/portfile.cmake @@ -1,5 +1,3 @@ -vcpkg_check_linkage(ONLY_STATIC_LIBRARY) - vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH REPO apache/pulsar-client-cpp @@ -11,13 +9,17 @@ vcpkg_from_github( ) string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" BUILD_STATIC_LIB) +option(BUILD_DYNAMIC_LIB ON) +if (MSVC AND BUILD_STATIC_LIB) + set(BUILD_DYNAMIC_LIB OFF) +endif () vcpkg_cmake_configure( SOURCE_PATH "${SOURCE_PATH}" OPTIONS -DBUILD_TESTS=OFF -DBUILD_PERF_TOOLS=OFF - -DBUILD_DYNAMIC_LIB=ON + -DBUILD_DYNAMIC_LIB=${BUILD_DYNAMIC_LIB} -DBUILD_STATIC_LIB=${BUILD_STATIC_LIB} ) diff --git a/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake b/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake index 7e1f46621eeea3..7f8decb519d1a1 100644 --- a/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake +++ b/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake @@ -7,32 +7,52 @@ if (NOT TARGET unofficial::pulsar::pulsar) if (CMAKE_BUILD_TYPE STREQUAL "Debug") set(VCPKG_IMPORT_PREFIX "${VCPKG_IMPORT_PREFIX}/debug") endif () - if ("@VCPKG_LIBRARY_LINKAGE" STREQUAL "dynamic" OR PULSAR_FORCE_DYNAMIC_LIBRARY) + if (VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic" OR (PULSAR_FORCE_DYNAMIC_LIBRARY AND NOT MSVC)) find_library(_pulsar_library NAMES libpulsar.so libpulsar.dylib pulsar.lib PATH ${VCPKG_IMPORT_PREFIX}) + set(_pulsar_link_static_library OFF) + message(STATUS "Found dynamic _pulsar_library: ${_pulsar_library}") else () find_library(_pulsar_library NAMES libpulsar.a pulsar-static.lib PATH ${VCPKG_IMPORT_PREFIX}) + set(_pulsar_link_static_library ON) + message(STATUS "Found static _pulsar_library: ${_pulsar_library}") endif () if (NOT _pulsar_include_dir OR NOT _pulsar_library) message(FATAL_ERROR "Broken installation of vcpkg port pulsar-client-cpp") endif () include(CMakeFindDependencyMacro) + find_dependency(OpenSSL) + find_dependency(ZLIB) find_dependency(protobuf CONFIG) find_dependency(CURL CONFIG) find_dependency(zstd CONFIG) find_dependency(snappy CONFIG) + if (MSVC) + find_dependency(dlfcn-win32 CONFIG) + endif () add_library(unofficial::pulsar::pulsar INTERFACE IMPORTED) set_target_properties(unofficial::pulsar::pulsar PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${_pulsar_include_dir}" IMPORTED_LOCATION "${_pulsar_library}") - target_link_libraries(unofficial::pulsar::pulsar INTERFACE + set(DEPENDENCIES ${_pulsar_library} + OpenSSL::SSL + OpenSSL::Crypto + ZLIB::ZLIB protobuf::libprotobuf CURL::libcurl $,zstd::libzstd_shared,zstd::libzstd_static> Snappy::snappy ) + if (MSVC) + set(DEPENDENCIES ${DEPENDENCIES} dlfcn-win32::dl) + endif () + if (_pulsar_link_static_library) + target_compile_definitions(unofficial::pulsar::pulsar INTERFACE PULSAR_STATIC) + endif () + target_link_libraries(unofficial::pulsar::pulsar INTERFACE ${DEPENDENCIES}) + unset(_pulsar_link_static_library) unset(_pulsar_library) unset(_pulsar_include_dir) endif () diff --git a/ports/pulsar-client-cpp/usage b/ports/pulsar-client-cpp/usage index ac7bb627fa8b09..0282bb1567737d 100644 --- a/ports/pulsar-client-cpp/usage +++ b/ports/pulsar-client-cpp/usage @@ -3,6 +3,6 @@ pulsar-client-cpp provides CMake targets: find_package(unofficial-pulsar CONFIG REQUIRED) target_link_libraries(main PRIVATE unofficial::pulsar::pulsar) - # When VCPKG_LIBRARY_LINKAGE is static, both static and dynamic libraries will be generated - # and the static library will be found. To link the dynamic library, set - # PULSAR_FORCE_DYNAMIC_LIBRARY to ON. + # For non-MSVC compilers, when VCPKG_LIBRARY_LINKAGE is static, both static + # and dynamic libraries will be generated and the static library will be + # found. To link the dynamic library, set PULSAR_FORCE_DYNAMIC_LIBRARY to ON. diff --git a/versions/p-/pulsar-client-cpp.json b/versions/p-/pulsar-client-cpp.json index 65ad47e63b9439..79ef1b4ed9154d 100644 --- a/versions/p-/pulsar-client-cpp.json +++ b/versions/p-/pulsar-client-cpp.json @@ -1,7 +1,7 @@ { "versions": [ { - "git-tree": "d8d761157af00807d6c8310d671e3908e5b8ce43", + "git-tree": "d8832fb8b95818026545cb7d987c54dcefc32f87", "version": "3.4.1", "port-version": 0 } From 4b94824cb2411b6421dc0e250b7194d6ccb9b7e2 Mon Sep 17 00:00:00 2001 From: Yunze Xu Date: Sun, 17 Dec 2023 01:51:58 +0800 Subject: [PATCH 05/12] Fix dynamic library not built when VCPKG_LIBRARY_LINKAGE is dynamic on Windows --- ports/pulsar-client-cpp/portfile.cmake | 8 ++++++-- versions/p-/pulsar-client-cpp.json | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ports/pulsar-client-cpp/portfile.cmake b/ports/pulsar-client-cpp/portfile.cmake index 32bcedd871f1ca..2374a77ae482ee 100644 --- a/ports/pulsar-client-cpp/portfile.cmake +++ b/ports/pulsar-client-cpp/portfile.cmake @@ -9,10 +9,14 @@ vcpkg_from_github( ) string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" BUILD_STATIC_LIB) -option(BUILD_DYNAMIC_LIB ON) -if (MSVC AND BUILD_STATIC_LIB) + +if (${VCPKG_TARGET_IS_WINDOWS} AND BUILD_STATIC_LIB) set(BUILD_DYNAMIC_LIB OFF) +else () + set(BUILD_DYNAMIC_LIB ON) endif () +message(STATUS "BUILD_DYNAMIC_LIB: ${BUILD_DYNAMIC_LIB}") +message(STATUS "BUILD_STATIC_LIB: ${BUILD_STATIC_LIB}") vcpkg_cmake_configure( SOURCE_PATH "${SOURCE_PATH}" diff --git a/versions/p-/pulsar-client-cpp.json b/versions/p-/pulsar-client-cpp.json index 79ef1b4ed9154d..6c975834f02333 100644 --- a/versions/p-/pulsar-client-cpp.json +++ b/versions/p-/pulsar-client-cpp.json @@ -1,7 +1,7 @@ { "versions": [ { - "git-tree": "d8832fb8b95818026545cb7d987c54dcefc32f87", + "git-tree": "100bb18e3fe85733879c0f5ea9a345f77821d5d0", "version": "3.4.1", "port-version": 0 } From d7d9fd37a456150ff9f2359f1b6fa3ef52d8fe76 Mon Sep 17 00:00:00 2001 From: Yunze Xu Date: Sun, 17 Dec 2023 02:13:04 +0800 Subject: [PATCH 06/12] Fix Linux and OSX failures --- ports/pulsar-client-cpp/portfile.cmake | 2 +- versions/p-/pulsar-client-cpp.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/pulsar-client-cpp/portfile.cmake b/ports/pulsar-client-cpp/portfile.cmake index 2374a77ae482ee..6486cb9fc6dbf5 100644 --- a/ports/pulsar-client-cpp/portfile.cmake +++ b/ports/pulsar-client-cpp/portfile.cmake @@ -10,7 +10,7 @@ vcpkg_from_github( string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" BUILD_STATIC_LIB) -if (${VCPKG_TARGET_IS_WINDOWS} AND BUILD_STATIC_LIB) +if (VCPKG_TARGET_IS_WINDOWS AND BUILD_STATIC_LIB) set(BUILD_DYNAMIC_LIB OFF) else () set(BUILD_DYNAMIC_LIB ON) diff --git a/versions/p-/pulsar-client-cpp.json b/versions/p-/pulsar-client-cpp.json index 6c975834f02333..1afde0dc88c87a 100644 --- a/versions/p-/pulsar-client-cpp.json +++ b/versions/p-/pulsar-client-cpp.json @@ -1,7 +1,7 @@ { "versions": [ { - "git-tree": "100bb18e3fe85733879c0f5ea9a345f77821d5d0", + "git-tree": "f6fecc396ebec7954b8b7408d60f51cf336a12f9", "version": "3.4.1", "port-version": 0 } From d505ce6482d813b0b84368a30f9337daed5a801e Mon Sep 17 00:00:00 2001 From: Yunze Xu Date: Sun, 17 Dec 2023 13:38:05 +0800 Subject: [PATCH 07/12] Remove PULSAR_FORCE_DYNAMIC_LIBRARY and upgrade version to 3.4.2 --- ports/pulsar-client-cpp/portfile.cmake | 13 +++---------- .../unofficial-pulsar-config.cmake | 2 +- ports/pulsar-client-cpp/usage | 4 ---- ports/pulsar-client-cpp/vcpkg.json | 2 +- versions/baseline.json | 2 +- versions/p-/pulsar-client-cpp.json | 7 ++++++- 6 files changed, 12 insertions(+), 18 deletions(-) diff --git a/ports/pulsar-client-cpp/portfile.cmake b/ports/pulsar-client-cpp/portfile.cmake index 6486cb9fc6dbf5..b41d30b82e76d7 100644 --- a/ports/pulsar-client-cpp/portfile.cmake +++ b/ports/pulsar-client-cpp/portfile.cmake @@ -2,21 +2,14 @@ vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH REPO apache/pulsar-client-cpp REF "v${VERSION}" - SHA512 ab257f5e82d3815a232dd73297c6ff032536de3d9e5adec6c53fa0276fc02efb1a84e153278f21881de1d3a786e26c4d4d2aff78c1d3fbf932f4d5b6e8cae9dc + SHA512 b1f56ca8d5edb7faaba68eb4e04fcb4e458ccf2c7a5b0fb6d66868c6507081344fb3f0ebb29afe9aef567295a249b09cdeb3fb00285746767bbccef65a0f6e70 HEAD_REF main PATCHES 0001-use-find-package.patch ) string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" BUILD_STATIC_LIB) - -if (VCPKG_TARGET_IS_WINDOWS AND BUILD_STATIC_LIB) - set(BUILD_DYNAMIC_LIB OFF) -else () - set(BUILD_DYNAMIC_LIB ON) -endif () -message(STATUS "BUILD_DYNAMIC_LIB: ${BUILD_DYNAMIC_LIB}") -message(STATUS "BUILD_STATIC_LIB: ${BUILD_STATIC_LIB}") +string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" BUILD_DYNAMIC_LIB) vcpkg_cmake_configure( SOURCE_PATH "${SOURCE_PATH}" @@ -37,6 +30,6 @@ endif() vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") configure_file("${CMAKE_CURRENT_LIST_DIR}/usage" "${CURRENT_PACKAGES_DIR}/share/${PORT}/usage" COPYONLY) -file(COPY "${CURRENT_PORT_DIR}/unofficial-pulsar-config.cmake" DESTINATION "${CURRENT_PACKAGES_DIR}/share/unofficial-pulsar/") +configure_file("${CMAKE_CURRENT_LIST_DIR}/unofficial-pulsar-config.cmake" "${CURRENT_PACKAGES_DIR}/share/unofficial-pulsar/unofficial-pulsar-config.cmake" @ONLY) vcpkg_copy_pdbs() diff --git a/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake b/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake index 7f8decb519d1a1..b1d03a9033a8e3 100644 --- a/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake +++ b/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake @@ -7,7 +7,7 @@ if (NOT TARGET unofficial::pulsar::pulsar) if (CMAKE_BUILD_TYPE STREQUAL "Debug") set(VCPKG_IMPORT_PREFIX "${VCPKG_IMPORT_PREFIX}/debug") endif () - if (VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic" OR (PULSAR_FORCE_DYNAMIC_LIBRARY AND NOT MSVC)) + if ("@VCPKG_LIBRARY_LINKAGE@" STREQUAL "dynamic") find_library(_pulsar_library NAMES libpulsar.so libpulsar.dylib pulsar.lib PATH ${VCPKG_IMPORT_PREFIX}) set(_pulsar_link_static_library OFF) message(STATUS "Found dynamic _pulsar_library: ${_pulsar_library}") diff --git a/ports/pulsar-client-cpp/usage b/ports/pulsar-client-cpp/usage index 0282bb1567737d..474d73f16f63f1 100644 --- a/ports/pulsar-client-cpp/usage +++ b/ports/pulsar-client-cpp/usage @@ -2,7 +2,3 @@ pulsar-client-cpp provides CMake targets: find_package(unofficial-pulsar CONFIG REQUIRED) target_link_libraries(main PRIVATE unofficial::pulsar::pulsar) - - # For non-MSVC compilers, when VCPKG_LIBRARY_LINKAGE is static, both static - # and dynamic libraries will be generated and the static library will be - # found. To link the dynamic library, set PULSAR_FORCE_DYNAMIC_LIBRARY to ON. diff --git a/ports/pulsar-client-cpp/vcpkg.json b/ports/pulsar-client-cpp/vcpkg.json index 99916831fad862..c746bb53120433 100644 --- a/ports/pulsar-client-cpp/vcpkg.json +++ b/ports/pulsar-client-cpp/vcpkg.json @@ -1,6 +1,6 @@ { "name": "pulsar-client-cpp", - "version": "3.4.1", + "version": "3.4.2", "description": "The Apache Pulsar C++ library", "homepage": "https://github.com/apache/pulsar-client-cpp", "license": "Apache-2.0", diff --git a/versions/baseline.json b/versions/baseline.json index f0446dc0f08e0b..3c5f0076b099a2 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -6853,7 +6853,7 @@ "port-version": 0 }, "pulsar-client-cpp": { - "baseline": "3.4.1", + "baseline": "3.4.2", "port-version": 0 }, "pulzed-mini": { diff --git a/versions/p-/pulsar-client-cpp.json b/versions/p-/pulsar-client-cpp.json index 1afde0dc88c87a..f39705ce4ecc2d 100644 --- a/versions/p-/pulsar-client-cpp.json +++ b/versions/p-/pulsar-client-cpp.json @@ -1,7 +1,12 @@ { "versions": [ { - "git-tree": "f6fecc396ebec7954b8b7408d60f51cf336a12f9", + "git-tree": "23883f83f0971e33da5724142ba9ade99b61e5c4", + "version": "3.4.2", + "port-version": 0 + }, + { + "git-tree": "f0e8879f5638f152daf0a97e9a16707f89f93f9e", "version": "3.4.1", "port-version": 0 } From 9886a37bf8241fd4b093a3c782b6b0f54e25f500 Mon Sep 17 00:00:00 2001 From: Yunze Xu Date: Mon, 18 Dec 2023 16:57:22 +0800 Subject: [PATCH 08/12] Reduce the changes to the upstream CMakeLists.txt --- .../0001-use-find-package.patch | 154 +++++------------- versions/p-/pulsar-client-cpp.json | 2 +- 2 files changed, 42 insertions(+), 114 deletions(-) diff --git a/ports/pulsar-client-cpp/0001-use-find-package.patch b/ports/pulsar-client-cpp/0001-use-find-package.patch index 5ca7255e13d3da..3138706a3ee6f6 100644 --- a/ports/pulsar-client-cpp/0001-use-find-package.patch +++ b/ports/pulsar-client-cpp/0001-use-find-package.patch @@ -1,84 +1,47 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt -index fb4f1b1..84b8b1a 100644 +index fb4f1b1..1bcfd47 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt -@@ -98,11 +98,7 @@ else () +@@ -96,6 +96,7 @@ if (APPLE AND NOT LINK_STATIC) + else () + set(LATEST_PROTOBUF FALSE) endif () ++set(LATEST_PROTOBUF FALSE) if (NOT CMAKE_CXX_STANDARD) -- if (LATEST_PROTOBUF) -- set(CMAKE_CXX_STANDARD 17) -- else () -- set(CMAKE_CXX_STANDARD 11) -- endif () -+ set(CMAKE_CXX_STANDARD 11) - endif () - set(CMAKE_C_STANDARD 11) - -@@ -148,43 +144,21 @@ if (APPLE) - set(OPENSSL_ROOT_DIR ${OPENSSL_ROOT_DIR} /usr/local/opt/openssl/ /opt/homebrew/opt/openssl) - endif () - find_package(OpenSSL REQUIRED) -+set(COMMON_LIBS ${COMMON_LIBS} OpenSSL::SSL OpenSSL::Crypto) - message("OPENSSL_INCLUDE_DIR: " ${OPENSSL_INCLUDE_DIR}) - message("OPENSSL_LIBRARIES: " ${OPENSSL_LIBRARIES}) - --if (LATEST_PROTOBUF) -- # See https://github.com/apache/arrow/issues/35987 -- add_definitions(-DPROTOBUF_USE_DLLS) -- # Use Config mode to avoid FindProtobuf.cmake does not find the Abseil library -- find_package(Protobuf REQUIRED CONFIG) --else () + if (LATEST_PROTOBUF) +@@ -157,14 +158,15 @@ if (LATEST_PROTOBUF) + # Use Config mode to avoid FindProtobuf.cmake does not find the Abseil library + find_package(Protobuf REQUIRED CONFIG) + else () - find_package(Protobuf REQUIRED) --endif () -+find_package(protobuf REQUIRED CONFIG) -+set(COMMON_LIBS ${COMMON_LIBS} protobuf::libprotobuf) ++ find_package(protobuf CONFIG REQUIRED) ++ set(Protobuf_LIBRARIES protobuf::libprotobuf) + endif () message("Protobuf_INCLUDE_DIRS: " ${Protobuf_INCLUDE_DIRS}) message("Protobuf_LIBRARIES: " ${Protobuf_LIBRARIES}) --# NOTE: CMake might not find curl and zlib on some platforms like Ubuntu, in this case, find them manually + # NOTE: CMake might not find curl and zlib on some platforms like Ubuntu, in this case, find them manually set(CURL_NO_CURL_CMAKE ON) -find_package(curl QUIET) --if (NOT CURL_FOUND) -- find_path(CURL_INCLUDE_DIRS NAMES curl/curl.h) -- find_library(CURL_LIBRARIES NAMES curl curllib libcurl_imp curllib_static libcurl) --endif () --message("CURL_INCLUDE_DIRS: " ${CURL_INCLUDE_DIRS}) --message("CURL_LIBRARIES: " ${CURL_LIBRARIES}) --if (NOT CURL_INCLUDE_DIRS OR NOT CURL_LIBRARIES) -- message(FATAL_ERROR "Could not find libcurl") --endif () +find_package(CURL REQUIRED) -+set(COMMON_LIBS ${COMMON_LIBS} CURL::libcurl) + if (NOT CURL_FOUND) + find_path(CURL_INCLUDE_DIRS NAMES curl/curl.h) + find_library(CURL_LIBRARIES NAMES curl curllib libcurl_imp curllib_static libcurl) +@@ -175,7 +177,7 @@ if (NOT CURL_INCLUDE_DIRS OR NOT CURL_LIBRARIES) + message(FATAL_ERROR "Could not find libcurl") + endif () -find_package(zlib QUIET) --if (NOT ZLIB_FOUND) -- find_path(ZLIB_INCLUDE_DIRS NAMES zlib.h) -- find_library(ZLIB_LIBRARIES NAMES z zlib zdll zlib1 zlibstatic) --endif () --message("ZLIB_INCLUDE_DIRS: " ${ZLIB_INCLUDE_DIRS}) --message("ZLIB_LIBRARIES: " ${ZLIB_LIBRARIES}) --if (NOT ZLIB_INCLUDE_DIRS OR NOT ZLIB_LIBRARIES) -- message(FATAL_ERROR "Could not find zlib") --endif () +find_package(ZLIB REQUIRED) -+set(COMMON_LIBS ${COMMON_LIBS} ZLIB::ZLIB) - - if (LINK_STATIC AND NOT VCPKG_TRIPLET) - find_library(LIB_ZSTD NAMES libzstd.a) -@@ -227,15 +201,15 @@ elseif (LINK_STATIC AND VCPKG_TRIPLET) + if (NOT ZLIB_FOUND) + find_path(ZLIB_INCLUDE_DIRS NAMES zlib.h) + find_library(ZLIB_LIBRARIES NAMES z zlib zdll zlib1 zlibstatic) +@@ -226,6 +228,17 @@ elseif (LINK_STATIC AND VCPKG_TRIPLET) + if (LIB_SNAPPY) message(STATUS "Found Snappy library: ${LIB_SNAPPY}") endif () - else() -- if (MSVC AND (${CMAKE_BUILD_TYPE} STREQUAL Debug)) -- find_library(LIB_ZSTD zstdd HINTS "${VCPKG_DEBUG_ROOT}/lib") -- else () -- find_library(LIB_ZSTD zstd) -- endif () -- if (MSVC AND (${CMAKE_BUILD_TYPE} STREQUAL Debug)) -- find_library(LIB_SNAPPY NAMES snappyd HINTS "${VCPKG_DEBUG_ROOT}/lib") -- else () -- find_library(LIB_SNAPPY NAMES snappy libsnappy) ++elseif (1) + find_package(zstd CONFIG REQUIRED) + set(HAS_ZSTD 1) + set(LIB_ZSTD @@ -88,59 +51,16 @@ index fb4f1b1..84b8b1a 100644 + set(LIB_SNAPPY Snappy::snappy) + if (MSVC) + find_package(dlfcn-win32 CONFIG REQUIRED) - endif () - endif () - -@@ -319,20 +293,10 @@ set(COMMON_LIBS - ${Boost_REGEX_LIBRARY} - ${Boost_SYSTEM_LIBRARY} - ${Boost_DATE_TIME_LIBRARY} -- ${CURL_LIBRARIES} -- ${OPENSSL_LIBRARIES} -- ${ZLIB_LIBRARIES} - ${ADDITIONAL_LIBRARIES} - ${CMAKE_DL_LIBS} - ) - --if (LATEST_PROTOBUF) -- # Protobuf_LIBRARIES is empty when finding Protobuf in Config mode -- set(COMMON_LIBS ${COMMON_LIBS} protobuf::libprotobuf) --else () -- set(COMMON_LIBS ${COMMON_LIBS} ${Protobuf_LIBRARIES}) --endif () -- - if (MSVC) - set(COMMON_LIBS - ${COMMON_LIBS} -@@ -377,10 +341,6 @@ endif () - - add_definitions(-DHAS_SNAPPY=${HAS_SNAPPY}) - --if(NOT APPLE AND NOT MSVC) -- set(COMMON_LIBS ${COMMON_LIBS} rt) --endif () -- - link_directories(${PROJECT_BINARY_DIR}/lib) - - set(LIB_NAME $ENV{PULSAR_LIBRARY_NAME}) ++ endif () + 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 8bd9749..007df90 100644 +index 8bd9749..551ac0c 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt -@@ -27,16 +27,16 @@ set(LIB_AUTOGEN_DIR ${AUTOGEN_DIR}/lib) - file(MAKE_DIRECTORY ${LIB_AUTOGEN_DIR}) - include_directories(${LIB_AUTOGEN_DIR}) - --# Protobuf generation is only supported natively starting from CMake 3.8 --# Using custom command for now -+add_library(proto-objects OBJECT "${CMAKE_SOURCE_DIR}/proto/PulsarApi.proto") -+target_link_libraries(proto-objects PUBLIC protobuf::libprotobuf) -+target_include_directories(proto-objects PUBLIC "${LIB_AUTOGEN_DIR}") -+protobuf_generate( -+ TARGET proto-objects -+ IMPORT_DIRS "${CMAKE_SOURCE_DIR}/proto" -+ PROTOC_OUT_DIR "${LIB_AUTOGEN_DIR}") -+ +@@ -31,12 +31,14 @@ include_directories(${LIB_AUTOGEN_DIR}) + # Using custom command for now set(PROTO_SOURCES ${LIB_AUTOGEN_DIR}/PulsarApi.pb.cc ${LIB_AUTOGEN_DIR}/PulsarApi.pb.h) set(PULSAR_SOURCES ${PULSAR_SOURCES} ${PROTO_SOURCES}) -ADD_CUSTOM_COMMAND( @@ -149,6 +69,14 @@ index 8bd9749..007df90 100644 - DEPENDS - ../proto/PulsarApi.proto - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) ++ ++add_library(proto-objects OBJECT "${CMAKE_SOURCE_DIR}/proto/PulsarApi.proto") ++target_link_libraries(proto-objects PUBLIC protobuf::libprotobuf) ++target_include_directories(proto-objects PUBLIC "${LIB_AUTOGEN_DIR}") ++protobuf_generate( ++ TARGET proto-objects ++ IMPORT_DIRS "${CMAKE_SOURCE_DIR}/proto" ++ PROTOC_OUT_DIR "${LIB_AUTOGEN_DIR}") set(LIBRARY_VERSION $ENV{PULSAR_LIBRARY_VERSION}) if (NOT LIBRARY_VERSION) diff --git a/versions/p-/pulsar-client-cpp.json b/versions/p-/pulsar-client-cpp.json index f39705ce4ecc2d..b00c8ac56e3285 100644 --- a/versions/p-/pulsar-client-cpp.json +++ b/versions/p-/pulsar-client-cpp.json @@ -1,7 +1,7 @@ { "versions": [ { - "git-tree": "23883f83f0971e33da5724142ba9ade99b61e5c4", + "git-tree": "96ce7cefca9a71540014b6f2f74ba70b6094c224", "version": "3.4.2", "port-version": 0 }, From 28ea68c25a180f02e9cdd7c1d3bf0db631c19ab3 Mon Sep 17 00:00:00 2001 From: Yunze Xu Date: Tue, 19 Dec 2023 10:46:50 +0800 Subject: [PATCH 09/12] Remove unused version --- versions/p-/pulsar-client-cpp.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/versions/p-/pulsar-client-cpp.json b/versions/p-/pulsar-client-cpp.json index b00c8ac56e3285..645a6bb920f9f9 100644 --- a/versions/p-/pulsar-client-cpp.json +++ b/versions/p-/pulsar-client-cpp.json @@ -4,11 +4,6 @@ "git-tree": "96ce7cefca9a71540014b6f2f74ba70b6094c224", "version": "3.4.2", "port-version": 0 - }, - { - "git-tree": "f0e8879f5638f152daf0a97e9a16707f89f93f9e", - "version": "3.4.1", - "port-version": 0 } ] } From 6fadad728571735a9862d21231f7101644d700c5 Mon Sep 17 00:00:00 2001 From: Yunze Xu Date: Tue, 19 Dec 2023 17:32:41 +0800 Subject: [PATCH 10/12] Optimize finding and linking dependency and patch the header for static library --- ports/pulsar-client-cpp/portfile.cmake | 6 ++++ .../unofficial-pulsar-config.cmake | 29 +++++-------------- versions/p-/pulsar-client-cpp.json | 2 +- 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/ports/pulsar-client-cpp/portfile.cmake b/ports/pulsar-client-cpp/portfile.cmake index b41d30b82e76d7..595d73e3a7b7e2 100644 --- a/ports/pulsar-client-cpp/portfile.cmake +++ b/ports/pulsar-client-cpp/portfile.cmake @@ -22,6 +22,12 @@ vcpkg_cmake_configure( vcpkg_cmake_install() +if (BUILD_STATIC_LIB) + vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/pulsar/defines.h" + "#ifdef PULSAR_STATIC" + "#if 1") +endif () + file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") if(VCPKG_LIBRARY_LINKAGE STREQUAL "static") file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" "${CURRENT_PACKAGES_DIR}/debug/bin") diff --git a/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake b/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake index b1d03a9033a8e3..e737b5a0e11484 100644 --- a/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake +++ b/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake @@ -3,19 +3,12 @@ if (NOT TARGET unofficial::pulsar::pulsar) get_filename_component(VCPKG_IMPORT_PREFIX "${VCPKG_IMPORT_PREFIX}" PATH) get_filename_component(VCPKG_IMPORT_PREFIX "${VCPKG_IMPORT_PREFIX}" PATH) - find_path(_pulsar_include_dir NAMES "pulsar/Client.h" PATH ${VCPKG_IMPORT_PREFIX}) + find_path(_pulsar_include_dir NAMES "pulsar/Client.h" PATH "${VCPKG_IMPORT_PREFIX}/include") if (CMAKE_BUILD_TYPE STREQUAL "Debug") set(VCPKG_IMPORT_PREFIX "${VCPKG_IMPORT_PREFIX}/debug") endif () - if ("@VCPKG_LIBRARY_LINKAGE@" STREQUAL "dynamic") - find_library(_pulsar_library NAMES libpulsar.so libpulsar.dylib pulsar.lib PATH ${VCPKG_IMPORT_PREFIX}) - set(_pulsar_link_static_library OFF) - message(STATUS "Found dynamic _pulsar_library: ${_pulsar_library}") - else () - find_library(_pulsar_library NAMES libpulsar.a pulsar-static.lib PATH ${VCPKG_IMPORT_PREFIX}) - set(_pulsar_link_static_library ON) - message(STATUS "Found static _pulsar_library: ${_pulsar_library}") - endif () + find_library(_pulsar_library NAMES pulsar pulsar-static NAMES NAMES_PER_DIR PATH "${VCPKG_IMPORT_PREFIX}" PATH_SUFFIXES "lib") + message(STATUS "Found _pulsar_library: ${_pulsar_library}") if (NOT _pulsar_include_dir OR NOT _pulsar_library) message(FATAL_ERROR "Broken installation of vcpkg port pulsar-client-cpp") endif () @@ -31,12 +24,11 @@ if (NOT TARGET unofficial::pulsar::pulsar) find_dependency(dlfcn-win32 CONFIG) endif () - add_library(unofficial::pulsar::pulsar INTERFACE IMPORTED) + add_library(unofficial::pulsar::pulsar UNKNOWN IMPORTED) set_target_properties(unofficial::pulsar::pulsar PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${_pulsar_include_dir}" IMPORTED_LOCATION "${_pulsar_library}") - set(DEPENDENCIES - ${_pulsar_library} + target_link_libraries(unofficial::pulsar::pulsar INTERFACE OpenSSL::SSL OpenSSL::Crypto ZLIB::ZLIB @@ -46,13 +38,8 @@ if (NOT TARGET unofficial::pulsar::pulsar) Snappy::snappy ) if (MSVC) - set(DEPENDENCIES ${DEPENDENCIES} dlfcn-win32::dl) - endif () - if (_pulsar_link_static_library) - target_compile_definitions(unofficial::pulsar::pulsar INTERFACE PULSAR_STATIC) + target_link_libraries(unofficial::pulsar::pulsar INTERFACE dlfcn-win32::dl) endif () - target_link_libraries(unofficial::pulsar::pulsar INTERFACE ${DEPENDENCIES}) - unset(_pulsar_link_static_library) - unset(_pulsar_library) - unset(_pulsar_include_dir) + unset(_pulsar_library CACHE) + unset(_pulsar_include_dir CACHE) endif () diff --git a/versions/p-/pulsar-client-cpp.json b/versions/p-/pulsar-client-cpp.json index 645a6bb920f9f9..122baf0b4f58c6 100644 --- a/versions/p-/pulsar-client-cpp.json +++ b/versions/p-/pulsar-client-cpp.json @@ -1,7 +1,7 @@ { "versions": [ { - "git-tree": "96ce7cefca9a71540014b6f2f74ba70b6094c224", + "git-tree": "7f9f9dafb74341c6f14c2162c13e79daf5e3f6cd", "version": "3.4.2", "port-version": 0 } From d0410af6087e65e4c13e1e207c1a486131e13468 Mon Sep 17 00:00:00 2001 From: Yunze Xu Date: Tue, 19 Dec 2023 21:03:10 +0800 Subject: [PATCH 11/12] Support multi-config generators --- .../unofficial-pulsar-config.cmake | 51 +++++++++++++++---- versions/p-/pulsar-client-cpp.json | 2 +- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake b/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake index e737b5a0e11484..aec27eb42f867b 100644 --- a/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake +++ b/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake @@ -4,15 +4,24 @@ if (NOT TARGET unofficial::pulsar::pulsar) get_filename_component(VCPKG_IMPORT_PREFIX "${VCPKG_IMPORT_PREFIX}" PATH) find_path(_pulsar_include_dir NAMES "pulsar/Client.h" PATH "${VCPKG_IMPORT_PREFIX}/include") - if (CMAKE_BUILD_TYPE STREQUAL "Debug") - set(VCPKG_IMPORT_PREFIX "${VCPKG_IMPORT_PREFIX}/debug") - endif () - find_library(_pulsar_library NAMES pulsar pulsar-static NAMES NAMES_PER_DIR PATH "${VCPKG_IMPORT_PREFIX}" PATH_SUFFIXES "lib") - message(STATUS "Found _pulsar_library: ${_pulsar_library}") - if (NOT _pulsar_include_dir OR NOT _pulsar_library) + find_library(_pulsar_library_release NAMES pulsar pulsar-static NAMES NAMES_PER_DIR PATH "${VCPKG_IMPORT_PREFIX}" PATH_SUFFIXES "lib") + find_library(_pulsar_library_debug NAMES pulsar pulsar-static NAMES NAMES_PER_DIR PATH "${VCPKG_IMPORT_PREFIX}/debug" PATH_SUFFIXES "lib") + message(STATUS "Found _pulsar_library_release: ${_pulsar_library_release}") + message(STATUS "Found _pulsar_library_debug: ${_pulsar_library_debug}") + if (NOT _pulsar_include_dir OR NOT _pulsar_library_release) message(FATAL_ERROR "Broken installation of vcpkg port pulsar-client-cpp") endif () + if (MSVC AND "@VCPKG_LIBRARY_LINKAGE@" STREQUAL "dynamic") + find_file(_pulsar_release_dll NAMES "pulsar.dll" PATHS "${VCPKG_IMPORT_PREFIX}/bin" NO_DEFAULT_PATH) + find_file(_pulsar_debug_dll NAMES "pulsar.dll" PATHS "${VCPKG_IMPORT_PREFIX}/debug/bin" NO_DEFAULT_PATH) + if (NOT _pulsar_release_dll) + message(FATAL_ERROR "No pulsar.dll found") + endif () + message(STATUS "Found _pulsar_release_dll: ${_pulsar_release_dll}") + message(STATUS "Found _pulsar_debug_dll: ${_pulsar_debug_dll}") + endif () + include(CMakeFindDependencyMacro) find_dependency(OpenSSL) find_dependency(ZLIB) @@ -24,10 +33,32 @@ if (NOT TARGET unofficial::pulsar::pulsar) find_dependency(dlfcn-win32 CONFIG) endif () - add_library(unofficial::pulsar::pulsar UNKNOWN IMPORTED) + if (_pulsar_release_dll) + add_library(unofficial::pulsar::pulsar SHARED IMPORTED) + set_target_properties(unofficial::pulsar::pulsar PROPERTIES + IMPORTED_CONFIGURATIONS "Release" + IMPORTED_IMPLIB_RELEASE "${_pulsar_library_release}" + IMPORTED_LOCATION_RELEASE "${_pulsar_release_dll}") + if (_pulsar_debug_dll) + set_target_properties(unofficial::pulsar::pulsar PROPERTIES + IMPORTED_CONFIGURATIONS "Release;DEBUG" + IMPORTED_IMPLIB_DEBUG "${_pulsar_library_debug}" + IMPORTED_LOCATION_DEBUG "${_pulsar_debug_dll}") + unset(_pulsar_debug_dll CACHE) + endif () + unset(_pulsar_release_dll CACHE) + else () + add_library(unofficial::pulsar::pulsar UNKNOWN IMPORTED) + set_target_properties(unofficial::pulsar::pulsar PROPERTIES + IMPORTED_LOCATION_RELEASE "${_pulsar_library_release}") + if (_pulsar_library_debug) + set_target_properties(unofficial::pulsar::pulsar PROPERTIES + IMPORTED_LOCATION_DEBUG "${_pulsar_library_debug}") + unset(_pulsar_library_debug CACHE) + endif () + endif () set_target_properties(unofficial::pulsar::pulsar PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${_pulsar_include_dir}" - IMPORTED_LOCATION "${_pulsar_library}") + INTERFACE_INCLUDE_DIRECTORIES "${_pulsar_include_dir}") target_link_libraries(unofficial::pulsar::pulsar INTERFACE OpenSSL::SSL OpenSSL::Crypto @@ -40,6 +71,6 @@ if (NOT TARGET unofficial::pulsar::pulsar) if (MSVC) target_link_libraries(unofficial::pulsar::pulsar INTERFACE dlfcn-win32::dl) endif () - unset(_pulsar_library CACHE) + unset(_pulsar_library_release CACHE) unset(_pulsar_include_dir CACHE) endif () diff --git a/versions/p-/pulsar-client-cpp.json b/versions/p-/pulsar-client-cpp.json index 122baf0b4f58c6..6224c2d45c8f5d 100644 --- a/versions/p-/pulsar-client-cpp.json +++ b/versions/p-/pulsar-client-cpp.json @@ -1,7 +1,7 @@ { "versions": [ { - "git-tree": "7f9f9dafb74341c6f14c2162c13e79daf5e3f6cd", + "git-tree": "d0841e7ed2527f08a24555a9df4ecb4742290f1e", "version": "3.4.2", "port-version": 0 } From 8a7274769a70d5c82bf263b814043c7c203115b2 Mon Sep 17 00:00:00 2001 From: Yunze Xu Date: Tue, 19 Dec 2023 21:52:38 +0800 Subject: [PATCH 12/12] Fix path for release libraries --- ports/pulsar-client-cpp/unofficial-pulsar-config.cmake | 9 +++++++-- versions/p-/pulsar-client-cpp.json | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake b/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake index aec27eb42f867b..d8406a7060040f 100644 --- a/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake +++ b/ports/pulsar-client-cpp/unofficial-pulsar-config.cmake @@ -4,8 +4,13 @@ if (NOT TARGET unofficial::pulsar::pulsar) get_filename_component(VCPKG_IMPORT_PREFIX "${VCPKG_IMPORT_PREFIX}" PATH) find_path(_pulsar_include_dir NAMES "pulsar/Client.h" PATH "${VCPKG_IMPORT_PREFIX}/include") - find_library(_pulsar_library_release NAMES pulsar pulsar-static NAMES NAMES_PER_DIR PATH "${VCPKG_IMPORT_PREFIX}" PATH_SUFFIXES "lib") - find_library(_pulsar_library_debug NAMES pulsar pulsar-static NAMES NAMES_PER_DIR PATH "${VCPKG_IMPORT_PREFIX}/debug" PATH_SUFFIXES "lib") + set(_temp_cmake_ignore_path ${CMAKE_IGNORE_PATH}) + # Without setting CMAKE_IGNORE_PATH, the library under debug/lib/ directory could be found + set(CMAKE_IGNORE_PATH "${VCPKG_IMPORT_PREFIX}/debug/lib") + find_library(_pulsar_library_release NAMES pulsar pulsar-static PATH "${VCPKG_IMPORT_PREFIX}/lib") + set(CMAKE_IGNORE_PATH ${_temp_cmake_ignore_path}) + unset(_temp_cmake_ignore_path) + find_library(_pulsar_library_debug NAMES pulsar pulsar-static PATH "${VCPKG_IMPORT_PREFIX}/debug/lib") message(STATUS "Found _pulsar_library_release: ${_pulsar_library_release}") message(STATUS "Found _pulsar_library_debug: ${_pulsar_library_debug}") if (NOT _pulsar_include_dir OR NOT _pulsar_library_release) diff --git a/versions/p-/pulsar-client-cpp.json b/versions/p-/pulsar-client-cpp.json index 6224c2d45c8f5d..1611cc33230a78 100644 --- a/versions/p-/pulsar-client-cpp.json +++ b/versions/p-/pulsar-client-cpp.json @@ -1,7 +1,7 @@ { "versions": [ { - "git-tree": "d0841e7ed2527f08a24555a9df4ecb4742290f1e", + "git-tree": "f022e5dacbf10b0a6cead0f065ce6ab885b4c9af", "version": "3.4.2", "port-version": 0 }