Skip to content

Commit 8258eb5

Browse files
authored
Merge pull request #376 from swiftlang/cmake-exports
Export CMake targets for use by SwiftPM
2 parents e97614b + adcc695 commit 8258eb5

File tree

32 files changed

+340
-63
lines changed

32 files changed

+340
-63
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)

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ let package = Package(
135135
swiftSettings: swiftSettings(languageMode: .v5)),
136136
.target(
137137
name: "SWBCSupport",
138+
exclude: ["empty.swift"],
138139
publicHeadersPath: ".",
139140
cSettings: [
140141
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows])),

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/CLibRemarksHelper.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515

1616
#include <stdbool.h>
1717

18+
#include "CSupportDefines.h"
19+
1820
// Swift has no way of checking if a weak_import symbol is available.
1921
// This function checks if LLVMRemarkVersion from libRemarks.dylib is available, which should be enough to assert the whole library is available as well.
20-
bool isLibRemarksAvailable(void);
22+
CSUPPORT_EXPORT bool isLibRemarksAvailable(void);
2123

2224
#endif /* CLibRemarksHelper_h */

0 commit comments

Comments
 (0)