From cd448bbe5cc989d8693ca75e9b08593eb143dea1 Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Tue, 24 Sep 2024 12:13:14 -0700 Subject: [PATCH] [6.0.2][CMake] Explicitly link Testing to Foundation (#713) Cherry-pick #693 into `release/6.0.2` * **Explanation**: Previously in CMake builds, when `Foundation` was not in the regular search directory (e.g. resource directory or SDK search paths) `#if canImport(Foundation)` used to fail, and the functionalities are not included. This patch provides a way to provide `Foundation_DIR` for `find_packgage(Foundation CONFIG)`, so that clients can correctly link Testing to Foundation * **Scope**: CMake builds * **Risk**: Low. No actual code changes. * **Testing**: Passes current test suite Also manually tested the build toolchain * **Issues**: N/A * **Reviewer**: @stmontgomery --------- Co-authored-by: Jonathan Grynspan --- CMakeLists.txt | 7 +++++++ Sources/Testing/CMakeLists.txt | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index a8b5712ca..1be9a4bed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,13 @@ endif() project(SwiftTesting LANGUAGES CXX Swift) +if(NOT APPLE) + if(NOT CMAKE_SYSTEM_NAME STREQUAL WASI) + find_package(dispatch CONFIG) + endif() + find_package(Foundation CONFIG) +endif() + include(GNUInstallDirs) list(APPEND CMAKE_MODULE_PATH diff --git a/Sources/Testing/CMakeLists.txt b/Sources/Testing/CMakeLists.txt index 69b851645..0ce337ac8 100644 --- a/Sources/Testing/CMakeLists.txt +++ b/Sources/Testing/CMakeLists.txt @@ -94,6 +94,14 @@ add_library(Testing Traits/Trait.swift) target_link_libraries(Testing PRIVATE _TestingInternals) +if(NOT APPLE) + if(NOT CMAKE_SYSTEM_NAME STREQUAL WASI) + target_link_libraries(Testing PUBLIC + dispatch) + endif() + target_link_libraries(Testing PUBLIC + Foundation) +endif() if(NOT BUILD_SHARED_LIBS) # When building a static library, tell clients to autolink the internal # library.