Skip to content

Commit 7503efd

Browse files
committed
[Runtimes][FindSwiftCore] Find Shims, OnoneSupport and Concurrency
This way we will match most of the targets that would be exported via SwiftCoreTargets.cmake. Take the chance to expand the documentation of the find module. Addresses rdar://151700875
1 parent 4efbe16 commit 7503efd

File tree

1 file changed

+134
-1
lines changed

1 file changed

+134
-1
lines changed

Runtimes/Supplemental/cmake/modules/FindSwiftCore.cmake

Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,73 @@ Hint Variables
2424
This only affects Linux and Windows builds.
2525
Apple builds always use the library provided by the SDK.
2626
27+
``SwiftCore_USE_STATIC_LIBS``
28+
Set to boolean true to find static libraries. If not
29+
set explicitly this is inferred from the value of
30+
`BUILD_SHARED_LIBS` and the current platform.
31+
32+
``SwiftCore_INCLUDE_DIR_HINTS``
33+
Additional paths to search the swiftmodules into. These
34+
are prepended to the ones searched by this find module
35+
36+
``SwiftCore_LIBRARY_HINTS``
37+
Additional paths to search the libraries into. These
38+
are prepended to the ones searched by this find module
39+
40+
``SwiftShims_INCLUDE_DIR_HINTS``
41+
Additional paths to search the shims into. These
42+
are prepended to the ones searched by this find module
43+
44+
``SwiftCore_NAMES``
45+
Additional names for the Core library
46+
47+
``SwiftOnoneSupport_NAMES``
48+
Additional names for the SwiftOnoneSupport library
49+
50+
``SwiftConcurrency_NAMES``
51+
Additional names for the Swift_Concurrency library
52+
53+
Result targets
54+
^^^^^^^^^^^^^^
55+
56+
If no error is generated, the following targets are available to the users
57+
58+
* ``swiftCore``
59+
* ``swiftSwiftOnoneSupport``
60+
* ``swift_Concurrency``
61+
* ``swiftShims``
62+
2763
Result Variables
2864
^^^^^^^^^^^^^^^^
2965
3066
The module may set the following variables if `SwiftCore_DIR` is not set.
67+
(although we suggest relying on the targets above instead)
3168
3269
``SwiftCore_FOUND``
3370
true if core was found
3471
3572
``SwiftCore_INCLUDE_DIR``
3673
the directory containing the Swift.swiftmodule folder
3774
75+
``SwiftCore_LIBRARY``
76+
path to the swiftCore library
77+
78+
``SwiftOnoneSupport_INCLUDE_DIR``
79+
the directory containing the SwiftOnoneSupport.swiftmodule folder
80+
81+
``SwiftOnoneSupport_LIBRARY``
82+
path to the SwiftOnoneSupport library
83+
84+
``SwiftConcurrency_INCLUDE_DIR``
85+
the directory containing the _Concurrency.swiftmodule folder
86+
87+
``SwiftConcurrency_LIBRARY``
88+
path to the swift_Concurrency library
89+
90+
``SwiftShims_INCLUDE_DIR``
91+
the directory containing the Swift shims directory
92+
(i.e. .../usr/lib/swift, not .../usr/lib/swift/shims)
93+
3894
#]=======================================================================]
3995

