From 70afb28a72ea77cadb04888fa1a5e15c761efa2d Mon Sep 17 00:00:00 2001 From: merge-script Date: Mon, 9 Sep 2024 12:33:57 +0100 Subject: [PATCH 01/10] Merge bitcoin/bitcoin#30824: cmake: decouple `FORTIFY_SOURCE` check from `Debug` build type 30803a35d54acda19ded88474c205f8954fea5e1 cmake: decouple FORTIFY_SOURCE check from Debug build type (fanquake) Pull request description: `FORTIFY_SOURCE` should be used if `ENABLE_HARDENING=ON` and optimisations are being used. This should not be coupled to any particular build type, because even if the build type is `Debug`, optimisations might still be in use. Fixes: #30800. Also somewhat of a followup to https://github.com/bitcoin/bitcoin/pull/30778#discussion_r1742257436. ACKs for top commit: ryanofsky: Code review ACK 30803a35d54acda19ded88474c205f8954fea5e1 TheCharlatan: ACK 30803a35d54acda19ded88474c205f8954fea5e1 Tree-SHA512: 298f8805a5bb2f1ff54e51ea31324d712c2070cc3eba26561c31001ace4bfa37ae6d18531cbd45e2faf610a0a1b83b420fcde6e329e17f02b021d26563583913 (cherry picked from commit 94bc3c4cc0845b5238c11e1c66d70882e459742a) --- CMakeLists.txt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e50e227491b..3b20a8675a24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -592,18 +592,21 @@ if(ENABLE_HARDENING) try_append_linker_flag("/HIGHENTROPYVA" TARGET hardening_interface) try_append_linker_flag("/NXCOMPAT" TARGET hardening_interface) else() + + # _FORTIFY_SOURCE requires that there is some level of optimization, + # otherwise it does nothing and just creates a compiler warning. try_append_cxx_flags("-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3" RESULT_VAR cxx_supports_fortify_source + SOURCE "int main() { + # if !defined __OPTIMIZE__ || __OPTIMIZE__ <= 0 + #error + #endif + }" ) if(cxx_supports_fortify_source) - # When the build configuration is Debug, all optimizations are disabled. - # However, _FORTIFY_SOURCE requires that there is some level of optimization, - # otherwise it does nothing and just creates a compiler warning. - # Since _FORTIFY_SOURCE is a no-op without optimizations, do not enable it - # when the build configuration is Debug. target_compile_options(hardening_interface INTERFACE - $<$>:-U_FORTIFY_SOURCE> - $<$>:-D_FORTIFY_SOURCE=3> + -U_FORTIFY_SOURCE + -D_FORTIFY_SOURCE=3 ) endif() unset(cxx_supports_fortify_source) From 2c303649c804a4bc96fa8d08d479100fa3ef4cad Mon Sep 17 00:00:00 2001 From: merge-script Date: Thu, 12 Sep 2024 09:28:20 +0100 Subject: [PATCH 02/10] Merge bitcoin/bitcoin#30867: build: Fix `ENABLE_WALLET` option 0037d53d1a21ec8a5a97a83ab716d68030446021 build: Fix `ENABLE_WALLET` option (Hennadii Stepanov) Pull request description: The removed commands were left over from the transition from autodetection to explicit options in the CMake staging branch. These commands prevented the `-DENABLE_WALLET=OFF` option from being work properly when building with depends. How to test: ``` $ make -C depends NO_QT=1 ``` On the master branch @ c66c68345efb0bb3d5613ebac703cde779fa0f01: ``` $ rm -rf build && cmake -B build --toolchain depends/x86_64-pc-linux-gnu/toolchain.cmake -DENABLE_WALLET=OFF < snip > Optional features: wallet support ...................... ON - descriptor wallets (SQLite) ...... ON - legacy wallets (Berkeley DB) ..... ON external signer ..................... ON < snip > ``` With this PR: ``` $ rm -rf build && cmake -B build --toolchain depends/x86_64-pc-linux-gnu/toolchain.cmake -DENABLE_WALLET=OFF < snip > Optional features: wallet support ...................... OFF external signer ..................... ON < snip > ACKs for top commit: maflcko: review ACK 0037d53d1a21ec8a5a97a83ab716d68030446021 kevkevinpal: ACK [0037d53](https://github.com/bitcoin/bitcoin/pull/30867/commits/0037d53d1a21ec8a5a97a83ab716d68030446021) pablomartin4btc: tACK 0037d53d1a21ec8a5a97a83ab716d68030446021 Tree-SHA512: 0eb14ef104f12a4205172d646c2af820e04514286b5b9a4ceb59c248ce880198dd4051d669098c46c0c0dce069bb60899d90509bbcae65cbeb958e52564fe920 (cherry picked from commit c77361888695aa7e7713a9c7f63861f050834e91) --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b20a8675a24..58995a8f392f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,14 +112,12 @@ if(WITH_SQLITE) find_package(SQLite3 3.7.17 REQUIRED) endif() set(USE_SQLITE ON) - set(ENABLE_WALLET ON) endif() option(WITH_BDB "Enable Berkeley DB (BDB) wallet support." OFF) cmake_dependent_option(WARN_INCOMPATIBLE_BDB "Warn when using a Berkeley DB (BDB) version other than 4.8." ON "WITH_BDB" OFF) if(WITH_BDB) find_package(BerkeleyDB 4.8 MODULE REQUIRED) set(USE_BDB ON) - set(ENABLE_WALLET ON) if(NOT BerkeleyDB_VERSION VERSION_EQUAL 4.8) message(WARNING "Found Berkeley DB (BDB) other than 4.8.\n" "BDB (legacy) wallets opened by this build will not be portable!" From 147cc23ef7909102b4145b20e7ebc6e211259747 Mon Sep 17 00:00:00 2001 From: merge-script Date: Thu, 12 Sep 2024 10:30:06 +0100 Subject: [PATCH 03/10] Merge bitcoin/bitcoin#30803: build: Minor build system fixes and amendments 1cc93fe7b40f10a7d1d1189058af98a2bce31381 build: Delete dead code that implements `IF_CHECK_FAILED` option (Hennadii Stepanov) 341ad238091d4df520c70f1757b017e6f6620f24 build: Delete MSVC special case for `BUILD_FOR_FUZZING` option (Hennadii Stepanov) fdad128b528bc8622bc6d8343026c28b18260f64 build: Stop enabling CMake's CMP0141 policy (Hennadii Stepanov) b2a6f545b4f6e3442ae51f66a6f3c1de92d00a1b doc: Drop `ctest` command from Windows cross-compiling instructions (Hennadii Stepanov) 73b618582dcf06dd01be062fe0f81060cfcb48d8 build: Print `CMAKE_CXX_COMPILER_ARG1` in summary (Hennadii Stepanov) f03c9420958de31fdfecec5fa3e23134aac61803 build, test: Add missed log options (Hennadii Stepanov) 6f2cb0eafdef81fb9464a4679c3a5905d19e5103 doc: Amend comment about ZeroMQ config files (Hennadii Stepanov) Pull request description: This PR addresses the following comments: - https://github.com/bitcoin/bitcoin/pull/30454#discussion_r1742342524 - https://github.com/bitcoin/bitcoin/pull/30454#discussion_r1728692369 - https://github.com/bitcoin/bitcoin/pull/30454#discussion_r1736110362 - https://github.com/bitcoin/bitcoin/pull/30454#discussion_r1742931121 - https://github.com/bitcoin/bitcoin/pull/30454#discussion_r1747723657 - https://github.com/bitcoin/bitcoin/pull/30454#discussion_r1742328675 - https://github.com/bitcoin/bitcoin/pull/30454#discussion_r1723106474 ACKs for top commit: sipsorcery: tACK 1cc93fe7b40f10a7d1d1189058af98a2bce31381 (win11 msvc). maflcko: re-ACK 1cc93fe7b40f10a7d1d1189058af98a2bce31381 Tree-SHA512: a390797bb4d3b7eb9163653b6c9c324e7a01090f6cdda74df7349a24a5c4a2084e5912878747f56561315afc70cae9adb1c363f47ceb0af96004ea591d25171b (cherry picked from commit db8350b0e3f5c65281585fdaeba05432069f2152) --- CMakeLists.txt | 12 ++++-------- cmake/module/FlagsSummary.cmake | 3 ++- cmake/module/TryAppendCXXFlags.cmake | 15 +-------------- cmake/module/TryAppendLinkerFlag.cmake | 9 +-------- src/test/CMakeLists.txt | 2 +- 5 files changed, 9 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 58995a8f392f..9245bf87f6a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,12 +8,6 @@ # Centos Stream 9, EOL in May 2027: # - CMake 3.26.5, https://mirror.stream.centos.org/9-stream/AppStream/x86_64/os/Packages/ cmake_minimum_required(VERSION 3.22) -if(POLICY CMP0141) - # MSVC debug information format flags are selected by an abstraction. - # We want to use the CMAKE_MSVC_DEBUG_INFORMATION_FORMAT variable - # to select the MSVC debug information format. - cmake_policy(SET CMP0141 NEW) -endif() if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) message(FATAL_ERROR "In-source builds are not allowed.") @@ -164,7 +158,9 @@ if(WITH_ZMQ) 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. + # 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) # TODO: This command will be redundant once @@ -232,7 +228,7 @@ cmake_dependent_option(ENABLE_PLATFORM_GUI "Enable Dash Platform (usernames, Das option(BUILD_BENCH "Build bench_bitcoin executable." OFF) option(BUILD_FUZZ_BINARY "Build fuzz binary." OFF) -cmake_dependent_option(BUILD_FOR_FUZZING "Build for fuzzing. Enabling this will disable all other targets and override BUILD_FUZZ_BINARY." OFF "NOT MSVC" OFF) +option(BUILD_FOR_FUZZING "Build for fuzzing. Enabling this will disable all other targets and override BUILD_FUZZ_BINARY." OFF) option(INSTALL_MAN "Install man pages." ON) diff --git a/cmake/module/FlagsSummary.cmake b/cmake/module/FlagsSummary.cmake index 9a408f715d91..91d1df90d99b 100644 --- a/cmake/module/FlagsSummary.cmake +++ b/cmake/module/FlagsSummary.cmake @@ -22,7 +22,8 @@ function(print_flags_per_config config indent_num) get_target_interface(definitions "${config}" core_interface COMPILE_DEFINITIONS) indent_message("Preprocessor defined macros ..........." "${definitions}" ${indent_num}) - string(STRIP "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${config_uppercase}}" combined_cxx_flags) + string(STRIP "${CMAKE_CXX_COMPILER_ARG1} ${CMAKE_CXX_FLAGS}" combined_cxx_flags) + string(STRIP "${combined_cxx_flags} ${CMAKE_CXX_FLAGS_${config_uppercase}}" combined_cxx_flags) string(STRIP "${combined_cxx_flags} ${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION}" combined_cxx_flags) if(CMAKE_POSITION_INDEPENDENT_CODE) string(JOIN " " combined_cxx_flags ${combined_cxx_flags} ${CMAKE_CXX_COMPILE_OPTIONS_PIC}) diff --git a/cmake/module/TryAppendCXXFlags.cmake b/cmake/module/TryAppendCXXFlags.cmake index 0f6e014d437a..c07455e89e0f 100644 --- a/cmake/module/TryAppendCXXFlags.cmake +++ b/cmake/module/TryAppendCXXFlags.cmake @@ -32,12 +32,6 @@ Usage examples: ) - try_append_cxx_flags("-Werror=return-type" TARGET core_interface - IF_CHECK_FAILED "-Wno-error=return-type" - SOURCE "#include \nint f(){ assert(false); }" - ) - - In configuration output, this function prints a string by the following pattern: -- Performing Test CXX_SUPPORTS_[flags] @@ -49,7 +43,7 @@ function(try_append_cxx_flags flags) TACXXF # prefix "SKIP_LINK" # options "TARGET;VAR;SOURCE;RESULT_VAR" # one_value_keywords - "IF_CHECK_PASSED;IF_CHECK_FAILED" # multi_value_keywords + "IF_CHECK_PASSED" # multi_value_keywords ) set(flags_as_string "${flags}") @@ -88,13 +82,6 @@ function(try_append_cxx_flags flags) string(STRIP "${${TACXXF_VAR}} ${flags_as_string}" ${TACXXF_VAR}) endif() endif() - elseif(DEFINED TACXXF_IF_CHECK_FAILED) - if(DEFINED TACXXF_TARGET) - target_compile_options(${TACXXF_TARGET} INTERFACE ${TACXXF_IF_CHECK_FAILED}) - endif() - if(DEFINED TACXXF_VAR) - string(STRIP "${${TACXXF_VAR}} ${TACXXF_IF_CHECK_FAILED}" ${TACXXF_VAR}) - endif() endif() if(DEFINED TACXXF_VAR) diff --git a/cmake/module/TryAppendLinkerFlag.cmake b/cmake/module/TryAppendLinkerFlag.cmake index 57220fbb913c..8cbd83678d93 100644 --- a/cmake/module/TryAppendLinkerFlag.cmake +++ b/cmake/module/TryAppendLinkerFlag.cmake @@ -22,7 +22,7 @@ function(try_append_linker_flag flag) TALF # prefix "" # options "TARGET;VAR;SOURCE;RESULT_VAR" # one_value_keywords - "IF_CHECK_PASSED;IF_CHECK_FAILED" # multi_value_keywords + "IF_CHECK_PASSED" # multi_value_keywords ) string(MAKE_C_IDENTIFIER "${flag}" result) @@ -58,13 +58,6 @@ function(try_append_linker_flag flag) string(STRIP "${${TALF_VAR}} ${flag}" ${TALF_VAR}) endif() endif() - elseif(DEFINED TALF_IF_CHECK_FAILED) - if(DEFINED TALF_TARGET) - target_link_options(${TALF_TARGET} INTERFACE ${TALF_IF_CHECK_FAILED}) - endif() - if(DEFINED TALF_VAR) - string(STRIP "${${TALF_VAR}} ${TALF_IF_CHECK_FAILED}" ${TALF_VAR}) - endif() endif() if(DEFINED TALF_VAR) diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 5d495f2984a3..8cb0e4ddf844 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -236,7 +236,7 @@ function(add_boost_test source_file) ) if(test_suite_name) add_test(NAME ${test_suite_name} - COMMAND test_bitcoin --run_test=${test_suite_name} --catch_system_error=no + COMMAND test_bitcoin --run_test=${test_suite_name} --catch_system_error=no --log_level=test_suite -- DEBUG_LOG_OUT ) set_property(TEST ${test_suite_name} PROPERTY SKIP_REGULAR_EXPRESSION "no test cases matching filter" "Skipping" From 475cd02b54ddd864c10d83e0bd2bc6ed569d43bf Mon Sep 17 00:00:00 2001 From: merge-script Date: Thu, 12 Sep 2024 15:29:33 +0100 Subject: [PATCH 04/10] Merge bitcoin/bitcoin#30865: build: Skip secp256k1 ctime tests when tests are not being built 23eedc5d1e24b3d31da7902ece5182b9b24672d8 build: Skip secp256k1 ctime tests when tests are not being built (Hennadii Stepanov) Pull request description: Fixes https://github.com/bitcoin/bitcoin/pull/30791#issuecomment-2340860619: > Building with a fuzz engine fails, because the ctime tests are auto-detected in cmake, based on whether or not valgrind-devel is installed or not. ACKs for top commit: maflcko: re-review ACK 23eedc5d1e24b3d31da7902ece5182b9b24672d8 fanquake: ACK 23eedc5d1e24b3d31da7902ece5182b9b24672d8 Tree-SHA512: bfc0f2798acd36be9c52073d578b42c002606c60ef3fe8ef633eaea4f5382a3e9765d31637e4c25d8b71fd70473b29c24af4732e55e5183f27b48725b61fa15b (cherry picked from commit cf786eccd7ab3e74dbec73febb3ee03d71e95c63) --- src/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ce4aca735453..633e4ad7c4f2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,6 +52,11 @@ set(SECP256K1_ENABLE_MODULE_RECOVERY ON CACHE BOOL "" FORCE) set(SECP256K1_BUILD_BENCHMARK OFF CACHE BOOL "" FORCE) set(SECP256K1_BUILD_TESTS ${BUILD_TESTS} CACHE BOOL "" FORCE) set(SECP256K1_BUILD_EXHAUSTIVE_TESTS ${BUILD_TESTS} CACHE BOOL "" FORCE) +if(NOT BUILD_TESTS) + # Always skip the ctime tests, if we are building no other tests. + # Otherwise, they are built if Valgrind is available. See SECP256K1_VALGRIND. + set(SECP256K1_BUILD_CTIME_TESTS ${BUILD_TESTS} CACHE BOOL "" FORCE) +endif() set(SECP256K1_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # We want to build libsecp256k1 with the most tested RelWithDebInfo configuration. enable_language(C) From 62d48220112705a19c7732b463ed895c4a973cbd Mon Sep 17 00:00:00 2001 From: merge-script Date: Fri, 6 Dec 2024 10:15:56 +0000 Subject: [PATCH 05/10] Merge bitcoin/bitcoin#31231: cmake: Fix `IF_CHECK_PASSED` option handling 97a18c85458b898fe5e3abda9528a2de442766ad cmake: Fix `IF_CHECK_PASSED` option handling (Hennadii Stepanov) Pull request description: `IF_CHECK_PASSED` is a multi-value keyword, resulting in a list value. Convert it to a string before applying any `string()` command. Split from https://github.com/bitcoin/bitcoin/pull/30861. No current CMake code is affected by this bug. ACKs for top commit: theuni: utACK 97a18c85458b898fe5e3abda9528a2de442766ad Tree-SHA512: d2556ca38c35a8992175e9f948c2028a789e71c2b2d5fdf365b31710c8ed3d5edf5d0363853c5d750d29abb58cfda3c78cdc2971a627e5b4c61aca4ec2a33356 (cherry picked from commit eb2ebe6f30ac2e94224aa0783f3adfcd310931b0) --- cmake/module/TryAppendCXXFlags.cmake | 3 ++- cmake/module/TryAppendLinkerFlag.cmake | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cmake/module/TryAppendCXXFlags.cmake b/cmake/module/TryAppendCXXFlags.cmake index c07455e89e0f..dc0a9b7f8f5f 100644 --- a/cmake/module/TryAppendCXXFlags.cmake +++ b/cmake/module/TryAppendCXXFlags.cmake @@ -72,7 +72,8 @@ function(try_append_cxx_flags flags) target_compile_options(${TACXXF_TARGET} INTERFACE ${TACXXF_IF_CHECK_PASSED}) endif() if(DEFINED TACXXF_VAR) - string(STRIP "${${TACXXF_VAR}} ${TACXXF_IF_CHECK_PASSED}" ${TACXXF_VAR}) + list(JOIN TACXXF_IF_CHECK_PASSED " " flags_if_check_passed_as_string) + string(STRIP "${${TACXXF_VAR}} ${flags_if_check_passed_as_string}" ${TACXXF_VAR}) endif() else() if(DEFINED TACXXF_TARGET) diff --git a/cmake/module/TryAppendLinkerFlag.cmake b/cmake/module/TryAppendLinkerFlag.cmake index 8cbd83678d93..be41a2e1cc2d 100644 --- a/cmake/module/TryAppendLinkerFlag.cmake +++ b/cmake/module/TryAppendLinkerFlag.cmake @@ -48,7 +48,8 @@ function(try_append_linker_flag flag) target_link_options(${TALF_TARGET} INTERFACE ${TALF_IF_CHECK_PASSED}) endif() if(DEFINED TALF_VAR) - string(STRIP "${${TALF_VAR}} ${TALF_IF_CHECK_PASSED}" ${TALF_VAR}) + list(JOIN TALF_IF_CHECK_PASSED " " flags_if_check_passed_as_string) + string(STRIP "${${TALF_VAR}} ${flags_if_check_passed_as_string}" ${TALF_VAR}) endif() else() if(DEFINED TALF_TARGET) From c2ddcca7abf0a5f4e747e0a0d96292decc02c339 Mon Sep 17 00:00:00 2001 From: merge-script Date: Wed, 12 Feb 2025 10:41:25 +0100 Subject: [PATCH 06/10] Merge bitcoin/bitcoin#31711: build: set build type and per-build-type flags as early as possible 56a9b847bba2b8deb6a9c3f3a7eb95b4c71c2d14 build: set build type and per-build-type flags as early as possible (Cory Fields) f605f7a9c26ebd434da1cbd9ed9b294d05c96ee8 build: refactor: set debug definitions in main CMakeLists (Cory Fields) Pull request description: This ensures that most compiler tests are not run with the wrong build type's flags. The initial c++ checks are an exception to that because many internal CMake variables are unset until a language is selected, so it's problematic to change our build type before that. The difference can be seen in `build/CMakeFiles/CMakeConfigureLog.yaml`. Before, `Debug` was used for many of the earlly checks. After this PR, it's only the first 2 checks. ACKs for top commit: hebasto: ACK 56a9b847bba2b8deb6a9c3f3a7eb95b4c71c2d14. Tree-SHA512: 87947352d6d4fd08554515822cb13634ed3be33fcda2af817c22ef943b1d0856ceb39311ddc01b8221397528fdc09f630dc7e74fc92f5a4a073f09c4ae493596 (cherry picked from commit 0b6ed342b574baba9732da8aad2252b5d5e57bec) --- CMakeLists.txt | 14 ++++++++++++-- cmake/module/ProcessConfigurations.cmake | 14 ++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9245bf87f6a0..0bd98ea749b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,6 +80,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/module) +include(ProcessConfigurations) #============================= # Configurable options @@ -301,11 +302,20 @@ endif() # Derive this after BUILD_FOR_FUZZING has applied its target overrides. set(HAVE_CONSENSUS_LIB ${BUILD_CONSENSUS_LIB}) -include(ProcessConfigurations) - include(TryAppendCXXFlags) include(TryAppendLinkerFlag) +# Redefine/adjust per-configuration flags. +# Dash uses DEBUG_CORE, not upstream's DEBUG, which is what span.h and +# init/common.cpp check. +target_compile_definitions(core_interface_debug INTERFACE + DEBUG_CORE + DEBUG_LOCKORDER + DEBUG_LOCKCONTENTION + RPC_DOC_CHECK + ABORT_ON_FAILED_ASSUME +) + if(WIN32) #[=[ This build system supports two ways to build binaries for Windows. diff --git a/cmake/module/ProcessConfigurations.cmake b/cmake/module/ProcessConfigurations.cmake index 03abb4936fd7..a685133dfc29 100644 --- a/cmake/module/ProcessConfigurations.cmake +++ b/cmake/module/ProcessConfigurations.cmake @@ -4,8 +4,6 @@ include_guard(GLOBAL) -include(TryAppendCXXFlags) - macro(normalize_string string) string(REGEX REPLACE " +" " " ${string} "${${string}}") string(STRIP "${${string}}" ${string}) @@ -138,16 +136,8 @@ endfunction() set_default_config(RelWithDebInfo) -# Redefine/adjust per-configuration flags. -# Dash uses DEBUG_CORE, not upstream's DEBUG, which is what span.h and -# init/common.cpp check. -target_compile_definitions(core_interface_debug INTERFACE - DEBUG_CORE - DEBUG_LOCKORDER - DEBUG_LOCKCONTENTION - RPC_DOC_CHECK - ABORT_ON_FAILED_ASSUME -) +include(TryAppendCXXFlags) + # We leave assertions on. if(MSVC) remove_cxx_flag_from_all_configs(/DNDEBUG) From 2d0b1842b25178d07a301abd106140399a127fda Mon Sep 17 00:00:00 2001 From: merge-script Date: Fri, 14 Feb 2025 18:02:35 +0100 Subject: [PATCH 07/10] Merge bitcoin/bitcoin#31359: cmake: Add `CheckLinkerSupportsPIE` module 81c174e3186efae084829dcde314b081cad3d3cb cmake: Refer to the configure log instead of printing PIE test error (Hennadii Stepanov) 65a0920ca6b11b4250b5cdcf174eaa9ea55fa6ed cmake: Add `CheckLinkerSupportsPIE` module (Hennadii Stepanov) Pull request description: This new module is a wrapper around CMake's `CheckPIESupported` module that fixes an upstream bug. See: https://gitlab.kitware.com/cmake/cmake/-/issues/26463. Fixes https://github.com/bitcoin/bitcoin/issues/30771. ACKs for top commit: theuni: utACK 81c174e3186efae084829dcde314b081cad3d3cb. vasild: ACK 81c174e3186efae084829dcde314b081cad3d3cb Tree-SHA512: 77d7022238551a4e69c59d1fe6b78975bb552cbbed5339459853d7ebf0086813036081f464fed230be330b3bd7d6cf8590b536b064028d2f786d6ae40f342f95 (cherry picked from commit 06b9236f4327525875768af5fc554c651c5ec3cf) --- CMakeLists.txt | 12 ++-------- cmake/module/CheckLinkerSupportsPIE.cmake | 27 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 cmake/module/CheckLinkerSupportsPIE.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 0bd98ea749b3..3e33f2b4ed8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -246,16 +246,8 @@ string(APPEND CMAKE_CXX_LINK_EXECUTABLE " ${APPEND_LDFLAGS}") set(configure_warnings) -include(CheckPIESupported) -check_pie_supported(OUTPUT_VARIABLE check_pie_output LANGUAGES CXX) -if(CMAKE_CXX_LINK_PIE_SUPPORTED) - set(CMAKE_POSITION_INDEPENDENT_CODE ON) -elseif(NOT WIN32) - # The warning is superfluous for Windows. - message(WARNING "PIE is not supported at link time: ${check_pie_output}") - list(APPEND configure_warnings "Position independent code disabled.") -endif() -unset(check_pie_output) +include(CheckLinkerSupportsPIE) +check_linker_supports_pie(configure_warnings) # The core_interface library aims to encapsulate common build flags. # It is a usage requirement for all targets except for secp256k1, which diff --git a/cmake/module/CheckLinkerSupportsPIE.cmake b/cmake/module/CheckLinkerSupportsPIE.cmake new file mode 100644 index 000000000000..f3897e56a9a5 --- /dev/null +++ b/cmake/module/CheckLinkerSupportsPIE.cmake @@ -0,0 +1,27 @@ +# 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/. + +include_guard(GLOBAL) + +function(check_linker_supports_pie warnings) + # Workaround for a bug in the check_pie_supported() function. + # See: + # - https://gitlab.kitware.com/cmake/cmake/-/issues/26463 + # - https://gitlab.kitware.com/cmake/cmake/-/merge_requests/10034 + if(CMAKE_VERSION VERSION_LESS 3.32) + # CMAKE_CXX_COMPILE_OPTIONS_PIE is a list, whereas CMAKE_REQUIRED_FLAGS + # must be a string. Therefore, a proper conversion is required. + list(JOIN CMAKE_CXX_COMPILE_OPTIONS_PIE " " CMAKE_REQUIRED_FLAGS) + endif() + + include(CheckPIESupported) + check_pie_supported(OUTPUT_VARIABLE output LANGUAGES CXX) + if(CMAKE_CXX_LINK_PIE_SUPPORTED) + set(CMAKE_POSITION_INDEPENDENT_CODE ON PARENT_SCOPE) + elseif(NOT WIN32) + # The warning is superfluous for Windows. + message(WARNING "PIE is not supported at link time. See the configure log for details.") + set(${warnings} ${${warnings}} "Position independent code disabled." PARENT_SCOPE) + endif() +endfunction() From 87567315220815f453c561ef5c885275e1c8aaf0 Mon Sep 17 00:00:00 2001 From: Ryan Ofsky Date: Thu, 8 May 2025 11:02:21 -0400 Subject: [PATCH 08/10] Merge bitcoin/bitcoin#32356: cmake: Respect user-provided configuration-specific flags edde96376a2961dec3730331b3d171ddf972589f cmake: Respect user-provided configuration-specific flags (Hennadii Stepanov) Pull request description: This PR addresses [this](https://github.com/bitcoin/bitcoin/issues/31491#issuecomment-2542140874) comment: > I suppose that should only happen if the `-O3` isn't coming from an explicitly set `CMAKE_CXX_FLAGS_RELEASE`. With this PR: ``` $ cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS_RELEASE="-O3" C++ compiler flags .................... -O3 -std=c++20 -fPIC -fno-extended-identifiers -fdebug-prefix-map=/home/hebasto/dev/bitcoin/src=. -fmacro-prefix-map=/home/hebasto/dev/bitcoin/src=. -fstack-reuse=none -Wall -Wextra -Wformat -Wformat-security -Wvla -Wredundant-decls -Wdate-time -Wduplicated-branches -Wduplicated-cond -Wlogical-op -Woverloaded-virtual -Wsuggest-override -Wimplicit-fallthrough -Wunreachable-code -Wbidi-chars=any -Wundef -Wno-unused-parameter -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -Wstack-protector -fstack-protector-all -fcf-protection=full -fstack-clash-protection Linker flags .......................... -O3 -fstack-reuse=none -fstack-protector-all -fcf-protection=full -fstack-clash-protection -Wl,-z,relro -Wl,-z,now -Wl,-z,separate-code -fPIE -pie ``` and ``` $ cmake -B build -DCMAKE_BUILD_TYPE=Release C++ compiler flags .................... -O2 -std=c++20 -fPIC -fno-extended-identifiers -fdebug-prefix-map=/home/hebasto/dev/bitcoin/src=. -fmacro-prefix-map=/home/hebasto/dev/bitcoin/src=. -fstack-reuse=none -Wall -Wextra -Wformat -Wformat-security -Wvla -Wredundant-decls -Wdate-time -Wduplicated-branches -Wduplicated-cond -Wlogical-op -Woverloaded-virtual -Wsuggest-override -Wimplicit-fallthrough -Wunreachable-code -Wbidi-chars=any -Wundef -Wno-unused-parameter -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -Wstack-protector -fstack-protector-all -fcf-protection=full -fstack-clash-protection Linker flags .......................... -O2 -fstack-reuse=none -fstack-protector-all -fcf-protection=full -fstack-clash-protection -Wl,-z,relro -Wl,-z,now -Wl,-z,separate-code -fPIE -pie ``` When calling `cmake` repeatedly using the same build directory, each newly provided `CMAKE_CXX_FLAGS_RELEASE` value will be accommodated. In such a scenario, if the user wishes to revert to the build system defaults, they should unset the `CMAKE_CXX_FLAGS_RELEASE` variable by passing `-UCMAKE_CXX_FLAGS_RELEASE` to `cmake`. --- This PR does not aim to resolve _all_ issues mentioned in https://github.com/bitcoin/bitcoin/issues/31491. ACKs for top commit: purpleKarrot: ACK edde96376a2961dec3730331b3d171ddf972589f janb84: ACK [edde963](https://github.com/bitcoin/bitcoin/commit/edde96376a2961dec3730331b3d171ddf972589f) ryanofsky: Code review ACK edde96376a2961dec3730331b3d171ddf972589f Tree-SHA512: 1fbc879bd02cf0be726ced490f65985e728f0686ccb3a32cd38787b56377aa666e1965448e5069515abc814df49a0083c8000bc3f6f322f5f395695638168fb6 (cherry picked from commit 1b4ddb0c2d106605b731211d71f8cfe00f56596a) --- CMakeLists.txt | 4 ++++ cmake/module/ProcessConfigurations.cmake | 15 +++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e33f2b4ed8c..569b85734435 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,10 @@ if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) message(FATAL_ERROR "In-source builds are not allowed.") endif() +# When adjusting CMake flag variables, we must not override those explicitly +# set by the user. These are a subset of the CACHE_VARIABLES property. +get_directory_property(precious_variables CACHE_VARIABLES) + #============================= # Project / Package metadata #============================= diff --git a/cmake/module/ProcessConfigurations.cmake b/cmake/module/ProcessConfigurations.cmake index a685133dfc29..5accf45d3ad6 100644 --- a/cmake/module/ProcessConfigurations.cmake +++ b/cmake/module/ProcessConfigurations.cmake @@ -124,14 +124,13 @@ function(append_flag_to_config lang config flag) endfunction() function(replace_cxx_flag_in_config config old_flag new_flag) - string(TOUPPER "${config}" config_uppercase) - string(REGEX REPLACE "(^| )${old_flag}( |$)" "\\1${new_flag}\\2" new_flags "${CMAKE_CXX_FLAGS_${config_uppercase}}") - set(CMAKE_CXX_FLAGS_${config_uppercase} "${new_flags}" PARENT_SCOPE) - set(CMAKE_CXX_FLAGS_${config_uppercase} "${new_flags}" - CACHE STRING - "Flags used by the CXX compiler during ${config_uppercase} builds." - FORCE - ) + string(TOUPPER "CMAKE_CXX_FLAGS_${config}" var_name) + if("${var_name}" IN_LIST precious_variables) + return() + endif() + string(REGEX REPLACE "(^| )${old_flag}( |$)" "\\1${new_flag}\\2" ${var_name} "${${var_name}}") + set(${var_name} "${${var_name}}" PARENT_SCOPE) + set_property(CACHE ${var_name} PROPERTY VALUE "${${var_name}}") endfunction() set_default_config(RelWithDebInfo) From 4734645606db35e180defa3f24f7bbac7b6f49bd Mon Sep 17 00:00:00 2001 From: pasta Date: Mon, 16 Nov 2026 06:11:10 +0000 Subject: [PATCH 09/10] build: respect user configuration-specific flags in append_flag_to_config Dash's append_flag_to_config(), which adds -g1 to Release/MinSizeRel and -fno-omit-frame-pointer to every non-debug configuration so libbacktrace stack traces stay usable, still forced its result into the cache. That overwrote a CMAKE__FLAGS_ value passed on the command line, which is the behaviour bitcoin#32356 removed from replace_cxx_flag_in_config(). Give it the same shape: skip variables the user set explicitly (precious_variables) and update the existing cache entry instead of re-creating it with FORCE. Because the cache entry is precious on every later configure, the flag is appended exactly once, so the explicit duplicate check is no longer needed. Default flags are unchanged: Release and MinSizeRel get -g1 -fno-omit-frame-pointer, RelWithDebInfo gets -fno-omit-frame-pointer, Debug is untouched. Co-Authored-By: Claude Opus 5.5 --- cmake/module/ProcessConfigurations.cmake | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/cmake/module/ProcessConfigurations.cmake b/cmake/module/ProcessConfigurations.cmake index 5accf45d3ad6..618617d25dbf 100644 --- a/cmake/module/ProcessConfigurations.cmake +++ b/cmake/module/ProcessConfigurations.cmake @@ -105,22 +105,13 @@ function(remove_cxx_flag_from_all_configs flag) endfunction() function(append_flag_to_config lang config flag) - string(TOUPPER "${config}" config_uppercase) - set(flags_var CMAKE_${lang}_FLAGS_${config_uppercase}) - set(flags "${${flags_var}}") - separate_arguments(flags) - # Appending unconditionally would re-append on every reconfigure, because the - # value read back here is the one this function forced into the cache last time. - if(NOT "${flag}" IN_LIST flags) - list(APPEND flags "${flag}") + string(TOUPPER "CMAKE_${lang}_FLAGS_${config}" var_name) + if("${var_name}" IN_LIST precious_variables) + return() endif() - list(JOIN flags " " new_flags) - set(${flags_var} "${new_flags}" PARENT_SCOPE) - set(${flags_var} "${new_flags}" - CACHE STRING - "Flags used by the ${lang} compiler during ${config_uppercase} builds." - FORCE - ) + string(STRIP "${${var_name}} ${flag}" ${var_name}) + set(${var_name} "${${var_name}}" PARENT_SCOPE) + set_property(CACHE ${var_name} PROPERTY VALUE "${${var_name}}") endfunction() function(replace_cxx_flag_in_config config old_flag new_flag) From 6a82c372725f4220f4a3b4496348dbf1ebfe52b3 Mon Sep 17 00:00:00 2001 From: pasta Date: Mon, 16 Nov 2026 06:29:53 +0000 Subject: [PATCH 10/10] test: only treat the raii_event_tests skip message as a skipped suite Since bitcoin#30803, ctest runs each unit test suite with --log_level=test_suite and DEBUG_LOG_OUT, so the node's debug log ends up in the output that SKIP_REGULAR_EXPRESSION is matched against. The bare "Skipping" pattern then matches Dash log lines such as the index "Skipping commit, index is ahead of flushed chainstate" and governance "Skipping payment exception" messages, and ctest reported ten suites (baseindex_tests, wallet_tests, txindex_tests, governance and masternode suites, ...) as skipped even though they ran. A suite reported as skipped also hides a failure. Match the one message that really means a suite was skipped, as upstream later did for its own skip message in bitcoin#31576. Co-Authored-By: Claude Opus 5.5 --- src/test/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 8cb0e4ddf844..28f704753738 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -239,7 +239,9 @@ function(add_boost_test source_file) COMMAND test_bitcoin --run_test=${test_suite_name} --catch_system_error=no --log_level=test_suite -- DEBUG_LOG_OUT ) set_property(TEST ${test_suite_name} PROPERTY - SKIP_REGULAR_EXPRESSION "no test cases matching filter" "Skipping" + SKIP_REGULAR_EXPRESSION + "no test cases matching filter" + "Skipping raii_event_tess" ) endif() endfunction()