Skip to content

Commit

Permalink
Merge bitcoin/bitcoin#30903: cmake: Add FindZeroMQ module
Browse files Browse the repository at this point in the history
915640e depends: zeromq: don't install .pc files and remove patches for them (Cory Fields)
6b8a744 cmake: Add `FindZeroMQ` module (Hennadii Stepanov)

Pull request description:

  This PR introduces the `FindZeroMQ` module, which first attempts to find the `libzmq` library using CMake's `find_package()` and falls back to `pkg_check_modules()` if unsuccessful.

  Addresses bitcoin/bitcoin#30876 for the ZeroMQ package.

ACKs for top commit:
  fanquake:
    ACK 915640e

Tree-SHA512: 2f17bae21be5d3f280a13425d22f5d1b2e23837a8aaf5ec89c433767509de030a42d598b261e102bdb5b860d8ede98013c124c3d25e081e956d4ee3a81b2584f
  • Loading branch information
fanquake committed Oct 29, 2024
2 parents da10e0b + 915640e commit dc97e7f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 77 deletions.
11 changes: 1 addition & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,7 @@ option(WITH_CCACHE "Attempt to use ccache for compiling." ON)

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)
Expand Down
41 changes: 41 additions & 0 deletions cmake/module/FindZeroMQ.cmake
Original file line number Diff line number Diff line change
@@ -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()
11 changes: 4 additions & 7 deletions depends/packages/zeromq.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -48,5 +44,6 @@ define $(package)_stage_cmds
endef

define $(package)_postprocess_cmds
rm -rf share
rm -rf share && \
rm -rf lib/pkgconfig
endef
31 changes: 0 additions & 31 deletions depends/patches/zeromq/fix_mingw_link.patch

This file was deleted.

25 changes: 0 additions & 25 deletions depends/patches/zeromq/remove_libstd_link.patch

This file was deleted.

5 changes: 1 addition & 4 deletions src/zmq/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ add_library(bitcoin_zmq STATIC EXCLUDE_FROM_ALL
target_compile_definitions(bitcoin_zmq
INTERFACE
ENABLE_ZMQ=1
PRIVATE
$<$<AND:$<PLATFORM_ID:Windows>,$<CXX_COMPILER_ID:GNU>>:ZMQ_STATIC>
)
target_link_libraries(bitcoin_zmq
PRIVATE
core_interface
univalue
$<TARGET_NAME_IF_EXISTS:libzmq>
$<TARGET_NAME_IF_EXISTS:PkgConfig::libzmq>
zeromq
)

0 comments on commit dc97e7f

Please sign in to comment.