diff --git a/Meta/CMake/FindSwiftTesting.cmake b/Meta/CMake/FindSwiftTesting.cmake new file mode 100644 index 00000000000..5ece653dcd1 --- /dev/null +++ b/Meta/CMake/FindSwiftTesting.cmake @@ -0,0 +1,45 @@ +# Finds the swift-testing library +# On Apple platforms, this is a framework included in the Xcode release + +# FIXME: Using Xcode's library actually doesn't work for rpath reasons +# When swift-testing ships better toolchain CMake support, we'll need to revisit this + +include(FetchContent) + +# Allow the Ninja generators to output messages as they happen by assigning +# these jobs to the 'console' job pool +set(console_access "") +if(CMAKE_GENERATOR MATCHES "^Ninja") + set(console_access + USES_TERMINAL_CONFIGURE YES + USES_TERMINAL_BUILD YES + USES_TERMINAL_INSTALL YES + ) +endif() + +set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE OPT_IN) +FetchContent_Declare(SwiftTesting + GIT_REPOSITORY https://github.com/swiftlang/swift-testing.git + GIT_TAG d00d46920f9bb35342ad29398ea4740a2bbf3d38 + PATCH_COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_LIST_DIR}/patches/git-patch.cmake" + "${CMAKE_CURRENT_LIST_DIR}/patches/swift-testing//0001-CMake-Allow-ExternalProjects-to-use-console-with-Nin.patch" + OVERRIDE_FIND_PACKAGE + SYSTEM + ${console_access} +) + +block() + add_cxx_compile_options(-Wno-error) + set(SwiftTesting_MACRO "") + FetchContent_MakeAvailable(SwiftTesting) + add_cxx_compile_options(-Werror) +endblock() + +if (NOT TARGET SwiftTesting::SwiftTesting) + # FIXME: This should be an interface property on the target itself, if the maintainers intend + # for the repository to be fetch-content-able + set_property(TARGET Testing APPEND PROPERTY INTERFACE_COMPILE_OPTIONS "$<$:SHELL:-load-plugin-executable ${CMAKE_BINARY_DIR}/bin/TestingMacros#TestingMacros>") + add_library(SwiftTesting::SwiftTesting ALIAS Testing) + set(SwiftTesting_LIBRARIES SwiftTesting::SwiftTesting) +endif() +set(SwiftTesting_FOUND TRUE) diff --git a/Meta/CMake/patches/swift-testing/0001-CMake-Allow-ExternalProjects-to-use-console-with-Nin.patch b/Meta/CMake/patches/swift-testing/0001-CMake-Allow-ExternalProjects-to-use-console-with-Nin.patch new file mode 100644 index 00000000000..148eaf7927a --- /dev/null +++ b/Meta/CMake/patches/swift-testing/0001-CMake-Allow-ExternalProjects-to-use-console-with-Nin.patch @@ -0,0 +1,68 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Andrew Kaster +Date: Mon, 26 Aug 2024 21:35:45 -0600 +Subject: [PATCH] [CMake] Allow ExternalProjects to use console with Ninja + generator + +Also stop forcing the SwiftMacros project to build every rebuild. +--- + Sources/CMakeLists.txt | 13 ++++++++++++- + Sources/TestingMacros/CMakeLists.txt | 14 +++++++++++++- + 2 files changed, 25 insertions(+), 2 deletions(-) + +diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt +index 83a9a2b2330c9847ebac89e273c6ade9bf398a25..d917509ba47c2ddaf6b7a2d7d17de2afaabc68fd 100644 +--- a/Sources/CMakeLists.txt ++++ b/Sources/CMakeLists.txt +@@ -43,10 +43,21 @@ if(SwiftTesting_MACRO STREQUAL "") + # Build and install the plugin into the current build directry. + set(SwiftTesting_MACRO_INSTALL_PREFIX "${CMAKE_BINARY_DIR}") + ++ # Allow the Ninja generators to output messages as they happen by assigning ++ # these jobs to the 'console' job pool ++ set(SwiftTesting_ConsoleAccess "") ++ if(CMAKE_GENERATOR MATCHES "^Ninja") ++ set(SwiftTesting_ConsoleAccess ++ USES_TERMINAL_CONFIGURE YES ++ USES_TERMINAL_BUILD YES ++ USES_TERMINAL_INSTALL YES) ++ endif() ++ + ExternalProject_Add(TestingMacros + PREFIX "tm" + SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/TestingMacros" +- BUILD_ALWAYS ON ++ BUILD_ALWAYS OFF ++ ${SwiftTesting_ConsoleAccess} + CMAKE_ARGS + -DCMAKE_MAKE_PROGRAM=${SwiftTesting_MACRO_MAKE_PROGRAM} + -DCMAKE_Swift_COMPILER=${SwiftTesting_MACRO_Swift_COMPILER} +diff --git a/Sources/TestingMacros/CMakeLists.txt b/Sources/TestingMacros/CMakeLists.txt +index a45663025a43adf39d17f0d94d692c9bf6092194..aa9939079ff18dee00288bf7fb0c92c124438228 100644 +--- a/Sources/TestingMacros/CMakeLists.txt ++++ b/Sources/TestingMacros/CMakeLists.txt +@@ -28,11 +28,23 @@ if(SwiftTesting_BuildMacrosAsExecutables) + # When building the macro plugin as an executable, clone and build + # swift-syntax. + include(FetchContent) ++ ++ # Allow the Ninja generators to output messages as they happen by assigning ++ # these jobs to the 'console' job pool ++ set(SwiftTesting_ConsoleAccess "") ++ if(CMAKE_GENERATOR MATCHES "^Ninja") ++ set(SwiftTesting_ConsoleAccess ++ USES_TERMINAL_CONFIGURE YES ++ USES_TERMINAL_BUILD YES ++ USES_TERMINAL_INSTALL YES) ++ endif() ++ + set(FETCHCONTENT_BASE_DIR ${CMAKE_BINARY_DIR}/_d) + # TODO: Update GIT_TAG to the 6.0 release tag once it is available. + FetchContent_Declare(SwiftSyntax + GIT_REPOSITORY https://github.com/swiftlang/swift-syntax +- GIT_TAG 27b74edd5de625d0e399869a5af08f1501af8837) ++ GIT_TAG 27b74edd5de625d0e399869a5af08f1501af8837 ++ ${SwiftTesting_ConsoleAccess}) + FetchContent_MakeAvailable(SwiftSyntax) + endif() +