Skip to content

Commit 00f047d

Browse files
authored
Merge pull request #84388 from edymtt/edymtt/split-find-swiftdarwin-from-find-swiftoverlay
Runtimes: provide a dedicated find module for Darwin overlay
2 parents 7818b8c + 5f6d3fa commit 00f047d

File tree

2 files changed

+73
-10
lines changed

2 files changed

+73
-10
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#[=======================================================================[.rst:
2+
FindSwiftDarwin
3+
------------
4+
5+
Find swiftDarwin in the underlying SDK (the only way we obtain such overlay).
6+
7+
Imported Targets
8+
^^^^^^^^^^^^^^^^
9+
10+
The following :prop_tgt:`IMPORTED` TARGETS may be defined:
11+
12+
``swiftDarwin``
13+
14+
#]=======================================================================]
15+
16+
include_guard(GLOBAL)
17+
18+
# This was loosely modelled after other find modules
19+
# (namely FindGLEW), where the equivalent parameter
20+
# is not stored in cache (possibly because we want
21+
# the project importing it to be able to use
22+
# it "immediately")
23+
if(NOT DEFINED SwiftDarwin_USE_STATIC_LIBS)
24+
set(SwiftDarwin_USE_STATIC_LIBS OFF)
25+
endif()
26+
27+
include(FindPackageHandleStandardArgs)
28+
include(PlatformInfo)
29+
30+
if(NOT APPLE)
31+
message(WARNING "Darwin is only produced on Apple platforms, so not attempting to search it here.")
32+
return()
33+
endif()
34+
35+
# Look in the SDK
36+
list(APPEND swiftDarwin_INCLUDE_DIR_HINTS
37+
"${CMAKE_OSX_SYSROOT}/usr/lib/swift")
38+
list(APPEND swiftDarwin_LIBRARY_HINTS
39+
"${CMAKE_OSX_SYSROOT}/usr/lib/swift")
40+
# When building for Apple platforms, swiftDarwin always comes from within the
41+
# SDK as a tbd for a shared library in the shared cache.
42+
list(APPEND swiftDarwin_NAMES libswiftDarwin.tbd)
43+
set(swiftDarwin_MODULE_NAME "Darwin.swiftmodule")
44+
45+
find_path(swiftDarwin_INCLUDE_DIR
46+
${swiftDarwin_MODULE_NAME}
47+
NO_CMAKE_FIND_ROOT_PATH
48+
HINTS
49+
${swiftDarwin_INCLUDE_DIR_HINTS})
50+
find_library(swiftDarwin_LIBRARY
51+
NAMES
52+
${swiftDarwin_NAMES}
53+
NO_CMAKE_FIND_ROOT_PATH
54+
HINTS
55+
${swiftDarwin_LIBRARY_HINTS})
56+
57+
if(SwiftDarwin_USE_STATIC_LIBS)
58+
add_library(swiftDarwin STATIC IMPORTED GLOBAL)
59+
else()
60+
add_library(swiftDarwin SHARED IMPORTED GLOBAL)
61+
endif()
62+
63+
target_include_directories(swiftDarwin INTERFACE
64+
"${swiftDarwin_INCLUDE_DIR}")
65+
66+
set_target_properties(swiftDarwin PROPERTIES
67+
IMPORTED_IMPLIB "${swiftDarwin_LIBRARY}")
68+
69+
find_package_handle_standard_args(SwiftDarwin DEFAULT_MSG
70+
"swiftDarwin_LIBRARY" "swiftDarwin_INCLUDE_DIR")

Runtimes/Supplemental/cmake/modules/FindSwiftOverlay.cmake

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,9 @@ include(FindPackageHandleStandardArgs)
5555
include(PlatformInfo)
5656

5757
if(APPLE)
58-
list(APPEND OVERLAY_TARGET_NAMES "swiftDarwin")
59-
# Look in the SDK
60-
list(APPEND swiftDarwin_INCLUDE_DIR_HINTS
61-
"${CMAKE_OSX_SYSROOT}/usr/lib/swift")
62-
list(APPEND swiftDarwin_LIBRARY_HINTS
63-
"${CMAKE_OSX_SYSROOT}/usr/lib/swift")
64-
# When building for Apple platforms, swiftDarwin always comes from within the
65-
# SDK as a tbd for a shared library in the shared cache.
66-
list(APPEND swiftDarwin_NAMES libswiftDarwin.tbd)
67-
set(swiftDarwin_MODULE_NAME "Darwin.swiftmodule")
58+
# Darwin has its own dedicated find module,
59+
# so that we can use it together with the CMake config file
60+
# generated by the Overlay build system
6861

6962
list(APPEND swift_Builtin_float_INCLUDE_DIR_HINTS
7063
"${CMAKE_OSX_SYSROOT}/usr/lib/swift")

0 commit comments

Comments
 (0)