CMake: Refactor FindSwiftTesting to find TestingMacros dir on macOS

Turns out we need this directory to pass to the -frontend command
for creating the interop header, so refactor the whole find module
to find it on each platform.
This commit is contained in:
Andrew Kaster 2025-03-24 14:39:11 -06:00 committed by Andrew Kaster
commit 1ed4e64575
Notes: github-actions[bot] 2025-04-03 22:49:11 +00:00
2 changed files with 63 additions and 18 deletions

View file

@ -17,6 +17,8 @@ endif()
include(${CMAKE_CURRENT_LIST_DIR}/InitializeSwift.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/GenerateSwiftHeader.cmake)
find_package(SwiftTesting REQUIRED)
# FIXME: https://gitlab.kitware.com/cmake/cmake/-/issues/26174
if (APPLE)
set(CMAKE_Swift_COMPILER_TARGET "${SWIFT_TARGET_TRIPLE}")
@ -60,6 +62,14 @@ function(add_swift_target_properties target_name)
get_target_property(_NATIVE_DIRS ${target_name} INCLUDE_DIRECTORIES)
list(APPEND _NATIVE_DIRS ${CMAKE_Swift_MODULE_DIRECTORY})
# Swift-testing in swift.org toolchains on macOS has its .swiftmodule in a testing/ subdirectory of
# the swift compiler's built-in lib dirs.
get_target_property(DEPENDENCIES ${target_name} LINK_LIBRARIES)
if (SwiftTesting::SwiftTesting IN_LIST DEPENDENCIES)
get_target_property(SWIFT_TESTING_INCLUDE_DIRS SwiftTesting::SwiftTesting INTERFACE_INCLUDE_DIRECTORIES)
list(APPEND _NATIVE_DIRS ${SWIFT_TESTING_INCLUDE_DIRS})
endif()
set(EXTRA_COMPILE_DEFINITIONS "")
foreach (compile_definition IN LISTS SWIFT_TARGET_COMPILE_DEFINITIONS)
list(APPEND EXTRA_COMPILE_DEFINITIONS "-Xcc" "-D${compile_definition}")