|
| 1 | +# Notes: |
| 2 | +# |
| 3 | +# The Demangling library uses `#if SWIFT_HAVE_CRASHREPORTERCLIENT` while the |
| 4 | +# runtime library uses `#ifdef SWIFT_HAVE_CRASHREPORTERCLIENT` to toggle that |
| 5 | +# functionality. When building the demangling library, the macro should be set |
| 6 | +# to 0 or 1 to indicate the presence of the crashreporter. |
| 7 | +# When building the runtime library, the existence of the macro indicates the |
| 8 | +# presence of the crashreporter. |
| 9 | +# |
| 10 | +# Runtime library pulls sources and headers from compiler sources (ThreadSanitizer) |
| 11 | +# Demangling library pulls sources and headers from compiler sources (all) |
| 12 | +# |
| 13 | +# |
| 14 | +# gyb pulls sources from compiler sources |
| 15 | +# |
| 16 | +# Stubs: |
| 17 | +# Pulls in headers from compiler |
| 18 | +# - include/swift/Basic |
| 19 | +# - include/swift/Runtime |
| 20 | +# - include/swift/Threading |
| 21 | + |
| 22 | +# TODO: |
| 23 | +# Platform support: |
| 24 | +# - Work on/Verify cross-compiling |
| 25 | +# - Work on/Verify Windows and Linux native builds |
| 26 | +# Embedded |
| 27 | +# -- -Xfrontend -emit-empty-object-file |
| 28 | +# Catalyst Support |
| 29 | +# -- Will need shadow invocations to generate swiftmodules for Swift parts |
| 30 | +# Install *.abi.json, swiftdoc, and swiftsourceinfo |
| 31 | +# Pointer bounds (SWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS) |
| 32 | + |
| 33 | +cmake_minimum_required(VERSION 3.26...3.29) |
| 34 | + |
| 35 | +set(CMAKE_C_VISIBILITY_PRESET "hidden") |
| 36 | +set(CMAKE_CXX_VISIBILITY_PRESET "hidden") |
| 37 | + |
| 38 | +set(SwiftCore_CMAKE_MODULES_DIR "${CMAKE_SOURCE_DIR}/cmake/modules") |
| 39 | +list(APPEND CMAKE_MODULE_PATH ${SwiftCore_CMAKE_MODULES_DIR}) |
| 40 | + |
| 41 | +include(CMakeWorkarounds) |
| 42 | +project(SwiftCore LANGUAGES C CXX Swift VERSION 6.1) |
| 43 | + |
| 44 | +# The Swift standard library is not intended for use as a sub-library as part of |
| 45 | +# another project. It is tightly coupled with the compiler version. |
| 46 | +if(NOT PROJECT_IS_TOP_LEVEL) |
| 47 | + message(FATAL_ERROR "Swift Core must build as a standalone project") |
| 48 | +endif() |
| 49 | + |
| 50 | +# FIXME: We should not need to refer back into the compiler sources. This is |
| 51 | +# needed by gyb, Demangling, Threading, the runtime (ThreadSanitizer.cpp) |
| 52 | +set(SwiftCore_SWIFTC_SOURCE_DIR |
| 53 | + "${PROJECT_SOURCE_DIR}/../../" |
| 54 | + CACHE FILEPATH "Path to the root source directory of the Swift compiler") |
| 55 | + |
| 56 | +# Hook point for vendor-specific extensions to the build system |
| 57 | +# Allowed extension points: |
| 58 | +# - DefaultSettings.cmake |
| 59 | +# - Settings.cmake |
| 60 | +set(SwiftCore_VENDOR_MODULE_DIR "${SwiftCore_CMAKE_MODULES_DIR}/vendor" |
| 61 | + CACHE FILEPATH "Location for private build system extension") |
| 62 | + |
| 63 | +include(GNUInstallDirs) |
| 64 | +include(AvailabilityMacros) |
| 65 | +include(CompilerSettings) |
| 66 | +include(DefaultSettings) |
| 67 | +include(EmitSwiftInterface) |
| 68 | +include(PlatformInfo) |
| 69 | +include(gyb) |
| 70 | + |
| 71 | +include("${SwiftCore_VENDOR_MODULE_DIR}/Settings.cmake" OPTIONAL) |
| 72 | + |
| 73 | +defaulted_option(SwiftCore_ENABLE_LIBRARY_EVOLUTION "Generate ABI resilient runtime libraries") |
| 74 | + |
| 75 | +defaulted_option(SwiftCore_ENABLE_CRASH_REPORTER_CLIENT "Enable Apple CrashReporter integration") |
| 76 | +defaulted_option(SwiftCore_ENABLE_OBJC_INTEROP "Enable runtime ObjC interop") |
| 77 | +defaulted_option(SwiftCore_ENABLE_TYPE_PRINTING "Enable printing type names") |
| 78 | +defaulted_option(SwiftCore_ENABLE_VECTOR_TYPES "Enable vector support") |
| 79 | +defaulted_option(SwiftCore_ENABLE_REFLECTION "Enable runtime support for mirrors and reflection support") |
| 80 | +defaulted_option(SwiftCore_ENABLE_COMMANDLINE_SUPPORT "Enable command line argument support") |
| 81 | +defaulted_option(SwiftCore_ENABLE_RUNTIME_FUNCTION_COUNTERS "Enable runtime function counter support") |
| 82 | +defaulted_option(SwiftCore_ENABLE_STDIN "Enable functions that use stdin support") |
| 83 | +defaulted_option(SwiftCore_ENABLE_ENVIRONMENT "Enable environment variable support") |
| 84 | +defaulted_option(SwiftCore_ENABLE_OVERRIDABLE_RETAIN_RELEASE "Enable override hooks for retain/release") |
| 85 | +defaulted_option(SwiftCore_ENABLE_MALLOC_TYPE "Enable malloc type information") |
| 86 | +defaulted_option(SwiftCore_ENABLE_RUNTIME_OS_VERSIONING "Enable runtime OS version detection") |
| 87 | +defaulted_option(SwiftCore_ENABLE_STATIC_PRINT "Disable full print") |
| 88 | +defaulted_option(SwiftCore_ENABLE_UNICODE_DATA "Embed Unicode info in Swift Core") |
| 89 | +defaulted_option(SwiftCore_ENABLE_COMPACT_ABSOLUTE_FUNCTION_POINTERS "Resolve absolute function pointer as identity") |
| 90 | +defaulted_option(SwiftCore_ENABLE_BACKDEPLOYMENT_SUPPORT "Add symbols for runtime backdeployment") |
| 91 | + |
| 92 | +defaulted_option(SwiftCore_ENABLE_BACKTRACING "Enable backtracing runtime support") |
| 93 | +defaulted_set(SwiftCore_BACKTRACER_PATH STRING "Set a fixed path to the Swift backtracer") |
| 94 | + |
| 95 | +option(SwiftCore_ENABLE_CLOBBER_FREED_OBJECTS "" OFF) |
| 96 | +option(SwiftCore_ENABLE_RUNTIME_LEAK_CHECKER "" OFF) |
| 97 | +option(SwiftCore_ENABLE_INTERNAL_CHECKS "" OFF) |
| 98 | + |
| 99 | +defaulted_set(SwiftCore_OBJECT_FORMAT STRING "Object format: ELF COFF") |
| 100 | + |
| 101 | +# TODO: Most of these should be attached to specific targets rather than applied |
| 102 | +# globally. They can be applied as part of the library interface if they |
| 103 | +# affect the behavior of libraries that build against a given target. |
| 104 | +add_compile_definitions( |
| 105 | + $<$<BOOL:${SwiftCore_ENABLE_OBJC_INTEROP}>:-DSWIFT_OBJC_INTEROP> |
| 106 | + $<$<BOOL:${SwiftCore_ENABLE_LIBRARY_EVOLUTION}>:-DSWIFT_LIBRARY_EVOLUTION> |
| 107 | + $<$<BOOL:${SwiftCore_ENABLE_CRASH_REPORTER_CLIENT}>:-DSWIFT_HAVE_CRASHREPORTERCLIENT> |
| 108 | + $<$<BOOL:${SwiftCore_ENABLE_VECTOR_TYPES}>:-DSWIFT_STDLIB_ENABLE_VECTOR_TYPES> |
| 109 | + $<$<BOOL:${SwiftCore_ENABLE_REFLECTION}>:-DSWIFT_ENABLE_REFLECTION> |
| 110 | + $<$<BOOL:${SwiftCore_ENABLE_RUNTIME_FUNCTION_COUNTERS}>:-DSWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS> |
| 111 | + $<$<BOOL:${SwiftCore_ENABLE_STDIN}>:-DSWIFT_STDLIB_HAS_STDIN> # core + stubs |
| 112 | + $<$<BOOL:${SwiftCore_ENABLE_RUNTIME_OS_VERSIONING}>:-DSWIFT_RUNTIME_OS_VERSIONING> # core + stubs |
| 113 | + $<$<BOOL:${SwiftCore_ENABLE_INTERNAL_CHECKS}>:-DINTERNAL_CHECKS_ENABLED> # core |
| 114 | + $<$<BOOL:${SwiftCore_ENABLE_STATIC_PRINT}>:-DSWIFT_STDLIB_STATIC_PRINT> # core + concurrency |
| 115 | + $<$<BOOL:${SwiftCore_ENABLE_UNICODE_DATA}>:-DSWIFT_STDLIB_ENABLE_UNICODE_DATA> # Stubs |
| 116 | + $<$<BOOL:${SwiftCore_ENABLE_ENVIRONMENT}>:-DSWIFT_STDLIB_HAS_ENVIRON> # Concurrency, runtime, shims, platform overlay |
| 117 | + $<$<BOOL:${SwiftCore_ENABLE_BACKDEPLOYMENT_SUPPORT}>:-DSWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT> # Concurrency, Compatibility override, magic symbols |
| 118 | + $<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_RUNTIME_ENABLE_LEAK_CHECKER=$<BOOL:${SwiftCore_ENABLE_RUNTIME_LEAK_CHECKER}>> |
| 119 | + $<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_RUNTIME_CLOBBER_FREED_OBJECTS=$<BOOL:${SwiftCore_ENABLE_CLOBBER_FREED_OBJECTS}>>) |
| 120 | + |
| 121 | +add_compile_options($<$<AND:$<COMPILE_LANGUAGE:Swift>,$<BOOL:${SwiftCore_ENABLE_LIBRARY_EVOLUTION}>>:-enable-library-evolution>) |
| 122 | + |
| 123 | +include_directories(include) |
| 124 | + |
| 125 | +add_subdirectory(LLVMSupport) |
| 126 | +add_subdirectory(SwiftShims/swift/shims) |
| 127 | +add_subdirectory(Demangling) |
| 128 | +add_subdirectory(Threading) |
| 129 | +add_subdirectory(runtime) |
| 130 | +add_subdirectory(stubs) |
| 131 | +add_subdirectory(CommandLineSupport) |
| 132 | +add_subdirectory(core) |
0 commit comments