Skip to content

Commit b12629b

Browse files
committed
Export CMake targets for use by SwiftPM
1 parent 7319148 commit b12629b

File tree

27 files changed

+247
-12
lines changed

27 files changed

+247
-12
lines changed

CMakeLists.txt

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ cmake_minimum_required(VERSION 3.26...3.29)
1212
project(SwiftBuild
1313
LANGUAGES C CXX Swift)
1414

15+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
16+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
17+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
18+
19+
set(CMAKE_INSTALL_RPATH "$<IF:$<PLATFORM_ID:Darwin>,@loader_path/..,$ORIGIN>")
20+
set(CMAKE_INSTALL_REMOVE_ENVIRONMENT_RPATH YES)
21+
22+
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
23+
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
24+
25+
option(BUILD_SHARED_LIBS "Build shared libraries by default" YES)
26+
1527
set(CMAKE_C_VISIBILITY hidden)
1628
set(CMAKE_CXX_VISIBILITY hidden)
1729
set(CMAKE_CXX_STANDARD 17)
@@ -35,7 +47,33 @@ add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-package-name SwiftBuild>
3547
# rdar://137809703
3648
# "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-upcoming-feature RegionBasedIsolation>"
3749
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-upcoming-feature ExistentialAny>"
38-
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-upcoming-feature InternalImportsByDefault>")
50+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-upcoming-feature InternalImportsByDefault>"
51+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-no-toolchain-stdlib-rpath>"
52+
# Turn off autolinking within this project to reduce linker overhead.
53+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBLibc>"
54+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBAndroidPlatform>"
55+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBApplePlatform>"
56+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBBuildService>"
57+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBCLibc>"
58+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBGenericUnixPlatform>"
59+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBTaskConstruction>"
60+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBUtil>"
61+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBUniversalPlatform>"
62+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBWindowsPlatform>"
63+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SwiftBuild>"
64+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBWebAssemblyPlatform>"
65+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBCSupport>"
66+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBMacro>"
67+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBProjectModel>"
68+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBTaskExecution>"
69+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBServiceCore>"
70+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBQNXPlatform>"
71+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBProtocol>"
72+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBLLBuild>"
73+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBCore>"
74+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBCAS>"
75+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBBuildSystem>"
76+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBCore>")
3977

4078
# Prefer the static initialization for the plugins.
4179
add_compile_definitions(USE_STATIC_PLUGIN_INITIALIZATION)
@@ -50,3 +88,4 @@ find_package(Threads)
5088
find_package(SQLite3)
5189

5290
add_subdirectory(Sources)
91+
add_subdirectory(cmake/modules)

Sources/SWBAndroidPlatform/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ file(CONFIGURE
2828
]]
2929
ESCAPE_QUOTES @ONLY NEWLINE_STYLE LF)
3030

31-
add_library(SWBAndroidPlatform STATIC
31+
add_library(SWBAndroidPlatform
3232
AndroidSDK.swift
3333
Plugin.swift)
3434
target_link_libraries(SWBAndroidPlatform PUBLIC
@@ -37,3 +37,11 @@ target_link_libraries(SWBAndroidPlatform PUBLIC
3737
SWBUtil)
3838
target_sources(SWBAndroidPlatform PRIVATE
3939
"${CMAKE_CURRENT_BINARY_DIR}/resource_bundle_accessor.swift")
40+
41+
set_target_properties(SWBAndroidPlatform PROPERTIES
42+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
43+
44+
set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBAndroidPlatform)
45+
46+
install(TARGETS SWBAndroidPlatform
47+
ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}")

Sources/SWBApplePlatform/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ file(CONFIGURE
2828
]]
2929
ESCAPE_QUOTES @ONLY NEWLINE_STYLE LF)
3030

