Skip to content

Commit 7870db6

Browse files
committed
CMake: Runtime Installation Story
Starting to work on a full installation story for the Swift runtimes. This involves generating the SwiftCoreConfig cmake files to allow importing the just-built runtimes into the overlays and supplemental libraries, setting up the flags appropriately for the given SwiftCore build configuration. This also separates out the development and runtime components to allow installing just the runtimes without the headers. Component List: - SwiftCore_runtime The runtime libraries that are required for running code. - SwiftCore_development The interface with the runtime libraries that are required for building code against the runtimes. - SwiftCore_cmake Files for interfacing CMake projects with the built runtimes. This includes the target list and flags needed to use the targets built by the specific configuration used to build the runtime libraries. These files are used for mapping flags, definitions, and locations into the overlay libraries and supplemental libraries. This adds install commands for the object libraries contributing to libswiftCore so that they are represented in SwiftCoreTargets.cmake. Object libraries do not contribute anything to the files actually installed.
1 parent 7484f01 commit 7870db6

File tree

13 files changed

+95
-20
lines changed

13 files changed

+95
-20
lines changed

Runtimes/Core/CMakeLists.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ add_compile_definitions(
143143
$<$<BOOL:${SwiftCore_ENABLE_OBJC_INTEROP}>:-DSWIFT_OBJC_INTEROP>
144144
$<$<BOOL:${SwiftCore_ENABLE_LIBRARY_EVOLUTION}>:-DSWIFT_LIBRARY_EVOLUTION>
145145
$<$<BOOL:${SwiftCore_ENABLE_CRASH_REPORTER_CLIENT}>:-DSWIFT_HAVE_CRASHREPORTERCLIENT>
146-
$<$<BOOL:${SwiftCore_ENABLE_VECTOR_TYPES}>:-DSWIFT_STDLIB_ENABLE_VECTOR_TYPES>
147146
$<$<BOOL:${SwiftCore_ENABLE_REFLECTION}>:-DSWIFT_ENABLE_REFLECTION>
148147
$<$<BOOL:${SwiftCore_ENABLE_RUNTIME_FUNCTION_COUNTERS}>:-DSWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS>
149148
$<$<BOOL:${SwiftCore_ENABLE_STDIN}>:-DSWIFT_STDLIB_HAS_STDIN> # core + stubs
@@ -225,3 +224,22 @@ endif()
225224
if(SwiftCore_ENABLE_CONCURRENCY)
226225
add_subdirectory(Concurrency)
227226
endif()
227+
228+
# Inter-project install info
229+
export(EXPORT SwiftCoreTargets
230+
FILE "cmake/SwiftCore/SwiftCoreTargets.cmake")
231+
install(EXPORT SwiftCoreTargets
232+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/SwiftCore"
233+
FILE "SwiftCoreTargets.cmake"
234+
COMPONENT SwiftCore_cmake)
235+
include(CMakePackageConfigHelpers)
236+
configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/interface/SwiftCoreConfig.cmake.in"
237+
"${CMAKE_CURRENT_BINARY_DIR}/cmake/SwiftCoreConfig.cmake"
238+
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/SwiftCore")
239+
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/cmake/SwiftCoreConfigVersion.cmake"
240+
VERSION "${PROJECT_VERSION}"
241+
COMPATIBILITY ExactVersion)
242+
install(FILES
243+
"${CMAKE_CURRENT_BINARY_DIR}/cmake/SwiftCoreConfig.cmake"
244+
"${CMAKE_CURRENT_BINARY_DIR}/cmake/SwiftCoreConfigVersion.cmake"
245+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/SwiftCore")

Runtimes/Core/CommandLineSupport/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ if(SwiftCore_ENABLE_COMMANDLINE_SUPPORT)
1010
swiftShims)
1111

1212
if(NOT BUILD_SHARED_LIBS)
13-
install(TARGETS swiftCommandLineSupport)
13+
install(TARGETS swiftCommandLineSupport
14+
EXPORT SwiftCoreTargets
15+
COMPONENT SwiftCore_runtime)
1416
endif()
1517
endif()

Runtimes/Core/Concurrency/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ set_target_properties(swift_Concurrency PROPERTIES
118118
Swift_MODULE_NAME _Concurrency)
119119

