CMake: Add find module for swift-testing

This project is a part of the Xcode-shipped toolchain on macOS, but
needs built from source on other platforms. However, using the Xcode
version of the framework leads to a bunch of rpath confusion when
trying to link it the expected way. I suspect that there will be a
more intuitive way to link this library from the toolchain when it
stabilizes. So we'll build it everywhere :)
This commit is contained in:
Andrew Kaster 2024-08-26 23:29:57 -06:00 committed by Andrew Kaster
parent 062e687289
commit 188b3bb9b8
Notes: github-actions[bot] 2024-08-29 03:28:35 +00:00
2 changed files with 113 additions and 0 deletions

View file

@ -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 "<auto>")
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 "$<$<COMPILE_LANGUAGE:Swift>: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)

View file

@ -0,0 +1,68 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Andrew Kaster <andrew@ladybird.org>
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 "<auto>")
# 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()