From b36175abdbbc0e71f6a2580cf74483c0c4b4e9dc Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Thu, 3 Apr 2025 16:56:28 -0700 Subject: [PATCH] Swift: Detect module triple from compiler On Swift versions later than 5.2, the compiler is able to specify target info, including the module triple among other properties about the underlying platform. Grab the triple and save it in the compiler info. --- Modules/CMakeDetermineSwiftCompiler.cmake | 13 +++++++++++++ Modules/CMakeSwiftCompiler.cmake.in | 2 ++ 2 files changed, 15 insertions(+) diff --git a/Modules/CMakeDetermineSwiftCompiler.cmake b/Modules/CMakeDetermineSwiftCompiler.cmake index a7dc1500e4..6d46e78f07 100644 --- a/Modules/CMakeDetermineSwiftCompiler.cmake +++ b/Modules/CMakeDetermineSwiftCompiler.cmake @@ -126,6 +126,19 @@ elseif(NOT DEFINED CMAKE_Swift_COMPILER_USE_OLD_DRIVER) unset(_CMAKE_Swift_COMPILER_CHECK_OUTPUT) endif() +if(CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 5.2) + set(target_info_command "${CMAKE_Swift_COMPILER}" -print-target-info) + if(CMAKE_Swift_COMPILER_TARGET) + list(APPEND target_info_command -target ${CMAKE_Swift_COMPILER_TARGET}) + endif() + execute_process( + COMMAND ${target_info_command} + OUTPUT_VARIABLE swift_target_info) + message(CONFIGURE_LOG "Swift target info:\n" "${swift_target_info}") + string(JSON module_triple GET "${swift_target_info}" "target" "moduleTriple") + set(CMAKE_Swift_MODULE_TRIPLE ${module_triple}) +endif() + if (NOT _CMAKE_TOOLCHAIN_LOCATION) get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_Swift_COMPILER}" PATH) endif () diff --git a/Modules/CMakeSwiftCompiler.cmake.in b/Modules/CMakeSwiftCompiler.cmake.in index 92108804db..5e2483a02d 100644 --- a/Modules/CMakeSwiftCompiler.cmake.in +++ b/Modules/CMakeSwiftCompiler.cmake.in @@ -16,3 +16,5 @@ set(CMAKE_Swift_SOURCE_FILE_EXTENSIONS swift) set(CMAKE_Swift_COMPILER_USE_OLD_DRIVER "@CMAKE_Swift_COMPILER_USE_OLD_DRIVER@") set(CMAKE_Swift_IMPLICIT_INCLUDE_DIRECTORIES "@CMAKE_Swift_IMPLICIT_INCLUDE_DIRECTORIES@") + +set(CMAKE_Swift_MODULE_TRIPLE "@CMAKE_Swift_MODULE_TRIPLE@")