|
| 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") |
0 commit comments