Skip to content

Commit 178a6ca

Browse files
etcwildektoso
authored andcommitted
Add Finddispatch module
Implementing an initial `Finddispatch.cmake` module to find Dispatch from the system SDK on Apple platforms. Still should implement a basic mechanism for finding it on Windows and Linux. Note that those platforms will likely use the dispatch config mechanism most frequently, but this should still work as a fallback. This mechanism is the only one that works for Apple platforms though as those use libdispatch from the SDK rather than building it with corelibs-libdispatch.
1 parent d7c9cfd commit 178a6ca

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#[=======================================================================[.rst:
2+
Finddispatch
3+
------------
4+
5+
Find libdispatch on macOS and Linux while deferring to dispatchConcig.cmake when
6+
available or requested.
7+
8+
Components
9+
^^^^^^^^^^
10+
11+
This module supports the optional component `Swift`, for use with the
12+
`COMPONENTS` argument of the :command:`find_package` command. This component
13+
defines the associated ``swiftDispatch`` IMPORT target.
14+
15+
Imported Targets
16+
^^^^^^^^^^^^^^^^
17+
18+
The following :prop_tgt:`IMPORTED` TARGETS may be defined:
19+
20+
``dispatch``
21+
22+
``swiftDispatch``
23+
24+
Result Variables
25+
^^^^^^^^^^^^^^^^
26+
27+
The module may set the following variables if `dispatch_DIR` is not set.
28+
29+
``dispatch_FOUND``
30+
true if dispatch headers and libraries were found
31+
32+
``dispatch_INCLUDE_DIR``
33+
the directory containing the libdispatch headers
34+
35+
``dispatch_LIBRARIES``
36+
the libraries to be linked
37+
38+
39+
#]=======================================================================]
40+
41+
# If the dispatch_DIR is specified, look there instead. The cmake-generated
42+
# config file is more accurate, but requires that the SDK has one available.
43+
if(dispatch_DIR)
44+
if(dispatch_FIND_REQUIRED)
45+
list(APPEND args REQUIRED)
46+
endif()
47+
if(dispatch_FIND_QUIETLY)
48+
list(APPEND args QUIET)
49+
endif()
50+
find_package(dispatch NO_MODULE ${args})
51+
return()
52+
endif()
53+
54+
if(APPLE)
55+
find_path(dispatch_INCLUDE_DIR "dispatch/dispatch.h")
56+
find_library(dispatch_LIBRARY NAMES "libdispatch.tbd"
57+
PATH "usr/lib/system"
58+
PATH_SUFFIXES system)
59+
60+
add_library(dispatch SHARED IMPORTED GLOBAL)
61+
set_target_properties(dispatch PROPERTIES
62+
IMPORTED_IMPLIB "${dispatch_LIBRARY}"
63+
INTERFACE_INCLUDE_DIRECTORIES "${dispatch_INCLUDE_DIR}")
64+
else()
65+
# TODO: Implement this for Linux and Windows
66+
message(FATAL_ERROR "Not implemented for platform")
67+
endif()

0 commit comments

Comments
 (0)