Skip to content

Commit

Permalink
cmake [KILL 3-STATE]: Switch WITH_ZMQ to boolean w/ default OFF
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Apr 22, 2024
1 parent 5bfecf4 commit 732b4e9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 33 deletions.
16 changes: 15 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,21 @@ if(WITH_MINIUPNPC)
find_package(MiniUPnPc MODULE REQUIRED)
endif()

tristate_option(WITH_ZMQ "Enable ZMQ notifications." "if libzmq is found." AUTO)
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.
include(CrossPkgConfig)
cross_pkg_check_modules(libzmq REQUIRED IMPORTED_TARGET libzmq>=4)
target_link_libraries(PkgConfig::libzmq INTERFACE
$<$<PLATFORM_ID:Windows>:iphlpapi;ws2_32>
)
endif()
endif()

tristate_option(WITH_USDT
"Enable tracepoints for Userspace, Statically Defined Tracing."
"if sys/sdt.h is found."
Expand Down
28 changes: 0 additions & 28 deletions cmake/optional.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,34 +50,6 @@ if(CCACHE)
mark_as_advanced(CCACHE_COMMAND)
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 AND TARGET PkgConfig::libzmq)
target_compile_definitions(PkgConfig::libzmq INTERFACE
$<$<PLATFORM_ID:Windows>:ZMQ_STATIC>
)
target_link_libraries(PkgConfig::libzmq INTERFACE
$<$<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()

if(WITH_USDT)
find_path(SystemTap_INCLUDE_DIR
NAMES sys/sdt.h
Expand Down
6 changes: 4 additions & 2 deletions depends/toolchain.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ if(NOT WITH_QRENCODE AND "@no_qr@" STREQUAL "1")
set(WITH_QRENCODE OFF CACHE STRING "Enable QR code support.")
endif()

if(NOT WITH_ZMQ AND "@no_zmq@" STREQUAL "1")
set(WITH_ZMQ OFF CACHE STRING "Enable ZMQ notifications.")
if("@no_zmq@")
set(WITH_ZMQ OFF CACHE BOOL "")
else()
set(WITH_ZMQ ON CACHE BOOL "")
endif()

if(NOT ENABLE_WALLET AND "@no_wallet@" STREQUAL "1")
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ target_link_libraries(bitcoin_consensus
)

if(WITH_ZMQ)
add_subdirectory(zmq EXCLUDE_FROM_ALL)
add_subdirectory(zmq)
endif()

# Home for common functionality shared by different executables and libraries.
Expand Down
4 changes: 3 additions & 1 deletion src/zmq/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.

add_library(bitcoin_zmq STATIC
add_library(bitcoin_zmq STATIC EXCLUDE_FROM_ALL
zmqabstractnotifier.cpp
zmqnotificationinterface.cpp
zmqpublishnotifier.cpp
Expand All @@ -12,6 +12,8 @@ add_library(bitcoin_zmq STATIC
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
Expand Down

0 comments on commit 732b4e9

Please sign in to comment.