Skip to content

Commit 30f6429

Browse files
committed
cmake: Add WERROR option
1 parent c98d4a4 commit 30f6429

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ cmake_dependent_option(BUILD_WALLET_TOOL "Build bitcoin-wallet tool." ${BUILD_TE
106106

107107
option(ENABLE_HARDENING "Attempt to harden the resulting executables." ON)
108108
option(REDUCE_EXPORTS "Attempt to reduce exported symbols in the resulting executables." OFF)
109+
option(WERROR "Treat compiler warnings as errors." OFF)
109110
option(WITH_CCACHE "Attempt to use ccache for compiling." ON)
110111

111112
option(WITH_NATPMP "Enable NAT-PMP." OFF)
@@ -412,6 +413,19 @@ if(REDUCE_EXPORTS)
412413
try_append_linker_flag("-Wl,-no_exported_symbols" VAR CMAKE_EXE_LINKER_FLAGS)
413414
endif()
414415

416+
if(WERROR)
417+
if(MSVC)
418+
set(werror_flag "/WX")
419+
else()
420+
set(werror_flag "-Werror")
421+
endif()
422+
try_append_cxx_flags(${werror_flag} TARGET core_interface SKIP_LINK RESULT_VAR compiler_supports_werror)
423+
if(NOT compiler_supports_werror)
424+
message(FATAL_ERROR "WERROR set but ${werror_flag} is not usable.")
425+
endif()
426+
unset(werror_flag)
427+
endif()
428+
415429
find_package(Python3 3.9 COMPONENTS Interpreter)
416430
if(Python3_EXECUTABLE)
417431
set(PYTHON_COMMAND ${Python3_EXECUTABLE})
@@ -471,6 +485,7 @@ message("C++ compiler .......................... ${CMAKE_CXX_COMPILER_ID} ${CMAK
471485
include(FlagsSummary)
472486
flags_summary()
473487
message("Attempt to harden executables ......... ${ENABLE_HARDENING}")
488+
message("Treat compiler warnings as errors ..... ${WERROR}")
474489
message("Use ccache for compiling .............. ${WITH_CCACHE}")
475490
message("\n")
476491
if(configure_warnings)

0 commit comments

Comments
 (0)