summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-12-09 13:15:54 (GMT)
committerKitware Robot <kwrobot@kitware.com>2023-12-09 13:16:01 (GMT)
commit2040b79a39a6d1ea3a60e9aba24907af54599134 (patch)
tree261983a98c2e05c6573d8c0c74d51200c0ea18dc /Modules
parentca08b492c3657d30c1dfb314bd7523177280863c (diff)
parentdf025444b216f69f57a6bf060a75ca883f5ddce8 (diff)
downloadCMake-2040b79a39a6d1ea3a60e9aba24907af54599134.zip
CMake-2040b79a39a6d1ea3a60e9aba24907af54599134.tar.gz
CMake-2040b79a39a6d1ea3a60e9aba24907af54599134.tar.bz2
Merge topic 'compute-compiler-linker'
df025444b2 LinkerId: Identify AIX and SunOS system linkers c1e48a19a5 LinkerId: Try multiple flags to detect linker id and version 1e42a0cf18 LinkerId: Match linker id and version more robustly Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !9057
Diffstat (limited to 'Modules')
-rw-r--r--Modules/CMakeParseImplicitLinkInfo.cmake2
-rw-r--r--Modules/Internal/CMakeDetermineLinkerId.cmake110
-rw-r--r--Modules/Platform/AIX-GNU.cmake1
3 files changed, 63 insertions, 50 deletions
diff --git a/Modules/CMakeParseImplicitLinkInfo.cmake b/Modules/CMakeParseImplicitLinkInfo.cmake
index 0c92634..f62de4c 100644
--- a/Modules/CMakeParseImplicitLinkInfo.cmake
+++ b/Modules/CMakeParseImplicitLinkInfo.cmake
@@ -75,7 +75,7 @@ function(cmake_parse_implicit_link_info2 text log_var obj_regex)
set(linker_regex "^( *|.*[/\\])(${linker}|${startfile}|([^/\\]+-)?ld|collect2)[^/\\]*( |$)")
set(linker_exclude_regex "collect2 version |^[A-Za-z0-9_]+=|/ldfe ")
set(linker_tool_regex "^[ \t]*(->|exec:|\")?[ \t]*(.*[/\\](${linker}))(\"|,| |$)")
- set(linker_tool_exclude_regex "cuda-fake-ld|-fuse-ld=")
+ set(linker_tool_exclude_regex "cuda-fake-ld|-fuse-ld=|--with-ld=")
set(linker_tool "NOTFOUND")
set(link_line_parsed 0)
string(APPEND log " link line regex: [${linker_regex}]\n")
diff --git a/Modules/Internal/CMakeDetermineLinkerId.cmake b/Modules/Internal/CMakeDetermineLinkerId.cmake
index ab851d7..05c83d2 100644
--- a/Modules/Internal/CMakeDetermineLinkerId.cmake
+++ b/Modules/Internal/CMakeDetermineLinkerId.cmake
@@ -19,63 +19,75 @@ function(cmake_determine_linker_id lang linker)
return()
endif()
- if (CMAKE_SYSTEM_NAME STREQUAL "Windows" OR linker MATCHES "lld$")
- set(flags "--version")
- else()
- set(flags "-v")
- endif()
- execute_process(COMMAND "${linker}" ${flags}
- OUTPUT_VARIABLE linker_desc
- ERROR_VARIABLE linker_desc
- OUTPUT_STRIP_TRAILING_WHITESPACE
- ERROR_STRIP_TRAILING_WHITESPACE)
-
+ set(linker_id)
set(linker_frontend)
set(linker_version)
- # Compute the linker ID
- if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND linker_desc MATCHES "@\\(#\\)PROGRAM:ld")
- set(linker_id "AppleClang")
- set(linker_frontend "GNU")
- elseif (linker_desc MATCHES "mold \\(sold\\)")
- set(linker_id "MOLD")
- set(linker_frontend "GNU")
- elseif (linker_desc MATCHES "mold")
- set(linker_id "MOLD")
- set(linker_frontend "GNU")
- elseif (linker_desc MATCHES "LLD")
- set(linker_id "LLD")
- set(linker_frontend "GNU")
- if (WIN32 AND NOT linker_desc MATCHES "compatible with GNU")
- set (linker_frontend "MSVC")
+ # Compute the linker ID and version.
+ foreach(flags IN ITEMS
+ "-v" # AppleClang, GNU, GNUgold, MOLD
+ "-V" # AIX, Solaris
+ "--version" # LLD
+ )
+ execute_process(COMMAND "${linker}" ${flags}
+ OUTPUT_VARIABLE linker_desc
+ ERROR_VARIABLE linker_desc
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_STRIP_TRAILING_WHITESPACE)
+
+ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND linker_desc MATCHES "@\\(#\\)PROGRAM:ld.+PROJECT:[a-z0-9]+-([0-9.]+).+")
+ set(linker_id "AppleClang")
+ set(linker_frontend "GNU")
+ set(linker_version "${CMAKE_MATCH_1}")
+ break()
+ elseif(linker_desc MATCHES "mold \\(sold\\) ([0-9.]+)")
+ set(linker_id "MOLD")
+ set(linker_frontend "GNU")
+ set(linker_version "${CMAKE_MATCH_1}")
+ break()
+ elseif(linker_desc MATCHES "mold ([0-9.]+)")
+ set(linker_id "MOLD")
+ set(linker_frontend "GNU")
+ set(linker_version "${CMAKE_MATCH_1}")
+ break()
+ elseif(linker_desc MATCHES "LLD ([0-9.]+)")
+ set(linker_id "LLD")
+ set(linker_frontend "GNU")
+ set(linker_version "${CMAKE_MATCH_1}")
+ if(WIN32 AND NOT linker_desc MATCHES "compatible with GNU")
+ set(linker_frontend "MSVC")
+ endif()
+ break()
+ elseif(linker_desc MATCHES "GNU ld \\([^)]+\\) ([0-9.]+)")
+ set(linker_id "GNU")
+ set(linker_frontend "GNU")
+ set(linker_version "${CMAKE_MATCH_1}")
+ break()
+ elseif(linker_desc MATCHES "GNU gold \\([^)]+\\) ([0-9.]+)")
+ set(linker_id "GNUgold")
+ set(linker_frontend "GNU")
+ set(linker_version "${CMAKE_MATCH_1}")
+ break()
+ elseif(linker_desc MATCHES "Microsoft \\(R\\) Incremental Linker Version ([0-9.]+)")
+ set(linker_id "MSVC")
+ set(linker_frontend "MSVC")
+ set(linker_version "${CMAKE_MATCH_1}")
+ break()
+ elseif (CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND linker_desc MATCHES "Solaris Link Editors: ([0-9.-]+)")
+ set(linker_id "Solaris")
+ set(linker_version "${CMAKE_MATCH_1}")
+ break()
+ elseif (CMAKE_SYSTEM_NAME STREQUAL "AIX" AND linker_desc MATCHES " LD ([0-9.]+)")
+ set(linker_id "AIX")
+ set(linker_version "${CMAKE_MATCH_1}")
+ break()
endif()
- elseif (linker_desc MATCHES "GNU ld")
- set(linker_id "GNU")
- set(linker_frontend "GNU")
- elseif (linker_desc MATCHES "GNU gold")
- set(linker_id "GNUgold")
- set(linker_frontend "GNU")
- elseif (linker_desc MATCHES "Microsoft \\(R\\) Incremental Linker")
- set(linker_id "MSVC")
- set(linker_frontend "MSVC")
- else()
+ endforeach()
+ if(NOT linker_id)
# unknown linker
set(linker_id "UNKNOWN")
endif()
- # Get linker version
- if (linker_id STREQUAL "AppleClang")
- string(REGEX REPLACE ".+PROJECT:[a-z0-9]+-([0-9.]+).+" "\\1" linker_version "${linker_desc}")
- elseif (linker_id MATCHES "MOLD|SOLD")
- string(REGEX REPLACE "^mold (\\(sold\\) )?([0-9.]+).+" "\\2" linker_version "${linker_desc}")
- elseif (linker_id STREQUAL "LLD")
- string(REGEX REPLACE ".*LLD ([0-9.]+).*" "\\1" linker_version "${linker_desc}")
- elseif (linker_id MATCHES "(GNU|GOLD)")
- string(REGEX REPLACE "^GNU [^ ]+ \\([^)]+\\) ([0-9.]+).*" "\\1" linker_version "${linker_desc}")
- elseif (linker_id STREQUAL "MSVC")
- string(REGEX REPLACE ".+Linker Version ([0-9.]+).+" "\\1" linker_version "${linker_desc}")
- endif()
-
set(CMAKE_${lang}_COMPILER_LINKER_ID "${linker_id}" PARENT_SCOPE)
if (linker_frontend)
set(CMAKE_${lang}_COMPILER_LINKER_FRONTEND_VARIANT "${linker_frontend}" PARENT_SCOPE)
diff --git a/Modules/Platform/AIX-GNU.cmake b/Modules/Platform/AIX-GNU.cmake
index 106eaec..55a6680 100644
--- a/Modules/Platform/AIX-GNU.cmake
+++ b/Modules/Platform/AIX-GNU.cmake
@@ -14,6 +14,7 @@ macro(__aix_compiler_gnu lang)
string(APPEND CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS " -Wl,-bnoipath")
set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-Wl,-bexpall") # CMP0065 old behavior
set(CMAKE_${lang}_USE_IMPLICIT_LINK_DIRECTORIES_IN_RUNTIME_PATH 1)
+ set(CMAKE_${lang}_VERBOSE_LINK_FLAG "-Wl,-v")
set(CMAKE_${lang}_LINK_FLAGS "-Wl,-bnoipath")
set(CMAKE_${lang}_LINK_LIBRARIES_PROCESSING ORDER=REVERSE UNICITY=ALL)