12
12
##
13
13
##===----------------------------------------------------------------------===##
14
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 ()
62
+
15
63
function (_foundation_install_target module )
16
- set (swift_os ${SWIFT_SYSTEM_NAME} )
17
64
get_target_property (type ${module} TYPE )
18
65
19
66
if (type STREQUAL STATIC_LIBRARY )
@@ -23,8 +70,8 @@ function(_foundation_install_target module)
23
70
endif ()
24
71
25
72
install (TARGETS ${module}
26
- ARCHIVE DESTINATION lib/${swift}/${swift_os}
27
- LIBRARY DESTINATION lib/${swift}/${swift_os}
73
+ ARCHIVE DESTINATION lib/${swift}/${SwiftFoundation_PLATFORM}$<$<BOOL:${SwiftFoundation_INSTALL_ARCH_SUBDIR}>:/${SwiftFoundation_ARCH}>
74
+ LIBRARY DESTINATION lib/${swift}/${SwiftFoundation_PLATFORM}$<$<BOOL:${SwiftFoundation_INSTALL_ARCH_SUBDIR}>:/${SwiftFoundation_ARCH}>
28
75
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
29
76
if (type STREQUAL EXECUTABLE )
30
77
return ()
@@ -36,10 +83,10 @@ function(_foundation_install_target module)
36
83
endif ()
37
84
38
85
install (FILES $< TARGET_PROPERTY:${module} ,Swift_MODULE_DIRECTORY> /${module_name}.swiftdoc
39
- DESTINATION lib/${swift}/${swift_os }/${module_name}.swiftmodule
86
+ DESTINATION lib/${swift}/${SwiftFoundation_PLATFORM }/${module_name}.swiftmodule
40
87
RENAME ${SwiftFoundation_MODULE_TRIPLE} .swiftdoc )
41
88
install (FILES $< TARGET_PROPERTY:${module} ,Swift_MODULE_DIRECTORY> /${module_name}.swiftmodule
42
- DESTINATION lib/${swift}/${swift_os }/${module_name}.swiftmodule
89
+ DESTINATION lib/${swift}/${SwiftFoundation_PLATFORM }/${module_name}.swiftmodule
43
90
RENAME ${SwiftFoundation_MODULE_TRIPLE} .swiftmodule )
44
91
45
92
endfunction ()
0 commit comments