Skip to content

Export CMake targets for use by SwiftPM #376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ cmake_minimum_required(VERSION 3.26...3.29)
project(SwiftBuild
LANGUAGES C CXX Swift)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

set(CMAKE_INSTALL_RPATH "$<IF:$<PLATFORM_ID:Darwin>,@loader_path/..,$ORIGIN>")
set(CMAKE_INSTALL_REMOVE_ENVIRONMENT_RPATH YES)

set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)

option(BUILD_SHARED_LIBS "Build shared libraries by default" YES)

set(CMAKE_C_VISIBILITY hidden)
set(CMAKE_CXX_VISIBILITY hidden)
set(CMAKE_CXX_STANDARD 17)
Expand All @@ -35,7 +47,33 @@ add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-package-name SwiftBuild>
# rdar://137809703
# "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-upcoming-feature RegionBasedIsolation>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-upcoming-feature ExistentialAny>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-upcoming-feature InternalImportsByDefault>")
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-upcoming-feature InternalImportsByDefault>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-no-toolchain-stdlib-rpath>"
# Turn off autolinking within this project to reduce linker overhead.
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBLibc>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBAndroidPlatform>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBApplePlatform>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBBuildService>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBCLibc>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBGenericUnixPlatform>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBTaskConstruction>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBUtil>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBUniversalPlatform>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBWindowsPlatform>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SwiftBuild>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBWebAssemblyPlatform>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBCSupport>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBMacro>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBProjectModel>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBTaskExecution>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBServiceCore>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBQNXPlatform>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBProtocol>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBLLBuild>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBCore>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBCAS>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBBuildSystem>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBCore>")

# Prefer the static initialization for the plugins.
add_compile_definitions(USE_STATIC_PLUGIN_INITIALIZATION)
Expand All @@ -50,3 +88,4 @@ find_package(Threads)
find_package(SQLite3)

add_subdirectory(Sources)
add_subdirectory(cmake/modules)
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ let package = Package(
swiftSettings: swiftSettings(languageMode: .v5)),
.target(
name: "SWBCSupport",
exclude: ["empty.swift"],
publicHeadersPath: ".",
cSettings: [
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows])),
Expand Down
10 changes: 9 additions & 1 deletion Sources/SWBAndroidPlatform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ file(CONFIGURE
]]
ESCAPE_QUOTES @ONLY NEWLINE_STYLE LF)

add_library(SWBAndroidPlatform STATIC
add_library(SWBAndroidPlatform
AndroidSDK.swift
Plugin.swift)
target_link_libraries(SWBAndroidPlatform PUBLIC
Expand All @@ -37,3 +37,11 @@ target_link_libraries(SWBAndroidPlatform PUBLIC
SWBUtil)
target_sources(SWBAndroidPlatform PRIVATE
"${CMAKE_CURRENT_BINARY_DIR}/resource_bundle_accessor.swift")

set_target_properties(SWBAndroidPlatform PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBAndroidPlatform)

install(TARGETS SWBAndroidPlatform
ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}")
10 changes: 9 additions & 1 deletion Sources/SWBApplePlatform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ file(CONFIGURE
]]
ESCAPE_QUOTES @ONLY NEWLINE_STYLE LF)

add_library(SWBApplePlatform STATIC
add_library(SWBApplePlatform
AppIntentsMetadataCompiler.swift
AppIntentsMetadataTaskProducer.swift
AppIntentsSSUTrainingCompiler.swift
Expand Down Expand Up @@ -75,3 +75,11 @@ target_link_libraries(SWBApplePlatform PUBLIC
SWBTaskConstruction)
target_sources(SWBApplePlatform PRIVATE
"${CMAKE_CURRENT_BINARY_DIR}/resource_bundle_accessor.swift")

set_target_properties(SWBApplePlatform PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBApplePlatform)

install(TARGETS SWBApplePlatform
ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}")
8 changes: 8 additions & 0 deletions Sources/SWBBuildService/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ target_link_libraries(SWBBuildService PUBLIC
SWBWebAssemblyPlatform
SWBWindowsPlatform
$<$<NOT:$<PLATFORM_ID:Darwin>>:SwiftSystem::SystemPackage>)

set_target_properties(SWBBuildService PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBBuildService)

install(TARGETS SWBBuildService
ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}")
2 changes: 2 additions & 0 deletions Sources/SWBBuildServiceBundle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ target_link_libraries(SWBBuildServiceBundle PRIVATE
SWBCore)

install(TARGETS SWBBuildServiceBundle)

set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBBuildServiceBundle)
8 changes: 8 additions & 0 deletions Sources/SWBBuildSystem/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ target_link_libraries(SWBBuildSystem PUBLIC
SWBCore
SWBTaskConstruction
SWBTaskExecution)

set_target_properties(SWBBuildSystem PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBBuildSystem)

install(TARGETS SWBBuildSystem
ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}")
8 changes: 8 additions & 0 deletions Sources/SWBCAS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ set_target_properties(SWBCAS PROPERTIES
target_link_libraries(SWBCAS PUBLIC
SWBUtil
SWBCSupport)

set_target_properties(SWBCAS PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBCAS)

install(TARGETS SWBCAS
ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}")
8 changes: 8 additions & 0 deletions Sources/SWBCLibc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ add_library(SWBCLibc
libc.c)
target_include_directories(SWBCLibc INTERFACE
include)

target_include_directories(SWBCLibc PUBLIC
${CMAKE_CURRENT_BINARY_DIR})

set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBCLibc)

install(TARGETS SWBCLibc
ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}")
4 changes: 3 additions & 1 deletion Sources/SWBCSupport/CLibRemarksHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@

#include <stdbool.h>

#include "CSupportDefines.h"

// Swift has no way of checking if a weak_import symbol is available.
// This function checks if LLVMRemarkVersion from libRemarks.dylib is available, which should be enough to assert the whole library is available as well.
bool isLibRemarksAvailable(void);
CSUPPORT_EXPORT bool isLibRemarksAvailable(void);

#endif /* CLibRemarksHelper_h */
Loading