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 if(POLICY CMP0157 AND CMAKE_Swift_COMPILER_USE_OLD_DRIVER) cmake_policy(SET CMP0157 OLD) endif() list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake/modules" "${CMAKE_SOURCE_DIR}/../../cmake/modules") include(SwiftProjectVersion) project(SwiftSynchronization LANGUAGES Swift VERSION ${SWIFT_RUNTIME_VERSION}) # FIXME(compnerd) this is a workaround for `GNUInstallDirs` which cannot be used # with a pure Swift project. enable_language(C) if(NOT PROJECT_IS_TOP_LEVEL) message(SEND_ERROR "Swift Synchronization must build as a standalone project") endif() set(CMAKE_POSITION_INDEPENDENT_CODE YES) set(${PROJECT_NAME}_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(${PROJECT_NAME}_VENDOR_MODULE_DIR "${CMAKE_SOURCE_DIR}/../cmake/modules/vendor" CACHE FILEPATH "Location for private build system extension") find_package(SwiftCore REQUIRED) find_package(SwiftOverlay) include(GNUInstallDirs) include(AvailabilityMacros) include(EmitSwiftInterface) include(InstallSwiftInterface) include(PlatformInfo) include(gyb) include(ResourceEmbedding) include(CatalystSupport) option(${PROJECT_NAME}_INSTALL_NESTED_SUBDIR "Install libraries under a platform and architecture subdirectory" ON) set(${PROJECT_NAME}_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>$<$:/${${PROJECT_NAME}_PLATFORM_SUBDIR}/${${PROJECT_NAME}_ARCH_SUBDIR}>" CACHE STRING "") set(${PROJECT_NAME}_INSTALL_SWIFTMODULEDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>$<$:/${${PROJECT_NAME}_PLATFORM_SUBDIR}>" CACHE STRING "") include("${${PROJECT_NAME}_VENDOR_MODULE_DIR}/Settings.cmake" OPTIONAL) option(${PROJECT_NAME}_ENABLE_LIBRARY_EVOLUTION "Generate ABI resilient runtime libraries" ${SwiftCore_ENABLE_LIBRARY_EVOLUTION}) option(${PROJECT_NAME}_ENABLE_PRESPECIALIZATION "Enable generic metadata prespecialization" ${SwiftCore_ENABLE_PRESPECIALIZATION}) option(${PROJECT_NAME}_SINGLE_THREADED_MODE "Build Synchronization assuming it will be used in an environment with only a single thread" OFF) add_compile_options( $<$:-explicit-module-build> $<$:-nostdlibimport> $<$:-enable-builtin-module> $<$:-strict-memory-safety> "$<$:SHELL:-swift-version 5>" "$<$:SHELL:-enable-experimental-feature NoncopyableGenerics2>" "$<$:SHELL:-enable-experimental-feature SuppressedAssociatedTypes>" "$<$:SHELL:-enable-experimental-feature SE427NoInferenceOnExtension>" "$<$:SHELL:-enable-experimental-feature NonescapableTypes>" "$<$:SHELL:-enable-experimental-feature LifetimeDependence>" "$<$:SHELL:-enable-experimental-feature InoutLifetimeDependence>" "$<$:SHELL:-enable-experimental-feature LifetimeDependenceMutableAccessors>" "$<$:SHELL:-enable-upcoming-feature MemberImportVisibility>" "$<$:SHELL:-enable-experimental-feature RawLayout>" "$<$:SHELL:-enable-experimental-feature StaticExclusiveOnly>" "$<$:SHELL:-enable-experimental-feature Extern>" "$<$:SHELL:-runtime-compatibility-version none>" "$<$:SHELL:-Xfrontend -disable-autolinking-runtime-compatibility-dynamic-replacements>" "$<$:SHELL:-Xfrontend -disable-autolinking-runtime-compatibility-concurrency>" "$<$:SHELL:-Xfrontend -disable-implicit-concurrency-module-import>" "$<$:SHELL:-Xfrontend -disable-implicit-string-processing-module-import>" "$<$:SHELL:-Xfrontend -enforce-exclusivity=unchecked>" "$<$:SHELL:-Xfrontend -target-min-inlining-version -Xfrontend min>" "$<$:SHELL:-Xfrontend -enable-lexical-lifetimes=false>" "$<$:-warn-implicit-overrides>" "$<$,$>:-enable-library-evolution>" "$<$,$>:SHELL:-Xfrontend -prespecialize-generic-metadata>") # 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>) gyb_expand(Atomics/AtomicIntegers.swift.gyb Atomics/AtomicIntegers.swift) gyb_expand(Atomics/AtomicStorage.swift.gyb Atomics/AtomicStorage.swift) add_library(swiftSynchronization Atomics/Atomic.swift Atomics/AtomicBool.swift Atomics/AtomicFloats.swift Atomics/AtomicLazyReference.swift Atomics/AtomicMemoryOrderings.swift Atomics/AtomicOptional.swift Atomics/AtomicPointers.swift Atomics/AtomicRepresentable.swift Atomics/WordPair.swift Atomics/AtomicStorage.swift Atomics/AtomicIntegers.swift Cell.swift) # Determine Mutex definition if(${PROJECT_NAME}_SINGLE_THREADED_MODE) target_sources(swiftSynchronization PRIVATE Mutex/MutexUnavailable.swift) else() target_sources(swiftSynchronization PRIVATE Mutex/Mutex.swift $<$:Mutex/DarwinImpl.swift> $<$:Mutex/LinuxImpl.swift> $<$:Mutex/SpinLoopHint.swift> $<$:Mutex/WindowsImpl.swift>) endif() set_target_properties(swiftSynchronization PROPERTIES Swift_MODULE_NAME Synchronization) target_link_libraries(swiftSynchronization PRIVATE swiftCore $<$:swiftAndroid> $<$:swiftDarwin> $<$:ClangModules>) if(WIN32 AND CMAKE_SYSTEM_PROCESSOR STREQUAL i686) # FIXME(#83765) `-whole-module-optimization` should not be needed. However, # without this, we will not properly optimize. On Windows i686 in particular, # we observe the formation of `__atomic_load` calls rather than the expected # native sequence. cmake_policy(GET CMP0157 _PolicyCMP0157) if(_PolicyCMP0157 STREQUAL NEW) set_target_properties(swiftSynchronization PROPERTIES Swift_COMPILATION_MODE wholemodule) else() target_compile_options(swiftSynchronization PRIVATE $<$:-whole-module-optimization>) endif() # WMO requires the early-swift-driver to be usable, which is not yet ready on # Windows. Workaround this by creating an empty stub for swiftCore, removing # the import library from the command line, and adding the library search path # associated with it. Due to the autolink, we will still link against the # library from the correct location but will also use an empty file for the # additional input allowing us to perform the WMO. if(CMAKE_Swift_COMPILER_USE_OLD_DRIVER) get_target_property(_swiftCore_IMPORTED_IMPLIB_RELEASE swiftCore IMPORTED_IMPLIB_RELEASE) if(_swiftCore_IMPORTED_IMPLIB_RELEASE) # Compute the library directory to allow us to find the import library by # name. get_filename_component(_swiftCore_IMPORTED_IMPLIB_RELEASE_DIRNAME ${_swiftCore_IMPORTED_IMPLIB_RELEASE} DIRECTORY) # Create a (empty) stub library file(TOUCH "${CMAKE_CURRENT_BINARY_DIR}/swiftCoreStub.lib") # Replace the import library with a stub to bypass the driver and frontend. # Add the library search path to allow linking via autolinking. set_target_properties(swiftCore PROPERTIES IMPORTED_IMPLIB_RELEASE "${CMAKE_CURRENT_BINARY_DIR}/swiftCoreStub.lib" INTERFACE_LINK_DIRECTORIES ${_swiftCore_IMPORTED_IMPLIB_RELEASE_DIRNAME}) endif() endif() endif() install(TARGETS swiftSynchronization EXPORT SwiftSynchronizationTargets COMPONENT ${PROJECT_NAME}_runtime ARCHIVE DESTINATION "${${PROJECT_NAME}_INSTALL_LIBDIR}" LIBRARY DESTINATION "${${PROJECT_NAME}_INSTALL_LIBDIR}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") emit_swift_interface(swiftSynchronization) install_swift_interface(swiftSynchronization) # Configure plist creation for Darwin platforms. generate_plist(swiftSynchronization "${CMAKE_PROJECT_VERSION}" swiftSynchronization) embed_manifest(swiftSynchronization) include("${${PROJECT_NAME}_VENDOR_MODULE_DIR}/swiftSynchronization.cmake" OPTIONAL)