cmake: Allow to make compile warnings fatal
authorManuel Nickschas <sputnick@quassel-irc.org>
Sun, 18 Nov 2018 20:02:12 +0000 (21:02 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 18 Nov 2018 23:59:46 +0000 (00:59 +0100)
Failing on any compile warning is very useful in CI builds,
so add an option for enabling this. The option defaults to OFF,
because we don't want to annoy users that don't want this.

Enable fatal warnings in Travis CI.

.travis.yml
CMakeLists.txt
cmake/QuasselCompileSettings.cmake

index 36b1e2f..a997607 100644 (file)
@@ -44,6 +44,7 @@ script:
                             -GNinja \
                             -DCMAKE_BUILD_TYPE=RelWithDebInfo \
                             -DBUILD_TESTING=ON \
+                            -DFATAL_WARNINGS=ON \
                       && ninja install \
                       && ccache -s \
                       && ctest -VV \
index 9f4e235..a27d1a6 100644 (file)
@@ -107,6 +107,7 @@ if (NOT EMBED_DEFAULT)
 endif()
 
 # The following options are not for end-user consumption, so don't list them in the feature summary
+option(FATAL_WARNINGS "Make compile warnings fatal (most useful for CI builds)" OFF)
 cmake_dependent_option(DEPLOY "Add required libs to bundle resources and create a dmg" OFF "APPLE" OFF)
 
 # List of authenticators and the cmake flags to build them
index 2914f42..2e5d592 100644 (file)
@@ -45,6 +45,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
         -Wundef
         -Wvla
         -Werror=return-type
+        "$<$<BOOL:${FATAL_WARNINGS}>:-Werror>"
         -Wno-unknown-pragmas
         "$<$<NOT:$<CONFIG:Debug>>:-U_FORTIFY_SOURCE;-D_FORTIFY_SOURCE=2>"
     )
@@ -68,7 +69,10 @@ elseif(MSVC)
     add_definitions(-DWIN32_LEAN_AND_MEAN -DUNICODE -D_UNICODE -D_USE_MATH_DEFINES -DNOMINMAX)
 
     # Compile options
-    add_compile_options(/EHsc)
+    add_compile_options(
+        /EHsc
+        "$<$<BOOL:${FATAL_WARNINGS}>:/WX>"
+    )
 
     # Increase warning level on MSVC
     # CMake puts /W3 in CMAKE_CXX_FLAGS which will be appended later, so we need to replace