cmake: Add libzmq optional package support

This commit is contained in:
Hennadii Stepanov 2024-04-29 21:23:42 +01:00
parent ae7b39a0e1
commit d2fda82b49
No known key found for this signature in database
GPG key ID: 410108112E7EA81F
3 changed files with 46 additions and 0 deletions

View file

@ -116,6 +116,23 @@ if(WITH_MINIUPNPC)
find_package(MiniUPnPc MODULE REQUIRED)
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.
# TODO: Switch to find_package(ZeroMQ) at some point in the future.
find_package(PkgConfig REQUIRED)
pkg_check_modules(libzmq REQUIRED IMPORTED_TARGET libzmq>=4)
# TODO: This command will be redundant once
# https://github.com/bitcoin/bitcoin/pull/30508 is merged.
target_link_libraries(PkgConfig::libzmq INTERFACE
$<$<PLATFORM_ID:Windows>:iphlpapi;ws2_32>
)
endif()
endif()
set(configure_warnings)
include(CheckPIESupported)
@ -291,6 +308,7 @@ endif()
message(" port mapping:")
message(" - using NAT-PMP .................... ${WITH_NATPMP}")
message(" - using UPnP ....................... ${WITH_MINIUPNPC}")
message(" ZeroMQ .............................. ${WITH_ZMQ}")
message("Tests:")
message(" test_bitcoin ........................ ${BUILD_TESTS}")
message("")

View file

@ -78,6 +78,9 @@ target_link_libraries(bitcoin_consensus
secp256k1
)
if(WITH_ZMQ)
add_subdirectory(zmq)
endif()
# Home for common functionality shared by different executables and libraries.
# Similar to `bitcoin_util` library, but higher-level.
@ -270,6 +273,7 @@ target_link_libraries(bitcoin_node
$<TARGET_NAME_IF_EXISTS:libevent::pthreads>
$<TARGET_NAME_IF_EXISTS:NATPMP::NATPMP>
$<TARGET_NAME_IF_EXISTS:MiniUPnPc::MiniUPnPc>
$<TARGET_NAME_IF_EXISTS:bitcoin_zmq>
)

24
src/zmq/CMakeLists.txt Normal file
View file

@ -0,0 +1,24 @@
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.
add_library(bitcoin_zmq STATIC EXCLUDE_FROM_ALL
zmqabstractnotifier.cpp
zmqnotificationinterface.cpp
zmqpublishnotifier.cpp
zmqrpc.cpp
zmqutil.cpp
)
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>
)