Skip to content

Commit

Permalink
cmake: Add libzmq optional package support
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Apr 5, 2023
1 parent 142bbc8 commit 33e90df
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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)
Expand Down Expand Up @@ -142,6 +143,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}")
Expand Down
26 changes: 26 additions & 0 deletions cmake/optional.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,29 @@ if(WITH_MINIUPNPC)
message(FATAL_ERROR "libminiupnpc requested, but not found.")
endif()
endif()

include(CrossPkgConfig)
if(WITH_ZMQ)
if(MSVC)
find_package(ZeroMQ CONFIG)
else()
cross_pkg_check_modules(libzmq IMPORTED_TARGET libzmq>=4)
if(libzmq_FOUND)
set_property(TARGET PkgConfig::libzmq APPEND PROPERTY
INTERFACE_COMPILE_DEFINITIONS $<$<PLATFORM_ID:Windows>:ZMQ_STATIC>
)
set_property(TARGET PkgConfig::libzmq APPEND PROPERTY
INTERFACE_LINK_LIBRARIES $<$<PLATFORM_ID:Windows>: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()
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -188,6 +191,7 @@ target_link_libraries(bitcoin_node
$<TARGET_NAME_IF_EXISTS:PkgConfig::libevent_pthreads>
$<TARGET_NAME_IF_EXISTS:NATPMP::NATPMP>
$<TARGET_NAME_IF_EXISTS:MiniUPnPc::MiniUPnPc>
$<TARGET_NAME_IF_EXISTS:bitcoin_zmq>
)


Expand Down
22 changes: 22 additions & 0 deletions src/zmq/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
$<TARGET_NAME_IF_EXISTS:libzmq>
$<TARGET_NAME_IF_EXISTS:PkgConfig::libzmq>
)

0 comments on commit 33e90df

Please sign in to comment.