forked from apple/swift-argument-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: add support for installation (apple#150)
This extends the CMake build to install the artifacts. This is required for redistribution of the build.
- Loading branch information
Showing
4 changed files
with
99 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Returns the architecture name in a variable | ||
# | ||
# Usage: | ||
# get_swift_host_arch(result_var_name) | ||
# | ||
# Sets ${result_var_name} with the converted architecture name derived from | ||
# CMAKE_SYSTEM_PROCESSOR. | ||
function(get_swift_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") | ||
set("${result_var_name}" "aarch64" PARENT_SCOPE) | ||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64") | ||
set("${result_var_name}" "powerpc64" PARENT_SCOPE) | ||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64le") | ||
set("${result_var_name}" "powerpc64le" PARENT_SCOPE) | ||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "s390x") | ||
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 "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") | ||
set("${result_var_name}" "itanium" PARENT_SCOPE) | ||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86") | ||
set("${result_var_name}" "i686" PARENT_SCOPE) | ||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686") | ||
set("${result_var_name}" "i686" PARENT_SCOPE) | ||
else() | ||
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(_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_swift_host_arch(swift_arch) | ||
get_target_property(module_name ${module} Swift_MODULE_NAME) | ||
if(NOT module_name) | ||
set(module_name ${module}) | ||
endif() | ||
|
||
if(CMAKE_SYSTEM_NAME STREQUAL Darwin) | ||
install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftdoc | ||
DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule | ||
RENAME ${swift_arch}.swiftdoc) | ||
install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftmodule | ||
DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule | ||
RENAME ${swift_arch}.swiftmodule) | ||
else() | ||
install(FILES | ||
$<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftdoc | ||
$<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftmodule | ||
DESTINATION lib/${swift}/${swift_os}/${swift_arch}) | ||
endif() | ||
endfunction() |