Fix warnings with Intel 2021.4
[alexxy/gromacs.git] / cmake / gmxTestCompilerProblems.cmake
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2012,2013,2014,2015,2016 by the GROMACS development team.
5 # Copyright (c) 2017,2018,2019,2020,2021, by the GROMACS development team, led by
6 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7 # and including many others, as listed in the AUTHORS file in the
8 # top-level source directory and at http://www.gromacs.org.
9 #
10 # GROMACS is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Lesser General Public License
12 # as published by the Free Software Foundation; either version 2.1
13 # of the License, or (at your option) any later version.
14 #
15 # GROMACS is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 # Lesser General Public License for more details.
19 #
20 # You should have received a copy of the GNU Lesser General Public
21 # License along with GROMACS; if not, see
22 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
23 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
24 #
25 # If you want to redistribute modifications to GROMACS, please
26 # consider that scientific software is very special. Version
27 # control is crucial - bugs must be traceable. We will be happy to
28 # consider code for inclusion in the official distribution, but
29 # derived work must not be called official GROMACS. Details are found
30 # in the README & COPYING files - if they are missing, get the
31 # official version at http://www.gromacs.org.
32 #
33 # To help us fund GROMACS development, we humbly ask that you cite
34 # the research papers on the package. Check out http://www.gromacs.org.
35
36 include(CheckCXXSourceCompiles)
37
38 # Macro that runs through a number of tests for buggy compiler
39 # versions, or other potential problems.
40 macro(gmx_test_compiler_problems)
41
42     # Warn if C and C++ compilers do not match
43     if(NOT CMAKE_C_COMPILER_ID STREQUAL CMAKE_CXX_COMPILER_ID)
44         message(WARNING "The ids of the C and C++ compilers do not match (${CMAKE_C_COMPILER_ID} and ${CMAKE_CXX_COMPILER_ID}, respectively). Mixing different C/C++ compilers can cause problems.")
45     endif()
46     if(NOT CMAKE_C_COMPILER_VERSION STREQUAL CMAKE_CXX_COMPILER_VERSION)
47         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.")
48     endif()
49
50     # Error if compiler doesn't support required C++17 features.
51     # cmake feature detection is currently inconsistent: gitlab.kitware.com/cmake/cmake/issues/18869
52     # We might want to switch to using feature test macros some time.
53     if(CMAKE_COMPILER_IS_GNUCXX)
54         if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7)
55             set(cxx_required_version "GCC version 7")
56         endif()
57     elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
58         if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.15)
59             set(cxx_required_version "Visual Studio 2017")
60         endif()
61     elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
62         if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5)
63             set(cxx_required_version "Clang 5")
64         endif()
65     elseif(CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM")
66         # All versions of IntelLLVM (a.k.a. DPCPP) compiler so far support C++17
67     else()
68         message(WARNING "You are using an unsupported compiler. Please make sure it fully supports C++17.")
69     endif()
70     if (cxx_required_version)
71         message(FATAL_ERROR "${cxx_required_version} or later required. "
72                             "Earlier versions don't have full C++17 support.")
73     endif()
74
75     if (CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND NOT CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM")
76         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")
77     endif()
78     # Intel LLVM 2021.2 defaults to no-finite-math which isn't OK for GROMACS and its dependencies (muParser and GTest).
79     # This is why we set the flags globally via CMAKE_CXX_FLAGS
80     if(GMX_INTEL_LLVM AND GMX_INTEL_LLVM_VERSION GREATER_EQUAL 2021020)
81         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-finite-math-only")
82     endif()
83
84
85     if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "XL")
86         check_cxx_source_compiles(
87 "// Test in-class array initalizers used with constructor initializer lists
88 struct TestStruct
89 {
90     float a[3][3] = {{0}}; // in-class initializer
91     float b; // not initialized until constructor initializer list
92     TestStruct();
93 };
94 TestStruct::TestStruct() : b(0) {}
95 }" XLC_COMPILES_CORRECTLY)
96         if (NOT XLC_COMPILES_CORRECTLY)
97             message(FATAL_ERROR "No known version of xlC can compile the normal C++11 code in GROMACS, highest version checked is 16.1.0")
98         endif()
99     endif()
100     if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "PGI")
101         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.")
102     endif()
103
104 endmacro(gmx_test_compiler_problems)