Skip to content

Commit 6b8a744

Browse files
committed
cmake: Add FindZeroMQ module
1 parent 0c4ff18 commit 6b8a744

File tree

3 files changed

+43
-14
lines changed

3 files changed

+43
-14
lines changed

CMakeLists.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,7 @@ endif()
133133

134134
option(WITH_ZMQ "Enable ZMQ notifications." OFF)
135135
if(WITH_ZMQ)
136-
if(VCPKG_TARGET_TRIPLET)
137-
find_package(ZeroMQ CONFIG REQUIRED)
138-
else()
139-
# The ZeroMQ project has provided config files since v4.2.2.
140-
# However, mainstream distributions do not yet provide CMake
141-
# config files for ZeroMQ packages. If they do in the future,
142-
# find_package(ZeroMQ) may be used instead.
143-
find_package(PkgConfig REQUIRED)
144-
pkg_check_modules(libzmq REQUIRED IMPORTED_TARGET libzmq>=4)
145-
endif()
136+
find_package(ZeroMQ 4.0.0 MODULE REQUIRED)
146137
endif()
147138

148139
option(WITH_USDT "Enable tracepoints for Userspace, Statically Defined Tracing." OFF)

cmake/module/FindZeroMQ.cmake

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (c) 2024-present The Bitcoin Core developers
2+
# Distributed under the MIT software license, see the accompanying
3+
# file COPYING or https://opensource.org/license/mit/.
4+
5+
#[=======================================================================[
6+
FindZeroMQ
7+
----------
8+
9+
Finds the ZeroMQ headers and library.
10+
11+
This is a wrapper around find_package()/pkg_check_modules() commands that:
12+
- facilitates searching in various build environments
13+
- prints a standard log message
14+
15+
#]=======================================================================]
16+
17+
include(FindPackageHandleStandardArgs)
18+
find_package(ZeroMQ ${ZeroMQ_FIND_VERSION} NO_MODULE QUIET)
19+
if(ZeroMQ_FOUND)
20+
find_package_handle_standard_args(ZeroMQ
21+
REQUIRED_VARS ZeroMQ_DIR
22+
VERSION_VAR ZeroMQ_VERSION
23+
)
24+
if(TARGET libzmq)
25+
add_library(zeromq ALIAS libzmq)
26+
elseif(TARGET libzmq-static)
27+
add_library(zeromq ALIAS libzmq-static)
28+
endif()
29+
mark_as_advanced(ZeroMQ_DIR)
30+
else()
31+
find_package(PkgConfig REQUIRED)
32+
pkg_check_modules(libzmq QUIET
33+
IMPORTED_TARGET
34+
libzmq>=${ZeroMQ_FIND_VERSION}
35+
)
36+
find_package_handle_standard_args(ZeroMQ
37+
REQUIRED_VARS libzmq_LIBRARY_DIRS
38+
VERSION_VAR libzmq_VERSION
39+
)
40+
add_library(zeromq ALIAS PkgConfig::libzmq)
41+
endif()

src/zmq/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@ add_library(bitcoin_zmq STATIC EXCLUDE_FROM_ALL
1212
target_compile_definitions(bitcoin_zmq
1313
INTERFACE
1414
ENABLE_ZMQ=1
15-
PRIVATE
16-
$<$<AND:$<PLATFORM_ID:Windows>,$<CXX_COMPILER_ID:GNU>>:ZMQ_STATIC>
1715
)
1816
target_link_libraries(bitcoin_zmq
1917
PRIVATE
2018
core_interface
2119
univalue
22-
$<TARGET_NAME_IF_EXISTS:libzmq>
23-
$<TARGET_NAME_IF_EXISTS:PkgConfig::libzmq>
20+
zeromq
2421
)

0 commit comments

Comments
 (0)