From d2fda82b4954f4af7e7d340cf42b9cb34d96cde1 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Mon, 29 Apr 2024 21:23:42 +0100 Subject: [PATCH] cmake: Add `libzmq` optional package support --- CMakeLists.txt | 18 ++++++++++++++++++ src/CMakeLists.txt | 4 ++++ src/zmq/CMakeLists.txt | 24 ++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 src/zmq/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index d13909a6739..6630d75d18e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 + $<$: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("") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1f0b09e2c56..ec26f372c59 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 $ $ $ + $ ) diff --git a/src/zmq/CMakeLists.txt b/src/zmq/CMakeLists.txt new file mode 100644 index 00000000000..8ecb236b460 --- /dev/null +++ b/src/zmq/CMakeLists.txt @@ -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 + $<$,$>:ZMQ_STATIC> +) +target_link_libraries(bitcoin_zmq + PRIVATE + core_interface + univalue + $ + $ +)