cmake: Allow deprecation warnings
[quassel.git] / cmake / QuasselCompileSettings.cmake
index 05c5a95..4493d4d 100644 (file)
@@ -1,6 +1,6 @@
 # This file contains compile flags and general build configuration for Quassel
 #
-# (C) 2014-2018 by the Quassel Project <devel@quassel-irc.org>
+# (C) 2014-2020 by the Quassel Project <devel@quassel-irc.org>
 #
 # Redistribution and use is allowed according to the terms of the BSD license.
 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
@@ -34,7 +34,6 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
         -fdiagnostics-color=always
         -fexceptions
         -fno-common
-        -fstack-protector-strong
         -Wall
         -Wextra
         -Wcast-align
@@ -45,10 +44,17 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
         -Wundef
         -Wvla
         -Werror=return-type
+        "$<$<BOOL:${FATAL_WARNINGS}>:-Werror>"
+        -Wno-error=deprecated  # Don't break on Qt upgrades
         -Wno-unknown-pragmas
         "$<$<NOT:$<CONFIG:Debug>>:-U_FORTIFY_SOURCE;-D_FORTIFY_SOURCE=2>"
     )
 
+    # ssp is currently very broken on MinGW
+    if(NOT MINGW)
+        add_compile_options(-fstack-protector-strong)
+    endif()
+
     # Check for and set linker flags
     check_and_set_linker_flag("-Wl,-z,relro"            RELRO            LINKER_FLAGS)
     check_and_set_linker_flag("-Wl,-z,now"              NOW              LINKER_FLAGS)
@@ -68,7 +74,26 @@ elseif(MSVC)
     add_definitions(-DWIN32_LEAN_AND_MEAN -DUNICODE -D_UNICODE -D_USE_MATH_DEFINES -DNOMINMAX)
 
     # Compile options
-    add_compile_options(-EHsc -W3)
+    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
+    string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+
+    # Silence annoying/useless warnings
+    #   C4127: conditional expression is constant
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4127")
+    #   C4244: 'identifier': conversion from 't1' to 't2', possible loss of data
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244")
+    #   C4456: declaration of 'identifier' hides previous local declaration
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4456")
+    #   C4458: declaration of 'identifier' hides class member
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4458")
+    #   C4996: deprecation warnings
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4996")
 
     # Link against the correct version of the C runtime
     set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/NODEFAULTLIB:libcmt /DEFAULTLIB:msvcrt ${CMAKE_EXE_LINKER_FLAGS_RELEASE}")