1- # Returns the os name in a variable
2- #
3- # Usage:
4- # get_swift_host_os(result_var_name)
5- #
6- #
7- # Sets ${result_var_name} with the converted OS name derived from
8- # CMAKE_SYSTEM_NAME.
9- function (get_swift_host_os result_var_name)
10- set (${result_var_name} ${SWIFT_SYSTEM_NAME} PARENT_SCOPE)
11- endfunction ()
1+ ##===----------------------------------------------------------------------===##
2+ ##
3+ ## This source file is part of the Swift open source project
4+ ##
5+ ## Copyright (c) 2025 Apple Inc. and the Swift project authors
6+ ## Licensed under Apache License v2.0
7+ ##
8+ ## See LICENSE.txt for license information
9+ ## See CONTRIBUTORS.md for the list of Swift project authors
10+ ##
11+ ## SPDX-License-Identifier: Apache-2.0
12+ ##
13+ ##===----------------------------------------------------------------------===##
14+
15+ if (NOT SwiftFoundation_MODULE_TRIPLE OR NOT SwiftFoundation_ARCH OR NOT SwiftFoundation_PLATFORM)
16+ # Get the target information from the Swift compiler.
17+ set (module_triple_command "${CMAKE_Swift_COMPILER} " -print-target -info)
18+ if (CMAKE_Swift_COMPILER_TARGET)
19+ list (APPEND module_triple_command -target ${CMAKE_Swift_COMPILER_TARGET} )
20+ endif ()
21+ execute_process (COMMAND ${module_triple_command} OUTPUT_VARIABLE target_info_json)
22+ endif ()
23+
24+ if (NOT SwiftFoundation_MODULE_TRIPLE)
25+ string (JSON module_triple GET "${target_info_json} " "target" "moduleTriple" )
26+ set (SwiftFoundation_MODULE_TRIPLE "${module_triple} " CACHE STRING "Triple used to install swiftmodule files" )
27+ mark_as_advanced (SwiftFoundation_MODULE_TRIPLE)
28+ message (CONFIGURE_LOG "Swift module triple: ${module_triple} " )
29+ endif ()
30+
31+ if (NOT SwiftFoundation_ARCH)
32+ if (CMAKE_Swift_COMPILER_VERSION VERSION_EQUAL 0.0.0 OR CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 6.2)
33+ # For newer compilers, we can use the -print-target-info command to get the architecture.
34+ string (JSON module_arch GET "${target_info_json} " "target" "arch" )
35+ else ()
36+ # For older compilers, extract the value from `SwiftFoundation_MODULE_TRIPLE`.
37+ string (REGEX MATCH "^[^-]+" module_arch "${SwiftFoundation_MODULE_TRIPLE} " )
38+ endif ()
39+
40+ set (SwiftFoundation_ARCH "${module_arch} " CACHE STRING "Arch folder name used to install libraries" )
41+ mark_as_advanced (SwiftFoundation_ARCH)
42+ message (CONFIGURE_LOG "Swift arch: ${SwiftFoundation_ARCH} " )
43+ endif ()
44+
45+ if (NOT SwiftFoundation_PLATFORM)
46+ if (CMAKE_Swift_COMPILER_VERSION VERSION_EQUAL 0.0.0 OR CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 6.2)
47+ # For newer compilers, we can use the -print-target-info command to get the platform.
48+ string (JSON swift_platform GET "${target_info_json} " "target" "platform" )
49+ else ()
50+ # For older compilers, compile the value from `CMAKE_SYSTEM_NAME`.
51+ if (APPLE )
52+ set (swift_platform macosx)
53+ else ()
54+ set (swift_platform "$<LOWER_CASE:${CMAKE_SYSTEM_NAME} >" )
55+ endif ()
56+ endif ()
57+
58+ set (SwiftFoundation_PLATFORM "${swift_platform} " CACHE STRING "Platform folder name used to install libraries" )
59+ mark_as_advanced (SwiftFoundation_PLATFORM)
60+ message (CONFIGURE_LOG "Swift platform: ${SwiftFoundation_PLATFORM} " )
61+ endif ()
1262
1363function (_swift_foundation_install_target module)
14- get_swift_host_os(swift_os)
1564 get_target_property (type ${module} TYPE )
1665
1766 if (type STREQUAL STATIC_LIBRARY)
@@ -21,8 +70,8 @@ function(_swift_foundation_install_target module)
2170 endif ()
2271
2372 install (TARGETS ${module}
24- ARCHIVE DESTINATION lib/${swift} /${swift_os }
25- LIBRARY DESTINATION lib/${swift} /${swift_os }
73+ ARCHIVE DESTINATION lib/${swift} /${SwiftFoundation_PLATFORM} / ${SwiftFoundation_ARCH }
74+ LIBRARY DESTINATION lib/${swift} /${SwiftFoundation_PLATFORM} / ${SwiftFoundation_ARCH }
2675 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
2776 if (type STREQUAL EXECUTABLE)
2877 return ()
@@ -33,22 +82,11 @@ function(_swift_foundation_install_target module)
3382 set (module_name ${module} )
3483 endif ()
3584
36- if (NOT SwiftFoundation_MODULE_TRIPLE)
37- set (module_triple_command "${CMAKE_Swift_COMPILER} " -print-target -info)
38- if (CMAKE_Swift_COMPILER_TARGET)
39- list (APPEND module_triple_command -target ${CMAKE_Swift_COMPILER_TARGET} )
40- endif ()
41- execute_process (COMMAND ${module_triple_command} OUTPUT_VARIABLE target_info_json)
42- string (JSON module_triple GET "${target_info_json} " "target" "moduleTriple" )
43- set (SwiftFoundation_MODULE_TRIPLE "${module_triple} " CACHE STRING "swift module triple used for installed swiftmodule and swiftinterface files" )
44- mark_as_advanced (SwiftFoundation_MODULE_TRIPLE)
45- endif ()
46-
4785 install (FILES $<TARGET_PROPERTY:${module} ,Swift_MODULE_DIRECTORY>/${module_name} .swiftdoc
48- DESTINATION lib/${swift} /${swift_os } /${module_name} .swiftmodule
86+ DESTINATION lib/${swift} /${SwiftFoundation_PLATFORM } /${module_name} .swiftmodule
4987 RENAME ${SwiftFoundation_MODULE_TRIPLE} .swiftdoc)
5088 install (FILES $<TARGET_PROPERTY:${module} ,Swift_MODULE_DIRECTORY>/${module_name} .swiftmodule
51- DESTINATION lib/${swift} /${swift_os } /${module_name} .swiftmodule
89+ DESTINATION lib/${swift} /${SwiftFoundation_PLATFORM } /${module_name} .swiftmodule
5290 RENAME ${SwiftFoundation_MODULE_TRIPLE} .swiftmodule)
5391
5492endfunction ()
0 commit comments