Skip to content

Commit 5065545

Browse files
committed
build: restructure the install location handling
Adopt the latest best practices for handling module installation. Introduce the new `XCTest_INSTALL_NESTED_SUBDIR` option to allow installation into platform/architecture subdirectory allowing multi-architecture installations for platforms like Windows and Android. This is currently opt-in and requires a newer toolchain (something within the last ~2w) to detect the defaults. The values can be overridden by the user if desired.
1 parent d7e4406 commit 5065545

File tree

2 files changed

+57
-9
lines changed

2 files changed

+57
-9
lines changed

CMakeLists.txt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ endif()
2424
include(SwiftSupport)
2525
include(GNUInstallDirs)
2626
include(CheckLinkerFlag)
27+
include(PlatformInfo)
2728

28-
if(CMAKE_SYSTEM_NAME STREQUAL Linux
29-
OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD
30-
OR CMAKE_SYSTEM_NAME STREQUAL OpenBSD)
29+
option(XCTest_INSTALL_NESTED_SUBDIR "Install libraries under a platform and architecture subdirectory" NO)
30+
set(XCTest_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>$<$<BOOL:${XCTest_INSTALL_NESTED_SUBDIR}>:/${XCTest_PLATFORM_SUBDIR}/${XCTest_ARCH_SUBDIR}>")
31+
set(XCTest_INSTALL_SWIFTMODULEDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>$<$<BOOL:${XCTest_INSTALL_NESTED_SUBDIR}>:/${XCTest_PLATFORM_SUBDIR}>")
32+
33+
if(UNIX)
3134
enable_language(C)
3235
check_linker_flag(C "LINKER:--build-id=sha1" LINKER_SUPPORTS_BUILD_ID)
3336
endif()
@@ -142,14 +145,18 @@ endif()
142145

143146

144147
set_property(GLOBAL APPEND PROPERTY XCTest_EXPORTS XCTest)
148+
149+
145150
get_swift_host_arch(swift_arch)
146151
install(TARGETS XCTest
147-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>
148-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>
152+
ARCHIVE DESTINATION ${XCTest_INSTALL_LIBDIR}
153+
LIBRARY DESTINATION ${XCTest_INSTALL_LIBDIR}
149154
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
150-
install(FILES
151-
${CMAKE_CURRENT_BINARY_DIR}/swift/XCTest.swiftdoc
152-
${CMAKE_CURRENT_BINARY_DIR}/swift/XCTest.swiftmodule
153-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>/${swift_arch})
155+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/swift/XCTest.swiftdoc
156+
DESTINATION ${XCTest_INSTALL_SWIFTMODULEDIR}/XCTest.swiftmodule
157+
RENAME ${XCTest_MODULE_TRIPLE}.swiftdoc)
158+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/swift/XCTest.swiftmodule
159+
DESTINATION ${XCTest_INSTALL_SWIFTMODULEDIR}/XCTest.swiftmodule
160+
RENAME ${XCTest_MODULE_TRIPLE}.swiftmodule)
154161

155162
add_subdirectory(cmake/modules)

cmake/modules/PlatformInfo.cmake

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
set(pti_command "${CMAKE_Swift_COMPILER}" -print-target-info)
3+
if(CMAKE_Swift_COMPILER_TARGET)
4+
list(APPEND pti_command -target ${CMAKE_Swift_COMPILER_TARGET})
5+
endif()
6+
execute_process(COMMAND ${pti_command} OUTPUT_VARIABLE target_info_json)
7+
message(CONFIGURE_LOG "Swift Target Info: ${pti_command}\n"
8+
"${target_info_json}")
9+
10+
if(NOT XCTest_MODULE_TRIPLE)
11+
string(JSON module_triple GET "${target_info_json}" "target" "moduleTriple")
12+
set(XCTest_MODULE_TRIPLE "${module_triple}" CACHE STRING "Triple used for installed swift{doc,module,interface} files")
13+
mark_as_advanced(XCTest_MODULE_TRIPLE)
14+
15+
message(CONFIGURE_LOG "Swift Module Triple: ${module_triple}")
16+
endif()
17+
18+
if(NOT XCTest_PLATFORM_SUBDIR)
19+
string(JSON platform GET "${target_info_json}" "target" "platform")
20+
if(NOT platform)
21+
if(NOT SWIFT_SYSTEM_NAME)
22+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
23+
set(platform macosx)
24+
else()
25+
set(platform $<LOWER_CASE:${CMAKE_SYSTEM_NAME}>)
26+
endif()
27+
endif()
28+
endif()
29+
set(XCTest_PLATFORM_SUBDIR "${platform}" CACHE STRING "Platform name used for installed swift{doc,module,interface} files")
30+
mark_as_advanced(XCTest_PLATFORM_SUBDIR)
31+
32+
message(CONFIGURE_LOG "Swift Platform: ${platform}")
33+
endif()
34+
35+
if(NOT XCTest_ARCH_SUBDIR)
36+
string(JSON arch GET "${target_info_json}" "target" "arch")
37+
set(XCTest_ARCH_SUBDIR "${arch}" CACHE STRING "Architecture used for setting the architecture subdirectory")
38+
mark_as_advanced(XCTest_ARCH_SUBDIR)
39+
40+
message(CONFIGURE_LOG "Swift Architecture: ${arch}")
41+
endif()

0 commit comments

Comments
 (0)