1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 02:08:27 +08:00

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.
This commit is contained in:
Evan Wilde
2025-04-03 16:56:28 -07:00
parent 6e111c39b9
commit b36175abdb
2 changed files with 15 additions and 0 deletions

View File

@@ -126,6 +126,19 @@ elseif(NOT DEFINED CMAKE_Swift_COMPILER_USE_OLD_DRIVER)
unset(_CMAKE_Swift_COMPILER_CHECK_OUTPUT) unset(_CMAKE_Swift_COMPILER_CHECK_OUTPUT)
endif() 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) if (NOT _CMAKE_TOOLCHAIN_LOCATION)
get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_Swift_COMPILER}" PATH) get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_Swift_COMPILER}" PATH)
endif () endif ()

View File

@@ -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_COMPILER_USE_OLD_DRIVER "@CMAKE_Swift_COMPILER_USE_OLD_DRIVER@")
set(CMAKE_Swift_IMPLICIT_INCLUDE_DIRECTORIES "@CMAKE_Swift_IMPLICIT_INCLUDE_DIRECTORIES@") set(CMAKE_Swift_IMPLICIT_INCLUDE_DIRECTORIES "@CMAKE_Swift_IMPLICIT_INCLUDE_DIRECTORIES@")
set(CMAKE_Swift_MODULE_TRIPLE "@CMAKE_Swift_MODULE_TRIPLE@")