mirror of
https://github.com/apple/swift.git
synced 2026-06-20 15:42:51 +02:00
9f5719221f
Starting with CMake 3.30, CMake is passing linker flags to the Swift invocation used as the linker driver. This causes issues because Swift does not understand the linker flags and fails to link. This is essentially a reland of #84306 with a few changes: * A new helper cmdlet takes care of adding the "right" version of the linker flags depending on the CMake version and the project configuration. * Android linker flags are handled differently to work around issues in the NDK CMake files. In addition, we need to pass a linker driver flag for C/C++/ASM libraries to use the just built ld.lld linker. This argument is not understood by the Swift driver so it can only be used with clang used as the linker driver. This also fixes a minor path normalization issue in swift shims, which causes a build failure with CMake 3.30+.
25 lines
1.0 KiB
CMake
25 lines
1.0 KiB
CMake
# This source file is part of the Swift.org open source project
|
|
#
|
|
# Copyright (c) 2014 - 2026 Apple Inc. and the Swift project authors
|
|
# Licensed under Apache License v2.0 with Runtime Library Exception
|
|
#
|
|
# See https://swift.org/LICENSE.txt for license information
|
|
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
|
|
# Included via CMAKE_PROJECT_INCLUDE for Android builds that use Swift.
|
|
#
|
|
# Handles Clang-only driver flags that Swift doesn't understand:
|
|
# - --ld-path: specifies the linker binary (Clang driver flag)
|
|
# - -Qunused-arguments: suppresses Clang warnings about unused flags
|
|
#
|
|
# The NDK's -Wl,<arg> linker flags are handled in build.ps1 by pre-setting
|
|
# CMAKE_*_LINKER_FLAGS with -Xlinker <arg> form before CMake runs.
|
|
|
|
# --ld-path for using the built lld instead of the NDK linker.
|
|
if(SWIFT_ANDROID_LD_PATH)
|
|
add_link_options($<$<LINK_LANGUAGE:C,CXX,ASM>:--ld-path=${SWIFT_ANDROID_LD_PATH}>)
|
|
endif()
|
|
|
|
# Clang-only driver flag, not understood by Swift.
|
|
add_link_options($<$<LINK_LANGUAGE:C,CXX,ASM>:-Qunused-arguments>)
|