build: replace WERROR with CMAKE_COMPILE_WARNING_AS_ERROR
What changed, and why it matters
This is a build-system cleanup. It swaps a custom Bitcoin Core option called WERROR for a standard CMake option called CMAKE_COMPILE_WARNING_AS_ERROR, which does the same thing: turn compiler warnings into build errors. No security vulnerability is present; it is purely a maintenance change to use upstream CMake functionality.
No security action needed. Reviewers should verify that CI still fails on compiler warnings as intended and that the previous-releases job's older CMake path remains functional.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit removes the custom cmake_dependent_option(WERROR …) and the manual logic that appended -Werror or /WX to compiler/linker flags. It replaces that with CMake’s native CMAKE_COMPILE_WARNING_AS_ERROR property/option (available since CMake 3.24). CI scripts and the GitHub workflow are updated to pass -DCMAKE_COMPILE_WARNING_AS_ERROR=ON instead of -DWERROR=ON. The previous-releases CI job, which runs on Ubuntu 22.04 with an older CMake, keeps -Werror via explicit C/CXX flags. A new –compile-no-warning-as-error escape hatch is noted for future CI use.
Changed components
CMake build configurationCI workflow scriptsGitHub Actions CIInspect captured patch +8 / −24
diff --git a/.github/ci-test-each-commit-exec.py b/.github/ci-test-each-commit-exec.py
index fcd3bbdb..cdbf4ff4 100755
--- a/.github/ci-test-each-commit-exec.py
+++ b/.github/ci-test-each-commit-exec.py
@@ -38,7 +38,7 @@ def main():
"-DAPPEND_CXXFLAGS='-O3 -g2'",
"-DAPPEND_CFLAGS='-O3 -g2'",
"-DCMAKE_BUILD_TYPE=Debug",
- "-DWERROR=ON",
+ "-DCMAKE_COMPILE_WARNING_AS_ERROR=ON",
"--preset=dev-mode",
# Tolerate unused member functions in intermediate commits in a pull request
"-DCMAKE_CXX_FLAGS=-Wno-error=unused-member-function",
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index ed0a77c2..8257f565 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -218,10 +218,10 @@ jobs:
job-type: [standard, fuzz]
include:
- job-type: standard
- generate-options: '-DBUILD_BENCH=ON -DBUILD_KERNEL_LIB=ON -DBUILD_UTIL_CHAINSTATE=ON -DWERROR=ON'
+ generate-options: '-DBUILD_BENCH=ON -DBUILD_KERNEL_LIB=ON -DBUILD_UTIL_CHAINSTATE=ON -DCMAKE_COMPILE_WARNING_AS_ERROR=ON'
job-name: 'Windows native, VS 2022'
- job-type: fuzz
- generate-options: '-DVCPKG_MANIFEST_NO_DEFAULT_FEATURES=ON -DVCPKG_MANIFEST_FEATURES="wallet" -DBUILD_GUI=OFF -DWITH_ZMQ=OFF -DBUILD_FOR_FUZZING=ON -DWERROR=ON'
+ generate-options: '-DVCPKG_MANIFEST_NO_DEFAULT_FEATURES=ON -DVCPKG_MANIFEST_FEATURES="wallet" -DBUILD_GUI=OFF -DWITH_ZMQ=OFF -DBUILD_FOR_FUZZING=ON -DCMAKE_COMPILE_WARNING_AS_ERROR=ON'
job-name: 'Windows native, fuzz, VS 2022'
steps:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 005b1074..f992a8d6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -119,7 +119,6 @@ endif()
cmake_dependent_option(BUILD_WALLET_TOOL "Build bitcoin-wallet tool." ${BUILD_TESTS} "ENABLE_WALLET" OFF)
option(REDUCE_EXPORTS "Attempt to reduce exported symbols in the resulting executables." OFF)
-option(WERROR "Treat compiler warnings as errors." OFF)
option(WITH_CCACHE "Attempt to use ccache for compiling." ON)
option(WITH_ZMQ "Enable ZMQ notifications." OFF)
@@ -568,19 +567,6 @@ if(REDUCE_EXPORTS)
try_append_linker_flag("-Wl,-no_exported_symbols" VAR CMAKE_EXE_LINKER_FLAGS)
endif()
-if(WERROR)
- if(MSVC)
- set(werror_flag "/WX")
- else()
- set(werror_flag "-Werror")
- endif()
- try_append_cxx_flags(${werror_flag} TARGET core_interface SKIP_LINK RESULT_VAR compiler_supports_werror)
- if(NOT compiler_supports_werror)
- message(FATAL_ERROR "WERROR set but ${werror_flag} is not usable.")
- endif()
- unset(werror_flag)
-endif()
-
# Prefer Unix-style package components over frameworks on macOS.
# This improves compatibility with Python version managers.
set(Python3_FIND_FRAMEWORK LAST CACHE STRING "")
@@ -685,7 +671,7 @@ message("Cross compiling ....................... ${cross_status}")
message("C++ compiler .......................... ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}, ${CMAKE_CXX_COMPILER}")
include(FlagsSummary)
flags_summary()
-message("Treat compiler warnings as errors ..... ${WERROR}")
+message("Treat compiler warnings as errors ..... ${CMAKE_COMPILE_WARNING_AS_ERROR}")
message("Use ccache for compiling .............. ${WITH_CCACHE}")
message("\n")
if(configure_warnings)
diff --git a/ci/test/00_setup_env_native_previous_releases.sh b/ci/test/00_setup_env_native_previous_releases.sh
index a44a51c3..d6af52c4 100755
--- a/ci/test/00_setup_env_native_previous_releases.sh
+++ b/ci/test/00_setup_env_native_previous_releases.sh
@@ -15,13 +15,14 @@ export TEST_RUNNER_EXTRA="--previous-releases --coverage --extended --exclude fe
export GOAL="install"
export CI_LIMIT_STACK_SIZE=1
export DOWNLOAD_PREVIOUS_RELEASES="true"
+# Use -Werror as the CMake version does not support CMAKE_COMPILE_WARNING_AS_ERROR
export BITCOIN_CONFIG="\
--preset=dev-mode \
-DREDUCE_EXPORTS=ON \
-DCMAKE_BUILD_TYPE=Debug \
- -DCMAKE_C_FLAGS='-funsigned-char' \
+ -DCMAKE_C_FLAGS='-funsigned-char -Werror' \
-DCMAKE_C_FLAGS_DEBUG='-g2 -O2' \
- -DCMAKE_CXX_FLAGS='-funsigned-char' \
+ -DCMAKE_CXX_FLAGS='-funsigned-char -Werror' \
-DCMAKE_CXX_FLAGS_DEBUG='-g2 -O2' \
-DAPPEND_CPPFLAGS='-DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE' \
"
diff --git a/ci/test/03_test_script.sh b/ci/test/03_test_script.sh
index 8d1a739d..c2117d7e 100755
--- a/ci/test/03_test_script.sh
+++ b/ci/test/03_test_script.sh
@@ -81,13 +81,10 @@ if [ "$DOWNLOAD_PREVIOUS_RELEASES" = "true" ]; then
test/get_previous_releases.py --target-dir "$PREVIOUS_RELEASES_DIR"
fi
-BITCOIN_CONFIG_ALL="-DBUILD_BENCH=ON -DBUILD_FUZZ_BINARY=ON"
+BITCOIN_CONFIG_ALL="-DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DBUILD_BENCH=ON -DBUILD_FUZZ_BINARY=ON"
if [ -z "$NO_DEPENDS" ]; then
BITCOIN_CONFIG_ALL="${BITCOIN_CONFIG_ALL} -DCMAKE_TOOLCHAIN_FILE=$DEPENDS_DIR/$HOST/toolchain.cmake"
fi
-if [ -z "$NO_WERROR" ]; then
- BITCOIN_CONFIG_ALL="${BITCOIN_CONFIG_ALL} -DWERROR=ON"
-fi
ccache --zero-stats
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.