Skip to content

Commit

Permalink
cmake: Add FindZeroMQ module
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Sep 14, 2024
1 parent 0c4ff18 commit 7f67ed7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
11 changes: 1 addition & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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()
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
zeromq
univalue
$<TARGET_NAME_IF_EXISTS:libzmq>
$<TARGET_NAME_IF_EXISTS:PkgConfig::libzmq>
)

0 comments on commit 7f67ed7

Please sign in to comment.