-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Runtimes][CMake] Refactor FindSwiftCore to put focus on targets... #82035
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 |
---|---|---|
|
@@ -37,6 +37,8 @@ The module may set the following variables if `SwiftCore_DIR` is not set. | |
|
||
#]=======================================================================] | ||
|
||
include_guard(GLOBAL) | ||
|
||
# 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) | ||
|
@@ -51,113 +53,112 @@ if(SwiftCore_DIR) | |
endif() | ||
|
||
include(FindPackageHandleStandardArgs) | ||
include(PlatformInfo) | ||
|
||
# This was loosely modelled after other find modules | ||
# (namely FindGLEW), where the equivalent parameter | ||
# is not stored in cache (possibly because we want | ||
# the project importing it to be able to | ||
# it "immediately") | ||
if(NOT DEFINED SwiftCore_USE_STATIC_LIBS) | ||
set(SwiftCore_USE_STATIC_LIBS OFF) | ||
if(NOT BUILD_SHARED_LIBS AND NOT APPLE) | ||
set(SwiftCore_USE_STATIC_LIBS ON) | ||
endif() | ||
endif() | ||
|
||
if(APPLE) | ||
list(APPEND SwiftCore_INCLUDE_DIR_HINTS | ||
"${CMAKE_OSX_SYSROOT}/usr/lib/swift") | ||
list(APPEND SwiftCore_LIBRARY_HINTS | ||
"${CMAKE_OSX_SYSROOT}/usr/lib/swift") | ||
# 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) | ||
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) | ||
list(APPEND SwiftCore_NAMES libswiftCore.tbd) | ||
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) | ||
if (SwiftCore_USE_STATIC_LIBS) | ||
list(APPEND SwiftCore_INCLUDE_DIR_HINTS | ||
"${Swift_SDKROOT}/usr/lib/swift_static/linux-static") | ||
list(APPEND SwiftCore_LIBRARY_HINTS | ||
"${Swift_SDKROOT}/usr/lib/swift_static/linux-static") | ||
list(APPEND SwiftCore_NAMES libswiftCore.a) | ||
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) | ||
list(APPEND SwiftCore_INCLUDE_DIR_HINTS | ||
"${Swift_SDKROOT}/usr/lib/swift/linux") | ||
list(APPEND SwiftCore_LIBRARY_HINTS | ||
"${Swift_SDKROOT}/usr/lib/swift/linux") | ||
list(APPEND SwiftCore_NAMES libswiftCore.so) | ||
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. I think that folding the cases with generator expressions would be reasonable. 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. I would need to double check if I can use generator expressions in this context -- my understanding is that we can employ those when setting properties on targets 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. I cobbled up a small example that uses a generator expression to provide the file name to Do you have any link to documentation or forums that shows how to use generator expressions in this context? From a quick search, the official CMake Documentation only mentions they can be used in target properties and file(GENERATE) Example CMake and configuration/generation outputcmake_minimum_required(VERSION 3.29)
project(Foo LANGUAGES Swift)
find_path(SwiftCore_INCLUDE_DIR
"Swift.swiftmodule"
NO_CMAKE_FIND_ROOT_PATH
HINTS
"${CMAKE_OSX_SYSROOT}/usr/lib/swift")
find_library(SwiftCore_LIBRARY
NAMES
$<<PLATFORM_ID:Darwin>,libswiftCore.tbd,libswiftCore.so>
NO_CMAKE_FIND_ROOT_PATH
HINTS
"${CMAKE_OSX_SYSROOT}/usr/lib/swift")
MESSAGE(STATUS "Library path for SwiftCore: ${SwiftCore_LIBRARY}")
add_library(swiftCore SHARED IMPORTED GLOBAL)
set_target_properties(swiftCore PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${SwiftCore_INCLUDE_DIR}")
set_target_properties(swiftCore PROPERTIES
IMPORTED_IMPLIB "${SwiftCore_LIBRARY}")
add_library(Foo foo.swift)
target_link_libraries(Foo PRIVATE swiftCore)
|
||
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) | ||
list(APPEND SwiftCore_INCLUDE_DIR_HINTS | ||
"${Swift_SDKROOT}/usr/lib/swift/windows" | ||
"$ENV{SDKROOT}/usr/lib/swift/windows") | ||
list(APPEND SwiftCore_LIBRARY_HINTS | ||
"${Swift_SDKROOT}/usr/lib/swift/${${PROJECT_NAME}_PLATFORM_SUBDIR}/${${PROJECT_NAME}_ARCH_SUBDIR}" | ||
"${Swift_SDKROOT}/usr/lib/swift" | ||
"$ENV{SDKROOT}/usr/lib/swift/${${PROJECT_NAME}_PLATFORM_SUBDIR}/${${PROJECT_NAME}_ARCH_SUBDIR}" | ||
"$ENV{SDKROOT}/usr/lib/swift") | ||
if (SwiftCore_USE_STATIC_LIBS) | ||
list(APPEND SwiftCore_NAMES libswiftCore.lib) | ||
else() | ||
list(APPEND SwiftCore_NAMES swiftCore.lib) | ||
endif() | ||
elseif(ANDROID) | ||
if(BUILD_SHARED_LIBS) | ||
find_path(SwiftCore_INCLUDE_DIR | ||
"Swift.swiftmodule" | ||
NO_CMAKE_FIND_ROOT_PATH | ||
HINTS | ||
"${Swift_SDKROOT}/usr/lib/swift/android" | ||
"$ENV{SDKROOT}/usr/lib/swift/android") | ||
find_library(SwiftCore_LIBRARY | ||
NO_CMAKE_FIND_ROOT_PATH | ||
NAMES "libswiftCore.so" | ||
HINTS | ||
"${Swift_SDKROOT}/usr/lib/swift/android/${SwiftCore_ARCH_SUBDIR}" | ||
"${Swift_SDKROOT}/usr/lib/swift" | ||
"$ENV{SDKROOT}/usr/lib/swift/android/${SwiftCore_ARCH_SUBDIR}" | ||
"$ENV{SDKROOT}/usr/lib/swift") | ||
|
||
add_library(swiftCore SHARED IMPORTED GLOBAL) | ||
if (SwiftCore_USE_STATIC_LIBS) | ||
list(APPEND SwiftCore_INCLUDE_DIR_HINTS | ||
"${Swift_SDKROOT}/usr/lib/swift_static/android" | ||
"$ENV{SDKROOT}/usr/lib/swift_static/android") | ||
list(APPEND SwiftCore_LIBRARY_HINTS | ||
"${Swift_SDKROOT}/usr/lib/swift_static/android/${${PROJECT_NAME}_ARCH_SUBDIR}" | ||
"${Swift_SDKROOT}/usr/lib/swift_static" | ||
"$ENV{SDKROOT}/usr/lib/swift_static/android/${${PROJECT_NAME}_ARCH_SUBDIR}" | ||
"$ENV{SDKROOT}/usr/lib/swift_static") | ||
list(APPEND SwiftCore_NAMES libswiftCore.a) | ||
else() | ||
find_path(SwiftCore_INCLUDE_DIR | ||
"Swift.swiftmodule" | ||
NO_CMAKE_FIND_ROOT_PATH | ||
HINTS | ||
"${Swift_SDKROOT}/usr/lib/swift_static/android" | ||
"$ENV{SDKROOT}/usr/lib/swift_static/android") | ||
find_library(SwiftCore_LIBRARY | ||
NO_CMAKE_FIND_ROOT_PATH | ||
NAMES "libswiftCore.a" | ||
HINTS | ||
"${Swift_SDKROOT}/usr/lib/swift_static/android/${SwiftCore_ARCH_SUBDIR}" | ||
"${Swift_SDKROOT}/usr/lib/swift_static" | ||
"$ENV{SDKROOT}/usr/lib/swift_static/android/${SwiftCore_ARCH_SUBDIR}" | ||
"$ENV{SDKROOT}/usr/lib/swift_static") | ||
|
||
add_library(swiftCore STATIC IMPORTED GLOBAL) | ||
list(APPEND SwiftCore_INCLUDE_DIR_HINTS | ||
"${Swift_SDKROOT}/usr/lib/swift/android" | ||
"$ENV{SDKROOT}/usr/lib/swift/android") | ||
list(APPEND SwiftCore_LIBRARY_HINTS | ||
"${Swift_SDKROOT}/usr/lib/swift/android/${${PROJECT_NAME}_ARCH_SUBDIR}" | ||
"${Swift_SDKROOT}/usr/lib/swift" | ||
"$ENV{SDKROOT}/usr/lib/swift/android/${${PROJECT_NAME}_ARCH_SUBDIR}" | ||
"$ENV{SDKROOT}/usr/lib/swift") | ||
list(APPEND SwiftCore_NAMES libswiftCore.so) | ||
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) | ||
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() | ||
|
||
find_path(SwiftCore_INCLUDE_DIR | ||
"Swift.swiftmodule" | ||
NO_CMAKE_FIND_ROOT_PATH | ||
HINTS | ||
${SwiftCore_INCLUDE_DIR_HINTS}) | ||
find_library(SwiftCore_LIBRARY | ||
NAMES | ||
${SwiftCore_NAMES} | ||
NO_CMAKE_FIND_ROOT_PATH | ||
HINTS | ||
${SwiftCore_LIBRARY_HINTS}) | ||
|
||
if(SwiftCore_USE_STATIC_LIBS) | ||
add_library(swiftCore STATIC IMPORTED GLOBAL) | ||
else() | ||
add_library(swiftCore SHARED IMPORTED GLOBAL) | ||
endif() | ||
|
||
set_target_properties(swiftCore PROPERTIES | ||
INTERFACE_INCLUDE_DIRECTORIES "${SwiftCore_INCLUDE_DIR}") | ||
|
||
if(LINUX OR ANDROID) | ||
set_target_properties(swiftCore PROPERTIES | ||
IMPORTED_LOCATION "${SwiftCore_LIBRARY}") | ||
else() | ||
set_target_properties(swiftCore PROPERTIES | ||
IMPORTED_IMPLIB "${SwiftCore_LIBRARY}") | ||
endif() | ||
|
||
find_package_handle_standard_args(SwiftCore DEFAULT_MSG | ||
SwiftCore_LIBRARY SwiftCore_INCLUDE_DIR) |
Uh oh!
There was an error while loading. Please reload this page.