CMake Lists
CMake Lists
6)
set(CMAKE_DISABLE_IN_SOURCE_BUILD YES)
if(DEFINED CMAKE_JOB_POOLS)
# CMake < 3.11 doesn't support CMAKE_JOB_POOLS. Manually set the property.
set_property(GLOBAL PROPERTY JOB_POOLS "${CMAKE_JOB_POOLS}")
else()
# Make a job pool for things that can't yet be distributed
cmake_host_system_information(
RESULT localhost_logical_cores QUERY NUMBER_OF_LOGICAL_CORES)
set_property(GLOBAL APPEND PROPERTY JOB_POOLS local_jobs=$
{localhost_logical_cores})
# Put linking in that category
set(CMAKE_JOB_POOL_LINK local_jobs)
endif()
enable_language(C)
enable_language(CXX)
if(SWIFT_ASM_AVAILABLE)
enable_language(${SWIFT_ASM_DIALECT})
endif()
# Use C++17.
set(SWIFT_MIN_CXX_STANDARD 17)
# Enable Swift for the host compiler build if we have the language. It is
# optional until we have a bootstrap story.
check_language(Swift)
if(CMAKE_Swift_COMPILER)
# we are not interested in logging any Swift module used
# when configuring the build system -- those are not useful
# since they will not contribute to the build of the compiler itself
unset(ENV{SWIFT_LOADED_MODULE_TRACE_FILE})
enable_language(Swift)
set(DEFAULT_SWIFT_MIN_RUNTIME_VERSION "${CMAKE_Swift_COMPILER_VERSION}")
else()
message(STATUS "WARNING! Did not find a host compiler swift?! Can not build
any compiler host sources written in Swift")
set(DEFAULT_SWIFT_MIN_RUNTIME_VERSION)
endif()
set(SWIFT_APPLE_PLATFORMS ${SWIFT_DARWIN_PLATFORMS})
if(SWIFT_FREESTANDING_FLAVOR STREQUAL "apple")
list(APPEND SWIFT_APPLE_PLATFORMS "FREESTANDING")
if(SWIFT_FREESTANDING_IS_DARWIN)
list(APPEND SWIFT_DARWIN_PLATFORMS "FREESTANDING")
endif()
endif()
#
# User-configurable options that control the inclusion and default build
# behavior for components which may not strictly be necessary (tools, examples,
# and tests).
#
# This is primarily to support building smaller or faster project files.
#
option(SWIFT_APPEND_VC_REV
"Embed the version control system revision in Swift"
TRUE)
option(SWIFT_INCLUDE_TOOLS
"Generate build targets for swift tools"
TRUE)
option(SWIFT_BUILD_REMOTE_MIRROR
"Build the Swift Remote Mirror Library"
TRUE)
option(SWIFT_BUILD_EXTERNAL_GENERIC_METADATA_BUILDER
"Build the Swift External Generic Metadata Builder Library"
TRUE)
option(SWIFT_BUILD_DYNAMIC_STDLIB
"Build dynamic variants of the Swift standard library"
TRUE)
option(SWIFT_BUILD_STATIC_STDLIB
"Build static variants of the Swift standard library"
FALSE)
option(SWIFT_STDLIB_STATIC_PRINT
"Build compile-time evaluated vprintf()"
FALSE)
option(SWIFT_STDLIB_ENABLE_UNICODE_DATA
"Include Unicode data files in the standard library.
NOTE: Disabling this will cause many String methods to crash."
TRUE)
option(SWIFT_BUILD_CLANG_OVERLAYS
"Build Swift overlays for the clang builtin modules"
TRUE)
option(SWIFT_BUILD_DYNAMIC_SDK_OVERLAY
"Build dynamic variants of the Swift SDK overlay"
TRUE)
option(SWIFT_BUILD_STATIC_SDK_OVERLAY
"Build static variants of the Swift SDK overlay"
FALSE)
option(SWIFT_BUILD_STDLIB_EXTRA_TOOLCHAIN_CONTENT
"If not building stdlib, controls whether to build 'stdlib/toolchain' content"
TRUE)
option(SWIFT_BUILD_STDLIB_CXX_MODULE
"If not building stdlib, controls whether to build the Cxx module"
TRUE)
# In many cases, the CMake build system needs to determine whether to include
# a directory, or perform other actions, based on whether the stdlib or SDK is
# being built at all -- statically or dynamically. Please note that these
# flags are not related to the deprecated build-script-impl arguments
# 'build-swift-stdlib' and 'build-swift-sdk-overlay'. These are not flags that
# the build script should be able to set.
if(SWIFT_BUILD_DYNAMIC_STDLIB OR SWIFT_BUILD_STATIC_STDLIB)
set(SWIFT_BUILD_STDLIB TRUE)
else()
set(SWIFT_BUILD_STDLIB FALSE)
endif()
if(SWIFT_BUILD_DYNAMIC_SDK_OVERLAY OR SWIFT_BUILD_STATIC_SDK_OVERLAY)
set(SWIFT_BUILD_SDK_OVERLAY TRUE)
else()
set(SWIFT_BUILD_SDK_OVERLAY FALSE)
endif()
option(SWIFT_BUILD_PERF_TESTSUITE
"Create in-tree targets for building swift performance benchmarks."
FALSE)
option(SWIFT_INCLUDE_TEST_BINARIES
"Create targets for building/running test binaries even if SWIFT_INCLUDE_TESTS is
disabled"
TRUE)
option(SWIFT_INCLUDE_DOCS
"Create targets for building docs."
TRUE)
set(_swift_include_apinotes_default FALSE)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(_swift_include_apinotes_default TRUE)
endif()
option(SWIFT_INCLUDE_APINOTES
"Create targets for installing the remaining apinotes in the built toolchain."
${_swift_include_apinotes_default})
#
# Miscellaneous User-configurable options.
#
# TODO: Please categorize these!
#
include(${CMAKE_CURRENT_LIST_DIR}/cmake/SwiftVersion.cmake)
option(SWIFT_DISABLE_DEAD_STRIPPING
"Turn off Darwin-specific dead stripping for Swift host tools." FALSE)
set(SWIFT_TOOLS_ENABLE_LTO OFF CACHE STRING "Build Swift tools with LTO. One
must specify the form of LTO by setting this to one of: 'full', 'thin'. This
option only affects the tools that run on the host (the compiler), and has
no effect on the target libraries (the standard library and the runtime).")
option(SWIFT_TOOLS_LD64_LTO_CODEGEN_ONLY_FOR_SUPPORTING_TARGETS
"When building ThinLTO using ld64 on Darwin, controls whether to opt out of
LLVM IR optimizations when linking targets that will get
little benefit from it (e.g. tools for bootstrapping or
debugging Swift)"
FALSE)
option(BOOTSTRAPPING_MODE [=[
How to build the swift compiler modules. Possible values are
OFF: build without swift modules
HOSTTOOLS: build with a pre-installed toolchain
BOOTSTRAPPING: build with a 2-stage bootstrapping process
BOOTSTRAPPING-WITH-HOSTLIBS: build with a 2-stage bootstrapping process,
but the compiler links against the host system swift libs (macOS
only)
CROSSCOMPILE: cross-compiledwith a native host compiler, provided in
`SWIFT_NATIVE_SWIFT_TOOLS_PATH` (non-Darwin only)
CROSSCOMPILE-WITH-HOSTLIBS: build with a bootstrapping-with-hostlibs
compiled
compiler, provided in
`SWIFT_NATIVE_SWIFT_TOOLS_PATH`
]=] OFF)
option(BRIDGING_MODE [=[
How swift-C++ bridging code is compiled:
INLINE: uses full swift C++ interop and briding functions are inlined
PURE: uses limited C++ interp an bridging functions are not inlined
DEFAULT: based on the build configuration
]=] DEFAULT)
# The following only works with the Ninja generator in CMake >= 3.0.
set(SWIFT_PARALLEL_LINK_JOBS "" CACHE STRING
"Define the maximum number of linker jobs for swift.")
#
# User-configurable Swift Standard Library specific options.
#
# TODO: Once the stdlib/compiler builds are split, this should be sunk into the
# stdlib cmake.
#
is_build_type_optimized("${SWIFT_STDLIB_BUILD_TYPE}" swift_optimized)
if(swift_optimized)
set(SWIFT_STDLIB_ASSERTIONS_default FALSE)
else()
set(SWIFT_STDLIB_ASSERTIONS_default TRUE)
endif()
option(SWIFT_STDLIB_ASSERTIONS
"Enable internal checks for the Swift standard library (useful for debugging
the library itself, does not affect checks required for safety)"
"${SWIFT_STDLIB_ASSERTIONS_default}")
option(SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER
"Use the host compiler and not the internal clang to build the swift
runtime"
FALSE)
option(SWIFT_RUN_TESTS_WITH_HOST_COMPILER
"Run tests against the host compiler and not the just built swift"
FALSE)
option(SWIFT_STDLIB_ENABLE_SIB_TARGETS
"Should we generate sib targets for the stdlib or not?"
FALSE)
#
# User-configurable Linux specific options.
#
#
# User-configurable WebAssembly specific options.
#
option(SWIFT_ENABLE_WASI_THREADS
"Build the Standard Library with WASI threads support"
FALSE)
#
# User-configurable Darwin-specific options.
#
option(SWIFT_EMBED_BITCODE_SECTION
"If non-empty, embeds LLVM bitcode binary sections in the standard library and
overlay binaries for supported platforms"
FALSE)
option(SWIFT_EMBED_BITCODE_SECTION_HIDE_SYMBOLS
"If non-empty, when embedding the LLVM bitcode binary sections into the relevant
binaries, pass in -bitcode_hide_symbols. Does nothing if
SWIFT_EMBED_BITCODE_SECTION is set to false."
FALSE)
option(SWIFT_RUNTIME_CRASH_REPORTER_CLIENT
"Whether to enable CrashReporter integration"
"${SWIFT_RUNTIME_CRASH_REPORTER_CLIENT_default}")
# We don't want to use the same install_name_dir as the standard library which
# will be installed in /usr/lib/swift. These private libraries should continue
# to use @rpath for now.
set(SWIFT_DARWIN_STDLIB_PRIVATE_INSTALL_NAME_DIR "@rpath" CACHE STRING
"The directory of the install_name for the private standard library dylibs")
option(SWIFT_ALLOW_LINKING_SWIFT_CONTENT_IN_DARWIN_TOOLCHAIN
"Adds search paths for libraries in the toolchain
when building Swift programs.
This is needed to support Apple internal configurations."
FALSE)
#
# Compatibility library deployment versions
#
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_OSX "10.9")
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_IOS "7.0")
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_TVOS "9.0")
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_WATCHOS "2.0")
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_XROS "1.0")
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_MACCATALYST "13.1")
#
# User-configurable debugging options.
#
option(SWIFT_SIL_VERIFY_ALL
"Run SIL verification after each transform when building Swift files in the
build process"
FALSE)
option(SWIFT_SIL_VERIFY_ALL_MACOS_ONLY
"Run SIL verification after each transform when building the macOS stdlib"
FALSE)
option(SWIFT_EMIT_SORTED_SIL_OUTPUT
"Sort SIL output by name to enable diffing of output"
FALSE)
if(SWIFT_STDLIB_ASSERTIONS)
set(SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS_default TRUE)
else()
set(SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS_default FALSE)
endif()
option(SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS
"Overwrite memory for deallocated Swift objects"
"${SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS_default}")
option(SWIFT_STDLIB_SIL_DEBUGGING
"Compile the Swift standard library with -sil-based-debuginfo to enable
debugging and profiling on SIL level"
FALSE)
option(SWIFT_CHECK_INCREMENTAL_COMPILATION
"Check if incremental compilation works when compiling the Swift libraries"
FALSE)
option(SWIFT_ENABLE_ARRAY_COW_CHECKS
"Compile the stdlib with Array COW checks enabled (only relevant for assert
builds)"
FALSE)
option(SWIFT_REPORT_STATISTICS
"Create json files which contain internal compilation statistics"
FALSE)
#
# User-configurable experimental options. Do not use in production builds.
#
option(SWIFT_RUNTIME_ENABLE_LEAK_CHECKER
"Should the runtime be built with support for non-thread-safe leak detecting
entrypoints"
FALSE)
option(SWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS
"Enable runtime function counters and expose the API."
FALSE)
option(SWIFT_ENABLE_STDLIBCORE_EXCLUSIVITY_CHECKING
"Build stdlibCore with exclusivity checking enabled"
FALSE)
option(SWIFT_STDLIB_ENABLE_DEBUG_PRECONDITIONS_IN_RELEASE
"Enable _debugPrecondition checks in the stdlib in Release configurations"
FALSE)
option(SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING
"Enable experimental Swift differentiable programming features"
FALSE)
option(SWIFT_IMPLICIT_CONCURRENCY_IMPORT
"Implicitly import the Swift concurrency module"
TRUE)
option(SWIFT_IMPLICIT_BACKTRACING_IMPORT
"Implicitly import the Swift backtracing module"
FALSE)
option(SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY
"Enable build of the Swift concurrency module"
FALSE)
option(SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP
"Enable experimental C++ interop modules"
FALSE)
option(SWIFT_ENABLE_CXX_INTEROP_SWIFT_BRIDGING_HEADER
"Install the <swift/bridging> C++ interoperability header alongside compiler"
TRUE)
option(SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED
"Enable experimental distributed actors and functions"
FALSE)
option(SWIFT_ENABLE_EXPERIMENTAL_NONESCAPABLE_TYPES
"Enable experimental NonescapableTypes"
FALSE)
option(SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING
"Enable experimental string processing"
FALSE)
option(SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION
"Enable build of the Swift observation module"
FALSE)
option(SWIFT_STDLIB_ENABLE_STRICT_CONCURRENCY_COMPLETE
"Build the stdlib with -strict-concurrency=complete"
FALSE)
option(SWIFT_ENABLE_SYNCHRONIZATION
"Enable build of the Swift Synchronization module"
FALSE)
option(SWIFT_ENABLE_DISPATCH
"Enable use of libdispatch"
TRUE)
option(SWIFT_ENABLE_GLOBAL_ISEL_ARM64
"Enable global isel on arm64"
FALSE)
option(SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION
"Enable experimental SwiftParser validation by default"
FALSE)
cmake_dependent_option(SWIFT_BUILD_SOURCEKIT
"Build SourceKit" TRUE
"SWIFT_ENABLE_DISPATCH" FALSE)
cmake_dependent_option(SWIFT_ENABLE_SOURCEKIT_TESTS
"Enable running SourceKit tests" TRUE
"SWIFT_BUILD_SOURCEKIT" FALSE)
option(SWIFT_THREADING_PACKAGE
"Override the threading package used for the build. This can either be a
single package name, or a semicolon separated sequence of sdk:package pairs.
Valid package names are 'pthreads', 'darwin', 'linux', 'win32', 'c11', 'none'
or the empty string for the SDK default.")
option(SWIFT_THREADING_HAS_DLSYM
"Enable the use of the dlsym() function. This gets used to provide TSan
support on some platforms."
TRUE)
option(SWIFT_ENABLE_MACCATALYST
"Build the Standard Library and overlays with MacCatalyst support"
FALSE)
option(SWIFT_ENABLE_BACKTRACING
"Build backtracing runtime support"
FALSE)
#
# End of user-configurable options.
#
set(SWIFT_BUILT_STANDALONE FALSE)
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
set(SWIFT_BUILT_STANDALONE TRUE)
endif()
if(SWIFT_BUILT_STANDALONE)
project(Swift C CXX ${SWIFT_ASM_DIALECT})
endif()
# Make some warnings errors as they are commonly occurring and flood the build
# with unnecessary noise.
if(CMAKE_C_COMPILER_ID MATCHES Clang)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Werror=c++98-compat-extra-semi>)
endif()
option(SWIFT_BUILD_SWIFT_SYNTAX
"Enable building swift syntax"
FALSE)
option(SWIFT_BUILD_REGEX_PARSER_IN_COMPILER
"Build the Swift regex parser as part of the compiler."
TRUE)
if(SWIFT_BUILD_REGEX_PARSER_IN_COMPILER AND NOT SWIFT_BUILD_SWIFT_SYNTAX)
message(WARNING "Force setting SWIFT_BUILD_REGEX_PARSER_IN_COMPILER=OFF because
Swift parser integration is disabled")
set(SWIFT_BUILD_REGEX_PARSER_IN_COMPILER OFF)
endif()
set(SWIFT_BUILD_HOST_DISPATCH FALSE)
if(SWIFT_ENABLE_DISPATCH AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
# Only build libdispatch for the host if the host tools are being built and
# specifically if these two libraries that depend on it are built.
if(SWIFT_INCLUDE_TOOLS AND SWIFT_BUILD_SOURCEKIT)
set(SWIFT_BUILD_HOST_DISPATCH TRUE)
endif()
if(SWIFT_BUILD_HOST_DISPATCH)
if(NOT EXISTS "${SWIFT_PATH_TO_LIBDISPATCH_SOURCE}")
message(SEND_ERROR "SourceKit requires libdispatch on non-Darwin hosts.
Please specify SWIFT_PATH_TO_LIBDISPATCH_SOURCE")
endif()
endif()
endif()
#
# Include CMake modules
#
include(CheckCXXSourceRuns)
include(CMakeParseArguments)
include(CMakePushCheckState)
swift_get_package_cmo_support(
Swift_COMPILER_PACKAGE_CMO_SUPPORT)
message(STATUS " Package CMO: ${Swift_COMPILER_PACKAGE_CMO_SUPPORT}")
else()
message(STATUS "Swift Compiler (None).")
endif()
set(THREADS_PREFER_PTHREAD_FLAG YES)
include(FindThreads)
if(SWIFT_PATH_TO_CMARK_BUILD)
execute_process(COMMAND ${SWIFT_PATH_TO_CMARK_BUILD}/src/cmark --version
OUTPUT_VARIABLE _CMARK_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "CMark Version: ${_CMARK_VERSION}")
elseif(SWIFT_INCLUDE_TOOLS)
find_package(cmark-gfm CONFIG REQUIRED)
endif()
message(STATUS "")
# Check if a prebuilt clang path was passed in, as this variable will be
# assigned if not, in SwiftSharedCMakeConfig.
if("${SWIFT_NATIVE_CLANG_TOOLS_PATH}" STREQUAL "")
set(SWIFT_PREBUILT_CLANG FALSE)
else()
set(SWIFT_PREBUILT_CLANG TRUE)
endif()
include(SwiftSharedCMakeConfig)
include(SwiftComponents)
include(SwiftHandleGybSources)
include(SwiftSetIfArchBitness)
include(AddSwift)
include(SwiftConfigureSDK)
include(SwiftComponents)
include(SwiftList)
include(AddPureSwift)
set(SWIFT_RUNTIME_OUTPUT_INTDIR "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin")
set(SWIFT_LIBRARY_OUTPUT_INTDIR "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib")
if("${SWIFT_NATIVE_SWIFT_TOOLS_PATH}" STREQUAL "")
# This is the normal case. We are not cross-compiling.
set(SWIFT_NATIVE_SWIFT_TOOLS_PATH "${SWIFT_RUNTIME_OUTPUT_INTDIR}")
set(SWIFT_EXEC_FOR_SWIFT_MODULES "${CMAKE_Swift_COMPILER}")
elseif(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
# If cross-compiling, we don't have to bootstrap. We can just use the previously
# built native swiftc to build the swift compiler modules.
message(STATUS "Building swift modules with previously built tools instead of
bootstrapping")
set(SWIFT_EXEC_FOR_SWIFT_MODULES "${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swiftc")
if(BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING-WITH-HOSTLIBS")
set(BOOTSTRAPPING_MODE "CROSSCOMPILE-WITH-HOSTLIBS")
elseif(BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING")
set(BOOTSTRAPPING_MODE "CROSSCOMPILE")
else()
set(BOOTSTRAPPING_MODE "HOSTTOOLS")
endif()
elseif(BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" OR SWIFT_BUILD_SWIFT_SYNTAX)
# We are building using a pre-installed host toolchain but not bootstrapping
# the Swift modules. This happens when building using 'build-tooling-libs'
# where we haven't built a new Swift compiler. Use the Swift compiler from the
# pre-installed host toolchain to build the Swift modules.
set(SWIFT_EXEC_FOR_SWIFT_MODULES "${CMAKE_Swift_COMPILER}")
endif()
# Directory to use as the Clang module cache when building Swift source files.
set(SWIFT_MODULE_CACHE_PATH
"${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/module-cache")
# Xcode: use libc++ and c++11 using proper build settings.
if(XCODE)
swift_common_xcode_cxx_config()
endif()
if(LLVM_USE_LINKER)
set(SWIFT_USE_LINKER_default "${LLVM_USE_LINKER}")
elseif(SWIFT_HOST_VARIANT_SDK STREQUAL "ANDROID")
set(SWIFT_USE_LINKER_default "lld")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND NOT CMAKE_HOST_SYSTEM_NAME STREQUAL
"Windows")
set(SWIFT_USE_LINKER_default "lld")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(SWIFT_USE_LINKER_default "")
else()
get_gold_version(gold_version)
if(NOT gold_version)
message(STATUS "GNU Gold not found; using lld instead")
set(SWIFT_USE_LINKER_default "lld")
elseif(gold_version VERSION_LESS "2.36")
message(STATUS "GNU Gold is too old (${gold_version}); using lld instead")
set(SWIFT_USE_LINKER_default "lld")
else()
message(STATUS "Using GNU Gold ${gold_version}")
set(SWIFT_USE_LINKER_default "gold")
endif()
endif()
set(SWIFT_USE_LINKER ${SWIFT_USE_LINKER_default} CACHE STRING
"Build Swift with a non-default linker")
include(CheckLinkerFlag)
#
# Enable additional warnings.
#
swift_common_cxx_warnings()
# Check if we're build with MSVC or Clang-cl, as these compilers have similar
command line arguments.
if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL
"MSVC")
set(SWIFT_COMPILER_IS_MSVC_LIKE TRUE)
endif()
#
# Display a message if the threading package has been overridden
#
if(SWIFT_THREADING_PACKAGE)
message(STATUS "")
message(STATUS "Threading package override enabled")
foreach(elt ${SWIFT_THREADING_PACKAGE})
string(REPLACE ":" ";" elt_list "${elt}")
list(LENGTH elt_list elt_list_len)
if(elt_list_len EQUAL 1)
set(elt_sdk "Global")
list(GET elt_list 0 elt_package)
elseif(elt_list_len EQUAL 2)
list(GET elt_list 0 elt_sdk)
list(GET elt_list 1 elt_package)
string(TOUPPER "${elt_sdk}" elt_sdk)
else()
message(FATAL_ERROR "Bad threading override \"${elt}\" -
SWIFT_THREADING_PACKAGE must be a semicolon separated list of package or
sdk:package pairs.")
endif()
string(TOLOWER "${elt_package}" elt_package)
message(STATUS " ${elt_sdk}: ${elt_package}")
endforeach()
message(STATUS "")
endif()
#
# Configure SDKs.
#
if(XCODE)
# FIXME: It used to be the case that Xcode would force
# -m${platform}-version-min flags that would conflict with those computed
# by build-script. version-min flags are deprecated in favor of -target since
# clang-11, so we might be able to undo this.
set(SWIFT_SDKS "OSX")
endif()
is_sdk_requested(LINUX swift_build_linux)
if(swift_build_linux)
if("${SWIFT_SDK_LINUX_ARCHITECTURES}" STREQUAL "")
set(SWIFT_SDK_LINUX_ARCHITECTURES "${SWIFT_HOST_VARIANT_ARCH}")
endif()
configure_sdk_unix("Linux" "${SWIFT_SDK_LINUX_ARCHITECTURES}")
endif()
is_sdk_requested(LINUX_STATIC swift_build_linux_static)
if(swift_build_linux_static)
if("${SWIFT_MUSL_PATH}" STREQUAL "")
message(FATAL_ERROR "You must set SWIFT_MUSL_PATH to point to the Musl
libraries and headers. Specifically, we expect to find Musl at
<SWIFT_MUSL_PATH>/<arch> for each requested architecture.")
endif()
configure_sdk_unix("Linux_Static" "${SWIFT_SDK_LINUX_STATIC_ARCHITECTURES}")
endif()
is_sdk_requested(FREESTANDING swift_build_freestanding)
if(swift_build_freestanding AND (SWIFT_FREESTANDING_FLAVOR STREQUAL "linux"))
# TODO
# configure_sdk_unix("FREESTANDING" "${SWIFT_HOST_VARIANT_ARCH}")
endif()
configure_sdk_unix("FreeBSD" "${SWIFT_HOST_VARIANT_ARCH}")
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
configure_sdk_unix("OpenBSD" "${SWIFT_HOST_VARIANT_ARCH}")
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
configure_sdk_unix("Haiku" "${SWIFT_HOST_VARIANT_ARCH}")
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
configure_sdk_unix("Android" "${SWIFT_SDK_ANDROID_ARCHITECTURES}")
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
configure_sdk_unix("WASI" "wasm32")
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
include(DarwinSDKs)
endif()
set(SWIFT_PRIMARY_VARIANT_SUFFIX
"-${SWIFT_SDK_${SWIFT_PRIMARY_VARIANT_SDK}_LIB_SUBDIR}-$
{SWIFT_PRIMARY_VARIANT_ARCH}")
if(SWIFT_PARALLEL_LINK_JOBS)
if(NOT CMAKE_MAKE_PROGRAM MATCHES "ninja")
message(WARNING "Job pooling is only available with Ninja generators.")
else()
set_property(GLOBAL APPEND PROPERTY JOB_POOLS swift_link_job_pool=$
{SWIFT_PARALLEL_LINK_JOBS})
set(CMAKE_JOB_POOL_LINK swift_link_job_pool)
endif()
endif()
swift_get_host_triple(SWIFT_HOST_TRIPLE)
set(SWIFT_HOST_MODULE_TRIPLE "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_$
{SWIFT_HOST_VARIANT_ARCH}_MODULE}")
set(SWIFT_HOST_LIBRARIES_DEST_DIR "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/swift/host")
if(SWIFT_INCLUDE_TOOLS)
message(STATUS "Building host Swift tools for ${SWIFT_HOST_VARIANT_SDK} $
{SWIFT_HOST_VARIANT_ARCH}")
message(STATUS " Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS " Assertions: ${LLVM_ENABLE_ASSERTIONS}")
message(STATUS " LTO: ${SWIFT_TOOLS_ENABLE_LTO}")
message(STATUS " Bootstrapping: ${BOOTSTRAPPING_MODE}")
message(STATUS " C++ Bridging: ${BRIDGING_MODE}")
message(STATUS " Swift parser: ${SWIFT_BUILD_SWIFT_SYNTAX}")
message(STATUS "")
else()
message(STATUS "Not building host Swift tools")
message(STATUS "")
endif()
if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_SDK_OVERLAY)
message(STATUS "Building Swift standard library and overlays for SDKs: $
{SWIFT_SDKS}")
message(STATUS " Build type: ${SWIFT_STDLIB_BUILD_TYPE}")
message(STATUS " Assertions: ${SWIFT_STDLIB_ASSERTIONS}")
message(STATUS "")
if(SWIFT_BUILD_LIBEXEC)
message(STATUS "Building Swift auxiliary executables for SDKs: ${SWIFT_SDKS}")
message(STATUS "")
endif()
if(SWIFT_BUILD_REMOTE_MIRROR)
message(STATUS "Building Swift Remote Mirror for SDKs: ${SWIFT_SDKS}")
message(STATUS "")
endif()
if(SWIFT_BUILD_EXTERNAL_GENERIC_METADATA_BUILDER)
message(STATUS "Building Swift External Generic Metadata Builder for SDKs: $
{SWIFT_SDKS}")
message(STATUS "")
endif()
#
# Find required dependencies.
#
find_package(Python3 3.6 COMPONENTS Interpreter REQUIRED)
#
# Find optional dependencies.
#
if(LLVM_ENABLE_LIBXML2)
find_package(LibXml2 REQUIRED)
else()
find_package(LibXml2)
endif()
if(LLVM_ENABLE_LIBEDIT)
find_package(LibEdit REQUIRED)
else()
find_package(LibEdit)
endif()
if(LibEdit_FOUND)
cmake_push_check_state()
list(APPEND CMAKE_REQUIRED_INCLUDES ${LibEdit_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_LIBRARIES ${LibEdit_LIBRARIES})
check_symbol_exists(el_wgets "histedit.h" HAVE_EL_WGETS)
if(HAVE_EL_WGETS)
set(LibEdit_HAS_UNICODE YES)
else()
set(LibEdit_HAS_UNICODE NO)
endif()
cmake_pop_check_state()
endif()
if (LLVM_ENABLE_DOXYGEN)
message(STATUS "Doxygen: enabled")
endif()
if(SWIFT_ENABLE_DISPATCH)
include(Libdispatch)
endif()
###############
# PLEASE READ #
###############
#
# We have to include stdlib/ before tools/.
# Do not move add_subdirectory(stdlib) after add_subdirectory(tools)!
#
# We must include stdlib/ before tools/ because stdlib/CMakeLists.txt
# declares the swift-stdlib-* set of targets. These targets will then
# implicitly depend on any targets declared with IS_STDLIB.
#
# https://github.com/apple/swift/issues/48534
if(SWIFT_BUILD_STDLIB)
add_subdirectory(stdlib)
else()
set(SWIFT_STDLIB_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/stdlib")
# Some of the things below depend on the threading library
add_subdirectory(stdlib/public/Threading)
if(SWIFT_BUILD_STDLIB_EXTRA_TOOLCHAIN_CONTENT)
add_subdirectory(stdlib/toolchain)
if(SWIFT_BUILD_STDLIB_CXX_MODULE)
add_subdirectory(stdlib/public/Cxx)
endif()
endif()
if(SWIFT_INCLUDE_APINOTES)
add_subdirectory(apinotes)
endif()
add_subdirectory(include)
if(SWIFT_INCLUDE_TOOLS)
add_subdirectory(lib)
add_subdirectory(SwiftCompilerSources)
add_subdirectory(utils)
add_subdirectory(userdocs)
if(SWIFT_INCLUDE_TESTS)
add_subdirectory(test)
add_subdirectory(unittests)
endif()
if(SWIFT_INCLUDE_DOCS)
add_subdirectory(docs)
endif()
add_subdirectory(cmake/modules)
swift_install_in_component(FILES "LICENSE.txt"
DESTINATION "share/swift"
COMPONENT license)
file(GLOB SWIFT_TOPLEVEL_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/include/swift${dir}/*.h
${CMAKE_CURRENT_SOURCE_DIR}/include/swift${dir}/*.td
${CMAKE_CURRENT_SOURCE_DIR}/include/swift${dir}/*.def)
add_custom_target(Miscellaneous
SOURCES ${SWIFT_TOPLEVEL_HEADERS})
endif()