From bf08502b9cf76ec026045099083f3b5a549ac488 Mon Sep 17 00:00:00 2001 From: Peter Keresztes Schmidt Date: Fri, 30 Apr 2021 00:13:32 +0200 Subject: [PATCH] Build: Add CMake option to enable Werror With -DENABLE_WERROR the -Werror flag will be passed to the compiler failing the build if a warning is emitted. --- CMakeLists.txt | 1 + cmake/compiler/clang/settings.cmake | 6 ++++++ cmake/compiler/gcc/settings.cmake | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c5007b396..700c80a20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,6 +90,7 @@ mark_as_advanced( ZM_SYSTEMD ZM_MANPAGE_DEST_PREFIX) +option(ENABLE_WERROR "Fail the build if a compiler warning is emitted" 0) option(BUILD_TEST_SUITE "Build the test suite" 0) option(BUILD_MAN "Build man pages" 1) option(ASAN "DEBUGGING: Build with AddressSanitizer (ASan) support" 0) diff --git a/cmake/compiler/clang/settings.cmake b/cmake/compiler/clang/settings.cmake index 1e5485001..6c5419a94 100644 --- a/cmake/compiler/clang/settings.cmake +++ b/cmake/compiler/clang/settings.cmake @@ -5,6 +5,12 @@ target_compile_options(zm-warning-interface -Wimplicit-fallthrough -Wno-unused-parameter) +if(ENABLE_WERROR) + target_compile_options(zm-warning-interface + INTERFACE + -Werror) +endif() + if(ASAN) target_compile_options(zm-compile-option-interface INTERFACE diff --git a/cmake/compiler/gcc/settings.cmake b/cmake/compiler/gcc/settings.cmake index 741b970ec..097270d51 100644 --- a/cmake/compiler/gcc/settings.cmake +++ b/cmake/compiler/gcc/settings.cmake @@ -9,6 +9,12 @@ target_compile_options(zm-warning-interface -Wno-unused-parameter -Woverloaded-virtual) +if(ENABLE_WERROR) + target_compile_options(zm-warning-interface + INTERFACE + -Werror) +endif() + if(ASAN) target_compile_options(zm-compile-option-interface INTERFACE