-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cmake] add FindSwiftCore module for supplemental libraries #81215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,121 @@ | ||||||||||||||||||
#[=======================================================================[.rst: | ||||||||||||||||||
FindSwiftCore | ||||||||||||||||||
------------ | ||||||||||||||||||
|
||||||||||||||||||
Find SwiftCore, deferring to SwiftCoreConfig.cmake when requested. | ||||||||||||||||||
This is meant to find the core library to be linked by the Supplemental libraries. | ||||||||||||||||||
|
||||||||||||||||||
Imported Targets | ||||||||||||||||||
^^^^^^^^^^^^^^^^ | ||||||||||||||||||
|
||||||||||||||||||
The following :prop_tgt:`IMPORTED` TARGETS may be defined: | ||||||||||||||||||
|
||||||||||||||||||
``SwiftCore`` | ||||||||||||||||||
|
||||||||||||||||||
Hint Variables | ||||||||||||||||||
^^^^^^^^^^^^^^ | ||||||||||||||||||
|
||||||||||||||||||
``SDKROOT`` (environment variable) | ||||||||||||||||||
Set the path to the Swift SDK Root. | ||||||||||||||||||
This only affects Windows builds. | ||||||||||||||||||
|
||||||||||||||||||
``Swift_SDKROOT`` | ||||||||||||||||||
Set the path to the Swift SDK installation. | ||||||||||||||||||
This only affects Linux and Windows builds. | ||||||||||||||||||
Apple builds always use the library provided by the SDK. | ||||||||||||||||||
|
||||||||||||||||||
Result Variables | ||||||||||||||||||
^^^^^^^^^^^^^^^^ | ||||||||||||||||||
|
||||||||||||||||||
The module may set the following variables if `SwiftCore_DIR` is not set. | ||||||||||||||||||
|
||||||||||||||||||
``SwiftCore_FOUND`` | ||||||||||||||||||
true if core was found | ||||||||||||||||||
|
||||||||||||||||||
``SwiftCore_INCLUDE_DIR`` | ||||||||||||||||||
the directory containing the Swift.swiftmodule folder | ||||||||||||||||||
|
||||||||||||||||||
#]=======================================================================] | ||||||||||||||||||
|
||||||||||||||||||
# If the SwiftCore_DIR_FLAG is specified, look there instead. The cmake-generated | ||||||||||||||||||
# config file is more accurate, but requires that the SDK has one available. | ||||||||||||||||||
if(SwiftCore_DIR) | ||||||||||||||||||
edymtt marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
if(SwiftCore_FIND_REQUIRED) | ||||||||||||||||||
list(APPEND args REQUIRED) | ||||||||||||||||||
endif() | ||||||||||||||||||
if(SwiftCore_FIND_QUIETLY) | ||||||||||||||||||
list(APPEND args QUIET) | ||||||||||||||||||
endif() | ||||||||||||||||||
find_package(SwiftCore NO_MODULE ${args}) | ||||||||||||||||||
return() | ||||||||||||||||||
endif() | ||||||||||||||||||
|
||||||||||||||||||
include(FindPackageHandleStandardArgs) | ||||||||||||||||||
|
||||||||||||||||||
if(APPLE) | ||||||||||||||||||
# When building for Apple platforms, SwiftCore always comes from within the | ||||||||||||||||||
# SDK as a tbd for a shared library in the shared cache. | ||||||||||||||||||
find_path(SwiftCore_INCLUDE_DIR | ||||||||||||||||||
"Swift.swiftmodule" | ||||||||||||||||||
HINTS | ||||||||||||||||||
"${CMAKE_OSX_SYSROOT}/usr/lib/swift") | ||||||||||||||||||
find_library(SwiftCore_IMPLIB | ||||||||||||||||||
NAMES "libswiftCore.tbd" | ||||||||||||||||||
HINTS | ||||||||||||||||||
"${CMAKE_OSX_SYSROOT}/usr/lib/swift") | ||||||||||||||||||
add_library(SwiftCore SHARED IMPORTED GLOBAL) | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When experimenting at desk I noticed that the case of the target does not match with the one we use in the build system swift/Runtimes/Core/core/CMakeLists.txt Lines 29 to 31 in 6534b9b
swift/Runtimes/Supplemental/Synchronization/CMakeLists.txt Lines 97 to 99 in 6534b9b
meaning we are relying on search paths known to the compiler to find this library, instead of CMake providing the explicit path to the tbd/so/lib file
Suggested change
|
||||||||||||||||||
set_target_properties(SwiftCore PROPERTIES | ||||||||||||||||||
IMPORTED_IMPLIB "${SwiftCore_IMPLIB}" | ||||||||||||||||||
INTERFACE_INCLUDE_DIRECTORIES "${SwiftCore_INCLUDE_DIR}") | ||||||||||||||||||
find_package_handle_standard_args(SwiftCore DEFAULT_MSG | ||||||||||||||||||
SwiftCore_IMPLIB SwiftCore_INCLUDE_DIR) | ||||||||||||||||||
elseif(LINUX) | ||||||||||||||||||
if (NOT BUILD_SHARED_LIBS) | ||||||||||||||||||
find_path(SwiftCore_INCLUDE_DIR | ||||||||||||||||||
"Swift.swiftmodule" | ||||||||||||||||||
HINTS | ||||||||||||||||||
"${Swift_SDKROOT}/usr/lib/swift_static/linux-static") | ||||||||||||||||||
find_library(SwiftCore_LIBRARY | ||||||||||||||||||
NAMES "libswiftCore.a" | ||||||||||||||||||
HINTS "${Swift_SDKROOT}/usr/lib/swift_static/linux-static") | ||||||||||||||||||
add_library(SwiftCore STATIC IMPORTED GLOBAL) | ||||||||||||||||||
else() | ||||||||||||||||||
find_path(SwiftCore_INCLUDE_DIR | ||||||||||||||||||
"Swift.swiftmodule" | ||||||||||||||||||
HINTS | ||||||||||||||||||
"${Swift_SDKROOT}/usr/lib/swift/linux") | ||||||||||||||||||
find_library(SwiftCore_LIBRARY | ||||||||||||||||||
NAMES "libswiftCore.so" | ||||||||||||||||||
HINTS "${Swift_SDKROOT}/usr/lib/swift/linux") | ||||||||||||||||||
add_library(SwiftCore SHARED IMPORTED GLOBAL) | ||||||||||||||||||
endif() | ||||||||||||||||||
set_target_properties(SwiftCore PROPERTIES | ||||||||||||||||||
IMPORTED_LOCATION "${SwiftCore_LIBRARY}" | ||||||||||||||||||
INTERFACE_INCLUDE_DIRECTORIES "${SwiftCore_INCLUDE_DIR}") | ||||||||||||||||||
find_package_handle_standard_args(SwiftCore DEFAULT_MSG | ||||||||||||||||||
SwiftCore_LIBRARY SwiftCore_INCLUDE_DIR) | ||||||||||||||||||
elseif(WIN32) | ||||||||||||||||||
find_path(SwiftCore_INCLUDE_DIR | ||||||||||||||||||
"Swift.swiftmodule" | ||||||||||||||||||
HINTS | ||||||||||||||||||
"${Swift_SDKROOT}/usr/lib/swift/windows" | ||||||||||||||||||
"$ENV{SDKROOT}/usr/lib/swift/windows") | ||||||||||||||||||
find_library(SwiftCore_LIBRARY | ||||||||||||||||||
NAMES "libswiftCore.lib" | ||||||||||||||||||
HINTS | ||||||||||||||||||
"${Swift_SDKROOT}/usr/lib/swift/${SwiftCore_PLATFORM_SUBDIR}/${SwiftCore_ARCH_SUBDIR}" | ||||||||||||||||||
"${Swift_SDKROOT}/usr/lib/swift" | ||||||||||||||||||
"$ENV{SDKROOT}/usr/lib/swift/${SwiftCore_PLATFORM_SUBDIR}/${SwiftCore_ARCH_SUBDIR}" | ||||||||||||||||||
"$ENV{SDKROOT}/usr/lib/swift") | ||||||||||||||||||
|
||||||||||||||||||
add_library(SwiftCore SHARED IMPORTED GLOBAL) | ||||||||||||||||||
set_target_properties(SwiftCore PROPERTIES | ||||||||||||||||||
IMPORTED_IMPLIB "${SwiftCore_LIBRARY}" | ||||||||||||||||||
INTERFACE_INCLUDE_DIRECTORIES "${SwiftCore_INCLUDE_DIR}") | ||||||||||||||||||
find_package_handle_standard_args(SwiftCore DEFAULT_MSG | ||||||||||||||||||
SwiftCore_LIBRARY SwiftCore_INCLUDE_DIR) | ||||||||||||||||||
else() | ||||||||||||||||||
message(FATAL_ERROR "FindSwiftCore.cmake module search not implemented for targeted platform\n" | ||||||||||||||||||
" Build Core for your platform and set `SwiftCore_DIR` to" | ||||||||||||||||||
" the directory containing SwiftCoreConfig.cmake\n") | ||||||||||||||||||
endif() |
Uh oh!
There was an error while loading. Please reload this page.