Skip to content

[SR-1738] add_swift_library takes SHARED/STATIC arg #3020

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
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
36 changes: 30 additions & 6 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ endfunction()
# target
# name
# [SHARED]
# [STATIC]
# [SDK sdk]
# [ARCHITECTURE architecture]
# [DEPENDS dep1 ...]
Expand Down Expand Up @@ -390,6 +391,9 @@ endfunction()
# SHARED
# Build a shared library.
#
# STATIC
# Build a static library.
#
# SDK sdk
# SDK to build for.
#
Expand Down Expand Up @@ -448,7 +452,7 @@ endfunction()
# Sources to add into this library
function(_add_swift_library_single target name)
set(SWIFTLIB_SINGLE_options
SHARED OBJECT_LIBRARY IS_STDLIB IS_STDLIB_CORE IS_SDK_OVERLAY
SHARED STATIC OBJECT_LIBRARY IS_STDLIB IS_STDLIB_CORE IS_SDK_OVERLAY
TARGET_LIBRARY FORCE_BUILD_FOR_HOST_SDK
API_NOTES_NON_OVERLAY DONT_EMBED_BITCODE)
cmake_parse_arguments(SWIFTLIB_SINGLE
Expand All @@ -473,6 +477,13 @@ function(_add_swift_library_single target name)
if("${SWIFTLIB_SINGLE_INSTALL_IN_COMPONENT}" STREQUAL "")
message(FATAL_ERROR "INSTALL_IN_COMPONENT is required")
endif()

if(NOT SWIFTLIB_SINGLE_SHARED AND
NOT SWIFTLIB_SINGLE_STATIC AND
NOT SWIFTLIB_SINGLE_OBJECT_LIBRARY)
message(FATAL_ERROR
"Either SHARED, STATIC, or OBJECT_LIBRARY must be specified")
endif()

# Determine the subdirectory where this library will be installed.
set(SWIFTLIB_SINGLE_SUBDIR
Expand Down Expand Up @@ -681,7 +692,7 @@ function(_add_swift_library_single target name)
# Do these LAST.

set(target_static)
if(SWIFTLIB_SINGLE_IS_STDLIB AND SWIFT_BUILD_STATIC_STDLIB)
if(SWIFTLIB_SINGLE_IS_STDLIB AND SWIFTLIB_SINGLE_STATIC)
set(target_static "${target}-static")

# We have already compiled Swift sources. Link everything into a static
Expand Down Expand Up @@ -920,6 +931,7 @@ endfunction()
# Usage:
# add_swift_library(name
# [SHARED]
# [STATIC]
# [DEPENDS dep1 ...]
# [LINK_LIBRARIES dep1 ...]
# [INTERFACE_LINK_LIBRARIES dep1 ...]
Expand Down Expand Up @@ -949,6 +961,9 @@ endfunction()
# SHARED
# Build a shared library.
#
# STATIC
# Build a static library.
#
# DEPENDS
# Targets that this library depends on.
#
Expand Down Expand Up @@ -1028,7 +1043,7 @@ endfunction()
# Sources to add into this library.
function(add_swift_library name)
set(SWIFTLIB_options
SHARED OBJECT_LIBRARY IS_STDLIB IS_STDLIB_CORE IS_SDK_OVERLAY
SHARED STATIC OBJECT_LIBRARY IS_STDLIB IS_STDLIB_CORE IS_SDK_OVERLAY
TARGET_LIBRARY FORCE_BUILD_FOR_HOST_SDK
API_NOTES_NON_OVERLAY DONT_EMBED_BITCODE HAS_SWIFT_CONTENT)
cmake_parse_arguments(SWIFTLIB
Expand All @@ -1042,7 +1057,6 @@ function(add_swift_library name)

if(SWIFTLIB_IS_SDK_OVERLAY)
set(SWIFTLIB_HAS_SWIFT_CONTENT TRUE)
set(SWIFTLIB_SHARED TRUE)
set(SWIFTLIB_IS_STDLIB TRUE)
set(SWIFTLIB_TARGET_LIBRARY TRUE)

Expand Down Expand Up @@ -1104,6 +1118,13 @@ function(add_swift_library name)
if("${SWIFTLIB_INSTALL_IN_COMPONENT}" STREQUAL "")
message(FATAL_ERROR "INSTALL_IN_COMPONENT is required")
endif()

if(NOT SWIFTLIB_SHARED AND
NOT SWIFTLIB_STATIC AND
NOT SWIFTLIB_OBJECT_LIBRARY)
message(FATAL_ERROR
"Either SHARED, STATIC, or OBJECT_LIBRARY must be specified")
endif()

if(SWIFTLIB_TARGET_LIBRARY)
# If we are building this library for targets, loop through the various
Expand Down Expand Up @@ -1196,6 +1217,7 @@ function(add_swift_library name)
${VARIANT_NAME}
${name}
${SWIFTLIB_SHARED_keyword}
${SWIFTLIB_STATIC_keyword}
${SWIFTLIB_OBJECT_LIBRARY_keyword}
${SWIFTLIB_SOURCES}
SDK ${sdk}
Expand Down Expand Up @@ -1231,7 +1253,7 @@ function(add_swift_library name)
endif()
endforeach()

if (SWIFT_BUILD_STATIC_STDLIB AND SWIFTLIB_IS_STDLIB)
if (SWIFTLIB_IS_STDLIB AND SWIFTLIB_STATIC)
# Add dependencies on the (not-yet-created) custom lipo target.
foreach(DEP ${SWIFTLIB_LINK_LIBRARIES})
if (NOT "${DEP}" STREQUAL "icucore")
Expand Down Expand Up @@ -1300,7 +1322,7 @@ function(add_swift_library name)
# If we built static variants of the library, create a lipo target for
# them.
set(lipo_target_static)
if (SWIFT_BUILD_STATIC_STDLIB AND SWIFTLIB_IS_STDLIB)
if (SWIFTLIB_IS_STDLIB AND SWIFTLIB_STATIC)
set(THIN_INPUT_TARGETS_STATIC)
foreach(TARGET ${THIN_INPUT_TARGETS})
list(APPEND THIN_INPUT_TARGETS_STATIC "${TARGET}-static")
Expand Down Expand Up @@ -1366,6 +1388,8 @@ function(add_swift_library name)
${name}
${name}
${SWIFTLIB_SHARED_keyword}
${SWIFTLIB_STATIC_keyword}
${SWIFTLIB_OBJECT_LIBRARY_keyword}
${SWIFTLIB_SOURCES}
SDK ${sdk}
ARCHITECTURE ${arch}
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftAST
add_swift_library(swiftAST STATIC
ArchetypeBuilder.cpp
ASTContext.cpp
ASTDumper.cpp
Expand Down
2 changes: 1 addition & 1 deletion lib/ASTSectionImporter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftASTSectionImporter
add_swift_library(swiftASTSectionImporter STATIC
ASTSectionImporter.cpp
LINK_LIBRARIES swiftBasic
COMPONENT_DEPENDS core)
Expand Down
2 changes: 1 addition & 1 deletion lib/Basic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ generate_revision_inc(swift_revision_inc Swift "${SWIFT_SOURCE_DIR}")
set(version_inc_files
${llvm_revision_inc} ${clang_revision_inc} ${swift_revision_inc})

add_swift_library(swiftBasic
add_swift_library(swiftBasic STATIC
Cache.cpp
ClusteredBitVector.cpp
Demangle.cpp
Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ handle_gyb_sources(
generated_include_sources
"")

add_swift_library(swiftClangImporter
add_swift_library(swiftClangImporter STATIC
CFTypeInfo.cpp
ClangDiagnosticConsumer.cpp
ClangImporter.cpp
Expand Down
2 changes: 1 addition & 1 deletion lib/Driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set(swiftDriver_sources

set(swiftDriver_targetDefines)

add_swift_library(swiftDriver
add_swift_library(swiftDriver STATIC
${swiftDriver_sources}
DEPENDS SwiftOptions
LINK_LIBRARIES swiftAST swiftBasic swiftFrontend swiftOption)
Expand Down
2 changes: 1 addition & 1 deletion lib/Frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftFrontend
add_swift_library(swiftFrontend STATIC
CompilerInvocation.cpp
DiagnosticVerifier.cpp
Frontend.cpp
Expand Down
2 changes: 1 addition & 1 deletion lib/FrontendTool/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftFrontendTool
add_swift_library(swiftFrontendTool STATIC
FrontendTool.cpp
DEPENDS SwiftOptions
LINK_LIBRARIES
Expand Down
2 changes: 1 addition & 1 deletion lib/IDE/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftIDE
add_swift_library(swiftIDE STATIC
CodeCompletion.cpp
CodeCompletionCache.cpp
CommentConversion.cpp
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftIRGen
add_swift_library(swiftIRGen STATIC
DebugTypeInfo.cpp
EnumPayload.cpp
ExtraInhabitants.cpp
Expand Down
2 changes: 1 addition & 1 deletion lib/Immediate/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftImmediate
add_swift_library(swiftImmediate STATIC
Immediate.cpp
REPL.cpp
LINK_LIBRARIES
Expand Down
2 changes: 1 addition & 1 deletion lib/Index/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftIndex
add_swift_library(swiftIndex STATIC
Index.cpp
IndexDataConsumer.cpp
IndexSymbol.cpp
Expand Down
2 changes: 1 addition & 1 deletion lib/LLVMPasses/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftLLVMPasses
add_swift_library(swiftLLVMPasses STATIC
LLVMSwiftAA.cpp
LLVMSwiftRCIdentity.cpp
LLVMARCOpts.cpp
Expand Down
2 changes: 1 addition & 1 deletion lib/Markup/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftMarkup
add_swift_library(swiftMarkup STATIC
AST.cpp
LineList.cpp
Markup.cpp
Expand Down
2 changes: 1 addition & 1 deletion lib/Option/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftOption
add_swift_library(swiftOption STATIC
Options.cpp
SanitizerOptions.cpp
DEPENDS SwiftOptions
Expand Down
2 changes: 1 addition & 1 deletion lib/Parse/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftParse
add_swift_library(swiftParse STATIC
Lexer.cpp
ParseDecl.cpp
ParseExpr.cpp
Expand Down
2 changes: 1 addition & 1 deletion lib/PrintAsObjC/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftPrintAsObjC
add_swift_library(swiftPrintAsObjC STATIC
PrintAsObjC.cpp

LINK_LIBRARIES
Expand Down
2 changes: 1 addition & 1 deletion lib/RemoteAST/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftRemoteAST
add_swift_library(swiftRemoteAST STATIC
RemoteAST.cpp
LINK_LIBRARIES
swiftSema swiftIRGen)
2 changes: 1 addition & 1 deletion lib/SIL/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftSIL
add_swift_library(swiftSIL STATIC
AbstractionPattern.cpp
Bridging.cpp
Dominance.cpp
Expand Down
2 changes: 1 addition & 1 deletion lib/SILGen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftSILGen
add_swift_library(swiftSILGen STATIC
ArgumentSource.cpp
Cleanup.cpp
Condition.cpp
Expand Down
2 changes: 1 addition & 1 deletion lib/SILOptimizer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ add_subdirectory(SILCombiner)
add_subdirectory(Transforms)
add_subdirectory(UtilityPasses)
add_subdirectory(Utils)
add_swift_library(swiftSILOptimizer
add_swift_library(swiftSILOptimizer STATIC
${ARC_SOURCES}
${ANALYSIS_SOURCES}
${SILCOMBINER_SOURCES}
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftSema
add_swift_library(swiftSema STATIC
CodeSynthesis.cpp
Constraint.cpp
ConstraintGraph.cpp
Expand Down
2 changes: 1 addition & 1 deletion lib/Serialization/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftSerialization
add_swift_library(swiftSerialization STATIC
Deserialization.cpp
DeserializeSIL.cpp
ModuleFile.cpp
Expand Down
6 changes: 6 additions & 0 deletions stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ else()
set(CMAKE_C_COMPILER_ARG1 "")
endif()

# FIXME: Make it possible to build *only* static libraries for the stdlib.
set(SWIFT_STDLIB_LIBRARY_BUILD_TYPES SHARED)
if(SWIFT_BUILD_STATIC_STDLIB)
list(APPEND SWIFT_STDLIB_LIBRARY_BUILD_TYPES STATIC)
endif()

add_custom_target(swift-stdlib-all)
foreach(SDK ${SWIFT_SDKS})
add_custom_target("swift-stdlib-${SWIFT_SDK_${SDK}_LIB_SUBDIR}")
Expand Down
2 changes: 1 addition & 1 deletion stdlib/internal/SwiftExperimental/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftSwiftExperimental SHARED IS_STDLIB
add_swift_library(swiftSwiftExperimental ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
# This file should be listed the first. Module name is inferred from the
# filename.
SwiftExperimental.swift
Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/StdlibCollectionUnittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if(SWIFT_HOST_VARIANT MATCHES "${SWIFT_DARWIN_VARIANTS}")
Foundation)
endif()

add_swift_library(swiftStdlibCollectionUnittest SHARED IS_STDLIB
add_swift_library(swiftStdlibCollectionUnittest ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
# This file should be listed the first. Module name is inferred from the
# filename.
StdlibCollectionUnittest.swift
Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/StdlibUnittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if(SWIFT_SERIALIZE_STDLIB_UNITTEST)
list(APPEND swift_stdlib_unittest_compile_flags "-Xfrontend" "-sil-serialize-all")
endif()

add_swift_library(swiftStdlibUnittest SHARED IS_STDLIB
add_swift_library(swiftStdlibUnittest ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
# This file should be listed the first. Module name is inferred from the
# filename.
StdlibUnittest.swift.gyb
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftStdlibUnittestFoundationExtras SHARED IS_STDLIB
add_swift_library(swiftStdlibUnittestFoundationExtras ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
# This file should be listed the first. Module name is inferred from the
# filename.
StdlibUnittestFoundationExtras.swift
Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/SwiftPrivate/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftSwiftPrivate SHARED IS_STDLIB
add_swift_library(swiftSwiftPrivate ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
# This file should be listed the first. Module name is inferred from the
# filename.
SwiftPrivate.swift
Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/SwiftPrivateLibcExtras/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ elseif(SWIFT_HOST_VARIANT STREQUAL "linux" OR SWIFT_HOST_VARIANT STREQUAL "freeb
Glibc)
endif()

add_swift_library(swiftSwiftPrivateLibcExtras SHARED IS_STDLIB
add_swift_library(swiftSwiftPrivateLibcExtras ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
# This file should be listed the first. Module name is inferred from the
# filename.
SwiftPrivateLibcExtras.swift
Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/SwiftPrivatePthreadExtras/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ elseif(SWIFT_HOST_VARIANT STREQUAL "linux" OR SWIFT_HOST_VARIANT STREQUAL "freeb
Glibc)
endif()

add_swift_library(swiftSwiftPrivatePthreadExtras SHARED IS_STDLIB
add_swift_library(swiftSwiftPrivatePthreadExtras ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
# This file should be listed the first. Module name is inferred from the
# filename.
SwiftPrivatePthreadExtras.swift
Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/SwiftReflectionTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftSwiftReflectionTest SHARED IS_STDLIB
add_swift_library(swiftSwiftReflectionTest ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
SwiftReflectionTest.swift
SWIFT_MODULE_DEPENDS Darwin
INSTALL_IN_COMPONENT stdlib-experimental)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/Platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ else()
DEPENDS glibc_modulemap)
endif()

add_swift_library(${swift_platform_name} IS_SDK_OVERLAY
add_swift_library(${swift_platform_name} ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
${swift_platform_sources}
${swift_platform_flags})

Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/Reflection/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftReflection TARGET_LIBRARY FORCE_BUILD_FOR_HOST_SDK
add_swift_library(swiftReflection STATIC TARGET_LIBRARY FORCE_BUILD_FOR_HOST_SDK
Demangle.cpp
MetadataSource.cpp
Remangle.cpp
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/SDK/AVFoundation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftAVFoundation IS_SDK_OVERLAY
add_swift_library(swiftAVFoundation ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
AVFoundation.swift
TARGET_SDKS OSX IOS IOS_SIMULATOR TVOS TVOS_SIMULATOR
SWIFT_MODULE_DEPENDS Foundation CoreMedia
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/SDK/AppKit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftAppKit IS_SDK_OVERLAY
add_swift_library(swiftAppKit ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
AppKit.swift
AppKit_FoundationExtensions.swift
NSError.swift
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/SDK/AssetsLibrary/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_swift_library(swiftAssetsLibrary IS_SDK_OVERLAY
add_swift_library(swiftAssetsLibrary ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
AssetsLibrary.swift
TARGET_SDKS IOS IOS_SIMULATOR
SWIFT_MODULE_DEPENDS ObjectiveC Foundation CoreGraphics
Expand Down
6 changes: 6 additions & 0 deletions stdlib/public/SDK/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# All libraries in this directory tree are overlays that depend on Darwin SDK.

# FIXME: Make it possible to build *only* static libraries for the SDK overlays.
set(SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES SHARED)
if(SWIFT_BUILD_STATIC_STDLIB)
list(APPEND SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES STATIC)
endif()

# Please keep this list sorted.
add_subdirectory(AppKit)
add_subdirectory(AVFoundation)
Expand Down
Loading