From 7f67ed7a1eda7449d5c723abeb702e495bf1117b Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sat, 14 Sep 2024 15:40:07 +0100 Subject: [PATCH] cmake: Add `FindZeroMQ` module --- CMakeLists.txt | 11 +--------- cmake/module/FindZeroMQ.cmake | 41 +++++++++++++++++++++++++++++++++++ src/zmq/CMakeLists.txt | 5 +---- 3 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 cmake/module/FindZeroMQ.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index b8fdeefbdae8b..a8921a0ca6614 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 0000000000000..eecd9b245362c --- /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 8ecb236b46003..8e6b2399e4bd1 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 + zeromq univalue - $ - $ )