build: replace WERROR with CMAKE_COMPILE_WARNING_AS_ERROR

-Werror is added to the previous releases job, given it runs on Ubuntu
22.04, which uses an older CMake.

`--compile-no-warning-as-error` can be used, if needed, in future, to
suppress the `CMAKE_COMPILE_WARNING_AS_ERROR` behaviour from a CI
config.

CMAKE_COMPILE_WARNING_AS_ERROR was added to CMake in 3.24.
See https://cmake.org/cmake/help/latest/prop_tgt/COMPILE_WARNING_AS_ERROR.html.

Co-authored-by: willcl-ark <will8clark@gmail.com>
This commit is contained in:
fanquake
2026-01-28 11:53:07 +00:00
parent eb97250421
commit 322c4ec442
5 changed files with 8 additions and 24 deletions

View File

@@ -38,7 +38,7 @@ def main():
"-DAPPEND_CXXFLAGS='-O3 -g2'", "-DAPPEND_CXXFLAGS='-O3 -g2'",
"-DAPPEND_CFLAGS='-O3 -g2'", "-DAPPEND_CFLAGS='-O3 -g2'",
"-DCMAKE_BUILD_TYPE=Debug", "-DCMAKE_BUILD_TYPE=Debug",
"-DWERROR=ON", "-DCMAKE_COMPILE_WARNING_AS_ERROR=ON",
"--preset=dev-mode", "--preset=dev-mode",
# Tolerate unused member functions in intermediate commits in a pull request # Tolerate unused member functions in intermediate commits in a pull request
"-DCMAKE_CXX_FLAGS=-Wno-error=unused-member-function", "-DCMAKE_CXX_FLAGS=-Wno-error=unused-member-function",

View File

@@ -218,10 +218,10 @@ jobs:
job-type: [standard, fuzz] job-type: [standard, fuzz]
include: include:
- job-type: standard - 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-name: 'Windows native, VS 2022'
- job-type: fuzz - 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' job-name: 'Windows native, fuzz, VS 2022'
steps: steps:

View File

@@ -119,7 +119,6 @@ endif()
cmake_dependent_option(BUILD_WALLET_TOOL "Build bitcoin-wallet tool." ${BUILD_TESTS} "ENABLE_WALLET" OFF) 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(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_CCACHE "Attempt to use ccache for compiling." ON)
option(WITH_ZMQ "Enable ZMQ notifications." OFF) 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) try_append_linker_flag("-Wl,-no_exported_symbols" VAR CMAKE_EXE_LINKER_FLAGS)
endif() 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. # Prefer Unix-style package components over frameworks on macOS.
# This improves compatibility with Python version managers. # This improves compatibility with Python version managers.
set(Python3_FIND_FRAMEWORK LAST CACHE STRING "") 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}") message("C++ compiler .......................... ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}, ${CMAKE_CXX_COMPILER}")
include(FlagsSummary) include(FlagsSummary)
flags_summary() 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("Use ccache for compiling .............. ${WITH_CCACHE}")
message("\n") message("\n")
if(configure_warnings) if(configure_warnings)

View File

@@ -15,13 +15,14 @@ export TEST_RUNNER_EXTRA="--previous-releases --coverage --extended --exclude fe
export GOAL="install" export GOAL="install"
export CI_LIMIT_STACK_SIZE=1 export CI_LIMIT_STACK_SIZE=1
export DOWNLOAD_PREVIOUS_RELEASES="true" export DOWNLOAD_PREVIOUS_RELEASES="true"
# Use -Werror as the CMake version does not support CMAKE_COMPILE_WARNING_AS_ERROR
export BITCOIN_CONFIG="\ export BITCOIN_CONFIG="\
--preset=dev-mode \ --preset=dev-mode \
-DREDUCE_EXPORTS=ON \ -DREDUCE_EXPORTS=ON \
-DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_C_FLAGS='-funsigned-char' \ -DCMAKE_C_FLAGS='-funsigned-char -Werror' \
-DCMAKE_C_FLAGS_DEBUG='-g2 -O2' \ -DCMAKE_C_FLAGS_DEBUG='-g2 -O2' \
-DCMAKE_CXX_FLAGS='-funsigned-char' \ -DCMAKE_CXX_FLAGS='-funsigned-char -Werror' \
-DCMAKE_CXX_FLAGS_DEBUG='-g2 -O2' \ -DCMAKE_CXX_FLAGS_DEBUG='-g2 -O2' \
-DAPPEND_CPPFLAGS='-DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE' \ -DAPPEND_CPPFLAGS='-DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE' \
" "

View File

@@ -81,13 +81,10 @@ if [ "$DOWNLOAD_PREVIOUS_RELEASES" = "true" ]; then
test/get_previous_releases.py --target-dir "$PREVIOUS_RELEASES_DIR" test/get_previous_releases.py --target-dir "$PREVIOUS_RELEASES_DIR"
fi 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 if [ -z "$NO_DEPENDS" ]; then
BITCOIN_CONFIG_ALL="${BITCOIN_CONFIG_ALL} -DCMAKE_TOOLCHAIN_FILE=$DEPENDS_DIR/$HOST/toolchain.cmake" BITCOIN_CONFIG_ALL="${BITCOIN_CONFIG_ALL} -DCMAKE_TOOLCHAIN_FILE=$DEPENDS_DIR/$HOST/toolchain.cmake"
fi fi
if [ -z "$NO_WERROR" ]; then
BITCOIN_CONFIG_ALL="${BITCOIN_CONFIG_ALL} -DWERROR=ON"
fi
ccache --zero-stats ccache --zero-stats