From 694bf42cecb624e81776e7e65e857a1987a91ce3 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 23 Nov 2023 17:34:17 -0800 Subject: [PATCH 1/2] build: simplify the build rules with newer CMake (NFC) Swift now requires CMake 3.19.6 as a minimum version. Assume that we can use CMake newer than 3.16 and simplify the build rules. --- CMakeLists.txt | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e2c28b25..b5c7fb1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,24 +1,12 @@ -cmake_minimum_required(VERSION 3.15.1) +cmake_minimum_required(VERSION 3.19) project(SwiftTSC LANGUAGES C Swift) -set(SWIFT_VERSION 5) -set(CMAKE_Swift_LANGUAGE_VERSION ${SWIFT_VERSION}) -if(CMAKE_VERSION VERSION_LESS 3.16) - add_compile_options($<$:-swift-version$${SWIFT_VERSION}>) - # Workaround for CMake 3.15 which doesn't link libraries properly on Windows - set(CMAKE_LINK_LIBRARY_FLAG "-l") -endif() - +set(CMAKE_Swift_LANGUAGE_VERSION 5) set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift) -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_DISABLE_IN_SOURCE_BUILD YES) From 0b7d13f26cb3c23c261de9ff495452ce4d534d23 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 23 Nov 2023 17:45:10 -0800 Subject: [PATCH 2/2] build: auto-Vendor SwiftSystem when not provided When SwiftSystem is not provided to be built against explicitly (i.e. `-D SwiftSystem_DIR=...`), vendor a copy of SwiftSystem to allow the library to be built by including and building its dependencies. This behaviour is similar to how SPM based builds function. --- CMakeLists.txt | 19 ++++++++++++++++++- Sources/TSCBasic/CMakeLists.txt | 4 ++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b5c7fb1f..0ce75443 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,7 @@ +if(POLICY CMP0028) + cmake_policy(SET CMP0028 NEW) +endif() + cmake_minimum_required(VERSION 3.19) project(SwiftTSC LANGUAGES C Swift) @@ -13,10 +17,23 @@ set(CMAKE_DISABLE_IN_SOURCE_BUILD YES) option(BUILD_SHARED_LIBS "Build shared libraries by default" YES) +# Toolchain bundled libraries find_package(dispatch QUIET) find_package(Foundation QUIET) + +# System Packages find_package(Threads QUIET) -find_package(SwiftSystem CONFIG REQUIRED) + +# Package Dependencies +find_package(SwiftSystem CONFIG) +if(NOT SwiftSystem_FOUND) + include(FetchContent) + message("-- Vendoring SwiftSystem") + FetchContent_Declare(SwiftSystem + GIT_REPOSITORY https://github.com/apple/swift-system + GIT_TAG 1.1.1) + FetchContent_MakeAvailable(SwiftSystem) +endif() add_subdirectory(Sources) add_subdirectory(cmake/modules) diff --git a/Sources/TSCBasic/CMakeLists.txt b/Sources/TSCBasic/CMakeLists.txt index 1217bdfc..97d70b51 100644 --- a/Sources/TSCBasic/CMakeLists.txt +++ b/Sources/TSCBasic/CMakeLists.txt @@ -6,6 +6,10 @@ # See http://swift.org/LICENSE.txt for license information # See http://swift.org/CONTRIBUTORS.txt for Swift project authors +if(NOT SwiftSystem_FOUND) + add_library(SwiftSystem::SystemPackage ALIAS SystemPackage) +endif() + add_library(TSCBasic Await.swift ByteString.swift