Skip to content

Commit 5858d45

Browse files
committed
cmake: Add WERROR option
1 parent 8ada936 commit 5858d45

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

CMakeLists.txt

+15
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)
@@ -285,6 +286,19 @@ if(REDUCE_EXPORTS)
285286
try_append_linker_flag("-Wl,--exclude-libs,ALL" TARGET core)
286287
endif()
287288

289+
if(WERROR)
290+
if(MSVC)
291+
set(werror_flag "/WX")
292+
else()
293+
set(werror_flag "-Werror")
294+
endif()
295+
try_append_cxx_flags(${werror_flag} TARGET core RESULT_VAR compiler_supports_werror)
296+
if(NOT compiler_supports_werror)
297+
message(FATAL_ERROR "WERROR set but ${werror_flag} is not usable.")
298+
endif()
299+
unset(werror_flag)
300+
endif()
301+
288302
find_package(Python3 3.9 COMPONENTS Interpreter)
289303
set(PYTHON_COMMAND ${Python3_EXECUTABLE})
290304

@@ -341,6 +355,7 @@ message("Linker flags for shared libraries ..... ${CMAKE_SHARED_LINKER_FLAGS}")
341355
print_config_flags()
342356
message("Use assembly routines ................. ${ASM}")
343357
message("Attempt to harden executables ......... ${HARDENING}")
358+
message("Treat compiler warnings as errors ..... ${WERROR}")
344359
message("Use ccache for compiling .............. ${CCACHE}")
345360
message("\n")
346361
if(configure_warnings)

0 commit comments

Comments
 (0)