Skip to content

Commit beb137b

Browse files
authored
Merge pull request #875 from swiftlang/ewilde/module-triple-modules
Install nested Swift modules
2 parents a1b9319 + 7172447 commit beb137b

File tree

3 files changed

+30
-48
lines changed

3 files changed

+30
-48
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ include(DispatchAppleOptions)
117117
include(DispatchSanitization)
118118
include(DispatchCompilerWarnings)
119119
include(DTrace)
120-
include(SwiftSupport)
121120

122121
# NOTE(abdulras) this is the CMake supported way to control whether we generate
123122
# shared or static libraries. This impacts the behaviour of `add_library` in

cmake/modules/SwiftSupport.cmake

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,30 @@
1+
include_guard()
12

2-
# Returns the current achitecture name in a variable
3-
#
4-
# Usage:
5-
# get_swift_host_arch(result_var_name)
6-
#
7-
# If the current architecture is supported by Swift, sets ${result_var_name}
8-
# with the sanitized host architecture name derived from CMAKE_SYSTEM_PROCESSOR.
9-
function(get_swift_host_arch result_var_name)
10-
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
11-
set("${result_var_name}" "x86_64" PARENT_SCOPE)
12-
elseif ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "AArch64|aarch64|arm64|ARM64")
13-
if(APPLE)
14-
set("${result_var_name}" "arm64" PARENT_SCOPE)
15-
else()
16-
set("${result_var_name}" "aarch64" PARENT_SCOPE)
17-
endif()
18-
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64")
19-
set("${result_var_name}" "powerpc64" PARENT_SCOPE)
20-
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64le")
21-
set("${result_var_name}" "powerpc64le" PARENT_SCOPE)
22-
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "s390x")
23-
set("${result_var_name}" "s390x" PARENT_SCOPE)
24-
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv6l")
25-
set("${result_var_name}" "armv6" PARENT_SCOPE)
26-
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a")
27-
set("${result_var_name}" "armv7" PARENT_SCOPE)
28-
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l")
29-
set("${result_var_name}" "armv7" PARENT_SCOPE)
30-
elseif("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "amd64|AMD64")
31-
if(WIN32)
32-
set("${result_var_name}" "x86_64" PARENT_SCOPE)
33-
else()
34-
set("${result_var_name}" "amd64" PARENT_SCOPE)
35-
endif()
36-
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "IA64")
37-
set("${result_var_name}" "itanium" PARENT_SCOPE)
38-
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86")
39-
set("${result_var_name}" "i686" PARENT_SCOPE)
40-
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
41-
set("${result_var_name}" "i686" PARENT_SCOPE)
42-
else()
43-
message(FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR}")
3+
if(NOT dispatch_MODULE_TRIPLE)
4+
set(module_triple_command "${CMAKE_Swift_COMPILER}" -print-target-info)
5+
if(CMAKE_Swift_COMPILER_TARGET)
6+
list(APPEND module_triple_command -target ${CMAKE_Swift_COMPILER_TARGET})
447
endif()
8+
execute_process(COMMAND ${module_triple_command} OUTPUT_VARIABLE target_info_json)
9+
10+
string(JSON module_triple GET "${target_info_json}" "target" "moduleTriple")
11+
set(dispatch_MODULE_TRIPLE "${module_triple}" CACHE STRING "Triple used to install swiftmodule files")
12+
mark_as_advanced(dispatch_MODULE_TRIPLE)
13+
14+
message(CONFIGURE_LOG "Swift module triple: ${module_triple}")
15+
endif()
16+
17+
function(install_swift_module target)
18+
get_target_property(module ${target} Swift_MODULE_NAME)
19+
if(NOT module)
20+
set(module ${target})
21+
endif()
22+
install(
23+
FILES $<TARGET_PROPERTY:${target},Swift_MODULE_DIRECTORY>/${module}.swiftdoc
24+
DESTINATION ${INSTALL_TARGET_DIR}/${module}.swiftmodule
25+
RENAME ${dispatch_MODULE_TRIPLE}.swiftdoc)
26+
install(
27+
FILES $<TARGET_PROPERTY:${target},Swift_MODULE_DIRECTORY>/${module}.swiftmodule
28+
DESTINATION ${INSTALL_TARGET_DIR}/${module}.swiftmodule
29+
RENAME ${dispatch_MODULE_TRIPLE}.swiftmodule)
4530
endfunction()

src/swift/CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include(SwiftSupport)
2+
13
if(HAVE_OBJC)
24
add_library(DispatchStubs STATIC
35
DispatchStubs.m)
@@ -36,11 +38,7 @@ if(NOT APPLE AND NOT WIN32)
3638
set_target_properties(swiftDispatch PROPERTIES INSTALL_RPATH "$ORIGIN")
3739
endif()
3840

39-
get_swift_host_arch(swift_arch)
40-
install(FILES
41-
${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftmodule
42-
${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftdoc
43-
DESTINATION ${INSTALL_TARGET_DIR}/${swift_arch})
41+
install_swift_module(swiftDispatch)
4442
set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS swiftDispatch)
4543
install(TARGETS swiftDispatch
4644
EXPORT dispatchExports

0 commit comments

Comments
 (0)