Skip to content

Commit 316e950

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 316e950

File tree

3 files changed

+57
-55
lines changed

3 files changed

+57
-55
lines changed

CMakeLists.txt

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin AND NOT DISABLE_XCTWAITER)
2121
find_package(Foundation CONFIG REQUIRED)
2222
endif()
2323

24-
include(SwiftSupport)
2524
include(GNUInstallDirs)
2625
include(CheckLinkerFlag)
26+
include(PlatformInfo)
2727

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

143145

144146
set_property(GLOBAL APPEND PROPERTY XCTest_EXPORTS XCTest)
145-
get_swift_host_arch(swift_arch)
147+
148+
146149
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}>
150+
ARCHIVE DESTINATION ${XCTest_INSTALL_LIBDIR}
151+
LIBRARY DESTINATION ${XCTest_INSTALL_LIBDIR}
149152
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})
153+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/swift/XCTest.swiftdoc
154+
DESTINATION ${XCTest_INSTALL_SWIFTMODULEDIR}/XCTest.swiftmodule
155+
RENAME ${XCTest_MODULE_TRIPLE}.swiftdoc)
156+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/swift/XCTest.swiftmodule
157+
DESTINATION ${XCTest_INSTALL_SWIFTMODULEDIR}/XCTest.swiftmodule
158+
RENAME ${XCTest_MODULE_TRIPLE}.swiftmodule)
154159

155160
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(print_target_info_invocation "${CMAKE_Swift_COMPILER}" -print-target-info)
3+
if(CMAKE_Swift_COMPILER_TARGET)
4+
list(APPEND print_target_info_invocation -target ${CMAKE_Swift_COMPILER_TARGET})
5+
endif()
6+
execute_process(COMMAND ${print_target_info_invocation} OUTPUT_VARIABLE target_info_json)
7+
message(CONFIGURE_LOG "Swift Target Info: ${print_target_info_invocation}\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()

cmake/modules/SwiftSupport.cmake

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)