summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2024-01-04 16:53:30 (GMT)
committerKitware Robot <kwrobot@kitware.com>2024-01-04 16:53:38 (GMT)
commit5a61984088adb39de48f7d852c79e269f35c09f9 (patch)
tree51b163cd79ba39abfb69ef80657b34279bd46d0e /Modules
parentd8d9b3f9e6a1acd74c95dfe6579aa976b45bae5a (diff)
parent459d1cc095f216170b9e3e0f28b58e58954607ad (diff)
downloadCMake-5a61984088adb39de48f7d852c79e269f35c09f9.zip
CMake-5a61984088adb39de48f7d852c79e269f35c09f9.tar.gz
CMake-5a61984088adb39de48f7d852c79e269f35c09f9.tar.bz2
Merge topic 'compute-compiler-linker'
459d1cc095 Tests: Verify that linker tool is detected and identified where expected 6aec4739c1 LinkerId: Record detection steps to configure log ba5f8dbba3 LinkerId: Use empty string for unknown linker id 6cbd0658c5 LinkerId: Match Apple linker on all Apple platforms 9324668517 LinkerId: Fix detection of GNU linker id without parenthesis in version output 37bc148870 LinkerId: Fix detection of linker tool without path 6e527c2d38 LinkerId: Fix detection of linker tool for Clang on OpenBSD 455aed3061 LinkerId: Fix detection of linker tool for MSVC ... Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !9086
Diffstat (limited to 'Modules')
-rw-r--r--Modules/CMakeParseImplicitLinkInfo.cmake38
-rw-r--r--Modules/Internal/CMakeDetermineLinkerId.cmake17
2 files changed, 38 insertions, 17 deletions
diff --git a/Modules/CMakeParseImplicitLinkInfo.cmake b/Modules/CMakeParseImplicitLinkInfo.cmake
index f62de4c..896eac0 100644
--- a/Modules/CMakeParseImplicitLinkInfo.cmake
+++ b/Modules/CMakeParseImplicitLinkInfo.cmake
@@ -74,9 +74,10 @@ function(cmake_parse_implicit_link_info2 text log_var obj_regex)
# whole line and just the command (argv[0]).
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=|--with-ld=")
+ set(linker_tool_regex "^[ \t]*(->|\")?[ \t]*(([^\"]*[/\\])?(${linker}))(\"|,| |$)")
+ set(linker_tool_exclude_regex "cuda-fake-ld|-fuse-ld=")
set(linker_tool "NOTFOUND")
+ set(linker_tool_fallback "")
set(link_line_parsed 0)
string(APPEND log " link line regex: [${linker_regex}]\n")
if(EXTRA_PARSE_COMPUTE_LINKER)
@@ -85,15 +86,22 @@ function(cmake_parse_implicit_link_info2 text log_var obj_regex)
string(REGEX REPLACE "\r?\n" ";" output_lines "${text}")
foreach(line IN LISTS output_lines)
if(EXTRA_PARSE_COMPUTE_LINKER AND
- NOT linker_tool AND NOT "${line}" MATCHES "${linker_tool_exclude_regex}"
- AND "${line}" MATCHES "${linker_tool_regex}")
- set(linker_tool "${CMAKE_MATCH_2}")
- if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
- # pick-up last path
- string(REGEX REPLACE "^.*([A-Za-z]:[/\\][^:]+)$" "\\1" linker_tool "${linker_tool}")
- cmake_path(SET linker_tool "${linker_tool}")
+ NOT linker_tool AND NOT "${line}" MATCHES "${linker_tool_exclude_regex}")
+ if("${line}" MATCHES "exec: ([^()]*/(${linker}))") # IBM XL as nvcc host compiler
+ set(linker_tool "${CMAKE_MATCH_1}")
+ elseif("${line}" MATCHES "^export XL_LINKER=(.*/${linker})[ \t]*$") # IBM XL
+ set(linker_tool "${CMAKE_MATCH_1}")
+ elseif("${line}" MATCHES "--with-ld=") # GNU
+ # The GNU compiler reports how it was configured.
+ # This does not account for -fuse-ld= so use it only as a fallback.
+ if("${line}" MATCHES " --with-ld=([^ ]+/${linker})( |$)")
+ set(linker_tool_fallback "${CMAKE_MATCH_1}")
+ endif()
+ elseif("${line}" MATCHES "vs_link.*-- +([^\"]*[/\\](${linker})) ") # cmake -E vs_link_exe
+ set(linker_tool "${CMAKE_MATCH_1}")
+ elseif("${line}" MATCHES "${linker_tool_regex}")
+ set(linker_tool "${CMAKE_MATCH_2}")
endif()
- string(APPEND log " linker tool for '${EXTRA_PARSE_LANGUAGE}': ${linker_tool}\n")
endif()
if(NOT (EXTRA_PARSE_COMPUTE_IMPLICIT_LIBS OR EXTRA_PARSE_COMPUTE_IMPLICIT_DIRS
OR EXTRA_PARSE_COMPUTE_IMPLICIT_FWKS OR EXTRA_PARSE_COMPUTE_IMPLICIT_OBJECTS))
@@ -259,6 +267,16 @@ function(cmake_parse_implicit_link_info2 text log_var obj_regex)
endif()
endforeach()
+ if(NOT linker_tool AND linker_tool_fallback)
+ set(linker_tool "${linker_tool_fallback}")
+ endif()
+ if(linker_tool)
+ if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
+ cmake_path(NORMAL_PATH linker_tool)
+ endif()
+ string(APPEND log " linker tool for '${EXTRA_PARSE_LANGUAGE}': ${linker_tool}\n")
+ endif()
+
# Look for library search paths reported by linker.
if(EXTRA_PARSE_COMPUTE_IMPLICIT_DIRS AND "${output_lines}" MATCHES ";Library search paths:((;\t[^;]+)+)")
string(REPLACE ";\t" ";" implicit_dirs_match "${CMAKE_MATCH_1}")
diff --git a/Modules/Internal/CMakeDetermineLinkerId.cmake b/Modules/Internal/CMakeDetermineLinkerId.cmake
index 05c83d2..45499a5 100644
--- a/Modules/Internal/CMakeDetermineLinkerId.cmake
+++ b/Modules/Internal/CMakeDetermineLinkerId.cmake
@@ -35,7 +35,14 @@ function(cmake_determine_linker_id lang linker)
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.]+).+")
+ string(JOIN "\" \"" flags_string ${flags})
+ string(REGEX REPLACE "\n\n.*" "" linker_desc_head "${linker_desc}")
+ message(CONFIGURE_LOG
+ "Running the ${lang} compiler's linker: \"${linker}\" \"${flags_string}\"\n"
+ "${linker_desc_head}\n"
+ )
+
+ if(CMAKE_EFFECTIVE_SYSTEM_NAME STREQUAL "Apple" 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}")
@@ -58,10 +65,10 @@ function(cmake_determine_linker_id lang linker)
set(linker_frontend "MSVC")
endif()
break()
- elseif(linker_desc MATCHES "GNU ld \\([^)]+\\) ([0-9.]+)")
+ elseif(linker_desc MATCHES "GNU ld (\\([^)]+\\)|version) ([0-9.]+)")
set(linker_id "GNU")
set(linker_frontend "GNU")
- set(linker_version "${CMAKE_MATCH_1}")
+ set(linker_version "${CMAKE_MATCH_2}")
break()
elseif(linker_desc MATCHES "GNU gold \\([^)]+\\) ([0-9.]+)")
set(linker_id "GNUgold")
@@ -83,10 +90,6 @@ function(cmake_determine_linker_id lang linker)
break()
endif()
endforeach()
- if(NOT linker_id)
- # unknown linker
- set(linker_id "UNKNOWN")
- endif()
set(CMAKE_${lang}_COMPILER_LINKER_ID "${linker_id}" PARENT_SCOPE)
if (linker_frontend)