|
| 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 | +if($ENV{BUILD_NUMBER}) |
| 13 | + math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535") |
| 14 | + set(BUILD_NUMBER ".${BUILD_NUMBER}") |
| 15 | +endif() |
| 16 | +project(SwiftVolatile |
| 17 | + LANGUAGES Swift |
| 18 | + VERSION 6.1.0${BUILD_NUMBER}) |
| 19 | +# FIXME(compnerd) this is a workaround for `GNUInstallDirs` which cannot be used |
| 20 | +# with a pure Swift project. |
| 21 | +enable_language(C) |
| 22 | + |
| 23 | +if(NOT PROJECT_IS_TOP_LEVEL) |
| 24 | + message(SEND_ERROR "Swift Observation must build as a standalone project") |
| 25 | +endif() |
| 26 | + |
| 27 | +list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake/modules") |
| 28 | + |
| 29 | +set(${PROJECT_NAME}_SWIFTC_SOURCE_DIR |
| 30 | + "${PROJECT_SOURCE_DIR}/../../../" |
| 31 | + CACHE FILEPATH "Path to the root source directory of the Swift compiler") |
| 32 | + |
| 33 | +# Hook point for vendor-specific extensions to the build system |
| 34 | +# Allowed extension points: |
| 35 | +# - DefaultSettings.cmake |
| 36 | +# - Settings.cmake |
| 37 | +set(${PROJECT_NAME}_VENDOR_MODULE_DIR "${CMAKE_SOURCE_DIR}/../cmake/modules/vendor" |
| 38 | + CACHE FILEPATH "Location for private build system extension") |
| 39 | + |
| 40 | +find_package(SwiftCore REQUIRED) |
| 41 | +find_package(SwiftOverlay REQUIRED) |
| 42 | + |
| 43 | +include(GNUInstallDirs) |
| 44 | + |
| 45 | +include(AvailabilityMacros) |
| 46 | +include(EmitSwiftInterface) |
| 47 | +include(InstallSwiftInterface) |
| 48 | +include(PlatformInfo) |
| 49 | +include(gyb) |
| 50 | +include(ResourceEmbedding) |
| 51 | +include(CatalystSupport) |
| 52 | + |
| 53 | +option(${PROJECT_NAME}_INSTALL_NESTED_SUBDIR "Install libraries under a platform and architecture subdirectory" ON) |
| 54 | +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 "") |
| 55 | +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 "") |
| 56 | + |
| 57 | +include("${${PROJECT_NAME}_VENDOR_MODULE_DIR}/Settings.cmake" OPTIONAL) |
| 58 | + |
| 59 | +option(${PROJECT_NAME}_ENABLE_LIBRARY_EVOLUTION "Generate ABI resilient runtime libraries" |
| 60 | + ${SwiftCore_ENABLE_LIBRARY_EVOLUTION}) |
| 61 | + |
| 62 | +option(${PROJECT_NAME}_ENABLE_PRESPECIALIZATION "Enable generic metadata prespecialization" |
| 63 | + ${SwiftCore_ENABLE_PRESPECIALIZATION}) |
| 64 | + |
| 65 | +add_compile_options( |
| 66 | + $<$<COMPILE_LANGUAGE:Swift>:-explicit-module-build> |
| 67 | + $<$<COMPILE_LANGUAGE:Swift>:-nostdlibimport> |
| 68 | + $<$<COMPILE_LANGUAGE:Swift>:-enable-builtin-module> |
| 69 | + $<$<COMPILE_LANGUAGE:Swift>:-strict-memory-safety> |
| 70 | + "$<$<AND:$<BOOL:${${PROJECT_NAME}_ENABLE_LIBRARY_EVOLUTION}>,$<COMPILE_LANGUAGE:Swift>>:-enable-library-evolution>" |
| 71 | + "$<$<AND:$<BOOL:${${PROJECT_NAME}_ENABLE_PRESPECIALIZATION}>,$<COMPILE_LANGUAGE:Swift>>:SHELL:-Xfrontend -prespecialize-generic-metadata>") |
| 72 | + |
| 73 | +# LNK4049: symbol 'symbol' defined in 'filename.obj' is imported |
| 74 | +# LNK4286: symbol 'symbol' defined in 'filename_1.obj' is imported by 'filename_2.obj' |
| 75 | +# LNK4217: symbol 'symbol' defined in 'filename_1.obj' is imported by 'filename_2.obj' in function 'function' |
| 76 | +# |
| 77 | +# We cannot selectively filter the linker warnings as we do not use the MSVC |
| 78 | +# frontned and `clang-cl` (and `clang`) currently do not support `/WX:nnnn`. As |
| 79 | +# a compromise, treat all linker warnings as errors. |
| 80 | +add_link_options($<$<PLATFORM_ID:Windows>:LINKER:/WX>) |
| 81 | + |
| 82 | +add_library(swiftVolatile |
| 83 | + Volatile.swift) |
| 84 | +set_target_properties(swiftVolatile PROPERTIES |
| 85 | + Swift_MODULE_NAME Volatile) |
| 86 | +target_compile_options(swiftVolatile PRIVATE |
| 87 | + -parse-stdlib) |
| 88 | +target_link_libraries(swiftVolatile PRIVATE |
| 89 | + swiftCore) |
| 90 | + |
| 91 | +install(TARGETS swiftVolatile |
| 92 | + EXPORT SwiftVolatileTargets |
| 93 | + COMPONENT ${PROJECT_NAME}_runtime |
| 94 | + ARCHIVE DESTINATION "${${PROJECT_NAME}_INSTALL_LIBDIR}" |
| 95 | + LIBRARY DESTINATION "${${PROJECT_NAME}_INSTALL_LIBDIR}" |
| 96 | + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") |
| 97 | +emit_swift_interface(swiftVolatile) |
| 98 | +install_swift_interface(swiftVolatile) |
| 99 | + |
| 100 | +# Configure plist creation for Darwin platforms. |
| 101 | +generate_plist("${CMAKE_PROJECT_NAME}" "${CMAKE_PROJECT_VERSION}" swiftVolatile) |
| 102 | +embed_manifest(swiftVolatile) |
| 103 | + |
| 104 | +include("${${PROJECT_NAME}_VENDOR_MODULE_DIR}/swiftVolatile.cmake" OPTIONAL) |
0 commit comments