@@ -55,6 +55,7 @@ cmake_dependent_option(CXX20 "Enable compilation in C++20 mode." OFF "NOT MSVC"
55
55
option (THREADLOCAL "Enable features that depend on the C++ thread_local keyword (currently just thread names in debug logs)." ON )
56
56
option (HARDENING "Attempt to harden the resulting executables." ON )
57
57
option (REDUCE_EXPORTS "Attempt to reduce exported symbols in the resulting executables." OFF )
58
+ option (WERROR "Treat compiler warnings as errors." OFF )
58
59
59
60
tristate_option(CCACHE "Use ccache for compiling." "if ccache is found." AUTO)
60
61
tristate_option(WITH_NATPMP "Enable NAT-PMP." "if libnatpmp is found." AUTO)
@@ -305,6 +306,21 @@ if(REDUCE_EXPORTS)
305
306
try_append_linker_flag(core "-Wl,--exclude-libs,ALL" )
306
307
endif ()
307
308
309
+ if (WERROR)
310
+ if (MSVC )
311
+ target_compile_options (core INTERFACE /WX)
312
+ else ()
313
+ set (error_cxx_flags)
314
+ try_append_cxxflag(error_cxx_flags "-Werror" )
315
+ if (NOT CXX_SUPPORTS_WERROR)
316
+ message (FATAL_ERROR "WERROR set but -Werror is not usable." )
317
+ endif ()
318
+ separate_arguments (error_cxx_flags)
319
+ target_compile_options (core INTERFACE ${error_cxx_flags} )
320
+ unset (error_cxx_flags)
321
+ endif ()
322
+ endif ()
323
+
308
324
find_package (Python3 3.8 COMPONENTS Interpreter)
309
325
set (PYTHON_COMMAND ${Python3_EXECUTABLE} )
310
326
@@ -372,6 +388,7 @@ message("Linker flags for shared libraries ..... ${CMAKE_SHARED_LINKER_FLAGS}")
372
388
print_config_flags()
373
389
message ("Use assembly routines ................. ${ASM} " )
374
390
message ("Attempt to harden executables ......... ${HARDENING} " )
391
+ message ("Treat compiler warnings as errors ..... ${WERROR} " )
375
392
message ("Use ccache for compiling .............. ${CCACHE} " )
376
393
message ("\n " )
377
394
if (configure_warnings)
0 commit comments