4096
include_guard(GLOBAL)
@@ -72,22 +128,35 @@ if(APPLE)
72128
"${CMAKE_OSX_SYSROOT}/usr/lib/swift")
73129
list(APPEND SwiftCore_LIBRARY_HINTS
74130
"${CMAKE_OSX_SYSROOT}/usr/lib/swift")
131+
list(APPEND SwiftShims_INCLUDE_DIR_HINTS
132+
"${CMAKE_OSX_SYSROOT}/usr/lib/swift")
75133
# When building for Apple platforms, SwiftCore always comes from within the
76134
# SDK as a tbd for a shared library in the shared cache.
77135
list(APPEND SwiftCore_NAMES libswiftCore.tbd)
136+
list(APPEND SwiftOnoneSupport_NAMES libswiftSwiftOnoneSupport.tbd)
137+
list(APPEND SwiftConcurrency_NAMES libswift_Concurrency.tbd)
78138
elseif(LINUX)
79139
if (SwiftCore_USE_STATIC_LIBS)
80140
list(APPEND SwiftCore_INCLUDE_DIR_HINTS
81141
"${Swift_SDKROOT}/usr/lib/swift_static/linux-static")
82142
list(APPEND SwiftCore_LIBRARY_HINTS
83143
"${Swift_SDKROOT}/usr/lib/swift_static/linux-static")
144+
list(APPEND SwiftShims_INCLUDE_DIR_HINTS
145+
"${Swift_SDKROOT}/usr/lib/swift_static"
146+
"${Swift_SDKROOT}/usr/lib/swift")
84147
list(APPEND SwiftCore_NAMES libswiftCore.a)
148+
list(APPEND SwiftOnoneSupport_NAMES libswiftSwiftOnoneSupport.a)
149+
list(APPEND SwiftConcurrency_NAMES libswift_Concurrency.a)
85150
else()
86151
list(APPEND SwiftCore_INCLUDE_DIR_HINTS
87152
"${Swift_SDKROOT}/usr/lib/swift/linux")
88153
list(APPEND SwiftCore_LIBRARY_HINTS
89154
"${Swift_SDKROOT}/usr/lib/swift/linux")
155+
list(APPEND SwiftShims_INCLUDE_DIR_HINTS
156+
"${Swift_SDKROOT}/usr/lib/swift")
90157
list(APPEND SwiftCore_NAMES libswiftCore.so)
158+
list(APPEND SwiftOnoneSupport_NAMES libswiftSwiftOnoneSupport.so)
159+
list(APPEND SwiftConcurrency_NAMES libswift_Concurrency.so)
91160
endif()
92161
elseif(WIN32)
93162
list(APPEND SwiftCore_INCLUDE_DIR_HINTS
@@ -98,10 +167,17 @@ elseif(WIN32)
98167
"${Swift_SDKROOT}/usr/lib/swift"
99168
"$ENV{SDKROOT}/usr/lib/swift/${${PROJECT_NAME}_PLATFORM_SUBDIR}/${${PROJECT_NAME}_ARCH_SUBDIR}"
100169
"$ENV{SDKROOT}/usr/lib/swift")
170+
list(APPEND SwiftShims_INCLUDE_DIR_HINTS
171+
"${Swift_SDKROOT}/usr/lib/swift"
172+
"$ENV{SDKROOT}/usr/lib/swift")
101173
if (SwiftCore_USE_STATIC_LIBS)
102174
list(APPEND SwiftCore_NAMES libswiftCore.lib)
175+
list(APPEND SwiftOnoneSupport_NAMES libswiftSwiftOnoneSupport.lib)
176+
list(APPEND SwiftConcurrency_NAMES libswift_Concurrency.lib)
103177
else()
104178
list(APPEND SwiftCore_NAMES swiftCore.lib)
179+
list(APPEND SwiftOnoneSupport_NAMES swiftSwiftOnoneSupport.lib)
180+
list(APPEND SwiftConcurrency_NAMES swift_Concurrency.lib)
105181
endif()
106182
elseif(ANDROID)
107183
if (SwiftCore_USE_STATIC_LIBS)
@@ -113,7 +189,11 @@ elseif(ANDROID)
113189
"${Swift_SDKROOT}/usr/lib/swift_static"
114190
"$ENV{SDKROOT}/usr/lib/swift_static/android/${${PROJECT_NAME}_ARCH_SUBDIR}"
115191
"$ENV{SDKROOT}/usr/lib/swift_static")
192+
list(APPEND SwiftShims_INCLUDE_DIR_HINTS
193+
"${Swift_SDKROOT}/usr/lib/swift_static")
116194
list(APPEND SwiftCore_NAMES libswiftCore.a)
195+
list(APPEND SwiftOnoneSupport_NAMES libswiftSwiftOnoneSupport.a)
196+
list(APPEND SwiftConcurrency_NAMES libswift_Concurrency.a)
117197
else()
118198
list(APPEND SwiftCore_INCLUDE_DIR_HINTS
119199
"${Swift_SDKROOT}/usr/lib/swift/android"
@@ -123,7 +203,11 @@ elseif(ANDROID)
123203
"${Swift_SDKROOT}/usr/lib/swift"
124204
"$ENV{SDKROOT}/usr/lib/swift/android/${${PROJECT_NAME}_ARCH_SUBDIR}"
125205
"$ENV{SDKROOT}/usr/lib/swift")
206+
list(APPEND SwiftShims_INCLUDE_DIR_HINTS
207+
"${Swift_SDKROOT}/usr/lib/swift")
126208
list(APPEND SwiftCore_NAMES libswiftCore.so)
209+
list(APPEND SwiftOnoneSupport_NAMES libswiftSwiftOnoneSupport.so)
210+
list(APPEND SwiftConcurrency_NAMES libswift_Concurrency.so)
127211
endif()
128212
else()
129213
message(FATAL_ERROR "FindSwiftCore.cmake module search not implemented for targeted platform\n"
@@ -143,22 +227,71 @@ find_library(SwiftCore_LIBRARY
143227
HINTS
144228
${SwiftCore_LIBRARY_HINTS})
145229

230+
find_path(SwiftOnoneSupport_INCLUDE_DIR
231+
"SwiftOnoneSupport.swiftmodule"
232+
NO_CMAKE_FIND_ROOT_PATH
233+
HINTS
234+
${SwiftCore_INCLUDE_DIR_HINTS})
235+
find_library(SwiftOnoneSupport_LIBRARY
236+
NAMES
237+
${SwiftOnoneSupport_NAMES}
238+
NO_CMAKE_FIND_ROOT_PATH
239+
HINTS
240+
${SwiftCore_LIBRARY_HINTS})
241+
242+
find_path(SwiftConcurrency_INCLUDE_DIR
243+
"_Concurrency.swiftmodule"
244+
NO_CMAKE_FIND_ROOT_PATH
245+
HINTS
246+
${SwiftCore_INCLUDE_DIR_HINTS})
247+
find_library(SwiftConcurrency_LIBRARY
248+
NAMES
249+
${SwiftConcurrency_NAMES}
250+
NO_CMAKE_FIND_ROOT_PATH
251+
HINTS
252+
${SwiftCore_LIBRARY_HINTS})
253+
146254
if(SwiftCore_USE_STATIC_LIBS)
147255
add_library(swiftCore STATIC IMPORTED GLOBAL)
256+
add_library(swiftSwiftOnoneSupport STATIC IMPORTED GLOBAL)
257+
add_library(swift_Concurrency STATIC IMPORTED GLOBAL)
148258
else()
149259
add_library(swiftCore SHARED IMPORTED GLOBAL)
260+
add_library(swiftSwiftOnoneSupport SHARED IMPORTED GLOBAL)
261+
add_library(swift_Concurrency SHARED IMPORTED GLOBAL)
150262
endif()
151263

152264
set_target_properties(swiftCore PROPERTIES
153265
INTERFACE_INCLUDE_DIRECTORIES "${SwiftCore_INCLUDE_DIR}")
266+
set_target_properties(swiftSwiftOnoneSupport PROPERTIES
267+
INTERFACE_INCLUDE_DIRECTORIES "${SwiftOnoneSupport_INCLUDE_DIR}")
268+
set_target_properties(swift_Concurrency PROPERTIES
269+
INTERFACE_INCLUDE_DIRECTORIES "${SwiftConcurrency_INCLUDE_DIR}")
154270

155271
if(LINUX OR ANDROID)
156272
set_target_properties(swiftCore PROPERTIES
157273
IMPORTED_LOCATION "${SwiftCore_LIBRARY}")
274+
set_target_properties(swiftSwiftOnoneSupport PROPERTIES
275+
IMPORTED_LOCATION "${SwiftOnoneSupport_LIBRARY}")
276+
set_target_properties(swift_Concurrency PROPERTIES
277+
IMPORTED_LOCATION "${SwiftConcurrency_LIBRARY}")
158278
else()
159279
set_target_properties(swiftCore PROPERTIES
160280
IMPORTED_IMPLIB "${SwiftCore_LIBRARY}")
281+
set_target_properties(swiftSwiftOnoneSupport PROPERTIES
282+
IMPORTED_IMPLIB "${SwiftOnoneSupport_LIBRARY}")
283+
set_target_properties(swift_Concurrency PROPERTIES
284+
IMPORTED_IMPLIB "${SwiftConcurrency_LIBRARY}")
161285
endif()
162286

287+
find_path(SwiftShims_INCLUDE_DIR "shims/module.modulemap" HINTS
288+
${SwiftShims_INCLUDE_DIR_HINTS})
289+
add_library(swiftShims INTERFACE IMPORTED GLOBAL)
290+
set_target_properties(swiftShims PROPERTIES
291+
INTERFACE_INCLUDE_DIRECTORIES "${SwiftShims_INCLUDE_DIR}/shims")
292+
163293
find_package_handle_standard_args(SwiftCore DEFAULT_MSG
164-
SwiftCore_LIBRARY SwiftCore_INCLUDE_DIR)
294+
SwiftCore_LIBRARY SwiftCore_INCLUDE_DIR
295+
SwiftShims_INCLUDE_DIR
296+
SwiftOnoneSupport_LIBRARY SwiftOnoneSupport_INCLUDE_DIR
297+
SwiftConcurrency_LIBRARY SwiftConcurrency_INCLUDE_DIR)

0 commit comments

Comments
 (0)