Skip to content

Commit 39b8e9d

Browse files
committed
cmake: Add WERROR option
1 parent ccf2c9c commit 39b8e9d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

CMakeLists.txt

+17
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ cmake_dependent_option(CXX20 "Enable compilation in C++20 mode." OFF "NOT MSVC"
5555
option(THREADLOCAL "Enable features that depend on the C++ thread_local keyword (currently just thread names in debug logs)." ON)
5656
option(HARDENING "Attempt to harden the resulting executables." ON)
5757
option(REDUCE_EXPORTS "Attempt to reduce exported symbols in the resulting executables." OFF)
58+
option(WERROR "Treat compiler warnings as errors." OFF)
5859

5960
tristate_option(CCACHE "Use ccache for compiling." "if ccache is found." AUTO)
6061
tristate_option(WITH_NATPMP "Enable NAT-PMP." "if libnatpmp is found." AUTO)
@@ -305,6 +306,21 @@ if(REDUCE_EXPORTS)
305306
try_append_linker_flag(core "-Wl,--exclude-libs,ALL")
306307
endif()
307308

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+
308324
find_package(Python3 3.8 COMPONENTS Interpreter)
309325
set(PYTHON_COMMAND ${Python3_EXECUTABLE})
310326

@@ -372,6 +388,7 @@ message("Linker flags for shared libraries ..... ${CMAKE_SHARED_LINKER_FLAGS}")
372388
print_config_flags()
373389
message("Use assembly routines ................. ${ASM}")
374390
message("Attempt to harden executables ......... ${HARDENING}")
391+
message("Treat compiler warnings as errors ..... ${WERROR}")
375392
message("Use ccache for compiling .............. ${CCACHE}")
376393
message("\n")
377394
if(configure_warnings)

0 commit comments

Comments
 (0)