@@ -19,6 +19,10 @@ if(POLICY CMP0171)
19
19
cmake_policy (SET CMP0171 NEW )
20
20
endif ()
21
21
22
+ # When adjusting CMake flag variables, we must not override those explicitly
23
+ # set by the user. These are a subset of the CACHE_VARIABLES property.
24
+ get_directory_property (precious_variables CACHE_VARIABLES )
25
+
22
26
#=============================
23
27
# Project / Package metadata
24
28
#=============================
@@ -90,6 +94,7 @@ endif()
90
94
#=============================
91
95
include (CMakeDependentOption )
92
96
# When adding a new option, end the <help_text> with a full stop for consistency.
97
+ option (BUILD_BITCOIN_BIN "Build bitcoin executable." ON )
93
98
option (BUILD_DAEMON "Build bitcoind executable." ON )
94
99
option (BUILD_GUI "Build bitcoin-qt executable." OFF )
95
100
option (BUILD_CLI "Build bitcoin-cli executable." ON )
@@ -111,25 +116,8 @@ if(ENABLE_WALLET)
111
116
find_package (SQLite3 3.7.17 REQUIRED )
112
117
endif ()
113
118
endif ()
114
- option (WITH_BDB "Enable Berkeley DB (BDB) wallet support." OFF )
115
- cmake_dependent_option (WARN_INCOMPATIBLE_BDB "Warn when using a Berkeley DB (BDB) version other than 4.8." ON "WITH_BDB" OFF )
116
- if (WITH_BDB )
117
- find_package (BerkeleyDB 4.8 MODULE REQUIRED )
118
- set (USE_BDB ON )
119
- if (NOT BerkeleyDB_VERSION VERSION_EQUAL 4.8 )
120
- message (WARNING "Found Berkeley DB (BDB) other than 4.8.\n "
121
- "BDB (legacy) wallets opened by this build will not be portable!"
122
- )
123
- if (WARN_INCOMPATIBLE_BDB )
124
- message (WARNING "If this is intended, pass \" -DWARN_INCOMPATIBLE_BDB=OFF\" .\n "
125
- "Passing \" -DWITH_BDB=OFF\" will suppress this warning."
126
- )
127
- endif ()
128
- endif ()
129
- endif ()
130
119
cmake_dependent_option (BUILD_WALLET_TOOL "Build bitcoin-wallet tool." ${BUILD_TESTS} "ENABLE_WALLET" OFF )
131
120
132
- option (ENABLE_HARDENING "Attempt to harden the resulting executables." ON )
133
121
option (REDUCE_EXPORTS "Attempt to reduce exported symbols in the resulting executables." OFF )
134
122
option (WERROR "Treat compiler warnings as errors." OFF )
135
123
option (WITH_CCACHE "Attempt to use ccache for compiling." ON )
@@ -144,15 +132,15 @@ if(WITH_USDT)
144
132
find_package (USDT MODULE REQUIRED )
145
133
endif ()
146
134
147
- cmake_dependent_option (ENABLE_EXTERNAL_SIGNER "Enable external signer support." ON "NOT WIN32" OFF )
135
+ option (ENABLE_EXTERNAL_SIGNER "Enable external signer support." ON )
148
136
149
137
cmake_dependent_option (WITH_QRENCODE "Enable QR code support." ON "BUILD_GUI" OFF )
150
138
if (WITH_QRENCODE )
151
139
find_package (QRencode MODULE REQUIRED )
152
140
set (USE_QRCODE TRUE )
153
141
endif ()
154
142
155
- cmake_dependent_option (WITH_DBUS "Enable DBus support." ON "CMAKE_SYSTEM_NAME STREQUAL \" Linux \" AND BUILD_GUI" OFF )
143
+ cmake_dependent_option (WITH_DBUS "Enable DBus support." ON "NOT CMAKE_SYSTEM_NAME MATCHES \" (Windows|Darwin) \" AND BUILD_GUI" OFF )
156
144
157
145
option (ENABLE_IPC "Build multiprocess bitcoin-node and bitcoin-gui executables in addition to monolithic bitcoind and bitcoin-qt executables. Requires libmultiprocess library. Experimental." OFF )
158
146
cmake_dependent_option (WITH_EXTERNAL_LIBMULTIPROCESS "Build with external libmultiprocess library instead of with local git subtree when ENABLE_IPC is enabled. This is not normally recommended, but can be useful for developing libmultiprocess itself." OFF "ENABLE_IPC" OFF )
@@ -216,6 +204,7 @@ target_link_libraries(core_interface INTERFACE
216
204
217
205
if (BUILD_FOR_FUZZING )
218
206
message (WARNING "BUILD_FOR_FUZZING=ON will disable all other targets and force BUILD_FUZZ_BINARY=ON." )
207
+ set (BUILD_BITCOIN_BIN OFF )
219
208
set (BUILD_DAEMON OFF )
220
209
set (BUILD_CLI OFF )
221
210
set (BUILD_TX OFF )
@@ -291,6 +280,10 @@ if(WIN32)
291
280
/Zc:__cplusplus
292
281
/sdl
293
282
)
283
+ target_link_options (core_interface INTERFACE
284
+ # We embed our own manifests.
285
+ /MANIFEST:NO
286
+ )
294
287
# Improve parallelism in MSBuild.
295
288
# See: https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/.
296
289
list (APPEND CMAKE_VS_GLOBALS "UseMultiToolTask=true" )
@@ -504,63 +497,71 @@ try_append_cxx_flags("-fmacro-prefix-map=A=B" TARGET core_interface SKIP_LINK
504
497
# -fstack-reuse=none for all gcc builds. (Only gcc understands this flag).
505
498
try_append_cxx_flags ("-fstack-reuse=none" TARGET core_interface )
506
499
507
- if (ENABLE_HARDENING )
508
- add_library (hardening_interface INTERFACE )
509
- target_link_libraries (core_interface INTERFACE hardening_interface )
510
- if (MSVC )
511
- try_append_linker_flag ("/DYNAMICBASE" TARGET hardening_interface )
512
- try_append_linker_flag ("/HIGHENTROPYVA" TARGET hardening_interface )
513
- try_append_linker_flag ("/NXCOMPAT" TARGET hardening_interface )
514
- else ()
500
+ if (MSVC )
501
+ try_append_linker_flag ("/DYNAMICBASE" TARGET core_interface )
502
+ try_append_linker_flag ("/HIGHENTROPYVA" TARGET core_interface )
503
+ try_append_linker_flag ("/NXCOMPAT" TARGET core_interface )
504
+ else ()
515
505
516
- # _FORTIFY_SOURCE requires that there is some level of optimization,
517
- # otherwise it does nothing and just creates a compiler warning.
518
- try_append_cxx_flags ("-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3"
519
- RESULT_VAR cxx_supports_fortify_source
520
- SOURCE "int main() {
521
- # if !defined __OPTIMIZE__ || __OPTIMIZE__ <= 0
522
- #error
523
- #endif
524
- }"
506
+ # _FORTIFY_SOURCE requires that there is some level of optimization,
507
+ # otherwise it does nothing and just creates a compiler warning.
508
+ try_append_cxx_flags ("-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3"
509
+ RESULT_VAR cxx_supports_fortify_source
510
+ SOURCE "int main() {
511
+ # if !defined __OPTIMIZE__ || __OPTIMIZE__ <= 0
512
+ #error
513
+ #endif
514
+ }"
515
+ )
516
+ if (cxx_supports_fortify_source )
517
+ target_compile_options (core_interface INTERFACE
518
+ -U_FORTIFY_SOURCE
519
+ -D_FORTIFY_SOURCE=3
525
520
)
526
- if (cxx_supports_fortify_source )
527
- target_compile_options (hardening_interface INTERFACE
528
- -U_FORTIFY_SOURCE
529
- -D_FORTIFY_SOURCE=3
530
- )
531
- endif ()
532
- unset (cxx_supports_fortify_source )
533
-
534
- try_append_cxx_flags ("-Wstack-protector" TARGET hardening_interface SKIP_LINK )
535
- try_append_cxx_flags ("-fstack-protector-all" TARGET hardening_interface )
536
- try_append_cxx_flags ("-fcf-protection=full" TARGET hardening_interface )
521
+ endif ()
522
+ unset (cxx_supports_fortify_source )
537
523
538
- if (MINGW )
539
- # stack-clash-protection is a no-op for Windows.
540
- # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90458 for more details.
541
- else ()
542
- try_append_cxx_flags ("-fstack-clash-protection" TARGET hardening_interface )
543
- endif ()
524
+ try_append_cxx_flags ("-Wstack-protector" TARGET core_interface SKIP_LINK )
525
+ try_append_cxx_flags ("-fstack-protector-all" TARGET core_interface )
526
+ try_append_cxx_flags ("-fcf-protection=full" TARGET core_interface )
544
527
545
- if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64" )
546
- if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" )
547
- try_append_cxx_flags ("-mbranch-protection=bti" TARGET hardening_interface SKIP_LINK )
548
- else ()
549
- try_append_cxx_flags ("-mbranch-protection=standard" TARGET hardening_interface SKIP_LINK )
550
- endif ()
551
- endif ()
528
+ if (MINGW )
529
+ # stack-clash-protection is a no-op for Windows.
530
+ # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90458 for more details.
531
+ else ()
532
+ try_append_cxx_flags ("-fstack-clash-protection" TARGET core_interface )
533
+ endif ()
552
534
553
- try_append_linker_flag ("-Wl,--enable-reloc-section" TARGET hardening_interface )
554
- try_append_linker_flag ("-Wl,--dynamicbase" TARGET hardening_interface )
555
- try_append_linker_flag ("-Wl,--nxcompat" TARGET hardening_interface )
556
- try_append_linker_flag ("-Wl,--high-entropy-va" TARGET hardening_interface )
557
- try_append_linker_flag ("-Wl,-z,relro" TARGET hardening_interface )
558
- try_append_linker_flag ("-Wl,-z,now" TARGET hardening_interface )
559
- try_append_linker_flag ("-Wl,-z,separate-code" TARGET hardening_interface )
535
+ if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64" )
560
536
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" )
561
- try_append_linker_flag ("-Wl,-fixup_chains" TARGET hardening_interface )
537
+ try_append_cxx_flags ("-mbranch-protection=bti" TARGET core_interface SKIP_LINK )
538
+ else ()
539
+ try_append_cxx_flags ("-mbranch-protection=standard" TARGET core_interface SKIP_LINK )
562
540
endif ()
563
541
endif ()
542
+
543
+ try_append_linker_flag ("-Wl,--enable-reloc-section" TARGET core_interface )
544
+ try_append_linker_flag ("-Wl,--dynamicbase" TARGET core_interface )
545
+ try_append_linker_flag ("-Wl,--nxcompat" TARGET core_interface )
546
+ try_append_linker_flag ("-Wl,--high-entropy-va" TARGET core_interface )
547
+ try_append_linker_flag ("-Wl,-z,relro" TARGET core_interface )
548
+ try_append_linker_flag ("-Wl,-z,now" TARGET core_interface )
549
+ # TODO: This can be dropped once Bitcoin Core no longer supports
550
+ # NetBSD 10.0 or if upstream fix is backported.
551
+ # NetBSD's dynamic linker ld.elf_so < 11.0 supports exactly 2
552
+ # `PT_LOAD` segments and binaries linked with `-z separate-code`
553
+ # have 4 `PT_LOAD` segments.
554
+ # Relevant discussions:
555
+ # - https://github.com/bitcoin/bitcoin/pull/28724#issuecomment-2589347934
556
+ # - https://mail-index.netbsd.org/tech-userlevel/2023/01/05/msg013666.html
557
+ if (CMAKE_SYSTEM_NAME STREQUAL "NetBSD" AND CMAKE_SYSTEM_VERSION VERSION_LESS 11.0 )
558
+ try_append_linker_flag ("-Wl,-z,noseparate-code" TARGET core_interface )
559
+ else ()
560
+ try_append_linker_flag ("-Wl,-z,separate-code" TARGET core_interface )
561
+ endif ()
562
+ if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" )
563
+ try_append_linker_flag ("-Wl,-fixup_chains" TARGET core_interface )
564
+ endif ()
564
565
endif ()
565
566
566
567
if (REDUCE_EXPORTS )
@@ -650,6 +651,7 @@ message("\n")
650
651
message ("Configure summary" )
651
652
message ("=================" )
652
653
message ("Executables:" )
654
+ message (" bitcoin ............................. ${BUILD_BITCOIN_BIN} " )
653
655
message (" bitcoind ............................ ${BUILD_DAEMON} " )
654
656
if (BUILD_DAEMON AND ENABLE_IPC )
655
657
set (bitcoin_daemon_status ON )
@@ -673,9 +675,6 @@ message(" libbitcoinkernel (experimental) ..... ${BUILD_KERNEL_LIB}")
673
675
message (" kernel-test (experimental) .......... ${BUILD_KERNEL_TEST} " )
674
676
message ("Optional features:" )
675
677
message (" wallet support ...................... ${ENABLE_WALLET} " )
676
- if (ENABLE_WALLET )
677
- message (" - legacy wallets (Berkeley DB) ..... ${WITH_BDB} " )
678
- endif ()
679
678
message (" external signer ..................... ${ENABLE_EXTERNAL_SIGNER} " )
680
679
message (" ZeroMQ .............................. ${WITH_ZMQ} " )
681
680
if (ENABLE_IPC )
@@ -690,7 +689,7 @@ endif()
690
689
message (" IPC ................................. ${ipc_status} " )
691
690
message (" USDT tracing ........................ ${WITH_USDT} " )
692
691
message (" QR code (GUI) ....................... ${WITH_QRENCODE} " )
693
- message (" DBus (GUI, Linux only) .............. ${WITH_DBUS} " )
692
+ message (" DBus (GUI) ............ .............. ${WITH_DBUS} " )
694
693
message ("Tests:" )
695
694
message (" test_bitcoin ........................ ${BUILD_TESTS} " )
696
695
message (" test_bitcoin-qt ..................... ${BUILD_GUI_TESTS} " )
@@ -706,7 +705,6 @@ message("Cross compiling ....................... ${cross_status}")
706
705
message ("C++ compiler .......................... ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} , ${CMAKE_CXX_COMPILER} " )
707
706
include (FlagsSummary )
708
707
flags_summary ()
709
- message ("Attempt to harden executables ......... ${ENABLE_HARDENING} " )
710
708
message ("Treat compiler warnings as errors ..... ${WERROR} " )
711
709
message ("Use ccache for compiling .............. ${WITH_CCACHE} " )
712
710
message ("\n " )
0 commit comments