|
1 | 1 | include_guard()
|
2 | 2 |
|
3 |
| -if(NOT dispatch_MODULE_TRIPLE) |
| 3 | +if(NOT dispatch_Swift_MODULE_TRIPLE OR NOT dispatch_Swift_ARCH OR NOT dispatch_Swift_SYSTEM) |
| 4 | + # Get the target information from the Swift compiler. |
4 | 5 | set(module_triple_command "${CMAKE_Swift_COMPILER}" -print-target-info)
|
5 | 6 | if(CMAKE_Swift_COMPILER_TARGET)
|
6 | 7 | list(APPEND module_triple_command -target ${CMAKE_Swift_COMPILER_TARGET})
|
7 | 8 | endif()
|
8 | 9 | execute_process(COMMAND ${module_triple_command} OUTPUT_VARIABLE target_info_json)
|
| 10 | +endif() |
9 | 11 |
|
| 12 | +if(NOT dispatch_Swift_MODULE_TRIPLE) |
10 | 13 | string(JSON module_triple GET "${target_info_json}" "target" "moduleTriple")
|
11 |
| - set(dispatch_MODULE_TRIPLE "${module_triple}" CACHE STRING "Triple used to install swiftmodule files") |
12 |
| - mark_as_advanced(dispatch_MODULE_TRIPLE) |
13 |
| - |
| 14 | + set(dispatch_Swift_MODULE_TRIPLE "${module_triple}" CACHE STRING "Triple used to install swiftmodule files") |
| 15 | + mark_as_advanced(dispatch_Swift_MODULE_TRIPLE) |
14 | 16 | message(CONFIGURE_LOG "Swift module triple: ${module_triple}")
|
15 | 17 | endif()
|
16 | 18 |
|
17 | 19 | if(NOT dispatch_Swift_ARCH)
|
18 | 20 | if(CMAKE_Swift_COMPILER_VERSION VERSION_EQUAL 0.0.0 OR CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 6.2)
|
19 | 21 | # For newer compilers, we can use the -print-target-info command to get the architecture.
|
20 |
| - set(module_arch_command "${CMAKE_Swift_COMPILER}" -print-target-info) |
21 |
| - if(CMAKE_Swift_COMPILER_TARGET) |
22 |
| - list(APPEND module_arch_command -target ${CMAKE_Swift_COMPILER_TARGET}) |
23 |
| - endif() |
24 |
| - execute_process(COMMAND ${module_arch_command} OUTPUT_VARIABLE target_info_json) |
25 | 22 | string(JSON module_arch GET "${target_info_json}" "target" "arch")
|
26 | 23 | else()
|
27 |
| - # For older compilers, extract the value from `dispatch_MODULE_TRIPLE`. |
28 |
| - string(REGEX MATCH "^[^-]+" module_arch "${dispatch_MODULE_TRIPLE}") |
| 24 | + # For older compilers, extract the value from `dispatch_Swift_MODULE_TRIPLE`. |
| 25 | + string(REGEX MATCH "^[^-]+" module_arch "${dispatch_Swift_MODULE_TRIPLE}") |
29 | 26 | endif()
|
30 | 27 |
|
31 | 28 | set(dispatch_Swift_ARCH "${module_arch}" CACHE STRING "Arch folder name used to install libraries")
|
32 | 29 | mark_as_advanced(dispatch_Swift_ARCH)
|
33 |
| - |
34 | 30 | message(CONFIGURE_LOG "Swift arch: ${dispatch_Swift_ARCH}")
|
35 | 31 | endif()
|
36 | 32 |
|
| 33 | +if(NOT dispatch_Swift_PLATFORM) |
| 34 | + if(CMAKE_Swift_COMPILER_VERSION VERSION_EQUAL 0.0.0 OR CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 6.2) |
| 35 | + # For newer compilers, we can use the -print-target-info command to get the platform. |
| 36 | + string(JSON swift_platform GET "${target_info_json}" "target" "platform") |
| 37 | + else() |
| 38 | + # For older compilers, compile the value from `CMAKE_SYSTEM_NAME`. |
| 39 | + if(APPLE) |
| 40 | + set(swift_platform macosx) |
| 41 | + else() |
| 42 | + set(swift_platform "$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>") |
| 43 | + endif() |
| 44 | + endif() |
| 45 | + |
| 46 | + set(dispatch_Swift_PLATFORM "${swift_platform}" CACHE STRING "Platform folder name used to install libraries") |
| 47 | + mark_as_advanced(dispatch_Swift_PLATFORM) |
| 48 | + message(CONFIGURE_LOG "Swift platform: ${dispatch_Swift_PLATFORM}") |
| 49 | +endif() |
| 50 | + |
37 | 51 | function(install_swift_module target)
|
38 | 52 | get_target_property(module ${target} Swift_MODULE_NAME)
|
39 | 53 | if(NOT module)
|
40 | 54 | set(module ${target})
|
41 | 55 | endif()
|
42 | 56 |
|
43 |
| - if(NOT SWIFT_SYSTEM_NAME) |
44 |
| - if(APPLE) |
45 |
| - set(SWIFT_SYSTEM_NAME macosx) |
46 |
| - else() |
47 |
| - set(SWIFT_SYSTEM_NAME "$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>") |
48 |
| - endif() |
49 |
| - endif() |
50 |
| - set(INSTALL_SWIFT_MODULE_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${SWIFT_SYSTEM_NAME}" CACHE PATH "Path where the swift modules will be installed") |
| 57 | + set(INSTALL_SWIFT_MODULE_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${dispatch_Swift_PLATFORM}" CACHE PATH "Path where the swift modules will be installed") |
51 | 58 |
|
52 | 59 | install(
|
53 | 60 | FILES $<TARGET_PROPERTY:${target},Swift_MODULE_DIRECTORY>/${module}.swiftdoc
|
54 | 61 | DESTINATION ${INSTALL_SWIFT_MODULE_DIR}/${module}.swiftmodule
|
55 |
| - RENAME ${dispatch_MODULE_TRIPLE}.swiftdoc) |
| 62 | + RENAME ${dispatch_Swift_MODULE_TRIPLE}.swiftdoc) |
56 | 63 | install(
|
57 | 64 | FILES $<TARGET_PROPERTY:${target},Swift_MODULE_DIRECTORY>/${module}.swiftmodule
|
58 | 65 | DESTINATION ${INSTALL_SWIFT_MODULE_DIR}/${module}.swiftmodule
|
59 |
| - RENAME ${dispatch_MODULE_TRIPLE}.swiftmodule) |
| 66 | + RENAME ${dispatch_Swift_MODULE_TRIPLE}.swiftmodule) |
60 | 67 | endfunction()
|
0 commit comments