diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f72f5ec013cf..6652104157c06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,7 @@ include(TristateOption) tristate_option(CCACHE "Use ccache for compiling." "if ccache is found." AUTO) tristate_option(WITH_NATPMP "Enable NAT-PMP." "if libnatpmp is found." AUTO) tristate_option(WITH_MINIUPNPC "Enable UPnP." "if libminiupnpc is found." AUTO) +tristate_option(WITH_ZMQ "Enable ZMQ notifications." "if libzmq is found." AUTO) if(CXX20) set(CMAKE_CXX_STANDARD 20) @@ -145,6 +146,7 @@ message(" bitcoind ............................ ${BUILD_DAEMON}") message("Optional packages:") message(" NAT-PMP ............................. ${WITH_NATPMP}") message(" UPnP ................................ ${WITH_MINIUPNPC}") +message(" ZeroMQ .............................. ${WITH_ZMQ}") message("") if(CMAKE_CROSSCOMPILING) set(cross_status "TRUE, for ${CMAKE_SYSTEM_NAME}, ${CMAKE_SYSTEM_PROCESSOR}") diff --git a/cmake/optional.cmake b/cmake/optional.cmake index 33a78b3788570..f7d49c07a5c87 100644 --- a/cmake/optional.cmake +++ b/cmake/optional.cmake @@ -57,3 +57,31 @@ if(WITH_MINIUPNPC) message(FATAL_ERROR "libminiupnpc requested, but not found.") endif() endif() + +if(WITH_ZMQ) + if(MSVC) + find_package(ZeroMQ CONFIG) + else() + # The ZeroMQ project has provided config files since v4.2.2. + # TODO: Switch to find_package(ZeroMQ) at some point in the future. + include(CrossPkgConfig) + cross_pkg_check_modules(libzmq IMPORTED_TARGET libzmq>=4) + if(libzmq_FOUND) + set_property(TARGET PkgConfig::libzmq APPEND PROPERTY + INTERFACE_COMPILE_DEFINITIONS $<$:ZMQ_STATIC> + ) + set_property(TARGET PkgConfig::libzmq APPEND PROPERTY + INTERFACE_LINK_LIBRARIES $<$:iphlpapi;ws2_32> + ) + endif() + endif() + if(TARGET libzmq OR TARGET PkgConfig::libzmq) + set(WITH_ZMQ ON) + elseif(WITH_ZMQ STREQUAL "AUTO") + message(WARNING "libzmq not found, disabling.\n" + "To skip libzmq check, use \"-DWITH_ZMQ=OFF\".\n") + set(WITH_ZMQ OFF) + else() + message(FATAL_ERROR "libzmq requested, but not found.") + endif() +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 14e9cfdcd6e22..b5afba7b6e59a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -29,6 +29,9 @@ add_library(bitcoin_consensus OBJECT EXCLUDE_FROM_ALL ) target_link_libraries(bitcoin_consensus PRIVATE secp256k1) +if(WITH_ZMQ) + add_subdirectory(zmq EXCLUDE_FROM_ALL) +endif() # Home for common functionality shared by different executables and libraries. # Similar to `bitcoin_util` library, but higher-level. @@ -188,6 +191,7 @@ target_link_libraries(bitcoin_node $ $ $ + $ ) diff --git a/src/zmq/CMakeLists.txt b/src/zmq/CMakeLists.txt new file mode 100644 index 0000000000000..39cef32fceb42 --- /dev/null +++ b/src/zmq/CMakeLists.txt @@ -0,0 +1,22 @@ +# Copyright (c) 2023 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +add_library(bitcoin_zmq STATIC + zmqabstractnotifier.cpp + zmqnotificationinterface.cpp + zmqpublishnotifier.cpp + zmqrpc.cpp + zmqutil.cpp +) +target_compile_definitions(bitcoin_zmq + INTERFACE + ENABLE_ZMQ=1 +) +target_link_libraries(bitcoin_zmq + PRIVATE + leveldb + univalue + $ + $ +)