From 0781022d1b89b92d4c4c90f1580cd25f5e932e92 Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Tue, 24 Sep 2024 07:04:24 -0700 Subject: [PATCH] [6.0] Explicitly link to `Foundation` in CMake builds (#709) Cherry-pick #693 into `release/6.0` * **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 --- CMakeLists.txt | 7 +++++++ Sources/Testing/CMakeLists.txt | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ef465083..211bab7b 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 573f198a..f96e2617 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() add_dependencies(Testing TestingMacros) target_compile_options(Testing PRIVATE