Skip to content

Commit

Permalink
[6.0.2][CMake] Explicitly link Testing to Foundation (#713)
Browse files Browse the repository at this point in the history
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 <jgrynspan@apple.com>
  • Loading branch information
rintaro and grynspan authored Sep 24, 2024
1 parent 981ef15 commit cd448bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions Sources/Testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit cd448bb

Please sign in to comment.