120120
install(TARGETS swift_Concurrency
121+
EXPORT SwiftCoreTargets
122+
COMPONENT SwiftCore_runtime
121123
ARCHIVE DESTINATION "${SwiftCore_INSTALL_LIBDIR}"
122124
LIBRARY DESTINATION "${SwiftCore_INSTALL_LIBDIR}"
123125
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")

Runtimes/Core/Demangling/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,7 @@ if(LINUX OR BSD)
4848
endif()
4949

5050
if(NOT BUILD_SHARED_LIBS)
51-
install(TARGETS swiftDemangling)
51+
install(TARGETS swiftDemangling
52+
EXPORT SwiftCoreTargets
53+
COMPONENT SwiftCore_runtime)
5254
endif()

Runtimes/Core/LLVMSupport/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ add_library(swiftLLVMSupport OBJECT
88
target_compile_options(swiftLLVMSupport
99
PRIVATE
1010
$<$<BOOL:${SwiftCore_HAS_ASL}>:-DSWIFT_STDLIB_HAS_ASL>)
11+
12+
if(NOT BUILD_SHARED_LIBS)
13+
install(TARGETS swiftLLVMSupport
14+
EXPORT SwiftCoreTargets
15+
COMPONENT SwiftCore_runtime)
16+
endif()

Runtimes/Core/SwiftOnoneSupport/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ target_link_libraries(swiftSwiftOnoneSupport
3232
swiftCore)
3333

3434
install(TARGETS swiftSwiftOnoneSupport
35+
EXPORT SwiftCoreTargets
36+
COMPONENT SwiftCore_runtime
3537
ARCHIVE DESTINATION "${SwiftCore_INSTALL_LIBDIR}"
3638
LIBRARY DESTINATION "${SwiftCore_INSTALL_LIBDIR}"
3739
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")

Runtimes/Core/SwiftShims/swift/shims/CMakeLists.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,19 @@ install(FILES
2828
_SwiftDistributed.h
2929
_SynchronizationShims.h
3030
module.modulemap
31-
DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift/shims")
31+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift/shims"
32+
COMPONENT SwiftCore_development)
3233

3334
add_library(swiftShims INTERFACE)
3435
target_include_directories(swiftShims INTERFACE
35-
$<$<COMPILE_LANGUAGE:C,CXX>:${CMAKE_CURRENT_SOURCE_DIR}/../../>
36-
$<$<COMPILE_LANGUAGE:Swift>:${CMAKE_CURRENT_SOURCE_DIR}>)
36+
$<$<COMPILE_LANGUAGE:C,CXX>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../>$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_LIBDIR}>>
37+
$<$<COMPILE_LANGUAGE:Swift>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_LIBDIR}/swift/shims>>)
3738
target_compile_definitions(swiftShims INTERFACE
3839
$<$<AND:$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>,$<COMPILE_LANGUAGE:C,CXX>>:SWIFT_STATIC_STDLIB>)
3940
target_compile_options(swiftShims INTERFACE
4041
"$<$<AND:$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>,$<COMPILE_LANGUAGE:Swift>>:SHELL:-Xcc -DSWIFT_STATIC_STDLIB>"
41-
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -fmodule-map-file=${CMAKE_CURRENT_SOURCE_DIR}/module.modulemap>")
42+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -fmodule-map-file=$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/module.modulemap>$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_LIBDIR}/swift/shims/module.modulemap>>")
43+
44+
install(TARGETS swiftShims
45+
EXPORT SwiftCoreTargets
46+
COMPONENT SwiftCore_development)

Runtimes/Core/Threading/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ target_link_libraries(swiftThreading PRIVATE swiftShims)
1313
# to avoid pulling in headers from the compiler.
1414
target_include_directories(swiftThreading PRIVATE
1515
"${SwiftCore_SWIFTC_SOURCE_DIR}/include")
16+
17+
if(NOT BUILD_SHARED_LIBS)
18+
install(TARGETS swiftThreading
19+
EXPORT SwiftCoreTargets
20+
COMPONENT SwiftCore_runtime)
21+
endif()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@PACKAGE_INIT@
2+
include("${CMAKE_CURRENT_LIST_DIR}/SwiftCoreTargets.cmake")
3+
4+
set(SwiftCore_ENABLE_LIBRARY_EVOLUTION @SwiftCore_ENABLE_LIBRARY_EVOLUTION@)
5+
6+
set(SwiftCore_ENABLE_VECTOR_TYPES @SwiftCore_ENABLE_VECTOR_TYPES@)

Runtimes/Core/cmake/modules/EmitSwiftInterface.cmake

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,36 @@ function(install_swift_interface target)
3838
# Install binary swift modules
3939
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule"
4040
RENAME "${SwiftCore_MODULE_TRIPLE}.swiftmodule"
41-
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule")
41+
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule"
42+
COMPONENT SwiftCore_development)
4243
if(SwiftCore_VARIANT_MODULE_TRIPLE)
4344
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${target}-${SwiftCore_VARIANT_MODULE_TRIPLE}/${target}.swiftmodule"
4445
RENAME "${SwiftCore_VARIANT_MODULE_TRIPLE}.swiftmodule"
45-
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule")
46+
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule"
47+
COMPONENT SwiftCore_development)
4648
endif()
4749

4850
# Install Swift interfaces if library-evolution is enabled
4951
if(SwiftCore_ENABLE_LIBRARY_EVOLUTION)
5052
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftinterface"
5153
RENAME "${SwiftCore_MODULE_TRIPLE}.swiftinterface"
52-
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule")
53-
54+
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule"
55+
COMPONENT SwiftCore_development)
5456
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.private.swiftinterface"
5557
RENAME "${SwiftCore_MODULE_TRIPLE}.private.swiftinterface"
56-
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule")
58+
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule"
59+
COMPONENT SwiftCore_development)
5760

5861
# Install catalyst interface files
5962
if(SwiftCore_VARIANT_MODULE_TRIPLE)
6063
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${target}-${SwiftCore_VARIANT_MODULE_TRIPLE}/${target}.swiftinterface"
6164
RENAME "${SwiftCore_VARIANT_MODULE_TRIPLE}.swiftinterface"
62-
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule")
65+
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule"
66+
COMPONENT SwiftCore_development)
6367
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${target}-${SwiftCore_VARIANT_MODULE_TRIPLE}/${target}.private.swiftinterface"
6468
RENAME "${SwiftCore_VARIANT_MODULE_TRIPLE}.private.swiftinterface"
65-
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule")
69+
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule"
70+
COMPONENT SwiftCore_development)
6671
endif()
6772
endif()
6873
endfunction()

0 commit comments

Comments
 (0)