Skip to content

Commit 8c41943

Browse files
authored
Merge pull request #971 from compnerd/installation
build: restructure the installation location
2 parents 4dd5548 + 162e8e8 commit 8c41943

File tree

3 files changed

+65
-77
lines changed

3 files changed

+65
-77
lines changed

CMakeLists.txt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,21 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
3232
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
3333
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
3434

35+
set(CMAKE_INSTALL_RPATH $<IF:$<PLATFORM_ID:Darwin>,"@loader_path/..","$ORIGIN">)
36+
set(CMAKE_INSTALL_REMOVE_ENVIRONMENT_RPATH YES)
37+
3538
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
3639
set(CMAKE_CXX_STANDARD 20)
3740
set(CMAKE_Swift_LANGUAGE_VERSION 6)
3841
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
3942

40-
if(NOT SWIFT_SYSTEM_NAME)
41-
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
42-
set(SWIFT_SYSTEM_NAME macosx)
43-
else()
44-
set(SWIFT_SYSTEM_NAME "$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")
45-
endif()
46-
endif()
47-
43+
include(PlatformInfo)
4844
include(SwiftModuleInstallation)
45+
46+
option(SwiftTesting_INSTALL_NESTED_SUBDIR "Install libraries under a platform and architecture subdirectory" NO)
47+
set(SwiftTesting_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${SwiftTesting_PLATFORM_SUBDIR}$<$<AND:$<PLATFORM_ID:Darwin>,$<NOT:$<BOOL:${SwiftTesting_INSTALL_NESTED_SUBDIR}>>>:/testing>$<$<BOOL:${SwiftTesting_INSTALL_NESTED_SUBDIR}>:/${SwiftTesting_ARCH_SUBDIR}>")
48+
set(SwiftTesting_INSTALL_SWIFTMODULEDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${SwiftTesting_PLATFORM_SUBDIR}$<$<AND:$<PLATFORM_ID:Darwin>,$<NOT:$<BOOL:${SwiftTesting_INSTALL_NESTED_SUBDIR}>>>:/testing>$<$<BOOL:${SwiftTesting_INSTALL_NESTED_SUBDIR}>:/${SwiftTesting_PLATFORM_SUBDIR}>")
49+
50+
add_compile_options($<$<COMPILE_LANGUAGE:Swift>:-no-toolchain-stdlib-rpath>)
51+
4952
add_subdirectory(Sources)

cmake/modules/PlatformInfo.cmake

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2025 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
set(print_target_info_invocation "${CMAKE_Swift_COMPILER}" -print-target-info)
10+
if(CMAKE_Swift_COMPILER_TARGET)
11+
list(APPEND print_target_info_invocation -target ${CMAKE_Swift_COMPILER_TARGET})
12+
endif()
13+
execute_process(COMMAND ${print_target_info_invocation} OUTPUT_VARIABLE target_info_json)
14+
message(CONFIGURE_LOG "Swift Target Info: ${print_target_info_invocation}\n"
15+
"${target_info_json}")
16+
17+
if(NOT SwiftTesting_MODULE_TRIPLE)
18+
string(JSON module_triple GET "${target_info_json}" "target" "moduleTriple")
19+
set(SwiftTesting_MODULE_TRIPLE "${module_triple}" CACHE STRING "Triple used for installed swift{doc,module,interface} files")
20+
mark_as_advanced(SwiftTesting_MODULE_TRIPLE)
21+
22+
message(CONFIGURE_LOG "Swift Module Triple: ${module_triple}")
23+
endif()
24+
25+
if(NOT SwiftTesting_PLATFORM_SUBDIR)
26+
string(JSON platform GET "${target_info_json}" "target" "platform")
27+
if(NOT platform)
28+
if(NOT SWIFT_SYSTEM_NAME)
29+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
30+
set(platform macosx)
31+
else()
32+
set(platform $<LOWER_CASE:${CMAKE_SYSTEM_NAME}>)
33+
endif()
34+
endif()
35+
endif()
36+
set(SwiftTesting_PLATFORM_SUBDIR "${platform}" CACHE STRING "Platform name used for installed swift{doc,module,interface} files")
37+
mark_as_advanced(SwiftTesting_PLATFORM_SUBDIR)
38+
39+
message(CONFIGURE_LOG "Swift Platform: ${platform}")
40+
endif()
41+
42+
if(NOT SwiftTesting_ARCH_SUBDIR)
43+
string(JSON arch GET "${target_info_json}" "target" "arch")
44+
set(SwiftTesting_ARCH_SUBDIR "${arch}" CACHE STRING "Architecture used for setting the architecture subdirectory")
45+
mark_as_advanced(SwiftTesting_ARCH_SUBDIR)
46+
47+
message(CONFIGURE_LOG "Swift Architecture: ${arch}")
48+
endif()

cmake/modules/SwiftModuleInstallation.cmake

Lines changed: 6 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -6,62 +6,13 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
# Returns the os name in a variable
10-
#
11-
# Usage:
12-
# get_swift_host_os(result_var_name)
13-
#
14-
#
15-
# Sets ${result_var_name} with the converted OS name derived from
16-
# CMAKE_SYSTEM_NAME.
17-
function(get_swift_host_os result_var_name)
18-
set(${result_var_name} ${SWIFT_SYSTEM_NAME} PARENT_SCOPE)
19-
endfunction()
20-
21-
# Returns the path to the Swift Testing library installation directory
22-
#
23-
# Usage:
24-
# get_swift_testing_install_lib_dir(type result_var_name)
25-
#
26-
# Arguments:
27-
# type: The type of the library (STATIC_LIBRARY, SHARED_LIBRARY, or EXECUTABLE).
28-
# Typically, the value of the TYPE target property.
29-
# result_var_name: The name of the variable to set
30-
function(get_swift_testing_install_lib_dir type result_var_name)
31-
get_swift_host_os(swift_os)
32-
if(type STREQUAL STATIC_LIBRARY)
33-
set(swift swift_static)
34-
else()
35-
set(swift swift)
36-
endif()
37-
38-
if(APPLE)
39-
set(${result_var_name} "lib/${swift}/${swift_os}/testing" PARENT_SCOPE)
40-
else()
41-
set(${result_var_name} "lib/${swift}/${swift_os}" PARENT_SCOPE)
42-
endif()
43-
endfunction()
44-
459
function(_swift_testing_install_target module)
46-
target_compile_options(${module} PRIVATE "-no-toolchain-stdlib-rpath")
47-
48-
if(APPLE)
49-
set_target_properties(${module} PROPERTIES
50-
INSTALL_RPATH "@loader_path/.."
51-
INSTALL_REMOVE_ENVIRONMENT_RPATH ON)
52-
else()
53-
set_target_properties(${module} PROPERTIES
54-
INSTALL_RPATH "$ORIGIN"
55-
INSTALL_REMOVE_ENVIRONMENT_RPATH ON)
56-
endif()
57-
58-
get_target_property(type ${module} TYPE)
59-
get_swift_testing_install_lib_dir(${type} lib_destination_dir)
60-
6110
install(TARGETS ${module}
62-
ARCHIVE DESTINATION "${lib_destination_dir}"
63-
LIBRARY DESTINATION "${lib_destination_dir}"
11+
ARCHIVE DESTINATION "${SwiftTesting_INSTALL_LIBDIR}"
12+
LIBRARY DESTINATION "${SwiftTesting_INSTALL_LIBDIR}"
6413
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
14+
15+
get_target_property(type ${module} TYPE)
6516
if(type STREQUAL EXECUTABLE)
6617
return()
6718
endif()
@@ -71,18 +22,7 @@ function(_swift_testing_install_target module)
7122
set(module_name ${module})
7223
endif()
7324

74-
if(NOT SwiftTesting_MODULE_TRIPLE)
75-
set(module_triple_command "${CMAKE_Swift_COMPILER}" -print-target-info)
76-
if(CMAKE_Swift_COMPILER_TARGET)
77-
list(APPEND module_triple_command -target ${CMAKE_Swift_COMPILER_TARGET})
78-
endif()
79-
execute_process(COMMAND ${module_triple_command} OUTPUT_VARIABLE target_info_json)
80-
string(JSON module_triple GET "${target_info_json}" "target" "moduleTriple")
81-
set(SwiftTesting_MODULE_TRIPLE "${module_triple}" CACHE STRING "swift module triple used for installed swiftmodule and swiftinterface files")
82-
mark_as_advanced(SwiftTesting_MODULE_TRIPLE)
83-
endif()
84-
85-
set(module_dir "${lib_destination_dir}/${module_name}.swiftmodule")
25+
set(module_dir ${SwiftTesting_INSTALL_SWIFTMODULEDIR}/${module_name}.swiftmodule)
8626
install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftdoc
8727
DESTINATION "${module_dir}"
8828
RENAME ${SwiftTesting_MODULE_TRIPLE}.swiftdoc)
@@ -104,9 +44,6 @@ endfunction()
10444
# swiftcrossimport_dir: The path to the source .swiftcrossimport directory
10545
# which will be installed.
10646
function(_swift_testing_install_swiftcrossimport module swiftcrossimport_dir)
107-
get_target_property(type ${module} TYPE)
108-
get_swift_testing_install_lib_dir(${type} lib_destination_dir)
109-
11047
install(DIRECTORY "${swiftcrossimport_dir}"
111-
DESTINATION "${lib_destination_dir}")
48+
DESTINATION "${SwiftTesting_INSTALL_SWIFTMODULEDIR}")
11249
endfunction()

0 commit comments

Comments
 (0)