]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Allow CXX14/17 autodetection for MSVC
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Tue, 12 Mar 2019 20:35:11 +0000 (21:35 +0100)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Wed, 13 Mar 2019 01:10:14 +0000 (02:10 +0100)
cmake/checks/check_01_cxx_features.cmake
cmake/checks/check_02_compiler_features.cmake
cmake/configure/configure_2_boost.cmake

index bf1aedec3bee4628ddb872403363d2ddc6d4897f..1f71219af41f4700bdf87a1831f3f3951da9d3b0 100644 (file)
@@ -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 <memory>
@@ -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]]
 #
index d108cc47672f3a934d20b9157f0b2711551fe974..d7d7c832189307ce8607762d8a2d1c202ac34322 100644 (file)
@@ -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; }
index 5c6f9c35a8065c7945cdff6d745aa1236e5e3f3e..1b5988fc8f361be4ecb54c5dd32d398b00054d41 100644 (file)
@@ -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(
     "

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.