Skip to content

Commit 0c403fe

Browse files
authored
[build] Pass target argument to the linker if needed (#31794)
Following #31125 and #31612, `-target` is not added automatically to linker flags when that's needed (e.g. when building for Apple SDKs) -- mimic the logic used to add it for compiler flags. Addresses rdar://63138761
1 parent eec5c01 commit 0c403fe

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,15 @@ function(add_swift_host_library name)
555555
target_link_options(${name} PRIVATE
556556
"LINKER:-current_version,${SWIFT_COMPILER_VERSION}")
557557
endif()
558+
559+
set(DEPLOYMENT_VERSION "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_DEPLOYMENT_VERSION}")
560+
# MSVC, clang-cl, gcc don't understand -target.
561+
if(CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT SWIFT_COMPILER_IS_MSVC_LIKE)
562+
get_target_triple(target target_variant "${SWIFT_HOST_VARIANT_SDK}" "${SWIFT_HOST_VARIANT_ARCH}"
563+
MACCATALYST_BUILD_FLAVOR ""
564+
DEPLOYMENT_VERSION "${DEPLOYMENT_VERSION}")
565+
target_link_options(${name} PRIVATE -target;${target})
566+
endif()
558567
endif()
559568

560569
add_dependencies(dev ${name})

0 commit comments

Comments
 (0)