From f8885a64aa8efb3840ad690ba3b7ae28e90d71c2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Szil=C3=A1rd=20P=C3=A1ll?= Date: Thu, 17 Jan 2013 06:43:53 +0100 Subject: [PATCH] use the compiler version provided by CMake >=2.8.9 With CMake <2.8.9 we still use our slightly naive compiler version detection code, but from 2.8.9 CMake provides a compiler version variable which should be more robust and portable, so we will use that instead. Change-Id: I3cefa227c4962d9a2fae06af2c5b2a0d22ef30c4 --- cmake/gmxGetCompilerInfo.cmake | 51 ++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/cmake/gmxGetCompilerInfo.cmake b/cmake/gmxGetCompilerInfo.cmake index 84599721f4..8c3b27f696 100644 --- a/cmake/gmxGetCompilerInfo.cmake +++ b/cmake/gmxGetCompilerInfo.cmake @@ -33,38 +33,55 @@ # the research papers on the package. Check out http://www.gromacs.org. # # This macro attempts to parse the version string of the C compiler in use. -# Currently supported are only compilers that accept "-dumpversion" argument: -# gcc, Intel Compiler (on Linux and Mac OS), Open64, EkoPath. +# With CMake 2.8.9 CMake provides a CMAKE_[C|CXX]_COMPILER_VERSION variable +# so we will use that if available. +# +# Currently supported are: +# - with cmake >2.8.8 all compilers supported by CMake +# - with cmake <=2.8.8: compilers that accept "-dumpversion" argument: +# gcc, Intel Compiler (on Linux and Mac OS), Open64, EkoPath, clang +# (and probably other gcc-compatible compilers). # # C_COMPILER_VERSION - version string of the current C compiler (CMAKE_C_COMPILER) # CXX_COMPILER_VERSION - version string of the current C++ compiler (CMAKE_CXX_COMPILER) # macro(get_compiler_version) if(NOT C_COMPILER_VERSION) - execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion - RESULT_VARIABLE _cc_dumpversion_res - OUTPUT_VARIABLE _cc_dumpversion_out - ERROR_VARIABLE _cc_dumpversion_err - OUTPUT_STRIP_TRAILING_WHITESPACE) + set(_cc_dumpversion_res 0) + if (DEFINED xCMAKE_C_COMPILER_VERSION AND CMAKE_VERSION VERSION_GREATER 2.8.8) + set(_cc_version ${CMAKE_C_COMPILER_VERSION}) + else() + execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion + RESULT_VARIABLE _cc_dumpversion_res + OUTPUT_VARIABLE _cc_version + OUTPUT_STRIP_TRAILING_WHITESPACE) + endif() if (${_cc_dumpversion_res} EQUAL 0) - SET(C_COMPILER_VERSION ${_cc_dumpversion_out} - CACHE STRING "C compiler version string" FORCE) + SET(C_COMPILER_VERSION ${_cc_version} + CACHE STRING "C compiler version" FORCE) else () SET(C_COMPILER_VERSION "" - CACHE STRING "C compiler version string not available" FORCE) + CACHE STRING "C compiler version not available" FORCE) endif () endif() + message("CMAKE_C_COMPILER_VERSION: ${CMAKE_C_COMPILER_VERSION}") + message("C_COMPILER_VERSION: ${C_COMPILER_VERSION}") + if(NOT CXX_COMPILER_VERSION AND CMAKE_CXX_COMPILER_LOADED) - execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion - RESULT_VARIABLE _cxx_dumpversion_res - OUTPUT_VARIABLE _cxx_dumpversion_out - ERROR_VARIABLE _cxx_dumpversion_err - OUTPUT_STRIP_TRAILING_WHITESPACE) + set(_cxx_dumpversion_res 0) + if (DEFINED CMAKE_CXX_COMPILER_VERSION AND CMAKE_VERSION VERSION_GREATER 2.8.8) + set(_cxx_version ${CMAKE_CXX_COMPILER_VERSION}) + else() + execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion + RESULT_VARIABLE _cxx_dumpversion_res + OUTPUT_VARIABLE _cxx_version + OUTPUT_STRIP_TRAILING_WHITESPACE) + endif() if (${_cxx_dumpversion_res} EQUAL 0) - SET(CXX_COMPILER_VERSION ${_cxx_dumpversion_out} + SET(CXX_COMPILER_VERSION ${_cxx_version} CACHE STRING "C++ compiler version string" FORCE) else () SET(CXX_COMPILER_VERSION "" @@ -73,7 +90,7 @@ macro(get_compiler_version) endif () if (NOT "${C_COMPILER_VERSION}" STREQUAL "${CXX_COMPILER_VERSION}" AND CMAKE_CXX_COMPILER_LOADED) - message(WARNING "The version string of the C and C++ compilers does not match!") + message(WARNING "The version of the C and C++ compilers does not match. Note that mixing different C/C++ compilers can cause problems!") endif () mark_as_advanced(C_COMPILER_VERSION CXX_COMPILER_VERSION) -- 2.22.0