2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2012, by the GROMACS development team, led by
5 # David van der Spoel, Berk Hess, Erik Lindahl, and including many
6 # others, as listed in the AUTHORS file in the top-level source
7 # directory and at http://www.gromacs.org.
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
35 # This macro attempts to parse the version string of the C compiler in use.
36 # With CMake 2.8.9 CMake provides a CMAKE_[C|CXX]_COMPILER_VERSION variable
37 # so we will use that if available.
39 # Currently supported are:
40 # - with cmake >2.8.8 all compilers supported by CMake
41 # - with cmake <=2.8.8: compilers that accept "-dumpversion" argument:
42 # gcc, Intel Compiler (on Linux and Mac OS), Open64, EkoPath, clang
43 # (and probably other gcc-compatible compilers).
45 # C_COMPILER_VERSION - version string of the current C compiler (CMAKE_C_COMPILER)
46 # CXX_COMPILER_VERSION - version string of the current C++ compiler (CMAKE_CXX_COMPILER)
48 macro(get_compiler_version)
49 if(NOT C_COMPILER_VERSION)
50 set(_cc_dumpversion_res 0)
51 if (DEFINED xCMAKE_C_COMPILER_VERSION AND CMAKE_VERSION VERSION_GREATER 2.8.8)
52 set(_cc_version ${CMAKE_C_COMPILER_VERSION})
54 execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
55 RESULT_VARIABLE _cc_dumpversion_res
56 OUTPUT_VARIABLE _cc_version
57 OUTPUT_STRIP_TRAILING_WHITESPACE)
60 if (${_cc_dumpversion_res} EQUAL 0)
61 SET(C_COMPILER_VERSION ${_cc_version}
62 CACHE STRING "C compiler version" FORCE)
64 SET(C_COMPILER_VERSION ""
65 CACHE STRING "C compiler version not available" FORCE)
69 if(NOT CXX_COMPILER_VERSION AND CMAKE_CXX_COMPILER_LOADED)
70 set(_cxx_dumpversion_res 0)
71 if (DEFINED CMAKE_CXX_COMPILER_VERSION AND CMAKE_VERSION VERSION_GREATER 2.8.8)
72 set(_cxx_version ${CMAKE_CXX_COMPILER_VERSION})
74 execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion
75 RESULT_VARIABLE _cxx_dumpversion_res
76 OUTPUT_VARIABLE _cxx_version
77 OUTPUT_STRIP_TRAILING_WHITESPACE)
80 if (${_cxx_dumpversion_res} EQUAL 0)
81 SET(CXX_COMPILER_VERSION ${_cxx_version}
82 CACHE STRING "C++ compiler version string" FORCE)
84 SET(CXX_COMPILER_VERSION ""
85 CACHE STRING "C++ compiler version string not available" FORCE)
89 if (NOT "${C_COMPILER_VERSION}" STREQUAL "${CXX_COMPILER_VERSION}" AND CMAKE_CXX_COMPILER_LOADED)
90 message(WARNING "The version of the C and C++ compilers does not match. Note that mixing different C/C++ compilers can cause problems!")
93 mark_as_advanced(C_COMPILER_VERSION CXX_COMPILER_VERSION)
96 # This macro attempts to get a reasonable version string for a compiler,
97 # and also extracts compiler flags.
100 # LANGUAGE - C or CXX, the compiler to check for
101 # BUILD_COMPILER - [output variable] string with compiler path, ID and
102 # some compiler-provided information
103 # BUILD_FLAGS - [output variable] flags for the compiler
105 macro(get_compiler_info LANGUAGE BUILD_COMPILER BUILD_FLAGS)
106 execute_process(COMMAND ${CMAKE_${LANGUAGE}_COMPILER} --version
107 RESULT_VARIABLE _exec_result
108 OUTPUT_VARIABLE _compiler_version
109 ERROR_VARIABLE _compiler_version)
110 # Try executing just the compiler command --version failed
112 execute_process(COMMAND ${CMAKE_${LANGUAGE}_COMPILER}
113 RESULT_VARIABLE _exec_result
114 OUTPUT_VARIABLE _compiler_version
115 ERROR_VARIABLE _compiler_version)
117 if(NOT "${_compiler_version}" STREQUAL "")
118 string(REGEX MATCH "[^\n]+" _compiler_version "${_compiler_version}")
121 set(${BUILD_COMPILER}
122 "${CMAKE_${LANGUAGE}_COMPILER} ${CMAKE_${LANGUAGE}_COMPILER_ID} ${_compiler_version}")
123 set(_build_flags "${CMAKE_${LANGUAGE}_FLAGS}")
124 string(TOUPPER ${CMAKE_BUILD_TYPE} _build_type)
125 set(_build_flags "${_build_flags} ${CMAKE_${LANGUAGE}_FLAGS_${_build_type}}")
126 set(${BUILD_FLAGS} ${_build_flags})