From 6b8a74463b5ce5d5d22263f220900f3587f730bd Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sat, 14 Sep 2024 15:40:07 +0100 Subject: [PATCH 1/2] cmake: Add `FindZeroMQ` module --- CMakeLists.txt | 11 +--------- cmake/module/FindZeroMQ.cmake | 41 +++++++++++++++++++++++++++++++++++ src/zmq/CMakeLists.txt | 5 +---- 3 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 cmake/module/FindZeroMQ.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index b8fdeefbdae..a8921a0ca66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -133,16 +133,7 @@ endif() option(WITH_ZMQ "Enable ZMQ notifications." OFF) if(WITH_ZMQ) - if(VCPKG_TARGET_TRIPLET) - find_package(ZeroMQ CONFIG REQUIRED) - else() - # The ZeroMQ project has provided config files since v4.2.2. - # However, mainstream distributions do not yet provide CMake - # config files for ZeroMQ packages. If they do in the future, - # find_package(ZeroMQ) may be used instead. - find_package(PkgConfig REQUIRED) - pkg_check_modules(libzmq REQUIRED IMPORTED_TARGET libzmq>=4) - endif() + find_package(ZeroMQ 4.0.0 MODULE REQUIRED) endif() option(WITH_USDT "Enable tracepoints for Userspace, Statically Defined Tracing." OFF) diff --git a/cmake/module/FindZeroMQ.cmake b/cmake/module/FindZeroMQ.cmake new file mode 100644 index 00000000000..eecd9b24536 --- /dev/null +++ b/cmake/module/FindZeroMQ.cmake @@ -0,0 +1,41 @@ +# Copyright (c) 2024-present The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or https://opensource.org/license/mit/. + +#[=======================================================================[ +FindZeroMQ +---------- + +Finds the ZeroMQ headers and library. + +This is a wrapper around find_package()/pkg_check_modules() commands that: + - facilitates searching in various build environments + - prints a standard log message + +#]=======================================================================] + +include(FindPackageHandleStandardArgs) +find_package(ZeroMQ ${ZeroMQ_FIND_VERSION} NO_MODULE QUIET) +if(ZeroMQ_FOUND) + find_package_handle_standard_args(ZeroMQ + REQUIRED_VARS ZeroMQ_DIR + VERSION_VAR ZeroMQ_VERSION + ) + if(TARGET libzmq) + add_library(zeromq ALIAS libzmq) + elseif(TARGET libzmq-static) + add_library(zeromq ALIAS libzmq-static) + endif() + mark_as_advanced(ZeroMQ_DIR) +else() + find_package(PkgConfig REQUIRED) + pkg_check_modules(libzmq QUIET + IMPORTED_TARGET + libzmq>=${ZeroMQ_FIND_VERSION} + ) + find_package_handle_standard_args(ZeroMQ + REQUIRED_VARS libzmq_LIBRARY_DIRS + VERSION_VAR libzmq_VERSION + ) + add_library(zeromq ALIAS PkgConfig::libzmq) +endif() diff --git a/src/zmq/CMakeLists.txt b/src/zmq/CMakeLists.txt index 8ecb236b460..19ac722b7ae 100644 --- a/src/zmq/CMakeLists.txt +++ b/src/zmq/CMakeLists.txt @@ -12,13 +12,10 @@ add_library(bitcoin_zmq STATIC EXCLUDE_FROM_ALL target_compile_definitions(bitcoin_zmq INTERFACE ENABLE_ZMQ=1 - PRIVATE - $<$,$>:ZMQ_STATIC> ) target_link_libraries(bitcoin_zmq PRIVATE core_interface univalue - $ - $ + zeromq ) From 915640e191b6a17a245f0502bc399d82a6502ccf Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Fri, 25 Oct 2024 16:28:36 +0000 Subject: [PATCH 2/2] depends: zeromq: don't install .pc files and remove patches for them --- depends/packages/zeromq.mk | 11 +++---- depends/patches/zeromq/fix_mingw_link.patch | 31 ------------------- .../patches/zeromq/remove_libstd_link.patch | 25 --------------- 3 files changed, 4 insertions(+), 63 deletions(-) delete mode 100644 depends/patches/zeromq/fix_mingw_link.patch delete mode 100644 depends/patches/zeromq/remove_libstd_link.patch diff --git a/depends/packages/zeromq.mk b/depends/packages/zeromq.mk index 67a0dd88e5d..743cc38cc77 100644 --- a/depends/packages/zeromq.mk +++ b/depends/packages/zeromq.mk @@ -4,15 +4,13 @@ $(package)_download_path=https://github.com/zeromq/libzmq/releases/download/v$($ $(package)_file_name=$(package)-$($(package)_version).tar.gz $(package)_sha256_hash=6653ef5910f17954861fe72332e68b03ca6e4d9c7160eb3a8de5a5a913bfab43 $(package)_build_subdir=build -$(package)_patches = remove_libstd_link.patch -$(package)_patches += macos_mktemp_check.patch +$(package)_patches = macos_mktemp_check.patch $(package)_patches += builtin_sha1.patch $(package)_patches += fix_have_windows.patch $(package)_patches += openbsd_kqueue_headers.patch $(package)_patches += cmake_minimum.patch $(package)_patches += cacheline_undefined.patch $(package)_patches += no_librt.patch -$(package)_patches += fix_mingw_link.patch define $(package)_set_vars $(package)_config_opts := -DCMAKE_BUILD_TYPE=None -DWITH_DOCS=OFF -DWITH_LIBSODIUM=OFF @@ -24,15 +22,13 @@ define $(package)_set_vars endef define $(package)_preprocess_cmds - patch -p1 < $($(package)_patch_dir)/remove_libstd_link.patch && \ patch -p1 < $($(package)_patch_dir)/macos_mktemp_check.patch && \ patch -p1 < $($(package)_patch_dir)/builtin_sha1.patch && \ patch -p1 < $($(package)_patch_dir)/cacheline_undefined.patch && \ patch -p1 < $($(package)_patch_dir)/fix_have_windows.patch && \ patch -p1 < $($(package)_patch_dir)/openbsd_kqueue_headers.patch && \ patch -p1 < $($(package)_patch_dir)/cmake_minimum.patch && \ - patch -p1 < $($(package)_patch_dir)/no_librt.patch && \ - patch -p1 < $($(package)_patch_dir)/fix_mingw_link.patch + patch -p1 < $($(package)_patch_dir)/no_librt.patch endef define $(package)_config_cmds @@ -48,5 +44,6 @@ define $(package)_stage_cmds endef define $(package)_postprocess_cmds - rm -rf share + rm -rf share && \ + rm -rf lib/pkgconfig endef diff --git a/depends/patches/zeromq/fix_mingw_link.patch b/depends/patches/zeromq/fix_mingw_link.patch deleted file mode 100644 index 1434557dc72..00000000000 --- a/depends/patches/zeromq/fix_mingw_link.patch +++ /dev/null @@ -1,31 +0,0 @@ -Fix CMake-generated `libzmq.pc` file - -This change mirrors the Autotools-based build system behavior for -cross-compiling for Windows with static linking. - -See https://github.com/zeromq/libzmq/pull/4706. - - -diff --git a/CMakeLists.txt b/CMakeLists.txt -index 03462271..0315e606 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -546,12 +546,18 @@ if(ZMQ_HAVE_WINDOWS) - # Cannot use check_library_exists because the symbol is always declared as char(*)(void) - set(CMAKE_REQUIRED_LIBRARIES "ws2_32.lib") - check_cxx_symbol_exists(WSAStartup "winsock2.h" HAVE_WS2_32) -+ if(HAVE_WS2_32) -+ set(pkg_config_libs_private "${pkg_config_libs_private} -lws2_32") -+ endif() - - set(CMAKE_REQUIRED_LIBRARIES "rpcrt4.lib") - check_cxx_symbol_exists(UuidCreateSequential "rpc.h" HAVE_RPCRT4) - - set(CMAKE_REQUIRED_LIBRARIES "iphlpapi.lib") - check_cxx_symbol_exists(GetAdaptersAddresses "winsock2.h;iphlpapi.h" HAVE_IPHLAPI) -+ if(HAVE_IPHLAPI) -+ set(pkg_config_libs_private "${pkg_config_libs_private} -liphlpapi") -+ endif() - check_cxx_symbol_exists(if_nametoindex "iphlpapi.h" HAVE_IF_NAMETOINDEX) - - set(CMAKE_REQUIRED_LIBRARIES "") diff --git a/depends/patches/zeromq/remove_libstd_link.patch b/depends/patches/zeromq/remove_libstd_link.patch deleted file mode 100644 index ddf91e6abfa..00000000000 --- a/depends/patches/zeromq/remove_libstd_link.patch +++ /dev/null @@ -1,25 +0,0 @@ -commit 47d4cd12a2c051815ddda78adebdb3923b260d8a -Author: fanquake -Date: Tue Aug 18 14:45:40 2020 +0800 - - Remove needless linking against libstdc++ - - This is broken for a number of reasons, including: - - g++ understands "static-libstdc++ -lstdc++" to mean "link against - whatever libstdc++ exists, probably shared", which in itself is buggy. - - another stdlib (libc++ for example) may be in use - - See #11981. - -diff --git a/src/libzmq.pc.in b/src/libzmq.pc.in -index 233bc3a..3c2bf0d 100644 ---- a/src/libzmq.pc.in -+++ b/src/libzmq.pc.in -@@ -7,6 +7,6 @@ Name: libzmq - Description: 0MQ c++ library - Version: @VERSION@ - Libs: -L${libdir} -lzmq --Libs.private: -lstdc++ @pkg_config_libs_private@ -+Libs.private: @pkg_config_libs_private@ - Requires.private: @pkg_config_names_private@ - Cflags: -I${includedir} @pkg_config_defines@