mirror of
https://github.com/apple/swift-asn1
synced 2026-11-22 04:10:39 +00:00
Clean up how the CMake build installs swiftmodules, using the full module triple instead of just the architecture. This change uses the compiler to compute the expected module triple instead of attempting to compute it in CMake script. This is more maintainable and robust to adding new platforms and architectures.
74 lines
2.5 KiB
CMake
74 lines
2.5 KiB
CMake
##===----------------------------------------------------------------------===##
|
|
##
|
|
## This source file is part of the SwiftASN1 open source project
|
|
##
|
|
## Copyright (c) 2023 Apple Inc. and the SwiftASN1 project authors
|
|
## Licensed under Apache License v2.0
|
|
##
|
|
## See LICENSE.txt for license information
|
|
## See CONTRIBUTORS.txt for the list of SwiftASN1 project authors
|
|
##
|
|
## SPDX-License-Identifier: Apache-2.0
|
|
##
|
|
##===----------------------------------------------------------------------===##
|
|
|
|
if(NOT SwiftASN1_SWIFTMODULE_TRIPLE)
|
|
set(target_info_cmd "${CMAKE_Swift_COMPILER}" -print-target-info)
|
|
if(CMAKE_Swift_COMPILER_TARGET)
|
|
list(APPEND target_info_cmd -target ${CMAKE_Swift_COMPILER_TARGET})
|
|
endif()
|
|
execute_process(COMMAND ${target_info_cmd} OUTPUT_VARIABLE target_info)
|
|
string(JSON module_triple GET "${target_info}" "target" "moduleTriple")
|
|
set(SwiftASN1_SWIFTMODULE_TRIPLE "${module_triple}" CACHE STRING "Triple used to install Swift module files")
|
|
mark_as_advanced(SwiftASN1_SWIFTMODULE_TRIPLE)
|
|
message(CONFIGURE_LOG "Swift module triple: ${module_triple}")
|
|
endif()
|
|
|
|
# Returns the os name in a variable
|
|
#
|
|
# Usage:
|
|
# get_swift_host_os(result_var_name)
|
|
#
|
|
#
|
|
# Sets ${result_var_name} with the converted OS name derived from
|
|
# CMAKE_SYSTEM_NAME.
|
|
function(get_swift_host_os result_var_name)
|
|
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
|
set(${result_var_name} macosx PARENT_SCOPE)
|
|
else()
|
|
string(TOLOWER ${CMAKE_SYSTEM_NAME} cmake_system_name_lc)
|
|
set(${result_var_name} ${cmake_system_name_lc} PARENT_SCOPE)
|
|
endif()
|
|
endfunction()
|
|
|
|
function(_install_target module)
|
|
get_swift_host_os(swift_os)
|
|
get_target_property(type ${module} TYPE)
|
|
|
|
if(type STREQUAL STATIC_LIBRARY)
|
|
set(swift swift_static)
|
|
else()
|
|
set(swift swift)
|
|
endif()
|
|
|
|
install(TARGETS ${module}
|
|
ARCHIVE DESTINATION lib/${swift}/${swift_os}
|
|
LIBRARY DESTINATION lib/${swift}/${swift_os}
|
|
RUNTIME DESTINATION bin)
|
|
if(type STREQUAL EXECUTABLE)
|
|
return()
|
|
endif()
|
|
|
|
get_target_property(module_name ${module} Swift_MODULE_NAME)
|
|
if(NOT module_name)
|
|
set(module_name ${module})
|
|
endif()
|
|
|
|
install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftdoc
|
|
DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule
|
|
RENAME ${SwiftASN1_SWIFTMODULE_TRIPLE}.swiftdoc)
|
|
install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftmodule
|
|
DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule
|
|
RENAME ${SwiftASN1_SWIFTMODULE_TRIPLE}.swiftmodule)
|
|
endfunction()
|