|
| 1 | +cmake_minimum_required(VERSION 3.29) |
| 2 | +# TODO before requiring CMake 4.1 or later |
| 3 | +# and/or enforcing CMP0195, please check/update |
| 4 | +# the implementation of `emit_swift_interface` |
| 5 | +# in `EmitSwiftInterface.cmake` |
| 6 | +# to ensure it keeps laying down nested swiftmodule folders |
| 7 | + |
| 8 | +if(POLICY CMP0157 AND CMAKE_Swift_COMPILER_USE_OLD_DRIVER) |
| 9 | + cmake_policy(SET CMP0157 OLD) |
| 10 | +endif() |
| 11 | + |
| 12 | +list(APPEND CMAKE_MODULE_PATH |
| 13 | + "${CMAKE_SOURCE_DIR}/../cmake/modules" |
| 14 | + "${CMAKE_SOURCE_DIR}/../../cmake/modules") |
| 15 | + |
| 16 | +include(SwiftProjectVersion) |
| 17 | +project(SwiftRuntime |
| 18 | + LANGUAGES Swift CXX |
| 19 | + VERSION ${SWIFT_RUNTIME_VERSION}) |
| 20 | + |
| 21 | +if(NOT PROJECT_IS_TOP_LEVEL) |
| 22 | + message(SEND_ERROR "Swift Runtime must build as a standalone project") |
| 23 | +endif() |
| 24 | + |
| 25 | +include(AsmSupport) |
| 26 | +enable_asm_language() |
| 27 | + |
| 28 | +set(CMAKE_CXX_STANDARD 17) |
| 29 | +set(CMAKE_CXX_STANDARD_REQUIRED YES) |
| 30 | +set(CMAKE_CXX_EXTENSIONS NO) |
| 31 | +set(CMAKE_POSITION_INDEPENDENT_CODE YES) |
| 32 | + |
| 33 | +set(${PROJECT_NAME}_SWIFTC_SOURCE_DIR |
| 34 | + "${PROJECT_SOURCE_DIR}/../../../" |
| 35 | + CACHE FILEPATH "Path to the root source directory of the Swift compiler") |
| 36 | + |
| 37 | +# Hook point for vendor-specific extensions to the build system |
| 38 | +# Allowed extension points: |
| 39 | +# - DefaultSettings.cmake |
| 40 | +# - Settings.cmake |
| 41 | +set(${PROJECT_NAME}_VENDOR_MODULE_DIR "${CMAKE_SOURCE_DIR}/../cmake/modules/vendor" |
| 42 | + CACHE FILEPATH "Location for private build system extension") |
| 43 | + |
| 44 | +find_package(SwiftCore REQUIRED) |
| 45 | +find_package(SwiftOverlay REQUIRED) |
| 46 | +#find_package(SwiftDarwin) |
| 47 | + |
| 48 | +include(GNUInstallDirs) |
| 49 | + |
| 50 | +include(AvailabilityMacros) |
| 51 | +include(EmitSwiftInterface) |
| 52 | +include(InstallSwiftInterface) |
| 53 | +include(PlatformInfo) |
| 54 | +include(gyb) |
| 55 | +include(ResourceEmbedding) |
| 56 | +include(CatalystSupport) |
| 57 | + |
| 58 | +option(${PROJECT_NAME}_INSTALL_NESTED_SUBDIR "Install libraries under a platform and architecture subdirectory" ON) |
| 59 | +set(${PROJECT_NAME}_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>$<$<BOOL:${${PROJECT_NAME}_INSTALL_NESTED_SUBDIR}>:/${${PROJECT_NAME}_PLATFORM_SUBDIR}/${${PROJECT_NAME}_ARCH_SUBDIR}>" CACHE STRING "") |
| 60 | +set(${PROJECT_NAME}_INSTALL_SWIFTMODULEDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>$<$<BOOL:${${PROJECT_NAME}_INSTALL_NESTED_SUBDIR}>:/${${PROJECT_NAME}_PLATFORM_SUBDIR}>" CACHE STRING "") |
| 61 | + |
| 62 | +include("${${PROJECT_NAME}_VENDOR_MODULE_DIR}/Settings.cmake" OPTIONAL) |
| 63 | + |
| 64 | +option(${PROJECT_NAME}_ENABLE_LIBRARY_EVOLUTION "Generate ABI resilient runtime libraries" |
| 65 | + ${SwiftCore_ENABLE_LIBRARY_EVOLUTION}) |
| 66 | + |
| 67 | +option(${PROJECT_NAME}_ENABLE_PRESPECIALIZATION "Enable generic metadata prespecialization" |
| 68 | + ${SwiftCore_ENABLE_PRESPECIALIZATION}) |
| 69 | + |
| 70 | +add_compile_options( |
| 71 | + $<$<COMPILE_LANGUAGE:Swift>:-explicit-module-build> |
| 72 | + $<$<COMPILE_LANGUAGE:Swift>:-nostdlibimport> |
| 73 | + $<$<COMPILE_LANGUAGE:Swift>:-parse-stdlib> |
| 74 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-swift-version 5>" |
| 75 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -enforce-exclusivity=unchecked>" |
| 76 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -target-min-inlining-version -Xfrontend min>" |
| 77 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-implicit-string-processing-module-import>" |
| 78 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature NoncopyableGenerics2>" |
| 79 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature SuppressedAssociatedTypes>" |
| 80 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature SE427NoInferenceOnExtension>" |
| 81 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature NonescapableTypes>" |
| 82 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature LifetimeDependence>" |
| 83 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature InoutLifetimeDependence>" |
| 84 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature LifetimeDependenceMutableAccessors>" |
| 85 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-disable-upcoming-feature MemberImportVisibility>" |
| 86 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -enable-lexical-lifetimes=false>" |
| 87 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -enable-ossa-modules>" |
| 88 | + "$<$<COMPILE_LANGUAGE:Swift>:-warn-implicit-overrides>" |
| 89 | + "$<$<COMPILE_LANGUAGE:Swift>:-cxx-interoperability-mode=default>" |
| 90 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -experimental-spi-only-imports>" |
| 91 | + "$<$<AND:$<BOOL:${${PROJECT_NAME}_ENABLE_LIBRARY_EVOLUTION}>,$<COMPILE_LANGUAGE:Swift>>:-enable-library-evolution>" |
| 92 | + "$<$<AND:$<BOOL:${${PROJECT_NAME}_ENABLE_PRESPECIALIZATION}>,$<COMPILE_LANGUAGE:Swift>>:SHELL:-Xfrontend -prespecialize-generic-metadata>") |
| 93 | + |
| 94 | +# LNK4049: symbol 'symbol' defined in 'filename.obj' is imported |
| 95 | +# LNK4286: symbol 'symbol' defined in 'filename_1.obj' is imported by 'filename_2.obj' |
| 96 | +# LNK4217: symbol 'symbol' defined in 'filename_1.obj' is imported by 'filename_2.obj' in function 'function' |
| 97 | +# |
| 98 | +# We cannot selectively filter the linker warnings as we do not use the MSVC |
| 99 | +# frontned and `clang-cl` (and `clang`) currently do not support `/WX:nnnn`. As |
| 100 | +# a compromise, treat all linker warnings as errors. |
| 101 | +add_link_options($<$<PLATFORM_ID:Windows>:LINKER:/WX>) |
| 102 | +# Ensure all symbols are fully resolved on Linux |
| 103 | +add_link_options($<$<PLATFORM_ID:Linux>:LINKER:-z,defs>) |
| 104 | + |
| 105 | +add_library(swiftRuntime |
| 106 | + Address.swift |
| 107 | + Backtrace.swift |
| 108 | + Backtrace+Codable.swift |
| 109 | + BacktraceFormatter.swift |
| 110 | + Base64.swift |
| 111 | + ByteSwapping.swift |
| 112 | + CachingMemoryReader.swift |
| 113 | + CompactBacktrace.swift |
| 114 | + CompactImageMap.swift |
| 115 | + Compression.swift |
| 116 | + Context.swift |
| 117 | + CoreSymbolication.swift |
| 118 | + Dwarf.swift |
| 119 | + EightByteBuffer.swift |
| 120 | + Elf.swift |
| 121 | + ElfImageCache.swift |
| 122 | + FramePointerUnwinder.swift |
| 123 | + Image.swift |
| 124 | + ImageMap.swift |
| 125 | + ImageMap+Darwin.swift |
| 126 | + ImageMap+Linux.swift |
| 127 | + ImageSource.swift |
| 128 | + Libc.swift |
| 129 | + LimitSequence.swift |
| 130 | + MemoryReader.swift |
| 131 | + OSReleaseScanner.swift |
| 132 | + ProcMapsScanner.swift |
| 133 | + Registers.swift |
| 134 | + Runtime.swift |
| 135 | + RichFrame.swift |
| 136 | + SymbolicatedBacktrace.swift |
| 137 | + Utils.swift |
| 138 | + Win32Extras.cpp |
| 139 | + get-cpu-context.${SWIFT_ASM_EXT}) |
| 140 | + |
| 141 | +set_target_properties(swiftRuntime PROPERTIES |
| 142 | + Swift_MODULE_NAME Runtime) |
| 143 | +target_compile_definitions(swiftRuntime PRIVATE |
| 144 | + SWIFT_ASM_AVAILABLE) |
| 145 | +target_compile_options(swiftRuntime PRIVATE |
| 146 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -fmodule-map-file=${CMAKE_CURRENT_SOURCE_DIR}/modules/module.modulemap>") |
| 147 | +# FIXME: We should split out the parts that are needed by the runtime to avoid |
| 148 | +# pulling in headers from the compiler. |
| 149 | +target_include_directories(swiftRuntime PRIVATE |
| 150 | + "${${PROJECT_NAME}_SWIFTC_SOURCE_DIR}/include") |
| 151 | +target_link_libraries(swiftRuntime PRIVATE |
| 152 | + swiftShims |
| 153 | + swiftCore |
| 154 | + swift_Concurrency |
| 155 | + swiftCxxStdlib |
| 156 | + $<$<PLATFORM_ID:Android>:swiftAndroid> |
| 157 | + #$<$<PLATFORM_ID:Darwin>:swiftDarwin> |
| 158 | + $<$<PLATFORM_ID:Linux>:swiftGlibc> |
| 159 | + $<$<PLATFORM_ID:Windows>:swiftWinSDK>) |
| 160 | + |
| 161 | +install(TARGETS swiftRuntime |
| 162 | + EXPORT SwiftRuntimeTargets |
| 163 | + COMPONENT ${PROJECT_NAME}_runtime |
| 164 | + ARCHIVE DESTINATION "${${PROJECT_NAME}_INSTALL_LIBDIR}" |
| 165 | + LIBRARY DESTINATION "${${PROJECT_NAME}_INSTALL_LIBDIR}" |
| 166 | + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") |
| 167 | +emit_swift_interface(swiftRuntime) |
| 168 | +install_swift_interface(swiftRuntime) |
| 169 | + |
| 170 | +# Configure plist creation for Darwin platforms. |
| 171 | +generate_plist(swiftRuntime "${CMAKE_PROJECT_VERSION}" swiftRuntime) |
| 172 | +embed_manifest(swiftRuntime) |
| 173 | + |
| 174 | +include("${${PROJECT_NAME}_VENDOR_MODULE_DIR}/SwiftRuntime.cmake" OPTIONAL) |
0 commit comments