|
| 1 | +# This source file is part of the Swift.org open source project |
| 2 | +# |
| 3 | +# Copyright (c) 2024 Apple Inc. and the Swift project authors |
| 4 | +# Licensed under Apache License v2.0 with Runtime Library Exception |
| 5 | +# |
| 6 | +# See http://swift.org/LICENSE.txt for license information |
| 7 | +# See http://swift.org/CONTRIBUTORS.txt for Swift project authors |
| 8 | + |
| 9 | +# Returns the os name in a variable |
| 10 | +# |
| 11 | +# Usage: |
| 12 | +# get_swift_host_os(result_var_name) |
| 13 | +# |
| 14 | +# |
| 15 | +# Sets ${result_var_name} with the converted OS name derived from |
| 16 | +# CMAKE_SYSTEM_NAME. |
| 17 | +function(get_swift_host_os result_var_name) |
| 18 | + set(${result_var_name} ${SWIFT_SYSTEM_NAME} PARENT_SCOPE) |
| 19 | +endfunction() |
| 20 | + |
| 21 | +function(_swift_testing_install_target module) |
| 22 | + get_swift_host_os(swift_os) |
| 23 | + get_target_property(type ${module} TYPE) |
| 24 | + |
| 25 | + if(type STREQUAL STATIC_LIBRARY) |
| 26 | + set(swift swift_static) |
| 27 | + else() |
| 28 | + set(swift swift) |
| 29 | + endif() |
| 30 | + |
| 31 | + install(TARGETS ${module} |
| 32 | + ARCHIVE DESTINATION lib/${swift}/${swift_os} |
| 33 | + LIBRARY DESTINATION lib/${swift}/${swift_os} |
| 34 | + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) |
| 35 | + if(type STREQUAL EXECUTABLE) |
| 36 | + return() |
| 37 | + endif() |
| 38 | + |
| 39 | + get_target_property(module_name ${module} Swift_MODULE_NAME) |
| 40 | + if(NOT module_name) |
| 41 | + set(module_name ${module}) |
| 42 | + endif() |
| 43 | + |
| 44 | + if(NOT SwiftTesting_MODULE_TRIPLE) |
| 45 | + set(module_triple_command "${CMAKE_Swift_COMPILER}" -print-target-info) |
| 46 | + if(CMAKE_Swift_COMPILER_TARGET) |
| 47 | + list(APPEND module_triple_command -target ${CMAKE_Swift_COMPILER_TARGET}) |
| 48 | + endif() |
| 49 | + execute_process(COMMAND ${module_triple_command} OUTPUT_VARIABLE target_info_json) |
| 50 | + string(JSON module_triple GET "${target_info_json}" "target" "moduleTriple") |
| 51 | + set(SwiftTesting_MODULE_TRIPLE "${module_triple}" CACHE STRING "swift module triple used for installed swiftmodule and swiftinterface files") |
| 52 | + mark_as_advanced(SwiftTesting_MODULE_TRIPLE) |
| 53 | + endif() |
| 54 | + |
| 55 | + install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftdoc |
| 56 | + DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule |
| 57 | + RENAME ${SwiftTesting_MODULE_TRIPLE}.swiftdoc) |
| 58 | + install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftmodule |
| 59 | + DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule |
| 60 | + RENAME ${SwiftTesting_MODULE_TRIPLE}.swiftmodule) |
| 61 | + install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftinterface |
| 62 | + DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule |
| 63 | + RENAME ${SwiftTesting_MODULE_TRIPLE}.swiftinterface) |
| 64 | +endfunction() |
0 commit comments