summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2024-04-03 13:33:46 (GMT)
committerKitware Robot <kwrobot@kitware.com>2024-04-03 13:34:06 (GMT)
commit3c8d4ed51ac405c200924f0d784c86d286e47be7 (patch)
treefc7f1c3b69585285df3ba1f426a105386e379f8b
parent8982fde7a996631c4312a605eee53b17876b1dc3 (diff)
parent3fb4092826319730d529563820eefdaa3449a276 (diff)
downloadCMake-3c8d4ed51ac405c200924f0d784c86d286e47be7.zip
CMake-3c8d4ed51ac405c200924f0d784c86d286e47be7.tar.gz
CMake-3c8d4ed51ac405c200924f0d784c86d286e47be7.tar.bz2
Merge topic 'swift-linker-selection'
3fb4092826 Swift: Add CMAKE_LINKER_TYPE support Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !9380
-rw-r--r--Help/release/3.29.rst6
-rw-r--r--Help/variable/LINKER_PREDEFINED_TYPES.txt39
-rw-r--r--Modules/Platform/Apple-Apple-Swift.cmake13
-rw-r--r--Modules/Platform/Linux-Apple-Swift.cmake5
-rw-r--r--Modules/Platform/Windows-Apple-Swift.cmake5
-rw-r--r--Tests/RunCMake/CMakeLists.txt1
-rw-r--r--Tests/RunCMake/LinkerSelection/AppleClassic.cmake7
-rw-r--r--Tests/RunCMake/LinkerSelection/CustomLinkerType.cmake17
-rw-r--r--Tests/RunCMake/LinkerSelection/RunCMakeTest.cmake8
-rw-r--r--Tests/RunCMake/LinkerSelection/ValidLinkerType.cmake13
-rw-r--r--Tests/RunCMake/LinkerSelection/main.swift1
11 files changed, 93 insertions, 22 deletions
diff --git a/Help/release/3.29.rst b/Help/release/3.29.rst
index f6d829d..0e6337d 100644
--- a/Help/release/3.29.rst
+++ b/Help/release/3.29.rst
@@ -199,3 +199,9 @@ Other Changes
``perMachine`` value. Previously, without a custom WiX template,
it produced installers that would only create start menu and uninstall
entries for the current user, even though they install for all users.
+
+.. 3.29.1 (unreleased)
+
+ * The :variable:`CMAKE_LINKER_TYPE` variable and corresponding
+ :prop_tgt:`LINKER_TYPE` target property now work with compilers
+ for the ``Swift`` language.
diff --git a/Help/variable/LINKER_PREDEFINED_TYPES.txt b/Help/variable/LINKER_PREDEFINED_TYPES.txt
index 69ac1c2..3c1b7b8 100644
--- a/Help/variable/LINKER_PREDEFINED_TYPES.txt
+++ b/Help/variable/LINKER_PREDEFINED_TYPES.txt
@@ -13,39 +13,43 @@ built-in types. The pre-defined linker types are:
``SYSTEM``
Use the standard linker provided by the platform or toolchain. For example,
- this implies the Microsoft linker for all ``MSVC``-compatible compilers.
+ this implies the Microsoft linker for all MSVC-compatible compilers.
This type is supported for the following platform-compiler combinations:
- * Linux: ``GNU``, ``Clang``, ``LLVMFlang`` and ``NVIDIA`` compilers.
- * All Apple variants: ``AppleClang``, ``Clang`` and ``GNU`` compilers.
- * Windows: ``MSVC``, ``GNU``, ``Clang`` and ``NVIDIA`` compilers.
+ * Linux: ``GNU``, ``Clang``, ``LLVMFlang``, ``NVIDIA``, and ``Swift``
+ compilers.
+ * Apple platforms: ``AppleClang``, ``Clang``, ``GNU``, and ``Swift``
+ compilers.
+ * Windows: ``MSVC``, ``GNU``, ``Clang``, ``NVIDIA``, and ``Swift`` compilers.
``LLD``
Use the ``LLVM`` linker. This type is supported for the following
platform-compiler combinations:
- * Linux: ``GNU``, ``Clang``, ``LLVMFlang`` and ``NVIDIA`` compilers.
- * All Apple variants: ``Clang`` and ``AppleClang`` compilers.
- * Windows: ``GNU``, ``Clang``, ``Clang`` compilers with ``GNU`` front-end,
- ``MSVC`` and ``NVIDIA`` compilers with ``MSVC`` front-end.
+ * Linux: ``GNU``, ``Clang``, ``LLVMFlang``, ``NVIDIA``, and ``Swift``
+ compilers.
+ * Apple platforms: ``Clang``, ``AppleClang``, and ``Swift`` compilers.
+ * Windows: ``GNU``, ``Clang`` with MSVC-like front-end, ``Clang`` with
+ GNU-like front-end, ``MSVC``, ``NVIDIA`` with MSVC-like front-end,
+ and ``Swift``.
``BFD``
Use the ``GNU`` linker. This type is supported for the following
platform-compiler combinations:
- * Linux: ``GNU``, ``Clang``, ``LLVMFlang`` and ``NVIDIA`` compilers.
- * Windows: ``GNU``, ``Clang`` compilers with ``GNU`` front-end.
+ * Linux: ``GNU``, ``Clang``, ``LLVMFlang``, and ``NVIDIA`` compilers.
+ * Windows: ``GNU``, ``Clang`` with GNU-like front-end.
``GOLD``
- Supported on Linux platform with ``GNU``, ``Clang``, ``LLVMFlang`` and
- ``NVIDIA`` compilers.
+ Supported on Linux platform with ``GNU``, ``Clang``, ``LLVMFlang``,
+ ``NVIDIA``, and ``Swift`` compilers.
``MOLD``
Use the `mold linker <https://github.com/rui314/mold>`_. This type is
supported on the following platform-compiler combinations:
- * Linux: ``GNU``, ``Clang``, ``LLVMFlang`` and ``NVIDIA`` compilers.
- * All Apple variants: ``Clang`` and ``AppleClang`` compilers (acts as an
+ * Linux: ``GNU``, ``Clang``, ``LLVMFlang``, and ``NVIDIA`` compilers.
+ * Apple platforms: ``Clang`` and ``AppleClang`` compilers (acts as an
alias to the `sold linker`_).
``SOLD``
@@ -54,11 +58,12 @@ built-in types. The pre-defined linker types are:
``APPLE_CLASSIC``
Use the Apple linker in the classic behavior (i.e. before ``Xcode 15.0``).
- This type is only supported on Apple platforms with ``GNU``, ``Clang`` and
- ``AppleClang`` compilers.
+ This type is only supported on Apple platforms with ``GNU``, ``Clang``,
+ ``AppleClang``, and ``Swift`` compilers.
``MSVC``
Use the Microsoft linker. This type is only supported on the Windows
- platform with ``MSVC`` and ``Clang`` compiler with ``MSVC`` front-end.
+ platform with ``MSVC``, ``Clang`` with MSVC-like front-end, and ``Swift``
+ compilers.
.. _sold linker: https://github.com/bluewhalesystems/sold
diff --git a/Modules/Platform/Apple-Apple-Swift.cmake b/Modules/Platform/Apple-Apple-Swift.cmake
index 7ca3e36..237f6e4 100644
--- a/Modules/Platform/Apple-Apple-Swift.cmake
+++ b/Modules/Platform/Apple-Apple-Swift.cmake
@@ -1 +1,14 @@
set(CMAKE_Swift_SYSROOT_FLAG "-sdk")
+
+# Linker Selections
+if("${CMAKE_GENERATOR}" STREQUAL Xcode)
+ # Xcode always uses clang to link, regardless of what the cmake link language
+ # is. Pass the clang flags when linking with Xcode.
+ set(CMAKE_Swift_USING_LINKER_APPLE_CLASSIC "-fuse-ld=ld" "LINKER:-ld_classic")
+ set(CMAKE_Swift_USING_LINKER_LLD "-fuse-ld=lld")
+ set(CMAKE_Swift_USING_LINKER_SYSTEM "-fuse-ld=ld")
+else()
+ set(CMAKE_Swift_USING_LINKER_APPLE_CLASSIC "-use-ld=ld" "LINKER:-ld_classic")
+ set(CMAKE_Swift_USING_LINKER_LLD "-use-ld=lld")
+ set(CMAKE_Swift_USING_LINKER_SYSTEM "-use-ld=ld")
+endif()
diff --git a/Modules/Platform/Linux-Apple-Swift.cmake b/Modules/Platform/Linux-Apple-Swift.cmake
new file mode 100644
index 0000000..22f0554
--- /dev/null
+++ b/Modules/Platform/Linux-Apple-Swift.cmake
@@ -0,0 +1,5 @@
+# Linker Selection
+# BFD is known to mislink Swift objects resulting in missing type info
+set(CMAKE_Swift_USING_LINKER_SYSTEM "")
+set(CMAKE_Swift_USING_LINKER_GOLD "-use-ld=gold")
+set(CMAKE_Swift_USING_LINKER_LLD "-use-ld=lld")
diff --git a/Modules/Platform/Windows-Apple-Swift.cmake b/Modules/Platform/Windows-Apple-Swift.cmake
index 3f754fd..87c81d6 100644
--- a/Modules/Platform/Windows-Apple-Swift.cmake
+++ b/Modules/Platform/Windows-Apple-Swift.cmake
@@ -1,3 +1,8 @@
set(CMAKE_Swift_IMPLIB_LINKER_FLAGS "-Xlinker -implib:<TARGET_IMPLIB>")
set(CMAKE_Swift_FLAGS_DEBUG_LINKER_FLAGS "-Xlinker -debug")
set(CMAKE_Swift_FLAGS_RELWITHDEBINFO_LINKER_FLAGS "-Xlinker -debug")
+
+# Linker Selection
+set(CMAKE_Swift_USING_LINKER_SYSTEM "-use-ld=link")
+set(CMAKE_Swift_USING_LINKER_LLD "-use-ld=lld")
+set(CMAKE_Swift_USING_LINKER_MSVC "-use-ld=link")
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index d5b204b..60388f1 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -789,6 +789,7 @@ if (CMAKE_SYSTEM_NAME MATCHES "(Linux|Darwin|Windows)"
AND CMAKE_C_COMPILER_ID MATCHES "^(AppleClang|Clang|GNU|MSVC|NVIDIA)$"
AND NOT CMAKE_GENERATOR STREQUAL "Green Hills MULTI")
add_RunCMake_test(LinkerSelection -DCMake_TEST_CUDA=${CMake_TEST_CUDA}
+ -DCMake_TEST_Swift=${CMake_TEST_Swift}
-DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID}
-DCMAKE_C_COMPILER_VERSION=${CMAKE_C_COMPILER_VERSION})
endif()
diff --git a/Tests/RunCMake/LinkerSelection/AppleClassic.cmake b/Tests/RunCMake/LinkerSelection/AppleClassic.cmake
index 62a12ad..170ae0c 100644
--- a/Tests/RunCMake/LinkerSelection/AppleClassic.cmake
+++ b/Tests/RunCMake/LinkerSelection/AppleClassic.cmake
@@ -1,7 +1,12 @@
-
enable_language(C)
set(CMAKE_LINKER_TYPE APPLE_CLASSIC)
add_executable(main main.c)
target_link_libraries(main PRIVATE m m)
+
+if(CMake_TEST_Swift)
+ enable_language(Swift)
+ add_executable(main_swift main.swift)
+ target_link_libraries(main_swift PRIVATE m m)
+endif()
diff --git a/Tests/RunCMake/LinkerSelection/CustomLinkerType.cmake b/Tests/RunCMake/LinkerSelection/CustomLinkerType.cmake
index 4bf98b0..1121608 100644
--- a/Tests/RunCMake/LinkerSelection/CustomLinkerType.cmake
+++ b/Tests/RunCMake/LinkerSelection/CustomLinkerType.cmake
@@ -15,6 +15,14 @@ if(CMake_TEST_CUDA)
set_property(TARGET mainCU PROPERTY LINKER_TYPE "$<$<LINK_LANGUAGE:C>:FOO_C>$<$<LINK_LANGUAGE:CUDA>:FOO_CUDA>")
endif()
+if(CMake_TEST_Swift)
+ enable_language(Swift)
+
+ set(CMAKE_Swift_USING_LINKER_FOO_Swift "${CMAKE_Swift_USING_LINKER_LLD}")
+ add_executable(mainSwift main.swift)
+ set_property(TARGET mainSwift PROPERTY LINKER_TYPE FOO_Swift)
+endif()
+
#
# Generate file for validation
#
@@ -32,5 +40,14 @@ if(CMake_TEST_CUDA)
string(APPEND LINKER_TYPE_OPTION "|${CUDA_LINKER}")
endif()
+if(CMake_TEST_Swift)
+ if(CMAKE_Swift_USING_LINKER_MODE STREQUAL "TOOL")
+ cmake_path(GET CMAKE_Swift_USING_LINKER_FOO_Swift FILENAME Swift_LINKER)
+ else()
+ set(Swift_LINKER "${CMAKE_Swift_USING_LINKER_FOO_Swift}")
+ endif()
+ string(APPEND LINKER_TYPE_OPTION "|${Swift_LINKER}")
+endif()
+
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/LINKER_TYPE_OPTION.cmake"
"set(LINKER_TYPE_OPTION \"${LINKER_TYPE_OPTION}\")\n")
diff --git a/Tests/RunCMake/LinkerSelection/RunCMakeTest.cmake b/Tests/RunCMake/LinkerSelection/RunCMakeTest.cmake
index 8929a0d..0a3f01c 100644
--- a/Tests/RunCMake/LinkerSelection/RunCMakeTest.cmake
+++ b/Tests/RunCMake/LinkerSelection/RunCMakeTest.cmake
@@ -17,12 +17,11 @@ endif()
find_program(LLD_LINKER NAMES ${LINKER_NAMES})
macro(run_cmake_and_build test)
- run_cmake_with_options(${test} -DCMake_TEST_CUDA=${CMake_TEST_CUDA})
+ run_cmake_with_options(${test}
+ -DCMake_TEST_CUDA=${CMake_TEST_CUDA}
+ -DCMake_TEST_Swift=${CMake_TEST_Swift})
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test}-build)
set(RunCMake_TEST_NO_CLEAN 1)
- if(CMake_TEST_CUDA)
- string(APPEND "|${CMAKE_CUDA_USING_LINKER_LLD}")
- endif()
run_cmake_command(${test}-build ${CMAKE_COMMAND} --build . --config Release --verbose ${ARGN})
unset(RunCMake_TEST_BINARY_DIR)
@@ -34,6 +33,7 @@ if(LLD_LINKER)
set(CMAKE_VERBOSE_MAKEFILE TRUE)
set(CMAKE_C_USE_RESPONSE_FILE_FOR_LIBRARIES FALSE)
set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_LIBRARIES FALSE)
+ set(CMAKE_Swift_USE_RESPONSE_FILE_FOR_LIBRARIES FALSE)
run_cmake_and_build(ValidLinkerType)
run_cmake_and_build(CustomLinkerType)
diff --git a/Tests/RunCMake/LinkerSelection/ValidLinkerType.cmake b/Tests/RunCMake/LinkerSelection/ValidLinkerType.cmake
index a685ac1..9170f5c 100644
--- a/Tests/RunCMake/LinkerSelection/ValidLinkerType.cmake
+++ b/Tests/RunCMake/LinkerSelection/ValidLinkerType.cmake
@@ -11,6 +11,11 @@ if(CMake_TEST_CUDA)
add_executable(mainCU main.cu)
endif()
+if(CMake_TEST_Swift)
+ enable_language(Swift)
+ add_executable(mainSwift main.swift)
+endif()
+
#
# Generate file for validation
#
@@ -27,6 +32,14 @@ if(CMake_TEST_CUDA)
endif()
string(APPEND LINKER_TYPE_OPTION "|${CUDA_LINKER}")
endif()
+if(CMake_TEST_Swift)
+ if(CMAKE_Swift_USING_LINKER_MODE STREQUAL "TOOL")
+ cmake_path(GET CMAKE_Swift_USING_LINKER_LLD FILENAME LINKER_TYPE_OPTION)
+ else()
+ set(Swift_LINKER "${CMAKE_Swift_USING_LINKER_LLD}")
+ endif()
+ string(APPEND LINKER_TYPE_OPTION "|${Swift_LINKER}")
+endif()
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/LINKER_TYPE_OPTION.cmake"
"set(LINKER_TYPE_OPTION \"${LINKER_TYPE_OPTION}\")\n")
diff --git a/Tests/RunCMake/LinkerSelection/main.swift b/Tests/RunCMake/LinkerSelection/main.swift
new file mode 100644
index 0000000..b80e322
--- /dev/null
+++ b/Tests/RunCMake/LinkerSelection/main.swift
@@ -0,0 +1 @@
+print("hi")