Skip to content

Commit c874044

Browse files
[cmake] add FindSwiftCore module for supplemental libraries
Addresses rdar://150396923
1 parent c8f1de2 commit c874044

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#[=======================================================================[.rst:
2+
FindSwiftCore
3+
------------
4+
5+
Find SwiftCore, deferring to SwiftCoreConfig.cmake when requested.
6+
This is meant to find the core library to be linked by the Supplemental libraries.
7+
8+
Imported Targets
9+
^^^^^^^^^^^^^^^^
10+
11+
The following :prop_tgt:`IMPORTED` TARGETS may be defined:
12+
13+
``SwiftCore``
14+
15+
Hint Variables
16+
^^^^^^^^^^^^^^
17+
18+
``SDKROOT``
19+
Set the path to the Swift SDK Root.
20+
This only affects Windows builds.
21+
22+
``Swift_SDKROOT``
23+
Set the path to the Swift SDK installation.
24+
This only affects Linux and Windows builds.
25+
Apple builds always use the library provided by the SDK.
26+
27+
Result Variables
28+
^^^^^^^^^^^^^^^^
29+
30+
The module may set the following variables if `SwiftCore_DIR` is not set.
31+
32+
``SwiftCore_FOUND``
33+
true if core was found
34+
35+
``SwiftCore_LIBRARIES`` OR ``SwiftCore_IMPLIB``
36+
the libraries to be linked
37+
38+
``SwiftCore_INCLUDE_DIR``
39+
the directory containing the Swift.swiftmodule folder
40+
41+
#]=======================================================================]
42+
43+
# If the SwiftCore_DIR_FLAG is specified, look there instead. The cmake-generated
44+
# config file is more accurate, but requires that the SDK has one available.
45+
if(SwiftCore_DIR)
46+
if(SwiftCore_FIND_REQUIRED)
47+
list(APPEND args REQUIRED)
48+
endif()
49+
if(SwiftCore_FIND_QUIETLY)
50+
list(APPEND args QUIET)
51+
endif()
52+
find_package(SwiftCore NO_MODULE ${args})
53+
return()
54+
endif()
55+
56+
include(FindPackageHandleStandardArgs)
57+
58+
if(APPLE)
59+
# When building for Apple platforms, SwiftCore always comes from within the
60+
# SDK as a tbd for a shared library in the shared cache.
61+
find_path(SwiftCore_INCLUDE_DIR
62+
"Swift.swiftmodule"
63+
HINTS
64+
"${CMAKE_OSX_SYSROOT}/usr/lib/swift")
65+
find_library(SwiftCore_IMPLIB
66+
NAMES "libswiftCore.tbd"
67+
HINTS
68+
"${CMAKE_OSX_SYSROOT}/usr/lib/swift")
69+
add_library(SwiftCore SHARED IMPORTED GLOBAL)
70+
set_target_properties(SwiftCore PROPERTIES
71+
IMPORTED_IMPLIB "${SwiftCore_IMPLIB}")
72+
find_package_handle_standard_args(SwiftCore DEFAULT_MSG
73+
SwiftCore_IMPLIB SwiftCore_INCLUDE_DIR)
74+
elseif(LINUX)
75+
if(SwiftCore_STATIC)
76+
find_path(SwiftCore_INCLUDE_DIR
77+
"Swift.swiftmodule"
78+
HINTS
79+
"${Swift_SDKROOT}/usr/lib/swift_static/linux-static")
80+
find_library(SwiftCore_LIBRARY
81+
NAMES "libswiftCore.a"
82+
HINTS "${Swift_SDKROOT}/usr/lib/swift_static/linux-static")
83+
add_library(SwiftCore STATIC IMPORTED GLOBAL)
84+
else()
85+
find_path(SwiftCore_INCLUDE_DIR
86+
"Swift.swiftmodule"
87+
HINTS
88+
"${Swift_SDKROOT}/usr/lib/swift/linux")
89+
find_library(SwiftCore_LIBRARY
90+
NAMES "libswiftCore.so"
91+
HINTS "${Swift_SDKROOT}/usr/lib/swift/linux")
92+
add_library(SwiftCore SHARED IMPORTED GLOBAL)
93+
endif()
94+
set_target_properties(SwiftCore PROPERTIES
95+
IMPORTED_LOCATION "${SwiftCore_LIBRARY}"
96+
INTERFACE_INCLUDE_DIRECTORIES "${SwiftCore_INCLUDE_DIR}")
97+
find_package_handle_standard_args(SwiftCore DEFAULT_MSG
98+
SwiftCore_LIBRARY SwiftCore_INCLUDE_DIR)
99+
elseif(WIN32)
100+
find_path(SwiftCore_INCLUDE_DIR
101+
"Swift.swiftmodule"
102+
HINTS
103+
"${Swift_SDKROOT}/usr/lib/swift/windows"
104+
"$ENV{SDKROOT}/usr/lib/swift/windows")
105+
find_library(SwiftCore_LIBRARY
106+
NAMES "libswiftCore.lib"
107+
HINTS
108+
"${Swift_SDKROOT}/usr/lib/swift/${SwiftCore_PLATFORM_SUBDIR}/${SwiftCore_ARCH_SUBDIR}"
109+
"${Swift_SDKROOT}/usr/lib/swift"
110+
"$ENV{SDKROOT}/usr/lib/swift/${SwiftCore_PLATFORM_SUBDIR}/${SwiftCore_ARCH_SUBDIR}"
111+
"$ENV{SDKROOT}/usr/lib/swift")
112+
113+
add_library(SwiftCore SHARED IMPORTED GLOBAL)
114+
set_target_properties(SwiftCore PROPERTIES
115+
IMPORTED_LOCATION "${SwiftCore_LIBRARY}"
116+
INTERFACE_INCLUDE_DIRECTORIES "${SwiftCore_INCLUDE_DIR}")
117+
find_package_handle_standard_args(SwiftCore DEFAULT_MSG
118+
SwiftCore_LIBRARY SwiftCore_INCLUDE_DIR)
119+
else()
120+
message(FATAL_ERROR "FindSwiftCore.cmake module search not implemented for targeted platform\n"
121+
" Build Core for your platform and set `SwiftCore_DIR` to"
122+
" the directory containing SwiftCoreConfig.cmake\n")
123+
endif()

0 commit comments

Comments
 (0)