Skip to content

Commit b14866c

Browse files
committed
Configure CMake build to install content into toolchain
1 parent 1b7dba9 commit b14866c

File tree

6 files changed

+112
-2
lines changed

6 files changed

+112
-2
lines changed

CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ set(CMAKE_CXX_STANDARD 20)
2828
set(CMAKE_Swift_LANGUAGE_VERSION 6)
2929
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
3030

31+
if(NOT SWIFT_SYSTEM_NAME)
32+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
33+
set(SWIFT_SYSTEM_NAME macosx)
34+
else()
35+
set(SWIFT_SYSTEM_NAME "$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")
36+
endif()
37+
endif()
38+
3139
add_subdirectory(Sources)

Sources/CMakeLists.txt

+22-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ include(ExternalProject)
1111
if(NOT SwiftTesting_MACRO_MAKE_PROGRAM)
1212
set(SwiftTesting_MACRO_MAKE_PROGRAM ${CMAKE_MAKE_PROGRAM})
1313
endif()
14+
if(NOT SwiftTesting_MACRO_Swift_COMPILER)
15+
set(SwiftTesting_MACRO_Swift_COMPILER ${CMAKE_Swift_COMPILER})
16+
endif()
17+
if(NOT SwiftTesting_MACRO_AR)
18+
set(SwiftTesting_MACRO_AR ${CMAKE_AR})
19+
endif()
20+
if(NOT SwiftTesting_MACRO_RANLIB)
21+
set(SwiftTesting_MACRO_RANLIB ${CMAKE_RANLIB})
22+
endif()
1423

1524
find_package(SwiftSyntax CONFIG GLOBAL)
1625
if(SwiftSyntax_FOUND)
@@ -23,13 +32,25 @@ ExternalProject_Add(TestingMacros
2332
PREFIX "tm"
2433
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/TestingMacros"
2534
CMAKE_ARGS
35+
-DCMAKE_Swift_COMPILER=${SwiftTesting_MACRO_Swift_COMPILER}
36+
-DCMAKE_AR=${SwiftTesting_MACRO_AR}
37+
-DCMAKE_RANLIB=${SwiftTesting_MACRO_RANLIB}
2638
-DCMAKE_MAKE_PROGRAM=${SwiftTesting_MACRO_MAKE_PROGRAM}
2739
-DSwiftTesting_BuildMacrosAsExecutables=${SwiftTesting_BuildMacrosAsExecutables}
2840
-DSwiftSyntax_DIR=${SwiftSyntax_DIR}
29-
INSTALL_COMMAND "")
41+
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>)
3042
ExternalProject_Get_Property(TestingMacros BINARY_DIR)
43+
ExternalProject_Get_Property(TestingMacros INSTALL_DIR)
3144

3245
include(AvailabilityDefinitions)
3346
include(CompilerSettings)
3447
add_subdirectory(_TestingInternals)
3548
add_subdirectory(Testing)
49+
50+
if(SwiftTesting_BuildMacrosAsExecutables)
51+
install(PROGRAMS "${INSTALL_DIR}/lib/libTestingMacros.dylib"
52+
# TODO: Finalize the install path
53+
ARCHIVE DESTINATION lib/swift/host/plugins
54+
LIBRARY DESTINATION lib/swift/host/plugins
55+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
56+
endif()

Sources/Testing/CMakeLists.txt

+9-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ target_link_libraries(Testing PRIVATE
9797
add_dependencies(Testing
9898
TestingMacros)
9999
target_compile_options(Testing PRIVATE
100-
-enable-library-evolution)
100+
-enable-library-evolution
101+
-emit-module-interface -emit-module-interface-path $<TARGET_PROPERTY:Testing,Swift_MODULE_DIRECTORY>/Testing.swiftinterface)
101102

102103
if(SwiftTesting_BuildMacrosAsExecutables)
103104
if(CMAKE_HOST_WIN32)
@@ -110,3 +111,10 @@ else()
110111
target_compile_options(Testing PUBLIC
111112
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-plugin-path ${BINARY_DIR}>")
112113
endif()
114+
115+
# TODO: @rpath-relative install name
116+
# This may or may not involve the `-(no-)toolchain-stdlib-rpath` Swift flag.
117+
118+
include(SwiftModuleInstallation)
119+
# TODO: Finalize the install path
120+
_swift_testing_install_target(Testing)

Sources/TestingMacros/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ if(SwiftTesting_BuildMacrosAsExecutables)
5858
target_compile_definitions(TestingMacros PRIVATE SWT_NO_LIBRARY_MACRO_PLUGINS)
5959
else()
6060
add_library(TestingMacros SHARED)
61+
62+
# Install the macro plugin to the default location.
63+
#
64+
# This is not the plugin's actual, final install location -- it's only
65+
# relative to this external project's install dir. The final location is
66+
# determined by the "outer" project.
67+
install(TARGETS TestingMacros DESTINATION "")
6168
endif()
6269

6370
target_sources(TestingMacros PRIVATE

Sources/_TestingInternals/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9+
set(CMAKE_CXX_SCAN_FOR_MODULES 0)
10+
911
include(LibraryVersion)
1012
add_library(_TestingInternals STATIC
1113
Discovery.cpp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2024 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+
# 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+
function(_swift_testing_install_target module)
22+
get_swift_host_os(swift_os)
23+
get_target_property(type ${module} TYPE)
24+
25+
if(type STREQUAL STATIC_LIBRARY)
26+
set(swift swift_static)
27+
else()
28+
set(swift swift)
29+
endif()
30+
31+
install(TARGETS ${module}
32+
ARCHIVE DESTINATION lib/${swift}/${swift_os}
33+
LIBRARY DESTINATION lib/${swift}/${swift_os}
34+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
35+
if(type STREQUAL EXECUTABLE)
36+
return()
37+
endif()
38+
39+
get_target_property(module_name ${module} Swift_MODULE_NAME)
40+
if(NOT module_name)
41+
set(module_name ${module})
42+
endif()
43+
44+
if(NOT SwiftTesting_MODULE_TRIPLE)
45+
set(module_triple_command "${CMAKE_Swift_COMPILER}" -print-target-info)
46+
if(CMAKE_Swift_COMPILER_TARGET)
47+
list(APPEND module_triple_command -target ${CMAKE_Swift_COMPILER_TARGET})
48+
endif()
49+
execute_process(COMMAND ${module_triple_command} OUTPUT_VARIABLE target_info_json)
50+
string(JSON module_triple GET "${target_info_json}" "target" "moduleTriple")
51+
set(SwiftTesting_MODULE_TRIPLE "${module_triple}" CACHE STRING "swift module triple used for installed swiftmodule and swiftinterface files")
52+
mark_as_advanced(SwiftTesting_MODULE_TRIPLE)
53+
endif()
54+
55+
install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftdoc
56+
DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule
57+
RENAME ${SwiftTesting_MODULE_TRIPLE}.swiftdoc)
58+
install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftmodule
59+
DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule
60+
RENAME ${SwiftTesting_MODULE_TRIPLE}.swiftmodule)
61+
install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftinterface
62+
DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule
63+
RENAME ${SwiftTesting_MODULE_TRIPLE}.swiftinterface)
64+
endfunction()

0 commit comments

Comments
 (0)