]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Replace '-Werror' by a _werror_flag variable 7801/head
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Wed, 13 Mar 2019 09:28:23 +0000 (10:28 +0100)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Wed, 13 Mar 2019 09:28:23 +0000 (10:28 +0100)
cmake/checks/check_01_cxx_features.cmake
cmake/checks/check_02_compiler_features.cmake

index 2f5cf61e7efc9c815d98b7891028bb4f6869542b..d1ec609daaf056d24f8d0b8b61739fa70e9cfcc7 100644 (file)
 #
 
 
+#
+# MSVC needs different compiler flags to turn warnings into errors
+# additionally a suitable exception handling model is required
+#
+IF(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
+  SET(_werror_flag "/WX /EHsc")
+ELSE()
+  SET(_werror_flag "-Werror")
+ENDIF()
+
+
 ########################################################################
 #                                                                      #
 #                         C++ Version Support:                         #
@@ -133,12 +144,7 @@ IF(NOT DEFINED DEAL_II_WITH_CXX17 OR DEAL_II_WITH_CXX17)
   IF(NOT "${DEAL_II_CXX_VERSION_FLAG}" STREQUAL "")
     # Set CMAKE_REQUIRED_FLAGS for the unit tests
     MESSAGE(STATUS "Using C++ version flag \"${DEAL_II_CXX_VERSION_FLAG}\"")
-    IF(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
-      ADD_FLAGS(CMAKE_REQUIRED_FLAGS "/WX /EHsc")
-    ELSE()
-      ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Werror")
-    ENDIF()
-    ADD_FLAGS(CMAKE_REQUIRED_FLAGS "${DEAL_II_CXX_VERSION_FLAG}")
+    ADD_FLAGS(CMAKE_REQUIRED_FLAGS "${DEAL_II_CXX_VERSION_FLAG} ${_werror_flag}")
 
     UNSET_IF_CHANGED(CHECK_CXX_FEATURES_FLAGS_CXX17_SAVED
       "${CMAKE_REQUIRED_FLAGS}${DEAL_II_CXX_VERSION_FLAG}"
@@ -586,10 +592,9 @@ UNSET_IF_CHANGED(CHECK_CXX_FEATURES_FLAGS_SAVED
 # possibilities here.
 #
 ADD_FLAGS(CMAKE_REQUIRED_FLAGS "${DEAL_II_CXX_FLAGS}")
-IF(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
-  ADD_FLAGS(CMAKE_REQUIRED_FLAGS "/WX")
-ELSE()
-  ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Werror -Wno-unused-command-line-argument")
+ADD_FLAGS(CMAKE_REQUIRED_FLAGS "${_werror_flag}")
+IF(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
+  ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Wno-unused-command-line-argument")
 ENDIF()
 #
 # first try the attribute [[fallthrough]]
index e844e7d904dcbc464f4c8d198e93b50946dcf85b..32019e2d331c85d70605009a107fc28242c41e34 100644 (file)
@@ -48,6 +48,15 @@ UNSET_IF_CHANGED(CHECK_CXX_FEATURES_FLAGS_SAVED
   DEAL_II_COMPILER_HAS_ATTRIBUTE_DEPRECATED
   )
 
+#
+# MSVC needs different compiler flags to turn warnings into errors
+# additionally a suitable exception handling model is required
+#
+IF(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
+  SET(_werror_flag "/WX /EHsc")
+ELSE()
+  SET(_werror_flag "-Werror")
+ENDIF()
 
 #
 # Check whether the compiler allows to use arithmetic operations
@@ -298,10 +307,9 @@ ENDIF()
 # "warning #1292: unknown attribute "deprecated"" (icc)
 # Hence, we treat warnings as errors:
 ADD_FLAGS(CMAKE_REQUIRED_FLAGS "${DEAL_II_CXX_FLAGS}")
-IF(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
-  ADD_FLAGS(CMAKE_REQUIRED_FLAGS "/WX")
-ELSE()
-  ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Werror -Wno-unused-command-line-argument")
+ADD_FLAGS(CMAKE_REQUIRED_FLAGS "${_werror_flag}")
+IF(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
+  ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Wno-unused-command-line-argument")
 ENDIF()
 
 # first see if the compiler accepts the attribute
@@ -409,11 +417,7 @@ ENDIF()
 #
 # - Matthias Maier, 2015
 #
-IF(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
-  ADD_FLAGS(CMAKE_REQUIRED_FLAGS "/WX")
-ELSE()
-  ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Werror")
-ENDIF()
+ADD_FLAGS(CMAKE_REQUIRED_FLAGS "${_werror_flag}")
 CHECK_CXX_SOURCE_COMPILES(
   "
   _Pragma(\"GCC diagnostic push\")

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.