Skip to content

Commit a012404

Browse files
committed
Merge #161: cmake: Switch from tri-state options to boolean. Stage ONE
df4e46b cmake [KILL 3-STATE]: Switch `MULTIPROCESS` to boolean w/ default OFF (Hennadii Stepanov) 732b4e9 cmake [KILL 3-STATE]: Switch `WITH_ZMQ` to boolean w/ default OFF (Hennadii Stepanov) 5bfecf4 cmake [KILL 3-STATE]: Switch `WITH_MINIUPNPC` to boolean w/ default OFF (Hennadii Stepanov) a4d6a0c cmake [KILL 3-STATE]: Switch `WITH_NATPMP` to boolean w/ default OFF (Hennadii Stepanov) dc20cdf fixup! build: Generate `share/toolchain.cmake` in depends (Hennadii Stepanov) 63bbe26 cmake: Add CI-specific presets (Hennadii Stepanov) Pull request description: This PR partially pulled from #83 with options, which default values seem non-controversial. As a bonus, the help string duplication in `depends/toolchain.cmake.in` has been eliminated for the touched lines. The [**Autotools vs CMake Feature Parity Table**](https://gist.github.com/hebasto/2ef97d3a726bfce08ded9df07f7dab5e) has been updated as well. ACKs for top commit: vasild: ACK df4e46b Tree-SHA512: c1079b929944b0f7ca60436c12ee655c4235ada03ebace25d091ef0b938e3beb2f48beea529b7205cd8ecec9d7377e6b6d9e0368c8902dd6e06303cacbc4747f
2 parents 9253cb7 + df4e46b commit a012404

File tree

7 files changed

+100
-88
lines changed

7 files changed

+100
-88
lines changed

.github/workflows/cmake.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ jobs:
227227

228228
- name: Generate build system
229229
run: |
230-
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
230+
cmake -B build --preset ci-linux -DCMAKE_C_COMPILER=gcc-11 -DCMAKE_CXX_COMPILER=g++-11 -DBoost_INCLUDE_DIR="${PWD}/${{ matrix.conf.boost_archive }}"
231231
232232
- name: Build
233233
working-directory: build
@@ -576,7 +576,7 @@ jobs:
576576

577577
- name: Generate build system
578578
run: |
579-
${{ matrix.xcode.configure_env }} cmake -B build -DWERROR=ON
579+
${{ matrix.xcode.configure_env }} cmake -B build --preset ci-darwin
580580
581581
- name: Build
582582
env:

CMakeLists.txt

+32-4
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,32 @@ option(REDUCE_EXPORTS "Attempt to reduce exported symbols in the resulting execu
7070
option(WERROR "Treat compiler warnings as errors." OFF)
7171

7272
tristate_option(CCACHE "Use ccache for compiling." "if ccache is found." AUTO)
73-
tristate_option(WITH_NATPMP "Enable NAT-PMP." "if libnatpmp is found." AUTO)
74-
tristate_option(WITH_MINIUPNPC "Enable UPnP." "if libminiupnpc is found." AUTO)
75-
tristate_option(WITH_ZMQ "Enable ZMQ notifications." "if libzmq is found." AUTO)
73+
74+
option(WITH_NATPMP "Enable NAT-PMP." OFF)
75+
if(WITH_NATPMP)
76+
find_package(NATPMP MODULE REQUIRED)
77+
endif()
78+
79+
option(WITH_MINIUPNPC "Enable UPnP." OFF)
80+
if(WITH_MINIUPNPC)
81+
find_package(MiniUPnPc MODULE REQUIRED)
82+
endif()
83+
84+
option(WITH_ZMQ "Enable ZMQ notifications." OFF)
85+
if(WITH_ZMQ)
86+
if(VCPKG_TARGET_TRIPLET)
87+
find_package(ZeroMQ CONFIG REQUIRED)
88+
else()
89+
# The ZeroMQ project has provided config files since v4.2.2.
90+
# TODO: Switch to find_package(ZeroMQ) at some point in the future.
91+
include(CrossPkgConfig)
92+
cross_pkg_check_modules(libzmq REQUIRED IMPORTED_TARGET libzmq>=4)
93+
target_link_libraries(PkgConfig::libzmq INTERFACE
94+
$<$<PLATFORM_ID:Windows>:iphlpapi;ws2_32>
95+
)
96+
endif()
97+
endif()
98+
7699
tristate_option(WITH_USDT
77100
"Enable tracepoints for Userspace, Statically Defined Tracing."
78101
"if sys/sdt.h is found."
@@ -84,7 +107,12 @@ tristate_option(WITH_EXTERNAL_SIGNER
84107
AUTO
85108
)
86109
tristate_option(WITH_QRENCODE "Enable QR code support." "if libqrencode is found." AUTO)
87-
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)
110+
111+
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)
112+
if(MULTIPROCESS)
113+
find_package(Libmultiprocess CONFIG REQUIRED)
114+
find_package(LibmultiprocessGen CONFIG REQUIRED)
115+
endif()
88116

