Skip to content

Commit 0781022

Browse files
authored
[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
1 parent 65138ff commit 0781022

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ endif()
1515
project(SwiftTesting
1616
LANGUAGES CXX Swift)
1717

18+
if(NOT APPLE)
19+
if(NOT CMAKE_SYSTEM_NAME STREQUAL WASI)
20+
find_package(dispatch CONFIG)
21+
endif()
22+
find_package(Foundation CONFIG)
23+
endif()
24+
1825
include(GNUInstallDirs)
1926

2027
list(APPEND CMAKE_MODULE_PATH

Sources/Testing/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ add_library(Testing
9494
Traits/Trait.swift)
9595
target_link_libraries(Testing PRIVATE
9696
_TestingInternals)
97+
if(NOT APPLE)
98+
if(NOT CMAKE_SYSTEM_NAME STREQUAL WASI)
99+
target_link_libraries(Testing PUBLIC
100+
dispatch)
101+
endif()
102+
target_link_libraries(Testing PUBLIC
103+
Foundation)
104+
endif()
97105
add_dependencies(Testing
98106
TestingMacros)
99107
target_compile_options(Testing PRIVATE

0 commit comments

Comments
 (0)