diff --git a/Runtimes/Core/CMakeLists.txt b/Runtimes/Core/CMakeLists.txt index 14e7d86d5bb1e..c255750512c31 100644 --- a/Runtimes/Core/CMakeLists.txt +++ b/Runtimes/Core/CMakeLists.txt @@ -43,23 +43,16 @@ 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}) +list(APPEND CMAKE_MODULE_PATH + ${SwiftCore_CMAKE_MODULES_DIR} + "${CMAKE_SOURCE_DIR}/../cmake/modules") include(CMakeWorkarounds) -# NOTE: always use the 3-component style as the expansion as -# `${PROJECT_VERSION}` will not extend this to the complete form and this can -# change the behaviour for comparison with non-SemVer compliant parsing. If -# possible, use the 4-version component as that is used to differentiate the -# builds of the runtime for Windows. -if($ENV{BUILD_NUMBER}) - # NOTE: SxS modules have a limit on each component being [0-65535]. - # https://learn.microsoft.com/en-us/windows/win32/sbscs/assembly-versions - math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535") - set(BUILD_NUMBER ".${BUILD_NUMBER}") -endif() + +include(SwiftProjectVersion) project(SwiftCore LANGUAGES C CXX Swift - VERSION 6.3.0${BUILD_NUMBER}) + 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. diff --git a/Runtimes/Overlay/CMakeLists.txt b/Runtimes/Overlay/CMakeLists.txt index 4aeef13e5f025..5f60cff85ed9e 100644 --- a/Runtimes/Overlay/CMakeLists.txt +++ b/Runtimes/Overlay/CMakeLists.txt @@ -10,26 +10,18 @@ set(CMAKE_C_VISIBILITY_PRESET "hidden") set(CMAKE_CXX_VISIBILITY_PRESET "hidden") set(CMAKE_VISIBILITY_INLINES_HIDDEN YES) -list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules") +list(APPEND CMAKE_MODULE_PATH + "${CMAKE_SOURCE_DIR}/cmake/modules" + "${CMAKE_SOURCE_DIR}/../cmake/modules") if(POLICY CMP0157 AND CMAKE_Swift_COMPILER_USE_OLD_DRIVER) cmake_policy(SET CMP0157 OLD) endif() -# NOTE: always use the 3-component style as the expansion as -# `${PROJECT_VERSION}` will not extend this to the complete form and this can -# change the behaviour for comparison with non-SemVer compliant parsing. If -# possible, use the 4-version component as that is used to differentiate the -# builds of the runtime for Windows. -if($ENV{BUILD_NUMBER}) - # NOTE: SxS modules have a limit on each component being [0-65535]. - # https://learn.microsoft.com/en-us/windows/win32/sbscs/assembly-versions - math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535") - set(BUILD_NUMBER ".${BUILD_NUMBER}") -endif() +include(SwiftProjectVersion) project(SwiftOverlay LANGUAGES C CXX Swift - VERSION 6.3.0${BUILD_NUMBER}) + VERSION ${SWIFT_RUNTIME_VERSION}) set(CMAKE_Swift_LANGUAGE_VERSION 5) diff --git a/Runtimes/Supplemental/Differentiation/CMakeLists.txt b/Runtimes/Supplemental/Differentiation/CMakeLists.txt index fe52dfba8cb36..20cc38a989fbd 100644 --- a/Runtimes/Supplemental/Differentiation/CMakeLists.txt +++ b/Runtimes/Supplemental/Differentiation/CMakeLists.txt @@ -9,13 +9,14 @@ if(POLICY CMP0157 AND CMAKE_Swift_COMPILER_USE_OLD_DRIVER) cmake_policy(SET CMP0157 OLD) endif() -if($ENV{BUILD_NUMBER}) - math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535") - set(BUILD_NUMBER ".${BUILD_NUMBER}") -endif() +list(APPEND CMAKE_MODULE_PATH + "${CMAKE_SOURCE_DIR}/../cmake/modules" + "${CMAKE_SOURCE_DIR}/../../cmake/modules") + +include(SwiftProjectVersion) project(SwiftDifferentiation LANGUAGES Swift C - VERSION 6.3.0${BUILD_NUMBER}) + VERSION ${SWIFT_RUNTIME_VERSION}) if(NOT PROJECT_IS_TOP_LEVEL) message(SEND_ERROR "Swift Differentiation must build as a standalone project") @@ -24,8 +25,6 @@ endif() set(CMAKE_POSITION_INDEPENDENT_CODE YES) set(CMAKE_Swift_LANGUAGE_VERSION 5) -list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake/modules") - set(${PROJECT_NAME}_SWIFTC_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../../../" CACHE FILEPATH "Path to the root source directory of the Swift compiler") diff --git a/Runtimes/Supplemental/Distributed/CMakeLists.txt b/Runtimes/Supplemental/Distributed/CMakeLists.txt index a6b7a90719dc6..53a278ad4b1d1 100644 --- a/Runtimes/Supplemental/Distributed/CMakeLists.txt +++ b/Runtimes/Supplemental/Distributed/CMakeLists.txt @@ -9,13 +9,14 @@ if(POLICY CMP0157 AND CMAKE_Swift_COMPILER_USE_OLD_DRIVER) cmake_policy(SET CMP0157 OLD) endif() -if($ENV{BUILD_NUMBER}) - math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535") - set(BUILD_NUMBER ".${BUILD_NUMBER}") -endif() +list(APPEND CMAKE_MODULE_PATH + "${CMAKE_SOURCE_DIR}/../cmake/modules" + "${CMAKE_SOURCE_DIR}/../../cmake/modules") + +include(SwiftProjectVersion) project(SwiftDistributed LANGUAGES C CXX Swift - VERSION 6.3.0${BUILD_NUMBER}) + VERSION ${SWIFT_RUNTIME_VERSION}) if(NOT PROJECT_IS_TOP_LEVEL) message(SEND_ERROR "Swift Distributed must build as a standalone project") @@ -34,8 +35,6 @@ set(CMAKE_CXX_VISIBILITY_PRESET "hidden") set(CMAKE_VISIBILITY_INLINES_HIDDEN YES) -list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake/modules") - set(${PROJECT_NAME}_SWIFTC_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../../../" CACHE FILEPATH "Path to the root source directory of the Swift compiler") diff --git a/Runtimes/Supplemental/Observation/CMakeLists.txt b/Runtimes/Supplemental/Observation/CMakeLists.txt index f2511f6ac5bda..2669df6aeb792 100644 --- a/Runtimes/Supplemental/Observation/CMakeLists.txt +++ b/Runtimes/Supplemental/Observation/CMakeLists.txt @@ -9,13 +9,14 @@ if(POLICY CMP0157 AND CMAKE_Swift_COMPILER_USE_OLD_DRIVER) cmake_policy(SET CMP0157 OLD) endif() -if($ENV{BUILD_NUMBER}) - math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535") - set(BUILD_NUMBER ".${BUILD_NUMBER}") -endif() +list(APPEND CMAKE_MODULE_PATH + "${CMAKE_SOURCE_DIR}/../cmake/modules" + "${CMAKE_SOURCE_DIR}/../../cmake/modules") + +include(SwiftProjectVersion) project(SwiftObservation LANGUAGES Swift CXX - VERSION 6.3.0${BUILD_NUMBER}) + VERSION ${SWIFT_RUNTIME_VERSION}) if(NOT PROJECT_IS_TOP_LEVEL) message(SEND_ERROR "Swift Observation must build as a standalone project") @@ -26,8 +27,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED YES) set(CMAKE_CXX_EXTENSIONS NO) set(CMAKE_POSITION_INDEPENDENT_CODE YES) -list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake/modules") - set(${PROJECT_NAME}_SWIFTC_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../../../" CACHE FILEPATH "Path to the root source directory of the Swift compiler") diff --git a/Runtimes/Supplemental/StringProcessing/CMakeLists.txt b/Runtimes/Supplemental/StringProcessing/CMakeLists.txt index 32e7fd642a839..abd97d3a918f6 100644 --- a/Runtimes/Supplemental/StringProcessing/CMakeLists.txt +++ b/Runtimes/Supplemental/StringProcessing/CMakeLists.txt @@ -9,13 +9,15 @@ if(POLICY CMP0157 AND CMAKE_Swift_COMPILER_USE_OLD_DRIVER) cmake_policy(SET CMP0157 OLD) endif() -if($ENV{BUILD_NUMBER}) - math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535") - set(BUILD_NUMBER ".${BUILD_NUMBER}") -endif() + +list(APPEND CMAKE_MODULE_PATH + "${CMAKE_SOURCE_DIR}/../cmake/modules" + "${CMAKE_SOURCE_DIR}/../../cmake/modules") + +include(SwiftProjectVersion) project(SwiftStringProcessing LANGUAGES Swift C - VERSION 6.3.0${BUILD_NUMBER}) + VERSION ${SWIFT_RUNTIME_VERSION}) if(NOT PROJECT_IS_TOP_LEVEL) message(FATAL_ERROR "Swift StringProcessing must build as a standalone project") @@ -23,8 +25,6 @@ endif() set(CMAKE_POSITION_INDEPENDENT_CODE YES) -list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake/modules") - set(${PROJECT_NAME}_SWIFTC_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../../../" CACHE FILEPATH "Path to the root source directory of the Swift compiler") diff --git a/Runtimes/Supplemental/Synchronization/CMakeLists.txt b/Runtimes/Supplemental/Synchronization/CMakeLists.txt index 3521f4d5035a0..4c25130b1c81e 100644 --- a/Runtimes/Supplemental/Synchronization/CMakeLists.txt +++ b/Runtimes/Supplemental/Synchronization/CMakeLists.txt @@ -9,13 +9,15 @@ if(POLICY CMP0157 AND CMAKE_Swift_COMPILER_USE_OLD_DRIVER) cmake_policy(SET CMP0157 OLD) endif() -if($ENV{BUILD_NUMBER}) - math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535") - set(BUILD_NUMBER ".${BUILD_NUMBER}") -endif() +list(APPEND CMAKE_MODULE_PATH + "${CMAKE_SOURCE_DIR}/../cmake/modules" + "${CMAKE_SOURCE_DIR}/../../cmake/modules") + +include(SwiftProjectVersion) project(SwiftSynchronization LANGUAGES Swift - VERSION 6.3.0${BUILD_NUMBER}) + VERSION ${SWIFT_RUNTIME_VERSION}) + # FIXME(compnerd) this is a workaround for `GNUInstallDirs` which cannot be used # with a pure Swift project. enable_language(C) @@ -26,8 +28,6 @@ endif() set(CMAKE_POSITION_INDEPENDENT_CODE YES) -list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake/modules") - set(${PROJECT_NAME}_SWIFTC_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../../../" CACHE FILEPATH "Path to the root source directory of the Swift compiler") diff --git a/Runtimes/Supplemental/Volatile/CMakeLists.txt b/Runtimes/Supplemental/Volatile/CMakeLists.txt index fcb250cc8e210..a0daab7542552 100644 --- a/Runtimes/Supplemental/Volatile/CMakeLists.txt +++ b/Runtimes/Supplemental/Volatile/CMakeLists.txt @@ -9,13 +9,15 @@ if(POLICY CMP0157 AND CMAKE_Swift_COMPILER_USE_OLD_DRIVER) cmake_policy(SET CMP0157 OLD) endif() -if($ENV{BUILD_NUMBER}) - math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535") - set(BUILD_NUMBER ".${BUILD_NUMBER}") -endif() +list(APPEND CMAKE_MODULE_PATH + "${CMAKE_SOURCE_DIR}/../cmake/modules" + "${CMAKE_SOURCE_DIR}/../../cmake/modules") + +include(SwiftProjectVersion) project(SwiftVolatile LANGUAGES Swift - VERSION 6.3.0${BUILD_NUMBER}) + VERSION ${SWIFT_RUNTIME_VERSION}) + # FIXME(compnerd) this is a workaround for `GNUInstallDirs` which cannot be used # with a pure Swift project. enable_language(C) @@ -24,8 +26,6 @@ if(NOT PROJECT_IS_TOP_LEVEL) message(SEND_ERROR "Swift Observation must build as a standalone project") endif() -list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake/modules") - set(${PROJECT_NAME}_SWIFTC_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../../../" CACHE FILEPATH "Path to the root source directory of the Swift compiler") diff --git a/Runtimes/cmake/modules/SwiftProjectVersion.cmake b/Runtimes/cmake/modules/SwiftProjectVersion.cmake new file mode 100644 index 0000000000000..36b7ae6b2db63 --- /dev/null +++ b/Runtimes/cmake/modules/SwiftProjectVersion.cmake @@ -0,0 +1,23 @@ +# This module sets the Swift version number variable consistently across the +# Swift runtime projects. + +## Result Variable +# +# ``SWIFT_RUNTIME_VERSION`` +# The computed version number applied to apply to the project. +# If ``SWIFT_RUNTIME_VERSION`` is set prior to entering the module, the version +# is not modified. + +block(PROPAGATE SWIFT_RUNTIME_VERSION) + if(SWIFT_RUNTIME_VERSION) + return() + endif() + + if($ENV{BUILD_NUMBER}) + # Microsoft build numbers limit each version number component to [0 - 65535] + # https://learn.microsoft.com/en-us/windows/win32/sbscs/assembly-versions + math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535") + set(BUILD_NUMBER ".${BUILD_NUMBER}") + endif() + set(SWIFT_RUNTIME_VERSION 6.3.0${BUILD_NUMBER}) +endblock()