Skip to content

Commit c5b5fff

Browse files
committed
build: centralise the install logic for the Swift modules
Add support for installation for macOS targets to the CMake installation. Centralise the logic for the installation of the files. This properly handles the installation of the swiftdoc, swiftinterface, swiftmodule and the runtime libraries across all the platforms in either static or shared configurations.
1 parent 60fb698 commit c5b5fff

File tree

4 files changed

+59
-27
lines changed

4 files changed

+59
-27
lines changed

Sources/Foundation/CMakeLists.txt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,4 @@ endif()
161161

162162

163163
set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS Foundation)
164-
install(TARGETS Foundation
165-
ARCHIVE DESTINATION lib/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>
166-
LIBRARY DESTINATION lib/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>
167-
RUNTIME DESTINATION bin)
168-
get_swift_host_arch(swift_arch)
169-
install(FILES
170-
$<TARGET_PROPERTY:Foundation,Swift_MODULE_DIRECTORY>/Foundation.swiftdoc
171-
$<TARGET_PROPERTY:Foundation,Swift_MODULE_DIRECTORY>/Foundation.swiftmodule
172-
DESTINATION lib/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>/${swift_arch})
164+
_install_target(Foundation)

Sources/FoundationNetworking/CMakeLists.txt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,4 @@ set_target_properties(FoundationNetworking PROPERTIES
7070

7171

7272
set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS FoundationNetworking)
73-
install(TARGETS FoundationNetworking
74-
ARCHIVE DESTINATION lib/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>
75-
LIBRARY DESTINATION lib/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>
76-
RUNTIME DESTINATION bin)
77-
get_swift_host_arch(swift_arch)
78-
install(FILES
79-
$<TARGET_PROPERTY:FoundationNetworking,Swift_MODULE_DIRECTORY>/FoundationNetworking.swiftdoc
80-
$<TARGET_PROPERTY:FoundationNetworking,Swift_MODULE_DIRECTORY>/FoundationNetworking.swiftmodule
81-
DESTINATION lib/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>/${swift_arch})
73+
_install_target(FoundationNetworking)

Sources/FoundationXML/CMakeLists.txt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,4 @@ set_target_properties(FoundationXML PROPERTIES
2222

2323

2424
set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS FoundationXML)
25-
install(TARGETS FoundationXML
26-
ARCHIVE DESTINATION lib/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>
27-
LIBRARY DESTINATION lib/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>
28-
RUNTIME DESTINATION bin)
29-
get_swift_host_arch(swift_arch)
30-
install(FILES
31-
$<TARGET_PROPERTY:FoundationXML,Swift_MODULE_DIRECTORY>/FoundationXML.swiftdoc
32-
$<TARGET_PROPERTY:FoundationXML,Swift_MODULE_DIRECTORY>/FoundationXML.swiftmodule
33-
DESTINATION lib/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>/${swift_arch})
25+
_install_target(FoundationXML)

cmake/modules/SwiftSupport.cmake

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,59 @@ function(get_swift_host_arch result_var_name)
3535
message(FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR}")
3636
endif()
3737
endfunction()
38+
39+
# Returns the os name in a variable
40+
#
41+
# Usage:
42+
# get_swift_host_os(result_var_name)
43+
#
44+
#
45+
# Sets ${result_var_name} with the converted OS name derived from
46+
# CMAKE_SYSTEM_NAME.
47+
function(get_swift_host_os result_var_name)
48+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
49+
set(${result_var_name} macosx PARENT_SCOPE)
50+
else()
51+
string(TOLOWER ${CMAKE_SYSTEM_NAME} cmake_system_name_lc)
52+
set(${result_var_name} ${cmake_system_name_lc} PARENT_SCOPE)
53+
endif()
54+
endfunction()
55+
56+
function(_install_target module)
57+
get_swift_host_os(swift_os)
58+
get_target_property(type ${module} TYPE)
59+
60+
if(type STREQUAL STATIC_LIBRARY)
61+
set(swift swift_static)
62+
else()
63+
set(swift swift)
64+
endif()
65+
66+
install(TARGETS ${module}
67+
ARCHIVE DESTINATION lib/${swift}/${swift_os}
68+
LIBRARY DESTINATION lib/${swift}/${swift_os}
69+
RUNTIME DESTINATION bin)
70+
if(type STREQUAL EXECUTABLE)
71+
return()
72+
endif()
73+
74+
get_swift_host_arch(swift_arch)
75+
get_target_property(module_name ${module} Swift_MODULE_NAME)
76+
if(NOT module_name)
77+
set(module_name ${module})
78+
endif()
79+
80+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
81+
install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftdoc
82+
DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule
83+
RENAME ${swift_arch}.swiftdoc)
84+
install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftmodule
85+
DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule
86+
RENAME ${swift_arch}.swiftmodule)
87+
else()
88+
install(FILES
89+
$<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftdoc
90+
$<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftmodule
91+
DESTINATION lib/${swift}/${swift_os}/${swift_arch})
92+
endif()
93+
endfunction()

0 commit comments

Comments
 (0)