Skip to content

Commit 60f0046

Browse files
committed
cmake: Add WERROR option
1 parent 3d5a730 commit 60f0046

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
@@ -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)
@@ -296,6 +297,19 @@ if(REDUCE_EXPORTS)
296297
try_append_linker_flag("-Wl,--exclude-libs,ALL" TARGET core)
297298
endif()
298299

300+
if(WERROR)
301+
if(MSVC)
302+
set(werror_flag "/WX")
303+
else()
304+
set(werror_flag "-Werror")
305+
endif()
306+
try_append_cxx_flags(${werror_flag} TARGET core RESULT_VAR compiler_supports_werror)
307+
if(NOT compiler_supports_werror)
308+
message(FATAL_ERROR "WERROR set but ${werror_flag} is not usable.")
309+
endif()
310+
unset(werror_flag)
311+
endif()
312+
299313
find_package(Python3 3.9 COMPONENTS Interpreter)
300314
set(PYTHON_COMMAND ${Python3_EXECUTABLE})
301315

@@ -352,6 +366,7 @@ message("Linker flags for shared libraries ..... ${CMAKE_SHARED_LINKER_FLAGS}")
352366
print_config_flags()
353367
message("Use assembly routines ................. ${ASM}")
354368
message("Attempt to harden executables ......... ${HARDENING}")
369+
message("Treat compiler warnings as errors ..... ${WERROR}")
355370
message("Use ccache for compiling .............. ${CCACHE}")
356371
message("\n")
357372
if(configure_warnings)

0 commit comments

Comments
 (0)