From 357db6c5e0d571c2e2eb72bfcbdd2fefe72014ca Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Fri, 5 Jul 2013 12:44:04 +0200 Subject: [PATCH 1/3] Add function to detect linker version The linker that is used (ld vs. gold for instance) is often hidden when using the compiler as a front-end (to include the correct runtime libraries). These functions enables us to probe the linker version and reports its finding in the log. --- cmake/Modules/UseCompVer.cmake | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/cmake/Modules/UseCompVer.cmake b/cmake/Modules/UseCompVer.cmake index 461898ef..cf0e3772 100644 --- a/cmake/Modules/UseCompVer.cmake +++ b/cmake/Modules/UseCompVer.cmake @@ -45,3 +45,34 @@ function (compiler_info) message (STATUS "GNU C++ compiler version: ${version}") endif (CMAKE_COMPILER_IS_GNUCXX) endfunction (compiler_info) + +function (get_ld_version ver_name) + # run linker to get the version number. interestingly, this option works + # (for our purposes) on all major platforms (Linux, Mac OS X and Windows); + # it returns the program version although it may have ended in error + exec_program (${CMAKE_LINKER} + ARGS "-v" + OUTPUT_VARIABLE _version + ) + + # keep only first line, even on Mac OS X there is no line end + list (GET _version 0 _version) + + # format of the version string is platform-specific + if (NOT WIN32) + if (APPLE) + string (REGEX REPLACE ".*, from Apple (.*\)" "\\1" _version "${_version}") + else (APPLE) + # assuming some GNU toolchain now + string (REGEX REPLACE "GNU ([a-zA-Z0-9_]*) \\(.*\\) (.*)" "\\1 \\2" _version "${_version}") + endif (APPLE) + endif (NOT WIN32) + + # return the string to the caller + set (${ver_name} "${_version}" PARENT_SCOPE) +endfunction (get_ld_version ver_name) + +function (linker_info) + get_ld_version (version) + message (STATUS "Linker: ${version}") +endfunction (linker_info) From 0696a2128017971de37138f625f766e0a29050aa Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Fri, 5 Jul 2013 12:45:39 +0200 Subject: [PATCH 2/3] Print linker version to log --- cmake/Modules/OpmLibMain.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/Modules/OpmLibMain.cmake b/cmake/Modules/OpmLibMain.cmake index 7705adcb..b4159f0d 100644 --- a/cmake/Modules/OpmLibMain.cmake +++ b/cmake/Modules/OpmLibMain.cmake @@ -50,6 +50,7 @@ vcs_info () # print toolchain information to identify compilers with potential bugs include (UseCompVer) compiler_info () +linker_info () # default settings: build static debug library include (OpmDefaults) From 56d3e1f8a43e5e8bfbf0ee874c46bf28d1d97e4e Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Fri, 5 Jul 2013 13:18:53 +0200 Subject: [PATCH 3/3] Parse RHEL5 linker strings better --- 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 cf0e3772..45cf5893 100644 --- a/cmake/Modules/UseCompVer.cmake +++ b/cmake/Modules/UseCompVer.cmake @@ -64,7 +64,7 @@ function (get_ld_version ver_name) string (REGEX REPLACE ".*, from Apple (.*\)" "\\1" _version "${_version}") else (APPLE) # assuming some GNU toolchain now - string (REGEX REPLACE "GNU ([a-zA-Z0-9_]*) \\(.*\\) (.*)" "\\1 \\2" _version "${_version}") + string (REGEX REPLACE "GNU ([a-zA-Z0-9_]*) (version|\\(.*\\)) ([^\\ ]*).*" "\\1 \\3" _version "${_version}") endif (APPLE) endif (NOT WIN32)