Fix warnings with Intel 2021.4
[alexxy/gromacs.git] / cmake / gmxTestCompilerProblems.cmake
index ecce618630abaa6f2c5bcc877eaa425ba27b9bef..c382cc85bbf57d59fe9ee3c69b7e35b8dcccb7c6 100644 (file)
@@ -2,7 +2,7 @@
 # This file is part of the GROMACS molecular simulation package.
 #
 # Copyright (c) 2012,2013,2014,2015,2016 by the GROMACS development team.
-# Copyright (c) 2017,2018,2019,2020, by the GROMACS development team, led by
+# Copyright (c) 2017,2018,2019,2020,2021, by the GROMACS development team, led by
 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 # and including many others, as listed in the AUTHORS file in the
 # top-level source directory and at http://www.gromacs.org.
@@ -47,33 +47,41 @@ macro(gmx_test_compiler_problems)
         message(WARNING "The versions of the C and C++ compilers do not match (${CMAKE_C_COMPILER_VERSION} and ${CMAKE_CXX_COMPILER_VERSION}, respectively). Mixing different C/C++ compilers can cause problems.")
     endif()
 
-    # Error if compiler doesn't support required C++14 features.
+    # Error if compiler doesn't support required C++17 features.
     # cmake feature detection is currently inconsistent: gitlab.kitware.com/cmake/cmake/issues/18869
-    # When we use C++17 we might want to switch to using feature test macros.
+    # We might want to switch to using feature test macros some time.
     if(CMAKE_COMPILER_IS_GNUCXX)
-        if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5)
-            set(cxx_required_version "GCC version 5")
+        if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7)
+            set(cxx_required_version "GCC version 7")
         endif()
     elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
         if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.15)
             set(cxx_required_version "Visual Studio 2017")
         endif()
     elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
-        if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.6) # For feature complete C++14 only 3.4 is needed.
-            set(cxx_required_version "Clang 3.6")        # But prior version have bugs (e.g. debug symbol support)
-        endif()
-    elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
-        if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17)
-            set(cxx_required_version "Intel Compiler 2017")
+        if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5)
+            set(cxx_required_version "Clang 5")
         endif()
+    elseif(CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM")
+        # All versions of IntelLLVM (a.k.a. DPCPP) compiler so far support C++17
     else()
-        message(WARNING "You are using an unsupported compiler. Please make sure it fully supports C++14.")
+        message(WARNING "You are using an unsupported compiler. Please make sure it fully supports C++17.")
     endif()
     if (cxx_required_version)
         message(FATAL_ERROR "${cxx_required_version} or later required. "
-                            "Earlier versions don't have full C++14 support.")
+                            "Earlier versions don't have full C++17 support.")
     endif()
 
+    if (CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND NOT CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM")
+        message(WARNING "The Intel classic compiler is no longer supported. It may pass the tests, but is not tested by the GROMACS developers. Use the clang-based compiler from oneAPI, or gcc")
+    endif()
+    # Intel LLVM 2021.2 defaults to no-finite-math which isn't OK for GROMACS and its dependencies (muParser and GTest).
+    # This is why we set the flags globally via CMAKE_CXX_FLAGS
+    if(GMX_INTEL_LLVM AND GMX_INTEL_LLVM_VERSION GREATER_EQUAL 2021020)
+        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-finite-math-only")
+    endif()
+
+
     if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "XL")
         check_cxx_source_compiles(
 "// Test in-class array initalizers used with constructor initializer lists
@@ -90,7 +98,7 @@ TestStruct::TestStruct() : b(0) {}
         endif()
     endif()
     if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "PGI")
-        message(WARNING "Currently tested PGI compiler versions (up to 15.7) generate binaries that do not pass all regression test, and the generated binaries are significantly slower than with GCC, ICC or Clang. For now we do not recommend PGI beyond development testing - make sure to run the regressiontests.")
+        message(WARNING "Currently tested PGI compiler versions (up to 15.7) generate binaries that do not pass all regression test, and the generated binaries are significantly slower than with GCC or Clang. For now we do not recommend PGI beyond development testing - make sure to run the regressiontests.")
     endif()
 
 endmacro(gmx_test_compiler_problems)