# Notes: # # The Demangling library uses `#if SWIFT_HAVE_CRASHREPORTERCLIENT` while the # runtime library uses `#ifdef SWIFT_HAVE_CRASHREPORTERCLIENT` to toggle that # functionality. When building the demangling library, the macro should be set # to 0 or 1 to indicate the presence of the crashreporter. # When building the runtime library, the existence of the macro indicates the # presence of the crashreporter. # # Runtime library pulls sources and headers from compiler sources (ThreadSanitizer) # Demangling library pulls sources and headers from compiler sources (all) # # # gyb pulls sources from compiler sources # # Stubs: # Pulls in headers from compiler # - include/swift/Basic # - include/swift/Runtime # - include/swift/Threading # TODO: # Platform support: # - Work on/Verify cross-compiling # - Work on/Verify Windows and Linux native builds # Embedded # -- -Xfrontend -emit-empty-object-file # Catalyst Support # -- Will need shadow invocations to generate swiftmodules for Swift parts # Install *.abi.json, swiftdoc, and swiftsourceinfo cmake_minimum_required(VERSION 3.29) # TODO before requiring CMake 4.1 or later # and/or enforcing CMP0195, please check/update # the implementation of `emit_swift_interface` # in `EmitSwiftInterface.cmake` # to ensure it keeps laying down nested swiftmodule folders set(CMAKE_C_VISIBILITY_PRESET "hidden") set(CMAKE_CXX_VISIBILITY_PRESET "hidden") set(CMAKE_VISIBILITY_INLINES_HIDDEN YES) set(CMAKE_POSITION_INDEPENDENT_CODE YES) set(SwiftCore_CMAKE_MODULES_DIR "${CMAKE_SOURCE_DIR}/cmake/modules") list(APPEND CMAKE_MODULE_PATH ${SwiftCore_CMAKE_MODULES_DIR} "${CMAKE_SOURCE_DIR}/../cmake/modules") include(CMakeWorkarounds) include(SwiftProjectVersion) project(SwiftCore LANGUAGES C CXX Swift VERSION ${SWIFT_RUNTIME_VERSION}) # The Swift standard library is not intended for use as a sub-library as part of # another project. It is tightly coupled with the compiler version. if(NOT PROJECT_IS_TOP_LEVEL) message(FATAL_ERROR "Swift Core must build as a standalone project") endif() # FIXME: We should not need to refer back into the compiler sources. This is # needed by gyb, Demangling, Threading, the runtime (ThreadSanitizer.cpp) set(SwiftCore_SWIFTC_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../../" CACHE FILEPATH "Path to the root source directory of the Swift compiler") # Hook point for vendor-specific extensions to the build system # Allowed extension points: # - DefaultSettings.cmake # - Settings.cmake set(SwiftCore_VENDOR_MODULE_DIR "${SwiftCore_CMAKE_MODULES_DIR}/vendor" CACHE FILEPATH "Location for private build system extension") include(GNUInstallDirs) include(CheckSymbolExists) include(CheckIncludeFileCXX) include(CompilerSettings) include(DefaultSettings) include(EmitSwiftInterface) include(InstallSwiftInterface) include(PlatformInfo) include(gyb) include(ResourceEmbedding) include(CatalystSupport) include(AvailabilityMacros) check_symbol_exists("asl_log" "asl.h" SwiftCore_HAS_ASL) check_symbol_exists("dladdr" "dlfcn.h" SwiftCore_HAS_DLADDR) check_symbol_exists("dlsym" "dlfcn.h" SwiftCore_HAS_DLSYM) check_symbol_exists("os_trace" "os/trace.h" SwiftCore_HAS_OS_TRACE) check_include_file_cxx("clocale" SwiftCore_HAS_LOCALE) include("${SwiftCore_VENDOR_MODULE_DIR}/Settings.cmake" OPTIONAL) defaulted_option(SwiftCore_ENABLE_LIBRARY_EVOLUTION "Generate ABI resilient runtime libraries") defaulted_option(SwiftCore_ENABLE_CRASH_REPORTER_CLIENT "Enable Apple CrashReporter integration") defaulted_option(SwiftCore_ENABLE_OBJC_INTEROP "Enable runtime ObjC interop") defaulted_option(SwiftCore_ENABLE_TYPE_PRINTING "Enable printing type names") defaulted_option(SwiftCore_ENABLE_VECTOR_TYPES "Enable vector support") defaulted_option(SwiftCore_ENABLE_REFLECTION "Enable runtime support for mirrors and reflection support") defaulted_option(SwiftCore_ENABLE_RUNTIME_FUNCTION_COUNTERS "Enable runtime function counter support") defaulted_option(SwiftCore_ENABLE_STDIN "Enable functions that use stdin support") defaulted_option(SwiftCore_ENABLE_ENVIRONMENT "Enable environment variable support") defaulted_option(SwiftCore_ENABLE_OVERRIDABLE_RETAIN_RELEASE "Enable override hooks for retain/release") defaulted_option(SwiftCore_ENABLE_RUNTIME_OS_VERSIONING "Enable runtime OS version detection") defaulted_option(SwiftCore_ENABLE_STATIC_PRINT "Disable full print") defaulted_option(SwiftCore_ENABLE_COMPACT_ABSOLUTE_FUNCTION_POINTERS "Resolve absolute function pointer as identity") defaulted_option(SwiftCore_ENABLE_BACKDEPLOYMENT_SUPPORT "Add symbols for runtime backdeployment") defaulted_option(SwiftCore_ENABLE_STDLIB_TRACING "Enable tracing in the runtime. Assumes the presence of os_log(3) and the os_signpost(3) API.") defaulted_option(SwiftCore_ENABLE_CONCURRENCY "Enable Concurrency runtime support") defaulted_option(SwiftCore_ENABLE_REMOTE_MIRROR "Enable RemoteMirror runtime support") defaulted_set(SwiftCore_CONCURRENCY_GLOBAL_EXECUTOR STRING "Default Concurrency global executor implementation") option(SwiftCore_ENABLE_COMMANDLINE_SUPPORT "Enable command line argument support" ON) option(SwiftCore_ENABLE_UNICODE_DATA "Include unicode data in Swift runtimes" ON) option(SwiftCore_ENABLE_SHORT_MANGLING_LOOKUPS "Build with fast-path context descriptor lookups based on well-known short manglings." ON) option(SwiftCore_ENABLE_FILESYSTEM_SUPPORT "Build for systems that have a filesystem" ON) option(SwiftCore_ENABLE_OS_TRACE_LAZY_INIT "Use os_trace call to check if lazy init has been completed before making os_signpost calls." ${SwiftCore_HAS_OS_TRACE}) option(SwiftCore_HAS_DARWIN_LIBMALLOC "Use Darwin malloc features" ${APPLE}) defaulted_option(SwiftCore_ENABLE_BACKTRACING "Enable backtracing runtime support") defaulted_set(SwiftCore_BACKTRACER_PATH STRING "Set a fixed path to the Swift backtracer") defaulted_option(SwiftCore_ENABLE_FATALERROR_BACKTRACE "Build stdlib fatalError with backtrace output") defaulted_option(SwiftCore_ENABLE_PRESPECIALIZATION "Enable generic metadata prespecialization") defaulted_option(SwiftCore_ENABLE_STRICT_AVAILABILITY "Enable strict availability; this will cause things to break at desk or in CI if the host OS is a lower version than some `@availability` annotations in the runtime code") option(SwiftCore_ENABLE_CLOBBER_FREED_OBJECTS "" OFF) option(SwiftCore_ENABLE_RUNTIME_LEAK_CHECKER "" OFF) option(SwiftCore_ENABLE_INTERNAL_CHECKS "" OFF) set(SwiftCore_OPTIMIZATION_REMARKS OFF CACHE STRING "Set opt-remark format") defaulted_set(SwiftCore_OBJECT_FORMAT STRING "Object format: ELF COFF") defaulted_set(SwiftCore_THREADING_PACKAGE STRING "Threading Package: C11 Linux PThreads Win32") option(SwiftCore_INSTALL_NESTED_SUBDIR "Install libraries under a platform and architecture subdirectory" ON) set(SwiftCore_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>$<$:/${SwiftCore_PLATFORM_SUBDIR}/${SwiftCore_ARCH_SUBDIR}>") set(SwiftCore_INSTALL_SWIFTMODULEDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>$<$:/${SwiftCore_PLATFORM_SUBDIR}>") option(SwiftCore_ENABLE_ONONESUPPORT "Enable Onone Support" YES) # TODO: Most of these should be attached to specific targets rather than applied # globally. They can be applied as part of the library interface if they # affect the behavior of libraries that build against a given target. add_compile_definitions( $<$:-DSWIFT_OBJC_INTEROP> $<$:-DSWIFT_LIBRARY_EVOLUTION> $<$:-DSWIFT_HAVE_CRASHREPORTERCLIENT> $<$:-DSWIFT_ENABLE_REFLECTION> $<$:-DSWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS> $<$:-DSWIFT_STDLIB_HAS_STDIN> # core + stubs $<$:-DSWIFT_RUNTIME_OS_VERSIONING> # core + stubs $<$:-DINTERNAL_CHECKS_ENABLED> # core $<$:-DSWIFT_STDLIB_STATIC_PRINT> # core + concurrency $<$:-DSWIFT_STDLIB_ENABLE_UNICODE_DATA> # Stubs $<$:-DSWIFT_STDLIB_HAS_ENVIRON> # Concurrency, runtime, shims, platform overlay $<$:-DSWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT> # Concurrency, Compatibility override, magic symbols $<$:-DSWIFT_STDLIB_HAS_DARWIN_LIBMALLOC> # Anything that includes include/swift/Runtime/Config.h $<$:-DSWIFT_THREADING_${SwiftCore_THREADING_PACKAGE}> $<$:-DSWIFT_RUNTIME_ENABLE_LEAK_CHECKER=$> $<$:-DSWIFT_RUNTIME_CLOBBER_FREED_OBJECTS>) add_compile_options( $<$:-fno-rtti> $<$:-fno-exceptions> $<$:-funwind-tables>) # LNK4049: symbol 'symbol' defined in 'filename.obj' is imported # LNK4286: symbol 'symbol' defined in 'filename_1.obj' is imported by 'filename_2.obj' # LNK4217: symbol 'symbol' defined in 'filename_1.obj' is imported by 'filename_2.obj' in function 'function' # # We cannot selectively filter the linker warnings as we do not use the MSVC # frontned and `clang-cl` (and `clang`) currently do not support `/WX:nnnn`. As # a compromise, treat all linker warnings as errors. add_link_options($<$:LINKER:/WX>) # Ensure all symbols are fully resolved on Linux add_link_options($<$:LINKER:-z,defs>) add_compile_options( $<$:-explicit-module-build> "$<$:-nostdlibimport>" "$<$:SHELL:-swift-version 5>" "$<$:SHELL:-library-level api>" "$<$:SHELL:-runtime-compatibility-version none>" "$<$:-disable-autolinking-runtime-compatibility-dynamic-replacements>" "$<$:SHELL:-Xfrontend -disable-autolinking-runtime-compatibility-concurrency>" "$<$:SHELL:-strict-memory-safety>" "$<$,$>:-save-optimization-record=${SwiftCore_OPTIMIZATION_REMARKS}>" "$<$:-warn-implicit-overrides>" "$<$:SHELL:-Xfrontend -enable-lexical-lifetimes=false>" "$<$:SHELL:-Xfrontend -disable-implicit-concurrency-module-import>" "$<$:SHELL:-Xfrontend -disable-implicit-string-processing-module-import>" "$<$:-no-link-objc-runtime>" "$<$:SHELL:-Xfrontend -enforce-exclusivity=unchecked>" "$<$:SHELL:-Xfrontend -enable-ossa-modules>" "$<$:SHELL:-Xfrontend -empty-abi-descriptor>" "$<$:SHELL:-Xfrontend -target-min-inlining-version -Xfrontend min>" "$<$>,$>:SHELL:-Xfrontend -disable-objc-interop>" "$<$,$>:SHELL:-Xcc -Xclang -Xcc -fbuiltin-headers-in-system-modules>" "$<$,$>:-enable-library-evolution>" "$<$,$>:SHELL:-Xfrontend -prespecialize-generic-metadata>") include(ExperimentalFeatures) include_directories(include) add_subdirectory(LLVMSupport) add_subdirectory(SwiftShims/swift/shims) add_subdirectory(Demangling) add_subdirectory(Threading) add_subdirectory(runtime) add_subdirectory(stubs) add_subdirectory(core) if(SwiftCore_ENABLE_COMMANDLINE_SUPPORT) add_subdirectory(CommandLineSupport) endif() if(SwiftCore_ENABLE_ONONESUPPORT) add_subdirectory(SwiftOnoneSupport) endif() if(SwiftCore_ENABLE_CONCURRENCY) add_subdirectory(Concurrency) endif() if(SwiftCore_ENABLE_REMOTE_MIRROR) add_subdirectory(RemoteInspection) add_subdirectory(SwiftRemoteMirror) endif() # Inter-project install info export(EXPORT SwiftCoreTargets FILE "cmake/SwiftCore/SwiftCoreTargets.cmake") install(EXPORT SwiftCoreTargets DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/SwiftCore" FILE "SwiftCoreTargets.cmake" COMPONENT SwiftCore_cmake) include(CMakePackageConfigHelpers) configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/interface/SwiftCoreConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake/SwiftCore/SwiftCoreConfig.cmake" INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/SwiftCore") write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/cmake/SwiftCore/SwiftCoreConfigVersion.cmake" VERSION "${PROJECT_VERSION}" COMPATIBILITY ExactVersion) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/SwiftCore/SwiftCoreConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/cmake/SwiftCore/SwiftCoreConfigVersion.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/SwiftCore")