build: improve installation
We would previously fail to install Yams from CMake due to searching for the swiftmodule in the wrong location. This uses the new improved generic installation rules that I've been using in a number of other projects to install the swift content across all the platforms.
This commit is contained in:
parent
6e6483a6dd
commit
cdafa7712f
|
@ -29,13 +29,5 @@ set_target_properties(Yams PROPERTIES
|
|||
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
|
||||
|
||||
set_property(GLOBAL APPEND PROPERTY YAMS_EXPORTS Yams)
|
||||
get_swift_host_arch(swift_arch)
|
||||
install(FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/swift/Yams.swiftmodule
|
||||
${CMAKE_CURRENT_BINARY_DIR}/swift/Yams.swiftdoc
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${swift_arch})
|
||||
install(TARGETS Yams
|
||||
EXPORT YamsExports
|
||||
RUNTIME DESTINATION bin
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
swift_install(TARGETS Yams
|
||||
EXPORT YamsExports)
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
|
||||
# Returns the current achitecture name in a variable
|
||||
include(CMakeParseArguments)
|
||||
|
||||
# Returns the architecture name in a variable
|
||||
#
|
||||
# Usage:
|
||||
# get_swift_host_arch(result_var_name)
|
||||
# swift_get_host_arch(result_var_name)
|
||||
#
|
||||
# If the current architecture is supported by Swift, sets ${result_var_name}
|
||||
# with the sanitized host architecture name derived from CMAKE_SYSTEM_PROCESSOR.
|
||||
function(get_swift_host_arch result_var_name)
|
||||
# Sets ${result_var_name} with the converted architecture name derived from
|
||||
# CMAKE_SYSTEM_PROCESSOR.
|
||||
function(swift_get_host_arch result_var_name)
|
||||
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
|
||||
set("${result_var_name}" "x86_64" PARENT_SCOPE)
|
||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
|
||||
|
@ -19,10 +21,10 @@ function(get_swift_host_arch result_var_name)
|
|||
set("${result_var_name}" "s390x" PARENT_SCOPE)
|
||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv6l")
|
||||
set("${result_var_name}" "armv6" PARENT_SCOPE)
|
||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a")
|
||||
set("${result_var_name}" "armv7" PARENT_SCOPE)
|
||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l")
|
||||
set("${result_var_name}" "armv7" PARENT_SCOPE)
|
||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a")
|
||||
set("${result_var_name}" "armv7" PARENT_SCOPE)
|
||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64")
|
||||
set("${result_var_name}" "x86_64" PARENT_SCOPE)
|
||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "IA64")
|
||||
|
@ -35,3 +37,77 @@ function(get_swift_host_arch result_var_name)
|
|||
message(FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# 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(swift_install)
|
||||
set(options)
|
||||
set(single_parameter_options EXPORT)
|
||||
set(multiple_parameter_options TARGETS)
|
||||
|
||||
cmake_parse_arguments(SI
|
||||
"${options}"
|
||||
"${single_parameter_options}"
|
||||
"${multiple_parameter_options}"
|
||||
${ARGN})
|
||||
|
||||
list(LENGTH ${SI_TARGETS} si_num_targets)
|
||||
if(si_num_targets GREATER 1)
|
||||
message(SEND_ERROR "swift_install only supports a single target at a time")
|
||||
endif()
|
||||
|
||||
get_swift_host_os(swift_os)
|
||||
get_target_property(type ${SI_TARGETS} TYPE)
|
||||
|
||||
if(type STREQUAL STATIC_LIBRARY)
|
||||
set(swift_dir swift_static)
|
||||
else()
|
||||
set(swift_dir swift)
|
||||
endif()
|
||||
|
||||
install(TARGETS ${SI_TARGETS}
|
||||
EXPORT ${SI_EXPORT}
|
||||
ARCHIVE DESTINATION lib/${swift_dir}/${swift_os}
|
||||
LIBRARY DESTINATION lib/${swift_dir}/${swift_os}
|
||||
RUNTIME DESTINATION bin)
|
||||
if(type STREQUAL EXECUTABLE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
swift_get_host_arch(swift_arch)
|
||||
get_target_property(module_name ${SI_TARGETS} Swift_MODULE_NAME)
|
||||
if(NOT module_name)
|
||||
set(module_name ${SI_TARGETS})
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
||||
install(FILES
|
||||
$<TARGET_PROPERTY:${SI_TARGETS},Swift_MODULE_DIRECTORY>/${module_name}.swiftdoc
|
||||
DESTINATION lib/${swift_dir}/${swift_os}/${module_name}.swiftmodule
|
||||
RENAME ${swift_arch}.swiftdoc)
|
||||
install(FILES
|
||||
$<TARGET_PROPERTY:${SI_TARGETS},Swift_MODULE_DIRECTORY>/${module_name}.swiftmodule
|
||||
DESTINATION lib/${swift_dir}/${swift_os}/${module_name}.swiftmodule
|
||||
RENAME ${swift_arch}.swiftmodule)
|
||||
else()
|
||||
install(FILES
|
||||
$<TARGET_PROPERTY:${SI_TARGETS},Swift_MODULE_DIRECTORY>/${module_name}.swiftdoc
|
||||
$<TARGET_PROPERTY:${SI_TARGETS},Swift_MODULE_DIRECTORY>/${module_name}.swiftmodule
|
||||
DESTINATION lib/${swift_dir}/${swift_os}/${swift_arch})
|
||||
endif()
|
||||
endfunction()
|
||||
|
|
Loading…
Reference in New Issue