From 281a92df6ca5515d5db9c81282a180cf20b2acc7 Mon Sep 17 00:00:00 2001 From: Si Beaumont Date: Wed, 4 Nov 2026 11:55:03 +0000 Subject: [PATCH] Build the CMake targets in the Swift 6 language mode (#501) ### Motivation: `Package.swift` uses tools version 6.2 and declares no `swiftLanguageModes`, so SwiftPM builds Swift Crypto in the Swift 6 language mode. The CMake build passes no `-swift-version`, so the compiler falls back to the Swift 5 language mode. The two build systems compile the same sources in different language modes. ### Modifications: - Set `CMAKE_Swift_LANGUAGE_VERSION` to 6 after the swift-asn1 `FetchContent` block, so swift-asn1 keeps its own language mode when CMake fetches it. - Raise the minimum CMake version to 3.16, the release that added `Swift_LANGUAGE_VERSION`. - Remove the branch that set Windows output directories for CMake versions before 3.16. ### Result: CMake builds Swift Crypto in the Swift 6 language mode, as SwiftPM does. --- CMakeLists.txt | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fd9da589..7334106a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ ## ##===----------------------------------------------------------------------===## -cmake_minimum_required(VERSION 3.15.1) +cmake_minimum_required(VERSION 3.16) if(POLICY CMP0157) cmake_policy(SET CMP0157 NEW) @@ -25,13 +25,8 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) include(SwiftSupport) -if(CMAKE_VERSION VERSION_LESS 3.16 AND CMAKE_SYSTEM_NAME STREQUAL Windows) - set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) -else() - set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) -endif() +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift) @@ -79,5 +74,8 @@ if(NOT SwiftASN1_FOUND) FetchContent_MakeAvailable(ASN1) endif() +# Set after vending swift-asn1 so its targets keep their own language mode. +set(CMAKE_Swift_LANGUAGE_VERSION 6) + add_subdirectory(Sources) add_subdirectory(cmake/modules)