diff --git a/CMakeLists.txt b/CMakeLists.txt index b8fdeefbdae..a8921a0ca66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -133,16 +133,7 @@ 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. - # However, mainstream distributions do not yet provide CMake - # config files for ZeroMQ packages. If they do in the future, - # find_package(ZeroMQ) may be used instead. - find_package(PkgConfig REQUIRED) - pkg_check_modules(libzmq REQUIRED IMPORTED_TARGET libzmq>=4) - endif() + find_package(ZeroMQ 4.0.0 MODULE REQUIRED) endif() option(WITH_USDT "Enable tracepoints for Userspace, Statically Defined Tracing." OFF) diff --git a/cmake/module/FindZeroMQ.cmake b/cmake/module/FindZeroMQ.cmake new file mode 100644 index 00000000000..eecd9b24536 --- /dev/null +++ b/cmake/module/FindZeroMQ.cmake @@ -0,0 +1,41 @@ +# Copyright (c) 2024-present The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or https://opensource.org/license/mit/. + +#[=======================================================================[ +FindZeroMQ +---------- + +Finds the ZeroMQ headers and library. + +This is a wrapper around find_package()/pkg_check_modules() commands that: + - facilitates searching in various build environments + - prints a standard log message + +#]=======================================================================] + +include(FindPackageHandleStandardArgs) +find_package(ZeroMQ ${ZeroMQ_FIND_VERSION} NO_MODULE QUIET) +if(ZeroMQ_FOUND) + find_package_handle_standard_args(ZeroMQ + REQUIRED_VARS ZeroMQ_DIR + VERSION_VAR ZeroMQ_VERSION + ) + if(TARGET libzmq) + add_library(zeromq ALIAS libzmq) + elseif(TARGET libzmq-static) + add_library(zeromq ALIAS libzmq-static) + endif() + mark_as_advanced(ZeroMQ_DIR) +else() + find_package(PkgConfig REQUIRED) + pkg_check_modules(libzmq QUIET + IMPORTED_TARGET + libzmq>=${ZeroMQ_FIND_VERSION} + ) + find_package_handle_standard_args(ZeroMQ + REQUIRED_VARS libzmq_LIBRARY_DIRS + VERSION_VAR libzmq_VERSION + ) + add_library(zeromq ALIAS PkgConfig::libzmq) +endif() diff --git a/src/zmq/CMakeLists.txt b/src/zmq/CMakeLists.txt index 8ecb236b460..19ac722b7ae 100644 --- a/src/zmq/CMakeLists.txt +++ b/src/zmq/CMakeLists.txt @@ -12,13 +12,10 @@ add_library(bitcoin_zmq STATIC EXCLUDE_FROM_ALL target_compile_definitions(bitcoin_zmq INTERFACE ENABLE_ZMQ=1 - PRIVATE - $<$,$>:ZMQ_STATIC> ) target_link_libraries(bitcoin_zmq PRIVATE core_interface univalue - $ - $ + zeromq )