|
| 1 | +#[=======================================================================[.rst: |
| 2 | +Finddispatch |
| 3 | +------------ |
| 4 | +
|
| 5 | +Find libdispatch, deferring to dispatchConfig.cmake when requested. |
| 6 | +This is meant to find the C implementation of libdispatch for use as the |
| 7 | +executor for Swift concurrency. This library is not intended for use by |
| 8 | +third-party program on Linux or Windows. |
| 9 | +
|
| 10 | +Imported Targets |
| 11 | +^^^^^^^^^^^^^^^^ |
| 12 | +
|
| 13 | +The following :prop_tgt:`IMPORTED` TARGETS may be defined: |
| 14 | +
|
| 15 | + ``dispatch`` |
| 16 | +
|
| 17 | +Hint Variables |
| 18 | +^^^^^^^^^^^^^^ |
| 19 | +
|
| 20 | + ``swift_SDKROOT`` |
| 21 | + Set the path to the Swift SDK installation. |
| 22 | + This only affects Linux and Windows builds. |
| 23 | + Apple builds always use the library provided by the SDK. |
| 24 | +
|
| 25 | + ``dispatch_STATIC`` |
| 26 | + Look for the libdispatch static archive instead of the dynamic library. |
| 27 | + This only affects Linux. Apple builds always use the |
| 28 | + dynamic library provided by the SDK. Windows does not currently have a static |
| 29 | + libdispatch implementation. |
| 30 | +
|
| 31 | +Result Variables |
| 32 | +^^^^^^^^^^^^^^^^ |
| 33 | +
|
| 34 | +The module may set the following variables if `dispatch_DIR` is not set. |
| 35 | +
|
| 36 | + ``dispatch_FOUND`` |
| 37 | + true if dispatch headers and libraries were found |
| 38 | +
|
| 39 | + ``dispatch_INCLUDE_DIR`` |
| 40 | + the directory containing the libdispatch headers |
| 41 | +
|
| 42 | + ``dispatch_LIBRARIES`` OR ``dispatch_IMPLIB`` |
| 43 | + the libraries to be linked |
| 44 | +
|
| 45 | +#]=======================================================================] |
| 46 | + |
| 47 | +# If the dispatch_DIR is specified, look there instead. The cmake-generated |
| 48 | +# config file is more accurate, but requires that the SDK has one available. |
| 49 | +if(dispatch_DIR) |
| 50 | + if(dispatch_FIND_REQUIRED) |
| 51 | + list(APPEND args REQUIRED) |
| 52 | + endif() |
| 53 | + if(dispatch_FIND_QUIETLY) |
| 54 | + list(APPEND args QUIET) |
| 55 | + endif() |
| 56 | + find_package(dispatch NO_MODULE ${args}) |
| 57 | + return() |
| 58 | +endif() |
| 59 | + |
| 60 | +include(FindPackageHandleStandardArgs) |
| 61 | + |
| 62 | +if(APPLE) |
| 63 | + # When building for Apple platforms, libdispatch always comes from within the |
| 64 | + # SDK as a tbd for a shared library in the shared cache. |
| 65 | + find_path(dispatch_INCLUDE_DIR "dispatch/dispatch.h") |
| 66 | + find_library(dispatch_IMPLIB |
| 67 | + NAMES "libdispatch.tbd" |
| 68 | + PATH "usr/lib" |
| 69 | + PATH_SUFFIXES system) |
| 70 | + add_library(dispatch SHARED IMPORTED GLOBAL) |
| 71 | + set_target_properties(dispatch PROPERTIES |
| 72 | + IMPORTED_IMPLIB "${dispatch_IMPLIB}" |
| 73 | + INTERFACE_INCLUDE_DIRECTORIES "${dispatch_INCLUDE_DIR}") |
| 74 | + find_package_handle_standard_args(dispatch DEFAULT_MSG |
| 75 | + dispatch_IMPLIB dispatch_INCLUDE_DIR) |
| 76 | +elseif(LINUX) |
| 77 | + if(dispatch_STATIC) |
| 78 | + find_path(dispatch_INCLUDE_DIR |
| 79 | + "dispatch/dispatch.h" |
| 80 | + HINTS "${Swift_SDKROOT}/usr/lib/swift_static") |
| 81 | + find_library(dispatch_LIBRARY |
| 82 | + NAMES "libdispatch.a" |
| 83 | + HINTS "${Swift_SDKROOT}/usr/lib/swift_static/linux") |
| 84 | + add_library(dispatch STATIC IMPORTED GLOBAL) |
| 85 | + else() |
| 86 | + find_path(dispatch_INCLUDE_DIR |
| 87 | + "dispatch/dispatch.h" |
| 88 | + HINTS "${Swift_SDKROOT}/usr/lib/swift") |
| 89 | + find_library(dispatch_LIBRARY |
| 90 | + NAMES "libdispatch.so" |
| 91 | + HINTS "${Swift_SDKROOT}/usr/lib/swift/linux") |
| 92 | + add_library(dispatch SHARED IMPORTED GLOBAL) |
| 93 | + endif() |
| 94 | + set_target_properties(dispatch |
| 95 | + IMPORTED_LOCATION "${dispatch_LIBRARY}" |
| 96 | + INTERFACE_INCLUDE_DIRECTORIES "${dispatch_INCLUDE_DIR}") |
| 97 | + find_package_handle_standard_args(dispatch DEFAULT_MSG |
| 98 | + dispatch_LIBRARY dispatch_INCLUDE_DIR) |
| 99 | +elseif(WIN32) |
| 100 | + find_path(dispatch_INCLUDE_DIR |
| 101 | + "dispatch/dispatch.h" |
| 102 | + HINTS |
| 103 | + "${Swift_SDKROOT}/usr/include" |
| 104 | + "$ENV{SDKROOT}/usr/include") |
| 105 | + find_library(dispatch_LIBRARY |
| 106 | + NAMES "dispatch.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(dispatch SHARED IMPORTED GLOBAL) |
| 114 | + set_target_properties(dispatch |
| 115 | + IMPORTED_IMPLIB "${dispatch_LIBRARY}" |
| 116 | + INTERFACE_INCLUDE_DIRECTORIES "${dispatch_INCLUDE_DIR}") |
| 117 | + find_package_handle_standard_args(dispatch DEFAULT_MSG |
| 118 | + dispatch_IMPLIB dispatch_INCLUDE_DIR) |
| 119 | +else() |
| 120 | + message(FATAL_ERROR "Finddispatch.cmake module search not implemented for targeted platform\n" |
| 121 | + " Build corelibs libdispatch for your platform and set `dispatch_DIR` to" |
| 122 | + " the directory containing dispatchConfig.cmake\n") |
| 123 | +endif() |
0 commit comments