From: Daniel Arndt Date: Tue, 12 Mar 2019 20:35:11 +0000 (+0100) Subject: Allow CXX14/17 autodetection for MSVC X-Git-Tag: v9.1.0-rc1~256^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f9053427795e0c23bbc54a1d8fd003a3d251197;p=dealii.git Allow CXX14/17 autodetection for MSVC --- diff --git a/cmake/checks/check_01_cxx_features.cmake b/cmake/checks/check_01_cxx_features.cmake index bf1aedec3b..1f71219af4 100644 --- a/cmake/checks/check_01_cxx_features.cmake +++ b/cmake/checks/check_01_cxx_features.cmake @@ -99,10 +99,17 @@ ENDIF() MACRO(_check_cxx_flag _suffix) IF("${DEAL_II_CXX_VERSION_FLAG}" STREQUAL "") - CHECK_CXX_COMPILER_FLAG("-std=c++${_suffix}" DEAL_II_HAVE_FLAG_stdcxx${_suffix}) - IF(DEAL_II_HAVE_FLAG_stdcxx${_suffix}) - SET(DEAL_II_CXX_VERSION_FLAG "-std=c++${_suffix}") - ENDIF() + IF(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + CHECK_CXX_COMPILER_FLAG("/std:c++${_suffix}" DEAL_II_HAVE_FLAG_stdcxx${_suffix}) + IF(DEAL_II_HAVE_FLAG_stdcxx${_suffix}) + SET(DEAL_II_CXX_VERSION_FLAG "/std:c++${_suffix}") + ENDIF() + ELSE() + CHECK_CXX_COMPILER_FLAG("-std=c++${_suffix}" DEAL_II_HAVE_FLAG_stdcxx${_suffix}) + IF(DEAL_II_HAVE_FLAG_stdcxx${_suffix}) + SET(DEAL_II_CXX_VERSION_FLAG "-std=c++${_suffix}") + ENDIF() + ENDIF() ENDIF() ENDMACRO() @@ -126,7 +133,12 @@ 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}\"") - ADD_FLAGS(CMAKE_REQUIRED_FLAGS "${DEAL_II_CXX_VERSION_FLAG} -Werror") + 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}") UNSET_IF_CHANGED(CHECK_CXX_FEATURES_FLAGS_CXX17_SAVED "${CMAKE_REQUIRED_FLAGS}${DEAL_II_CXX_VERSION_FLAG}" @@ -512,6 +524,9 @@ _bailout("17" "1z") # try to avoid adding an extra flag by doing one last test: # RESET_CMAKE_REQUIRED() +IF(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + ADD_FLAGS(CMAKE_REQUIRED_FLAGS "/Zc:__cplusplus") +ENDIF() CHECK_CXX_SOURCE_COMPILES( " #include @@ -527,6 +542,7 @@ CHECK_CXX_SOURCE_COMPILES( } " DEAL_II_COMPILER_DEFAULTS_TO_CXX11_OR_NEWER) + RESET_CMAKE_REQUIRED() IF(_user_provided_cxx_version_flag OR NOT DEAL_II_COMPILER_DEFAULTS_TO_CXX11_OR_NEWER OR @@ -570,7 +586,11 @@ UNSET_IF_CHANGED(CHECK_CXX_FEATURES_FLAGS_SAVED # possibilities here. # ADD_FLAGS(CMAKE_REQUIRED_FLAGS "${DEAL_II_CXX_FLAGS}") -ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Werror -Wno-unused-command-line-argument") +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") +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 d108cc4767..d7d7c83218 100644 --- a/cmake/checks/check_02_compiler_features.cmake +++ b/cmake/checks/check_02_compiler_features.cmake @@ -298,7 +298,11 @@ ENDIF() # "warning #1292: unknown attribute "deprecated"" (icc) # Hence, we treat warnings as errors: ADD_FLAGS(CMAKE_REQUIRED_FLAGS "${DEAL_II_CXX_FLAGS}") -ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Werror -Wno-unused-command-line-argument") +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") +ENDIF() # first see if the compiler accepts the attribute CHECK_CXX_SOURCE_COMPILES( @@ -405,7 +409,11 @@ ENDIF() # # - Matthias Maier, 2015 # -ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Werror") +IF(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + ADD_FLAGS(CMAKE_REQUIRED_FLAGS "/WX") +ELSE() + ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Werror") +ENDIF() CHECK_CXX_SOURCE_COMPILES( " _Pragma(\"GCC diagnostic push\") @@ -439,7 +447,12 @@ IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang") ELSEIF(CMAKE_CXX_COMPILER_ID MATCHES "Intel") ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-diag-error warn") ENDIF() -ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Werror -fuse-ld=lld") +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 "-fuse-ld=lld") CHECK_CXX_SOURCE_COMPILES( " int main() { return 0; } @@ -452,7 +465,12 @@ IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang") ELSEIF(CMAKE_CXX_COMPILER_ID MATCHES "Intel") ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-diag-error warn") ENDIF() -ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Werror -fuse-ld=gold") +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 "-fuse-ld=gold") CHECK_CXX_SOURCE_COMPILES( " int main() { return 0; } diff --git a/cmake/configure/configure_2_boost.cmake b/cmake/configure/configure_2_boost.cmake index 5c6f9c35a8..1b5988fc8f 100644 --- a/cmake/configure/configure_2_boost.cmake +++ b/cmake/configure/configure_2_boost.cmake @@ -58,7 +58,11 @@ MACRO(FEATURE_BOOST_CONFIGURE_COMMON) # Older boost versions can't know about this but provide a possibility to # circumvent the issue. Hence, we just check ourselves. ADD_FLAGS(CMAKE_REQUIRED_FLAGS "${DEAL_II_CXX_VERSION_FLAG}") - ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Werror") + IF(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + ADD_FLAGS(CMAKE_REQUIRED_FLAGS "/WX") + ELSE() + ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Werror") + ENDIF() CHECK_CXX_SOURCE_COMPILES( "