Skip to content

Commit a6f0512

Browse files
authored
Merge pull request #889 from Steelskin/fabrice/package-swift-libs-arch-folder
build: Install libraries in an `arch` sub-folder
2 parents 4c271c4 + 0fcef7d commit a6f0512

File tree

3 files changed

+44
-14
lines changed

3 files changed

+44
-14
lines changed

CMakeLists.txt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,10 @@ add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:HAVE_CONFIG_H>)
307307

308308

309309
if(ENABLE_SWIFT)
310-
if(NOT SWIFT_SYSTEM_NAME)
311-
if(APPLE)
312-
set(SWIFT_SYSTEM_NAME macosx)
313-
else()
314-
set(SWIFT_SYSTEM_NAME "$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")
315-
endif()
316-
endif()
310+
include(SwiftSupport)
311+
option(dispatch_INSTALL_ARCH_SUBDIR "Install libraries under an architecture subdirectory" NO)
317312

318-
set(INSTALL_TARGET_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${SWIFT_SYSTEM_NAME}" CACHE PATH "Path where the libraries will be installed")
313+
set(INSTALL_TARGET_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${dispatch_PLATFORM}$<$<BOOL:${dispatch_INSTALL_ARCH_SUBDIR}>:/${dispatch_ARCH}>" CACHE PATH "Path where the libraries will be installed")
319314
set(INSTALL_DISPATCH_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/dispatch" CACHE PATH "Path where the headers will be installed for libdispatch")
320315
set(INSTALL_BLOCK_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/Block" CACHE PATH "Path where the headers will be installed for the blocks runtime")
321316
set(INSTALL_OS_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/os" CACHE PATH "Path where the os/ headers will be installed")

cmake/modules/SwiftSupport.cmake

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,67 @@
11
include_guard()
22

3-
if(NOT dispatch_MODULE_TRIPLE)
3+
if(NOT dispatch_MODULE_TRIPLE OR NOT dispatch_ARCH OR NOT dispatch_PLATFORM)
4+
# Get the target information from the Swift compiler.
45
set(module_triple_command "${CMAKE_Swift_COMPILER}" -print-target-info)
56
if(CMAKE_Swift_COMPILER_TARGET)
67
list(APPEND module_triple_command -target ${CMAKE_Swift_COMPILER_TARGET})
78
endif()
89
execute_process(COMMAND ${module_triple_command} OUTPUT_VARIABLE target_info_json)
10+
endif()
911

12+
if(NOT dispatch_MODULE_TRIPLE)
1013
string(JSON module_triple GET "${target_info_json}" "target" "moduleTriple")
1114
set(dispatch_MODULE_TRIPLE "${module_triple}" CACHE STRING "Triple used to install swiftmodule files")
1215
mark_as_advanced(dispatch_MODULE_TRIPLE)
13-
1416
message(CONFIGURE_LOG "Swift module triple: ${module_triple}")
1517
endif()
1618

19+
if(NOT dispatch_ARCH)
20+
if(CMAKE_Swift_COMPILER_VERSION VERSION_EQUAL 0.0.0 OR CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 6.2)
21+
# For newer compilers, we can use the -print-target-info command to get the architecture.
22+
string(JSON module_arch GET "${target_info_json}" "target" "arch")
23+
else()
24+
# For older compilers, extract the value from `dispatch_MODULE_TRIPLE`.
25+
string(REGEX MATCH "^[^-]+" module_arch "${dispatch_MODULE_TRIPLE}")
26+
endif()
27+
28+
set(dispatch_ARCH "${module_arch}" CACHE STRING "Arch folder name used to install libraries")
29+
mark_as_advanced(dispatch_ARCH)
30+
message(CONFIGURE_LOG "Swift arch: ${dispatch_ARCH}")
31+
endif()
32+
33+
if(NOT dispatch_PLATFORM)
34+
if(CMAKE_Swift_COMPILER_VERSION VERSION_EQUAL 0.0.0 OR CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 6.2)
35+
# For newer compilers, we can use the -print-target-info command to get the platform.
36+
string(JSON swift_platform GET "${target_info_json}" "target" "platform")
37+
else()
38+
# For older compilers, compile the value from `CMAKE_SYSTEM_NAME`.
39+
if(APPLE)
40+
set(swift_platform macosx)
41+
else()
42+
set(swift_platform "$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")
43+
endif()
44+
endif()
45+
46+
set(dispatch_PLATFORM "${swift_platform}" CACHE STRING "Platform folder name used to install libraries")
47+
mark_as_advanced(dispatch_PLATFORM)
48+
message(CONFIGURE_LOG "Swift platform: ${dispatch_PLATFORM}")
49+
endif()
50+
1751
function(install_swift_module target)
1852
get_target_property(module ${target} Swift_MODULE_NAME)
1953
if(NOT module)
2054
set(module ${target})
2155
endif()
56+
57+
set(INSTALL_SWIFT_MODULE_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${dispatch_PLATFORM}" CACHE PATH "Path where the swift modules will be installed")
58+
2259
install(
2360
FILES $<TARGET_PROPERTY:${target},Swift_MODULE_DIRECTORY>/${module}.swiftdoc
24-
DESTINATION ${INSTALL_TARGET_DIR}/${module}.swiftmodule
61+
DESTINATION ${INSTALL_SWIFT_MODULE_DIR}/${module}.swiftmodule
2562
RENAME ${dispatch_MODULE_TRIPLE}.swiftdoc)
2663
install(
2764
FILES $<TARGET_PROPERTY:${target},Swift_MODULE_DIRECTORY>/${module}.swiftmodule
28-
DESTINATION ${INSTALL_TARGET_DIR}/${module}.swiftmodule
65+
DESTINATION ${INSTALL_SWIFT_MODULE_DIR}/${module}.swiftmodule
2966
RENAME ${dispatch_MODULE_TRIPLE}.swiftmodule)
3067
endfunction()

src/swift/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
include(SwiftSupport)
2-
31
if(HAVE_OBJC)
42
add_library(DispatchStubs STATIC
53
DispatchStubs.m)

0 commit comments

Comments
 (0)