From: Daniel Arndt Date: Wed, 13 Mar 2019 09:28:23 +0000 (+0100) Subject: Replace '-Werror' by a _werror_flag variable X-Git-Tag: v9.1.0-rc1~256^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F7801%2Fhead;p=dealii.git Replace '-Werror' by a _werror_flag variable --- diff --git a/cmake/checks/check_01_cxx_features.cmake b/cmake/checks/check_01_cxx_features.cmake index 2f5cf61e7e..d1ec609daa 100644 --- a/cmake/checks/check_01_cxx_features.cmake +++ b/cmake/checks/check_01_cxx_features.cmake @@ -32,6 +32,17 @@ # +# +# 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]] diff --git a/cmake/checks/check_02_compiler_features.cmake b/cmake/checks/check_02_compiler_features.cmake index e844e7d904..32019e2d33 100644 --- a/cmake/checks/check_02_compiler_features.cmake +++ b/cmake/checks/check_02_compiler_features.cmake @@ -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\")