89117
option(BUILD_TESTS "Build test_bitcoin executable." ON)
90118
cmake_dependent_option(BUILD_GUI_TESTS "Build test_bitcoin-qt executable." ON "BUILD_TESTS" OFF)

CMakePresets.json

+42
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,48 @@
22
"version": 3,
33
"cmakeMinimumRequired": {"major": 3, "minor": 21, "patch": 0},
44
"configurePresets": [
5+
{
6+
"name": "ci-common",
7+
"hidden": true,
8+
"cacheVariables": {
9+
"ENABLE_WALLET": "ON",
10+
"WITH_SQLITE": "ON",
11+
"WITH_BDB": "ON",
12+
"WITH_NATPMP": "ON",
13+
"WITH_MINIUPNPC": "ON",
14+
"WITH_ZMQ": "ON",
15+
"WERROR": "ON",
16+
"CCACHE": "ON"
17+
}
18+
},
19+
{
20+
"name": "ci-linux",
21+
"inherits": "ci-common",
22+
"displayName": "Build for CI tests on Linux",
23+
"condition": {
24+
"type": "equals",
25+
"lhs": "${hostSystemName}",
26+
"rhs": "Linux"
27+
},
28+
"cacheVariables": {
29+
"WITH_EXTERNAL_SIGNER": "ON",
30+
"WITH_USDT": "ON"
31+
}
32+
},
33+
{
34+
"name": "ci-darwin",
35+
"inherits": "ci-common",
36+
"displayName": "Build for CI tests on macOS",
37+
"condition": {
38+
"type": "equals",
39+
"lhs": "${hostSystemName}",
40+
"rhs": "Darwin"
41+
},
42+
"cacheVariables": {
43+
"WITH_GUI": "Qt5",
44+
"WITH_EXTERNAL_SIGNER": "ON"
45+
}
46+
},
547
{
648
"name": "vs2022",
749
"displayName": "Build using 'Visual Studio 17 2022' generator and 'x64-windows' triplet",

cmake/optional.cmake

-66
Original file line numberDiff line numberDiff line change
@@ -50,60 +50,6 @@ if(CCACHE)
5050
mark_as_advanced(CCACHE_COMMAND)
5151
endif()
5252

53-
if(WITH_NATPMP)
54-
find_package(NATPMP MODULE)
55-
if(NATPMP_FOUND)
56-
set(WITH_NATPMP ON)
57-
elseif(WITH_NATPMP STREQUAL "AUTO")
58-
message(WARNING "libnatpmp not found, disabling.\n"
59-
"To skip libnatpmp check, use \"-DWITH_NATPMP=OFF\".\n")
60-
set(WITH_NATPMP OFF)
61-
else()
62-
message(FATAL_ERROR "libnatpmp requested, but not found.")
63-
endif()
64-
endif()
65-
66-
if(WITH_MINIUPNPC)
67-
find_package(MiniUPnPc MODULE)
68-
if(MiniUPnPc_FOUND)
69-
set(WITH_MINIUPNPC ON)
70-
elseif(WITH_MINIUPNPC STREQUAL "AUTO")
71-
message(WARNING "libminiupnpc not found, disabling.\n"
72-
"To skip libminiupnpc check, use \"-DWITH_MINIUPNPC=OFF\".\n")
73-
set(WITH_MINIUPNPC OFF)
74-
else()
75-
message(FATAL_ERROR "libminiupnpc requested, but not found.")
76-
endif()
77-
endif()
78-
79-
if(WITH_ZMQ)
80-
if(MSVC)
81-
find_package(ZeroMQ CONFIG)
82-
else()
83-
# The ZeroMQ project has provided config files since v4.2.2.
84-
# TODO: Switch to find_package(ZeroMQ) at some point in the future.
85-
include(CrossPkgConfig)
86-
cross_pkg_check_modules(libzmq IMPORTED_TARGET libzmq>=4)
87-
if(libzmq_FOUND AND TARGET PkgConfig::libzmq)
88-
target_compile_definitions(PkgConfig::libzmq INTERFACE
89-
$<$<PLATFORM_ID:Windows>:ZMQ_STATIC>
90-
)
91-
target_link_libraries(PkgConfig::libzmq INTERFACE
92-
$<$<PLATFORM_ID:Windows>:iphlpapi;ws2_32>
93-
)
94-
endif()
95-
endif()
96-
if(TARGET libzmq OR TARGET PkgConfig::libzmq)
97-
set(WITH_ZMQ ON)
98-
elseif(WITH_ZMQ STREQUAL "AUTO")
99-
message(WARNING "libzmq not found, disabling.\n"
100-
"To skip libzmq check, use \"-DWITH_ZMQ=OFF\".\n")
101-
set(WITH_ZMQ OFF)
102-
else()
103-
message(FATAL_ERROR "libzmq requested, but not found.")
104-
endif()
105-
endif()
106-
10753
if(WITH_USDT)
10854
find_path(SystemTap_INCLUDE_DIR
10955
NAMES sys/sdt.h
@@ -208,15 +154,3 @@ if(WITH_GUI AND WITH_QRENCODE)
208154
message(FATAL_ERROR "libqrencode requested, but not found.")
209155
endif()
210156
endif()
211-
212-
if(MULTIPROCESS)
213-
find_package(Libmultiprocess CONFIG)
214-
find_package(LibmultiprocessGen CONFIG)
215-
if(TARGET Libmultiprocess::multiprocess AND TARGET Libmultiprocess::mpgen)
216-
set(MULTIPROCESS ON)
217-
elseif(MULTIPROCESS STREQUAL "AUTO")
218-
set(MULTIPROCESS OFF)
219-
else()
220-
message(FATAL_ERROR "\"-DMULTIPROCESS=ON\" specified, but libmultiprocess library was not found.")
221-
endif()
222-
endif()

depends/toolchain.cmake.in

+20-14
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ if(NOT WITH_QRENCODE AND "@no_qr@" STREQUAL "1")
122122
set(WITH_QRENCODE OFF CACHE STRING "Enable QR code support.")
123123
endif()
124124

125-
if(NOT WITH_ZMQ AND "@no_zmq@" STREQUAL "1")
126-
set(WITH_ZMQ OFF CACHE STRING "Enable ZMQ notifications.")
125+
if("@no_zmq@")
126+
set(WITH_ZMQ OFF CACHE BOOL "")
127+
else()
128+
set(WITH_ZMQ ON CACHE BOOL "")
127129
endif()
128130

129131
if(NOT ENABLE_WALLET AND "@no_wallet@" STREQUAL "1")
@@ -138,27 +140,31 @@ if(NOT WITH_SQLITE AND "@no_sqlite@" STREQUAL "1")
138140
set(WITH_SQLITE OFF CACHE STRING "Enable SQLite wallet support.")
139141
endif()
140142

141-
if(NOT WITH_MINIUPNPC AND "@no_upnp@" STREQUAL "1")
142-
set(WITH_MINIUPNPC OFF CACHE STRING "Enable UPnP.")
143+
if("@no_upnp@")
144+
set(WITH_MINIUPNPC OFF CACHE BOOL "")
145+
else()
146+
set(WITH_MINIUPNPC ON CACHE BOOL "")
143147
endif()
144148

145-
if(NOT WITH_NATPMP AND "@no_natpmp@" STREQUAL "1")
146-
set(WITH_NATPMP OFF CACHE STRING "Enable NAT-PMP.")
149+
if("@no_natpmp@")
150+
set(WITH_NATPMP OFF CACHE BOOL "")
151+
else()
152+
set(WITH_NATPMP ON CACHE BOOL "")
147153
endif()
148154

149155
if(NOT WITH_USDT AND "@no_usdt@" STREQUAL "1")
150156
set(WITH_USDT OFF CACHE STRING "Enable tracepoints for Userspace, Statically Defined Tracing.")
151157
endif()
152158

153-
if(NOT HARDENING AND "@no_harden@" STREQUAL "1")
154-
set(HARDENING OFF CACHE STRING "Attempt to harden the resulting executables.")
159+
if("@no_harden@")
160+
set(HARDENING OFF CACHE BOOL "")
161+
else()
162+
set(HARDENING ON CACHE BOOL "")
155163
endif()
156164

157165
if("@multiprocess@" STREQUAL "1")
158-
if(NOT MULTIPROCESS)
159-
set(MULTIPROCESS ON CACHE STRING "")
160-
endif()
161-
if(NOT LibmultiprocessGen_DIR)
162-
set(LibmultiprocessGen_DIR "${CMAKE_FIND_ROOT_PATH}/native/lib/cmake/LibmultiprocessGen" CACHE PATH "")
163-
endif()
166+
set(MULTIPROCESS ON CACHE BOOL "")
167+
set(LibmultiprocessGen_DIR "${CMAKE_FIND_ROOT_PATH}/native/lib/cmake/LibmultiprocessGen" CACHE PATH "")
168+
else()
169+
set(MULTIPROCESS OFF CACHE BOOL "")
164170
endif()

src/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ target_link_libraries(bitcoin_consensus
6868
)
6969

7070
if(WITH_ZMQ)
71-
add_subdirectory(zmq EXCLUDE_FROM_ALL)
71+
add_subdirectory(zmq)
7272
endif()
7373

7474
# Home for common functionality shared by different executables and libraries.

src/zmq/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Distributed under the MIT software license, see the accompanying
33
# file COPYING or https://opensource.org/license/mit/.
44

5-
add_library(bitcoin_zmq STATIC
5+
add_library(bitcoin_zmq STATIC EXCLUDE_FROM_ALL
66
zmqabstractnotifier.cpp
77
zmqnotificationinterface.cpp
88
zmqpublishnotifier.cpp
@@ -12,6 +12,8 @@ add_library(bitcoin_zmq STATIC
1212
target_compile_definitions(bitcoin_zmq
1313
INTERFACE
1414
ENABLE_ZMQ=1
15+
PRIVATE
16+
$<$<AND:$<PLATFORM_ID:Windows>,$<CXX_COMPILER_ID:GNU>>:ZMQ_STATIC>
1517
)
1618
target_link_libraries(bitcoin_zmq
1719
PRIVATE

0 commit comments

Comments
 (0)