cmake: Add WERROR option

This commit is contained in:
Hennadii Stepanov 2024-07-04 00:24:49 +01:00
parent c98d4a4c34
commit 30f642952c
No known key found for this signature in database
GPG key ID: 410108112E7EA81F

View file

@ -106,6 +106,7 @@ cmake_dependent_option(BUILD_WALLET_TOOL "Build bitcoin-wallet tool." ${BUILD_TE
option(ENABLE_HARDENING "Attempt to harden the resulting executables." ON) option(ENABLE_HARDENING "Attempt to harden the resulting executables." ON)
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_NATPMP "Enable NAT-PMP." OFF) option(WITH_NATPMP "Enable NAT-PMP." OFF)
@ -412,6 +413,19 @@ 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()
find_package(Python3 3.9 COMPONENTS Interpreter) find_package(Python3 3.9 COMPONENTS Interpreter)
if(Python3_EXECUTABLE) if(Python3_EXECUTABLE)
set(PYTHON_COMMAND ${Python3_EXECUTABLE}) set(PYTHON_COMMAND ${Python3_EXECUTABLE})
@ -471,6 +485,7 @@ message("C++ compiler .......................... ${CMAKE_CXX_COMPILER_ID} ${CMAK
include(FlagsSummary) include(FlagsSummary)
flags_summary() flags_summary()
message("Attempt to harden executables ......... ${ENABLE_HARDENING}") message("Attempt to harden executables ......... ${ENABLE_HARDENING}")
message("Treat compiler warnings as errors ..... ${WERROR}")
message("Use ccache for compiling .............. ${WITH_CCACHE}") message("Use ccache for compiling .............. ${WITH_CCACHE}")
message("\n") message("\n")
if(configure_warnings) if(configure_warnings)