From bc4057a0d421f75ed07b02ac1f7f783354060df5 Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Thu, 7 Mar 2013 11:22:32 +0100 Subject: [PATCH 1/3] Provide function that identifies compiler to patch-level Some distributions modify -dumpversion so that it only returns major and minor numbers, not the patch level. This is usually OK for determining features, but when debugging the output log, we really want the full number. --- cmake/Modules/UseCompVer.cmake | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/cmake/Modules/UseCompVer.cmake b/cmake/Modules/UseCompVer.cmake index 48e21638..2c617c3a 100644 --- a/cmake/Modules/UseCompVer.cmake +++ b/cmake/Modules/UseCompVer.cmake @@ -13,3 +13,35 @@ function (get_gcc_version language ver_name) set (${ver_name} "" PARENT_SCOPE) endif (CMAKE_${language}_COMPILER_ID STREQUAL GNU) endfunction (get_gcc_version ver_name) + +# less reliable, but includes the patch number +function (get_gcc_patch language ver_name) + if(CMAKE_${language}_COMPILER_ID STREQUAL GNU) + # exec_program is deprecated, but execute_process does't work :-( + exec_program (${CMAKE_${language}_COMPILER} + ARGS ${CMAKE_${language}_COMPILER_ARG1} --version + OUTPUT_VARIABLE _version + ) + # split multi-line string into list + if (WIN32) + string (REPLACE "\r\n" ";" _version "${_version}") + else (WIN32) + string (REPLACE "\n" ";" _version "${_version}") + endif (WIN32) + # only keep first line + list (GET _version 0 _version) + # extract version number from it (this is the fragile part) + string (REGEX REPLACE "^.+(\\(.*\\))?.*([0-9]+\\.[0-9]+\\.[0-9]+)" "\\2" _version "${_version}") + # return this to the caller + set (${ver_name} ${_version} PARENT_SCOPE) + else (CMAKE_${language}_COMPILER_ID STREQUAL GNU) + set (${ver_name} "" PARENT_SCOPE) + endif (CMAKE_${language}_COMPILER_ID STREQUAL GNU) +endfunction (get_gcc_patch language ver_name) + +function (compiler_info) + if (CMAKE_COMPILER_IS_GNUCXX) + get_gcc_patch (CXX version) + message (STATUS "GNU C++ compiler version: ${version}") + endif (CMAKE_COMPILER_IS_GNUCXX) +endfunction (compiler_info) From 3ae89d0754aac3abbe9c932c19cbaf92a5980887 Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Thu, 7 Mar 2013 11:23:51 +0100 Subject: [PATCH 2/3] Print compiler version number when configuring --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b04af27..90b2efa3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,6 +63,10 @@ system_info () include (UseVCSInfo) vcs_info () +# print toolchain information to identify compilers with potential bugs +include (UseCompVer) +compiler_info () + # include special if (CMAKE_VERSION VERSION_LESS "2.8.7") message (STATUS "Enabling backward compatibility modules for CMake ${CMAKE_VERSION}") From c81bd58c3fd2128fc766efbaa2dfd1d8c82bf9af Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Thu, 7 Mar 2013 12:29:23 +0100 Subject: [PATCH 3/3] Update regular expression to handle more variants Older CentOS versions returns the version string on this format: gcc (aaa) x.y.z yyyymmdd (bbb) --- cmake/Modules/UseCompVer.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/UseCompVer.cmake b/cmake/Modules/UseCompVer.cmake index 2c617c3a..461898ef 100644 --- a/cmake/Modules/UseCompVer.cmake +++ b/cmake/Modules/UseCompVer.cmake @@ -31,7 +31,7 @@ function (get_gcc_patch language ver_name) # only keep first line list (GET _version 0 _version) # extract version number from it (this is the fragile part) - string (REGEX REPLACE "^.+(\\(.*\\))?.*([0-9]+\\.[0-9]+\\.[0-9]+)" "\\2" _version "${_version}") + string (REGEX REPLACE "^[^\\(]+(\\([^\\)]*\\))?[\ \t]*([0-9]+\\.[0-9]+\\.[0-9]+)(.*\\(.*\\))?" "\\2" _version "${_version}") # return this to the caller set (${ver_name} ${_version} PARENT_SCOPE) else (CMAKE_${language}_COMPILER_ID STREQUAL GNU)