31-
add_library(SWBApplePlatform STATIC
31+
add_library(SWBApplePlatform
3232
AppIntentsMetadataCompiler.swift
3333
AppIntentsMetadataTaskProducer.swift
3434
AppIntentsSSUTrainingCompiler.swift
@@ -75,3 +75,11 @@ target_link_libraries(SWBApplePlatform PUBLIC
7575
SWBTaskConstruction)
7676
target_sources(SWBApplePlatform PRIVATE
7777
"${CMAKE_CURRENT_BINARY_DIR}/resource_bundle_accessor.swift")
78+
79+
set_target_properties(SWBApplePlatform PROPERTIES
80+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
81+
82+
set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBApplePlatform)
83+
84+
install(TARGETS SWBApplePlatform
85+
ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}")

Sources/SWBBuildService/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,11 @@ target_link_libraries(SWBBuildService PUBLIC
3737
SWBWebAssemblyPlatform
3838
SWBWindowsPlatform
3939
$<$<NOT:$<PLATFORM_ID:Darwin>>:SwiftSystem::SystemPackage>)
40+
41+
set_target_properties(SWBBuildService PROPERTIES
42+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
43+
44+
set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBBuildService)
45+
46+
install(TARGETS SWBBuildService
47+
ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}")

Sources/SWBBuildServiceBundle/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ target_link_libraries(SWBBuildServiceBundle PRIVATE
2020
SWBCore)
2121

2222
install(TARGETS SWBBuildServiceBundle)
23+
24+
set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBBuildServiceBundle)

Sources/SWBBuildSystem/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,11 @@ target_link_libraries(SWBBuildSystem PUBLIC
2222
SWBCore
2323
SWBTaskConstruction
2424
SWBTaskExecution)
25+
26+
set_target_properties(SWBBuildSystem PROPERTIES
27+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
28+
29+
set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBBuildSystem)
30+
31+
install(TARGETS SWBBuildSystem
32+
ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}")

Sources/SWBCAS/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ set_target_properties(SWBCAS PROPERTIES
1919
target_link_libraries(SWBCAS PUBLIC
2020
SWBUtil
2121
SWBCSupport)
22+
23+
set_target_properties(SWBCAS PROPERTIES
24+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
25+
26+
set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBCAS)
27+
28+
install(TARGETS SWBCAS
29+
ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}")

Sources/SWBCLibc/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,11 @@ add_library(SWBCLibc
1212
libc.c)
1313
target_include_directories(SWBCLibc INTERFACE
1414
include)
15+
16+
target_include_directories(SWBCLibc PUBLIC
17+
${CMAKE_CURRENT_BINARY_DIR})
18+
19+
set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBCLibc)
20+
21+
install(TARGETS SWBCLibc
22+
ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}")

Sources/SWBCSupport/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,26 @@ See http://swift.org/LICENSE.txt for license information
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
]]
1010

11-
add_library(SWBCSupport STATIC
11+
add_library(SWBCSupport
1212
CLibclang.cpp
1313
CLibRemarksHelper.c)
1414
target_compile_definitions(SWBCSupport PRIVATE
1515
$<$<PLATFORM_ID:Windows>:_CRT_SECURE_NO_WARNINGS>
1616
$<$<PLATFORM_ID:Windows>:_CRT_NONSTDC_NO_WARNINGS>)
1717
target_compile_options(SWBCSupport PRIVATE
1818
-fblocks)
19+
target_link_options(SWBCSupport PUBLIC
20+
$<$<PLATFORM_ID:Darwin>:-lc++>)
1921
target_include_directories(SWBCSupport PUBLIC
2022
${CMAKE_CURRENT_SOURCE_DIR})
2123
# TODO(compnerd) wire this up with `find_package`
2224
target_link_libraries(SWBCSupport PRIVATE
2325
$<$<NOT:$<PLATFORM_ID:Darwin>>:BlocksRuntime>)
26+
27+
target_include_directories(SWBCSupport PUBLIC
28+
${CMAKE_CURRENT_BINARY_DIR})
29+
30+
set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBCSupport)
31+
32+
install(TARGETS SWBCSupport
33+
ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}")

Sources/SWBCore/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,11 @@ target_link_libraries(SWBCore PUBLIC
207207
SwiftDriver)
208208
target_sources(SWBCore PRIVATE
209209
"${CMAKE_CURRENT_BINARY_DIR}/resource_bundle_accessor.swift")
210+
211+
set_target_properties(SWBCore PROPERTIES
212+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
213+
214+
set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBCore)
215+
216+
install(TARGETS SWBCore
217+
ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}")

0 commit comments

Comments
 (0)