diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 2e9d67be5c222..b425fc4ea1e64 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -227,7 +227,7 @@ jobs: - name: Generate build system run: | - cmake -B build -DCMAKE_C_COMPILER=gcc-11 -DCMAKE_CXX_COMPILER=g++-11 -DBoost_INCLUDE_DIR="${PWD}/${{ matrix.conf.boost_archive }}" -DENABLE_WALLET=ON -DWITH_EXTERNAL_SIGNER=ON -DWITH_MINIUPNPC=ON -DWITH_NATPMP=ON -DWITH_ZMQ=ON -DWITH_USDT=ON -DWERROR=ON + cmake -B build --preset ci-linux -DCMAKE_C_COMPILER=gcc-11 -DCMAKE_CXX_COMPILER=g++-11 -DBoost_INCLUDE_DIR="${PWD}/${{ matrix.conf.boost_archive }}" - name: Build working-directory: build @@ -576,7 +576,7 @@ jobs: - name: Generate build system run: | - ${{ matrix.xcode.configure_env }} cmake -B build -DWERROR=ON + ${{ matrix.xcode.configure_env }} cmake -B build --preset ci-darwin - name: Build env: diff --git a/CMakeLists.txt b/CMakeLists.txt index bc8dccaea9b47..824cbfea14144 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,9 +70,32 @@ option(REDUCE_EXPORTS "Attempt to reduce exported symbols in the resulting execu option(WERROR "Treat compiler warnings as errors." OFF) 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) + +option(WITH_NATPMP "Enable NAT-PMP." OFF) +if(WITH_NATPMP) + find_package(NATPMP MODULE REQUIRED) +endif() + +option(WITH_MINIUPNPC "Enable UPnP." OFF) +if(WITH_MINIUPNPC) + find_package(MiniUPnPc MODULE REQUIRED) +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. + # 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 + $<$:iphlpapi;ws2_32> + ) + endif() +endif() + tristate_option(WITH_USDT "Enable tracepoints for Userspace, Statically Defined Tracing." "if sys/sdt.h is found." @@ -84,7 +107,12 @@ tristate_option(WITH_EXTERNAL_SIGNER AUTO ) tristate_option(WITH_QRENCODE "Enable QR code support." "if libqrencode is found." AUTO) -tristate_option(MULTIPROCESS "Build multiprocess bitcoin-node, bitcoin-wallet, and bitcoin-gui executables in addition to monolithic bitcoind and bitcoin-qt executables. Requires libmultiprocess library. Experimental." "if libmultiprocess is found." OFF) + +option(MULTIPROCESS "Build multiprocess bitcoin-node, bitcoin-wallet, and bitcoin-gui executables in addition to monolithic bitcoind and bitcoin-qt executables. Requires libmultiprocess library. Experimental." OFF) +if(MULTIPROCESS) + find_package(Libmultiprocess CONFIG REQUIRED) + find_package(LibmultiprocessGen CONFIG REQUIRED) +endif() option(BUILD_TESTS "Build test_bitcoin executable." ON) cmake_dependent_option(BUILD_GUI_TESTS "Build test_bitcoin-qt executable." ON "BUILD_TESTS" OFF) diff --git a/CMakePresets.json b/CMakePresets.json index b5bcd3238f6c5..6078f81b02bb4 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -2,6 +2,48 @@ "version": 3, "cmakeMinimumRequired": {"major": 3, "minor": 21, "patch": 0}, "configurePresets": [ + { + "name": "ci-common", + "hidden": true, + "cacheVariables": { + "ENABLE_WALLET": "ON", + "WITH_SQLITE": "ON", + "WITH_BDB": "ON", + "WITH_NATPMP": "ON", + "WITH_MINIUPNPC": "ON", + "WITH_ZMQ": "ON", + "WERROR": "ON", + "CCACHE": "ON" + } + }, + { + "name": "ci-linux", + "inherits": "ci-common", + "displayName": "Build for CI tests on Linux", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + }, + "cacheVariables": { + "WITH_EXTERNAL_SIGNER": "ON", + "WITH_USDT": "ON" + } + }, + { + "name": "ci-darwin", + "inherits": "ci-common", + "displayName": "Build for CI tests on macOS", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Darwin" + }, + "cacheVariables": { + "WITH_GUI": "Qt5", + "WITH_EXTERNAL_SIGNER": "ON" + } + }, { "name": "vs2022", "displayName": "Build using 'Visual Studio 17 2022' generator and 'x64-windows' triplet", diff --git a/cmake/optional.cmake b/cmake/optional.cmake index f2a0c24f484bb..b9e167a36abe4 100644 --- a/cmake/optional.cmake +++ b/cmake/optional.cmake @@ -50,60 +50,6 @@ if(CCACHE) mark_as_advanced(CCACHE_COMMAND) endif() -if(WITH_NATPMP) - find_package(NATPMP MODULE) - if(NATPMP_FOUND) - set(WITH_NATPMP ON) - elseif(WITH_NATPMP STREQUAL "AUTO") - message(WARNING "libnatpmp not found, disabling.\n" - "To skip libnatpmp check, use \"-DWITH_NATPMP=OFF\".\n") - set(WITH_NATPMP OFF) - else() - message(FATAL_ERROR "libnatpmp requested, but not found.") - endif() -endif() - -if(WITH_MINIUPNPC) - find_package(MiniUPnPc MODULE) - if(MiniUPnPc_FOUND) - set(WITH_MINIUPNPC ON) - elseif(WITH_MINIUPNPC STREQUAL "AUTO") - message(WARNING "libminiupnpc not found, disabling.\n" - "To skip libminiupnpc check, use \"-DWITH_MINIUPNPC=OFF\".\n") - set(WITH_MINIUPNPC OFF) - else() - 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 AND TARGET PkgConfig::libzmq) - target_compile_definitions(PkgConfig::libzmq INTERFACE - $<$:ZMQ_STATIC> - ) - target_link_libraries(PkgConfig::libzmq INTERFACE - $<$: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 @@ -189,12 +135,13 @@ else() endif() if(WITH_GUI AND WITH_QRENCODE) - if(MSVC) + if(VCPKG_TARGET_TRIPLET) # TODO: vcpkg fails to build libqrencode package due to # the build error in its libiconv dependency. # See: https://github.com/microsoft/vcpkg/issues/36924. else() - cross_pkg_check_modules(libqrencode libqrencode IMPORTED_TARGET) + include(CrossPkgConfig) + cross_pkg_check_modules(libqrencode IMPORTED_TARGET libqrencode) endif() if(TARGET PkgConfig::libqrencode) set_target_properties(PkgConfig::libqrencode PROPERTIES @@ -207,15 +154,3 @@ if(WITH_GUI AND WITH_QRENCODE) message(FATAL_ERROR "libqrencode requested, but not found.") endif() endif() - -if(MULTIPROCESS) - find_package(Libmultiprocess CONFIG) - find_package(LibmultiprocessGen CONFIG) - if(TARGET Libmultiprocess::multiprocess AND TARGET Libmultiprocess::mpgen) - set(MULTIPROCESS ON) - elseif(MULTIPROCESS STREQUAL "AUTO") - set(MULTIPROCESS OFF) - else() - message(FATAL_ERROR "\"-DMULTIPROCESS=ON\" specified, but libmultiprocess library was not found.") - endif() -endif() diff --git a/depends/toolchain.cmake.in b/depends/toolchain.cmake.in index f5178585c1529..3ccaf8fdf0c78 100644 --- a/depends/toolchain.cmake.in +++ b/depends/toolchain.cmake.in @@ -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") @@ -138,27 +140,31 @@ if(NOT WITH_SQLITE AND "@no_sqlite@" STREQUAL "1") set(WITH_SQLITE OFF CACHE STRING "Enable SQLite wallet support.") endif() -if(NOT WITH_MINIUPNPC AND "@no_upnp@" STREQUAL "1") - set(WITH_MINIUPNPC OFF CACHE STRING "Enable UPnP.") +if("@no_upnp@") + set(WITH_MINIUPNPC OFF CACHE BOOL "") +else() + set(WITH_MINIUPNPC ON CACHE BOOL "") endif() -if(NOT WITH_NATPMP AND "@no_natpmp@" STREQUAL "1") - set(WITH_NATPMP OFF CACHE STRING "Enable NAT-PMP.") +if("@no_natpmp@") + set(WITH_NATPMP OFF CACHE BOOL "") +else() + set(WITH_NATPMP ON CACHE BOOL "") endif() if(NOT WITH_USDT AND "@no_usdt@" STREQUAL "1") set(WITH_USDT OFF CACHE STRING "Enable tracepoints for Userspace, Statically Defined Tracing.") endif() -if(NOT HARDENING AND "@no_harden@" STREQUAL "1") - set(HARDENING OFF CACHE STRING "Attempt to harden the resulting executables.") +if("@no_harden@") + set(HARDENING OFF CACHE BOOL "") +else() + set(HARDENING ON CACHE BOOL "") endif() if("@multiprocess@" STREQUAL "1") - if(NOT MULTIPROCESS) - set(MULTIPROCESS ON CACHE STRING "") - endif() - if(NOT LibmultiprocessGen_DIR) - set(LibmultiprocessGen_DIR "${CMAKE_FIND_ROOT_PATH}/native/lib/cmake/LibmultiprocessGen" CACHE PATH "") - endif() + set(MULTIPROCESS ON CACHE BOOL "") + set(LibmultiprocessGen_DIR "${CMAKE_FIND_ROOT_PATH}/native/lib/cmake/LibmultiprocessGen" CACHE PATH "") +else() + set(MULTIPROCESS OFF CACHE BOOL "") endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2100664b4c200..6409965a1f3c0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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. diff --git a/src/zmq/CMakeLists.txt b/src/zmq/CMakeLists.txt index 61fdaa819ff1e..8ecb236b46003 100644 --- a/src/zmq/CMakeLists.txt +++ b/src/zmq/CMakeLists.txt @@ -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 @@ -12,6 +12,8 @@ add_library(bitcoin_zmq STATIC target_compile_definitions(bitcoin_zmq INTERFACE ENABLE_ZMQ=1 + PRIVATE + $<$,$>:ZMQ_STATIC> ) target_link_libraries(bitcoin_zmq PRIVATE