summaryrefslogtreecommitdiffstats
path: root/Modules/Platform
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2023-09-27 13:22:55 (GMT)
committerMarc Chevrier <marc.chevrier@gmail.com>2023-10-13 09:52:35 (GMT)
commit96a953b1ed7e41260aa0869bad0ff14c788cf57e (patch)
treed9bedd8494b073f3795e4ed80f01b22a2b5a9093 /Modules/Platform
parentee5f31ba727e392e1ebc9f5be54c74ac1868d029 (diff)
downloadCMake-96a953b1ed7e41260aa0869bad0ff14c788cf57e.zip
CMake-96a953b1ed7e41260aa0869bad0ff14c788cf57e.tar.gz
CMake-96a953b1ed7e41260aa0869bad0ff14c788cf57e.tar.bz2
Add options to specify linker tool
Offer the capability, through variable `CMAKE_LINKER_TYPE`, as well as the target property `LINKER_TYPE` to specify which linker must be used. The implementation of this capability is specified by variables specific to the language and linker type: `CMAKE_<LANG>_USING_LINKER_<TYPE>`. Some definitions are provided as part of `CMake`. For example, to select the `LLVM` linker rather than the standard one, the type `LLD` should be specified through the variable `CMAKE_LINKER_TYPE`. And, on `Apple`, `Linux` and some environments on `Windows`, the variable `CMAKE_<LANG>_USING_LINKER_LLD` has value `-fuse-ld=lld`. And for `Windows` environments based on `MSVC`, where the linker is used directly, the tool `lld-link.exe` will be used rather than `link.exe`. Fixes: #19174, #24254, #24990
Diffstat (limited to 'Modules/Platform')
-rw-r--r--Modules/Platform/Apple-Clang.cmake7
-rw-r--r--Modules/Platform/Apple-GNU.cmake3
-rw-r--r--Modules/Platform/Linux-Clang-CUDA.cmake2
-rw-r--r--Modules/Platform/Linux-GNU.cmake7
-rw-r--r--Modules/Platform/Linux-NVIDIA-CUDA.cmake7
-rw-r--r--Modules/Platform/Windows-Clang.cmake10
-rw-r--r--Modules/Platform/Windows-GNU.cmake5
-rw-r--r--Modules/Platform/Windows-MSVC.cmake6
-rw-r--r--Modules/Platform/Windows-NVIDIA-CUDA.cmake6
9 files changed, 51 insertions, 2 deletions
diff --git a/Modules/Platform/Apple-Clang.cmake b/Modules/Platform/Apple-Clang.cmake
index 57b3910..5fe4300 100644
--- a/Modules/Platform/Apple-Clang.cmake
+++ b/Modules/Platform/Apple-Clang.cmake
@@ -18,6 +18,13 @@ macro(__apple_compiler_clang lang)
set(CMAKE_${lang}_LINK_LIBRARY_USING_FRAMEWORK "-framework <LIBRARY>")
set(CMAKE_${lang}_LINK_LIBRARY_USING_FRAMEWORK_SUPPORTED TRUE)
+ # linker selection
+ set(CMAKE_${lang}_USING_LINKER_SYSTEM "-fuse-ld=ld")
+ set(CMAKE_${lang}_USING_LINKER_APPLE_CLASSIC "-fuse-ld=ld" "LINKER:-ld_classic")
+ set(CMAKE_${lang}_USING_LINKER_LLD "-fuse-ld=lld")
+ set(CMAKE_${lang}_USING_LINKER_MOLD "-fuse-ld=mold")
+ set(CMAKE_${lang}_USING_LINKER_SOLD "-fuse-ld=sold")
+
if(_CMAKE_OSX_SYSROOT_PATH MATCHES "/iPhoneOS")
set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "-miphoneos-version-min=")
elseif(_CMAKE_OSX_SYSROOT_PATH MATCHES "/iPhoneSimulator")
diff --git a/Modules/Platform/Apple-GNU.cmake b/Modules/Platform/Apple-GNU.cmake
index 823c790..15f6a71 100644
--- a/Modules/Platform/Apple-GNU.cmake
+++ b/Modules/Platform/Apple-GNU.cmake
@@ -17,6 +17,9 @@ macro(__apple_compiler_gnu lang)
set(CMAKE_${lang}_LINK_LIBRARY_USING_FRAMEWORK "-framework <LIBRARY>")
set(CMAKE_${lang}_LINK_LIBRARY_USING_FRAMEWORK_SUPPORTED TRUE)
+
+ set(CMAKE_${lang}_USING_LINKER_SYSTEM "")
+ set(CMAKE_${lang}_USING_LINKER_APPLE_CLASSIC "LINKER:-ld_classic")
endmacro()
macro(cmake_gnu_set_sysroot_flag lang)
diff --git a/Modules/Platform/Linux-Clang-CUDA.cmake b/Modules/Platform/Linux-Clang-CUDA.cmake
new file mode 100644
index 0000000..4a9337e
--- /dev/null
+++ b/Modules/Platform/Linux-Clang-CUDA.cmake
@@ -0,0 +1,2 @@
+include(Platform/Linux-GNU)
+__linux_compiler_gnu(CUDA)
diff --git a/Modules/Platform/Linux-GNU.cmake b/Modules/Platform/Linux-GNU.cmake
index 6878254..b8ce521 100644
--- a/Modules/Platform/Linux-GNU.cmake
+++ b/Modules/Platform/Linux-GNU.cmake
@@ -12,4 +12,11 @@ macro(__linux_compiler_gnu lang)
# We pass this for historical reasons. Projects may have
# executables that use dlopen but do not set ENABLE_EXPORTS.
set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-rdynamic")
+
+ # linker selection
+ set(CMAKE_${lang}_USING_LINKER_SYSTEM "")
+ set(CMAKE_${lang}_USING_LINKER_LLD "-fuse-ld=lld")
+ set(CMAKE_${lang}_USING_LINKER_BFD "-fuse-ld=bfd")
+ set(CMAKE_${lang}_USING_LINKER_GOLD "-fuse-ld=gold")
+ set(CMAKE_${lang}_USING_LINKER_MOLD "-fuse-ld=mold")
endmacro()
diff --git a/Modules/Platform/Linux-NVIDIA-CUDA.cmake b/Modules/Platform/Linux-NVIDIA-CUDA.cmake
new file mode 100644
index 0000000..4b416de
--- /dev/null
+++ b/Modules/Platform/Linux-NVIDIA-CUDA.cmake
@@ -0,0 +1,7 @@
+
+# linker selection
+set(CMAKE_CUDA_USING_LINKER_SYSTEM "")
+set(CMAKE_CUDA_USING_LINKER_LLD "-fuse-ld=lld")
+set(CMAKE_CUDA_USING_LINKER_BFD "-fuse-ld=bfd")
+set(CMAKE_CUDA_USING_LINKER_GOLD "-fuse-ld=gold")
+set(CMAKE_CUDA_USING_LINKER_MOLD "-fuse-ld=mold")
diff --git a/Modules/Platform/Windows-Clang.cmake b/Modules/Platform/Windows-Clang.cmake
index 33d271d..a03fc9e 100644
--- a/Modules/Platform/Windows-Clang.cmake
+++ b/Modules/Platform/Windows-Clang.cmake
@@ -53,6 +53,12 @@ macro(__windows_compiler_clang_gnu lang)
set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "")
set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "")
+ # linker selection
+ set(CMAKE_${lang}_USING_LINKER_DEFAULT "-fuse-ld=lld-link")
+ set(CMAKE_${lang}_USING_LINKER_SYSTEM "-fuse-ld=link")
+ set(CMAKE_${lang}_USING_LINKER_LLD "-fuse-ld=lld-link")
+ set(CMAKE_${lang}_USING_LINKER_MSVC "-fuse-ld=link")
+
set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_OBJECTS 1)
set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_LIBRARIES 1)
set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_INCLUDES 1)
@@ -74,10 +80,10 @@ macro(__windows_compiler_clang_gnu lang)
set(CMAKE_${lang}_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_${lang}_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
set(CMAKE_${lang}_CREATE_SHARED_LIBRARY
- "<CMAKE_${lang}_COMPILER> -fuse-ld=lld-link -nostartfiles -nostdlib <CMAKE_SHARED_LIBRARY_${lang}_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS> -o <TARGET> ${CMAKE_GNULD_IMAGE_VERSION} -Xlinker /MANIFEST:EMBED -Xlinker /implib:<TARGET_IMPLIB> -Xlinker /pdb:<TARGET_PDB> -Xlinker /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR> <OBJECTS> <LINK_LIBRARIES> <MANIFESTS>")
+ "<CMAKE_${lang}_COMPILER> -nostartfiles -nostdlib <CMAKE_SHARED_LIBRARY_${lang}_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS> -o <TARGET> ${CMAKE_GNULD_IMAGE_VERSION} -Xlinker /MANIFEST:EMBED -Xlinker /implib:<TARGET_IMPLIB> -Xlinker /pdb:<TARGET_PDB> -Xlinker /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR> <OBJECTS> <LINK_LIBRARIES> <MANIFESTS>")
set(CMAKE_${lang}_CREATE_SHARED_MODULE ${CMAKE_${lang}_CREATE_SHARED_LIBRARY})
set(CMAKE_${lang}_LINK_EXECUTABLE
- "<CMAKE_${lang}_COMPILER> -fuse-ld=lld-link -nostartfiles -nostdlib <FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> -Xlinker /MANIFEST:EMBED -Xlinker /implib:<TARGET_IMPLIB> -Xlinker /pdb:<TARGET_PDB> -Xlinker /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR> ${CMAKE_GNULD_IMAGE_VERSION} <LINK_LIBRARIES> <MANIFESTS>")
+ "<CMAKE_${lang}_COMPILER> -nostartfiles -nostdlib <FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> -Xlinker /MANIFEST:EMBED -Xlinker /implib:<TARGET_IMPLIB> -Xlinker /pdb:<TARGET_PDB> -Xlinker /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR> ${CMAKE_GNULD_IMAGE_VERSION} <LINK_LIBRARIES> <MANIFESTS>")
set(CMAKE_${lang}_CREATE_WIN32_EXE "-Xlinker /subsystem:windows")
set(CMAKE_${lang}_CREATE_CONSOLE_EXE "-Xlinker /subsystem:console")
diff --git a/Modules/Platform/Windows-GNU.cmake b/Modules/Platform/Windows-GNU.cmake
index 412af6b..ac990d5 100644
--- a/Modules/Platform/Windows-GNU.cmake
+++ b/Modules/Platform/Windows-GNU.cmake
@@ -112,6 +112,11 @@ macro(__windows_compiler_gnu lang)
set(CMAKE_${type}_LINK_DYNAMIC_${lang}_FLAGS "-Wl,-Bdynamic")
endforeach()
+ # linker selection
+ set(CMAKE_${lang}_USING_LINKER_SYSTEM "")
+ set(CMAKE_${lang}_USING_LINKER_BFD "-fuse-ld=bfd")
+ set(CMAKE_${lang}_USING_LINKER_LLD "-fuse-ld=lld")
+
# No -fPIC on Windows
set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "")
set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "")
diff --git a/Modules/Platform/Windows-MSVC.cmake b/Modules/Platform/Windows-MSVC.cmake
index 829ab9b..1fbf0cc 100644
--- a/Modules/Platform/Windows-MSVC.cmake
+++ b/Modules/Platform/Windows-MSVC.cmake
@@ -512,6 +512,12 @@ macro(__windows_compiler_msvc lang)
set(CMAKE_DEPFILE_FLAGS_${lang} "/showIncludes")
set(CMAKE_${lang}_DEPFILE_FORMAT msvc)
endif()
+
+ # linker selection
+ set(CMAKE_${lang}_USING_LINKER_SYSTEM "${CMAKE_LINKER_LINK}")
+ set(CMAKE_${lang}_USING_LINKER_LLD "${CMAKE_LINKER_LLD}")
+ set(CMAKE_${lang}_USING_LINKER_MSVC "${CMAKE_LINKER_LINK}")
+ set(CMAKE_${lang}_USING_LINKER_MODE TOOL)
endmacro()
macro(__windows_compiler_msvc_enable_rc flags)
diff --git a/Modules/Platform/Windows-NVIDIA-CUDA.cmake b/Modules/Platform/Windows-NVIDIA-CUDA.cmake
index 326e715..6489841 100644
--- a/Modules/Platform/Windows-NVIDIA-CUDA.cmake
+++ b/Modules/Platform/Windows-NVIDIA-CUDA.cmake
@@ -47,6 +47,12 @@ set(CMAKE_CUDA_DEVICE_LINK_EXECUTABLE
"<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Xcompiler=-Fd<TARGET_COMPILE_PDB>,-FS${__IMPLICIT_DLINK_FLAGS}")
unset(__IMPLICIT_DLINK_FLAGS)
+# linker selection
+set(CMAKE_CUDA_USING_LINKER_SYSTEM "${CMAKE_LINKER_LINK}")
+set(CMAKE_CUDA_USING_LINKER_LLD "${CMAKE_LINKER_LLD}")
+set(CMAKE_CUDA_USING_LINKER_MSVC "${CMAKE_LINKER_LINK}")
+set(CMAKE_CUDA_USING_LINKER_MODE TOOL)
+
string(REPLACE "/D" "-D" _PLATFORM_DEFINES_CUDA "${_PLATFORM_DEFINES}${_PLATFORM_DEFINES_CXX}")
if(CMAKE_MSVC_RUNTIME_LIBRARY_DEFAULT)