|
1 | 1 | include_guard()
|
2 | 2 |
|
3 |
| -if(NOT dispatch_MODULE_TRIPLE) |
| 3 | +if(NOT dispatch_MODULE_TRIPLE OR NOT dispatch_ARCH OR NOT dispatch_PLATFORM) |
| 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_MODULE_TRIPLE) |
10 | 13 | string(JSON module_triple GET "${target_info_json}" "target" "moduleTriple")
|
11 | 14 | set(dispatch_MODULE_TRIPLE "${module_triple}" CACHE STRING "Triple used to install swiftmodule files")
|
12 | 15 | mark_as_advanced(dispatch_MODULE_TRIPLE)
|
13 |
| - |
14 | 16 | message(CONFIGURE_LOG "Swift module triple: ${module_triple}")
|
15 | 17 | endif()
|
16 | 18 |
|
| 19 | +if(NOT dispatch_ARCH) |
| 20 | + if(CMAKE_Swift_COMPILER_VERSION VERSION_EQUAL 0.0.0 OR CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 6.2) |
| 21 | + # For newer compilers, we can use the -print-target-info command to get the architecture. |
| 22 | + string(JSON module_arch GET "${target_info_json}" "target" "arch") |
| 23 | + else() |
| 24 | + # For older compilers, extract the value from `dispatch_MODULE_TRIPLE`. |
| 25 | + string(REGEX MATCH "^[^-]+" module_arch "${dispatch_MODULE_TRIPLE}") |
| 26 | + endif() |
| 27 | + |
| 28 | + set(dispatch_ARCH "${module_arch}" CACHE STRING "Arch folder name used to install libraries") |
| 29 | + mark_as_advanced(dispatch_ARCH) |
| 30 | + message(CONFIGURE_LOG "Swift arch: ${dispatch_ARCH}") |
| 31 | +endif() |
| 32 | + |
| 33 | +if(NOT dispatch_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_PLATFORM "${swift_platform}" CACHE STRING "Platform folder name used to install libraries") |
| 47 | + mark_as_advanced(dispatch_PLATFORM) |
| 48 | + message(CONFIGURE_LOG "Swift platform: ${dispatch_PLATFORM}") |
| 49 | +endif() |
| 50 | + |
17 | 51 | function(install_swift_module target)
|
18 | 52 | get_target_property(module ${target} Swift_MODULE_NAME)
|
19 | 53 | if(NOT module)
|
20 | 54 | set(module ${target})
|
21 | 55 | endif()
|
| 56 | + |
| 57 | + set(INSTALL_SWIFT_MODULE_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${dispatch_PLATFORM}" CACHE PATH "Path where the swift modules will be installed") |
| 58 | + |
22 | 59 | install(
|
23 | 60 | FILES $<TARGET_PROPERTY:${target},Swift_MODULE_DIRECTORY>/${module}.swiftdoc
|
24 |
| - DESTINATION ${INSTALL_TARGET_DIR}/${module}.swiftmodule |
| 61 | + DESTINATION ${INSTALL_SWIFT_MODULE_DIR}/${module}.swiftmodule |
25 | 62 | RENAME ${dispatch_MODULE_TRIPLE}.swiftdoc)
|
26 | 63 | install(
|
27 | 64 | FILES $<TARGET_PROPERTY:${target},Swift_MODULE_DIRECTORY>/${module}.swiftmodule
|
28 |
| - DESTINATION ${INSTALL_TARGET_DIR}/${module}.swiftmodule |
| 65 | + DESTINATION ${INSTALL_SWIFT_MODULE_DIR}/${module}.swiftmodule |
29 | 66 | RENAME ${dispatch_MODULE_TRIPLE}.swiftmodule)
|
30 | 67 | endfunction()
|
0 commit comments