]> danny-edel.de - dspdfviewer.git/commitdiff
make Werror optional and default to off
authorDanny Edel <mail@danny-edel.de>
Wed, 26 Apr 2023 21:17:35 +0000 (23:17 +0200)
committerDanny Edel <mail@danny-edel.de>
Wed, 26 Apr 2023 21:17:35 +0000 (23:17 +0200)
CMakeLists.txt
cmake/compiler_clang.cmake
cmake/compiler_gnu_gcc.cmake

index 3feef42198bbea27df60fc3d7e6cadf89e0458b8..42dcff3303ebb07e55a9133683633d315818a1b7 100644 (file)
@@ -43,6 +43,7 @@ option(BoostStaticLink "Link statically against the boost libraries" OFF)
 option(WindowsStaticLink "Windows/MSVC only: Link statically against the dependencies and set /MT instead of /MD" ON)
 option(UsePrerenderedPDF "Use prerendered PDFs included in the source for testing, instead of building with pdflatex" OFF)
 option(CodeCoverage "Add coverage analysis code to the program. Will slow it down. A lot. Only supported on GCC right now." OFF)
+option(WarningAsError "Turn on -Werror and similar compiler settings.  This can be useful during development, but is disabled by default for release build scripts." OFF)
 
 include(cmake/platforms.cmake)
 include(cmake/filelists.cmake)
index 796f6344c7b320e07a400e3fc412a34173b2b1af..53f0da6c5c99a40e64620ead9bb3f2728356be08 100644 (file)
@@ -5,8 +5,6 @@ add_definitions("-std=c++11")
 
 # Turn on a lot of warnings, hopefully helping with code quality.
 add_definitions(-Weverything)
-# And turn them into errors.
-add_definitions(-Werror)
 
 # Disable warnings irrelevant to the project:
 #   c++98 compatibility warnings
@@ -25,28 +23,33 @@ if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug" )
        add_definitions(-Wno-unreachable-code -Wno-disabled-macro-expansion)
 endif()
 
-# Qt's moc (Meta Object Compiler) generates code that triggers warnings
-# about undefined behaviours.
+if(WarningAsError)
+    # Turn warnings into errors.
+    add_definitions(-Werror)
 
-# So don't set Werror for it.
-# FIXME: Set this only for the automoc files
-add_definitions(-Wno-error=undefined-reinterpret-cast)
-add_definitions(-Wno-error=redundant-parens)
-add_definitions(-Wno-error=extra-semi-stmt)
+    # Qt's moc (Meta Object Compiler) generates code that triggers warnings
+    # about undefined behaviours.
 
-# FIXME: These are apple-clang specific
-add_definitions(-Wno-error=poison-system-directories)
-add_definitions("-Wno-error=#warnings")
+    # So don't set Werror for it.
+    # FIXME: Set this only for the automoc files
+    add_definitions(-Wno-error=undefined-reinterpret-cast)
+    add_definitions(-Wno-error=redundant-parens)
+    add_definitions(-Wno-error=extra-semi-stmt)
 
-# Clang on recent XCode fails to compile the boost tests
-add_definitions(-Wno-error=disabled-macro-expansion)
+    # FIXME: These are apple-clang specific
+    add_definitions(-Wno-error=poison-system-directories)
+    add_definitions("-Wno-error=#warnings")
 
+    # Clang on recent XCode fails to compile the boost tests
+    add_definitions(-Wno-error=disabled-macro-expansion)
+
+    # unit_test_log from boost::test will trigger this warning
+    add_definitions(-Wno-error=used-but-marked-unused)
+endif()
 # clang will complain about -isystem passed but not used.
 # This adds unnecessary noise
 add_definitions(-Wno-unused-command-line-argument)
 
-# unit_test_log from boost::test will trigger this warning
-add_definitions(-Wno-error=used-but-marked-unused)
 
 # qrc system generates code that triggers a lot of the
 # clang warnings.
index 5b2fb0ab74a8724398d7b9c8c1e919acd650cef2..650b66818b5b4d367ca116db350a8f621ad3841a 100644 (file)
@@ -2,8 +2,20 @@
 
 include(CheckCXXCompilerFlag)
 
+CHECK_CXX_COMPILER_FLAG("-std=c++20" C20FLAG)
+CHECK_CXX_COMPILER_FLAG("-std=c++17" C17FLAG)
+CHECK_CXX_COMPILER_FLAG("-std=c++14" C14FLAG)
 CHECK_CXX_COMPILER_FLAG("-std=c++11" C11FLAG)
-if(C11FLAG)
+if(C20FLAG)
+    message(STATUS "Compiler supports -std=c++20, using it.")
+    add_definitions(-std=c++20)
+elseif(C17FLAG)
+    message(STATUS "Compiler supports -std=c++17, using it.")
+    add_definitions(-std=c++17)
+elseif(C14FLAG)
+    message(STATUS "Compiler supports -std=c++14, using it.")
+    add_definitions(-std=c++14)
+elseif(C11FLAG)
        message(STATUS "Compiler supports -std=c++11, using it.")
        add_definitions(-std=c++11)
 else()
@@ -29,8 +41,10 @@ add_definitions(
        -Weffc++
 )
 
-# Turn all warnings into errors
-add_definitions(-Werror -pedantic-errors)
+if(WarningAsError)
+    # Turn all warnings into errors
+    add_definitions(-Werror -pedantic-errors)
+endif()
 
 if(CodeCoverage)
        message(STATUS "Adding gcov as test coverage helper")