From 538ff514b5e3ce9275728df78e78167d54b87cdb Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Mon, 16 Oct 2023 11:42:03 +0200 Subject: Link Step: use the correct linker for depfile handling Follow up commit 375e6fdbbe (Link step: use linker dependency linker file, 2023-04-19, v3.27.0-rc1~126^2). --- Modules/Compiler/GNU.cmake | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/Modules/Compiler/GNU.cmake b/Modules/Compiler/GNU.cmake index d01054b..9be7c32 100644 --- a/Modules/Compiler/GNU.cmake +++ b/Modules/Compiler/GNU.cmake @@ -74,15 +74,19 @@ macro(__compiler_gnu lang) if (NOT DEFINED CMAKE_${lang}_LINKER_DEPFILE_SUPPORTED) ## check if this feature is supported by the linker - execute_process(COMMAND "${CMAKE_${lang}_COMPILER}" -Wl,--help - OUTPUT_VARIABLE _linker_capabilities - ERROR_VARIABLE _linker_capabilities) - if(_linker_capabilities MATCHES "--dependency-file") - set(CMAKE_${lang}_LINKER_DEPFILE_SUPPORTED TRUE) + if (CMAKE_${lang}_COMPILER_LINKER AND CMAKE_${lang}_COMPILER_LINKER_ID MATCHES "GNU|LLD") + execute_process(COMMAND "${CMAKE_${lang}_COMPILER}" --help + OUTPUT_VARIABLE _linker_capabilities + ERROR_VARIABLE _linker_capabilities) + if(_linker_capabilities MATCHES "--dependency-file") + set(CMAKE_${lang}_LINKER_DEPFILE_SUPPORTED TRUE) + else() + set(CMAKE_${lang}_LINKER_DEPFILE_SUPPORTED FALSE) + endif() + unset(_linker_capabilities) else() set(CMAKE_${lang}_LINKER_DEPFILE_SUPPORTED FALSE) endif() - unset(_linker_capabilities) endif() endif() if (CMAKE_${lang}_LINKER_DEPFILE_SUPPORTED) @@ -91,11 +95,14 @@ macro(__compiler_gnu lang) unset(CMAKE_${lang}_LINK_DEPENDS_USE_LINKER) endif() - # For now, due to GNU binutils ld bug when LTO is enabled (see GNU bug - # `30568 `_), - # deactivate this feature. - if (NOT DEFINED CMAKE_LINK_DEPENDS_USE_LINKER) - set(CMAKE_LINK_DEPENDS_USE_LINKER FALSE) + # Due to GNU binutils ld bug when LTO is enabled (see GNU bug + # `30568 `_), + # deactivate this feature if the version is less than 2.41. + # For now, all known versions of gold linker have also this bug. + if (CMAKE_${lang}_COMPILER_LINKER_ID STREQUAL "GNUgold" + OR (CMAKE_${lang}_COMPILER_LINKER_ID STREQUAL "GNU" + AND CMAKE_${lang}_COMPILER_LINKER_VERSION VERSION_LESS "2.41")) + set(CMAKE_${lang}_LINK_DEPENDS_USE_LINKER FALSE) endif() # Initial configuration flags. -- cgit v0.12