Skip to content

Commit 24dea3e

Browse files
committed
build: add a cmake based build system
This is far from complete, but is sufficient to build a Linux version of libdispatch. It shows what a potential cmake based build system could look like, and if desired can be completed to build all the various flavours with cmake.
1 parent 012f48b commit 24dea3e

File tree

8 files changed

+580
-0
lines changed

8 files changed

+580
-0
lines changed

CMakeLists.txt

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
2+
cmake_minimum_required(VERSION 3.4.3)
3+
4+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
5+
6+
project(dispatch C)
7+
8+
set(CMAKE_C_VISIBILITY_PRESET hidden)
9+
10+
include(GNUInstallDirs)
11+
12+
set(WITH_KQUEUE "" CACHE PATH "Path to kqueue headers")
13+
set(WITH_BLOCKS_RUNTIME "" CACHE PATH "Path to blocks runtime")
14+
set(WITH_PTHREAD_WORKQUEUES "" CACHE PATH "Path to pthread-workqueues")
15+
16+
include(DispatchAppleOptions)
17+
18+
option(ENABLE_DISPATCH_INIT_CONSTRUCTOR "enable libdispatch_init as a constructor" OFF)
19+
option(ENABLE_THREAD_LOCAL_STORAGE "enable usage of thread local storage via __thread" OFF)
20+
21+
if(ENABLE_DISPATCH_INIT_CONSTRUCTOR)
22+
add_definitions(-DUSE_LIBDISPATCH_INIT_CONSTRUCTOR=1)
23+
endif()
24+
if(ENABLE_THREAD_LOCAL_STORAGE)
25+
add_definitions(-DDISPATCH_USE_THREAD_LOCAL_STORAGE=1)
26+
endif()
27+
28+
include(CheckCSourceCompiles)
29+
include(CheckFunctionExists)
30+
include(CheckIncludeFiles)
31+
include(CheckLibraryExists)
32+
include(CheckSymbolExists)
33+
34+
check_c_source_compiles(
35+
"
36+
#include <features.h>
37+
#if defined(__GNU_LIBRARY__)
38+
int main() { return 0; }
39+
#endif
40+
"
41+
_GNU_SOURCE)
42+
if(_GNU_SOURCE)
43+
set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -D_GNU_SOURCE)
44+
add_definitions(-D_GNU_SOURCE)
45+
endif()
46+
47+
find_library(HAVE_LIBRT NAMES rt)
48+
if(HAVE_LIBRT)
49+
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} rt)
50+
endif()
51+
52+
check_function_exists(_pthread_workqueue_init HAVE__PTHREAD_WORKQUEUE_INIT)
53+
check_function_exists(getprogname HAVE_GETPROGNAME)
54+
check_function_exists(mach_absolute_time HAVE_MACH_ABSOLUTE_TIME)
55+
check_function_exists(mach_port_construct HAVE_MACH_PORT_CONSTRUCT)
56+
check_function_exists(malloc_create_zone HAVE_MALLOC_CREATE_ZONE)
57+
check_function_exists(pthread_key_init_np HAVE_PTHREAD_KEY_INIT_NP)
58+
check_function_exists(pthread_main_np HAVE_PTHREAD_MAIN_NP)
59+
check_function_exists(pthread_workqueue_setdispatch_np HAVE_PTHREAD_WORKQUEUE_SETDISPATCH_NP)
60+
check_function_exists(strlcpy HAVE_STRLCPY)
61+
check_function_exists(sysconf HAVE_SYSCONF)
62+
63+
if(NOT HAVE_STRLCPY AND NOT HAVE_GETPROGNAME)
64+
include(FindPkgConfig)
65+
pkg_check_modules(BSD_OVERLAY libbsd-overlay)
66+
if(BSD_OVERLAY_FOUND)
67+
set(HAVE_STRLCPY 1)
68+
set(HAVE_GETPROGNAME 1)
69+
endif()
70+
endif()
71+
72+
check_include_files("TargetConditionals.h" HAVE_TARGETCONDITIONALS_H)
73+
check_include_files("dlfcn.h" HAVE_DLFCN_H)
74+
check_include_files("fcntl.h" HAVE_FCNTL_H)
75+
check_include_files("inttypes.h" HAVE_INTTYPES_H)
76+
check_include_files("libkern/OSAtomic.h" HAVE_LIBKERN_OSATOMIC_H)
77+
check_include_files("libkern/OSCrossEndian.h" HAVE_LIBKERN_OSCROSSENDIAN_H)
78+
check_include_files("libproc_internal.h" HAVE_LIBPROC_INTERNAL_H)
79+
check_include_files("mach/mach.h" HAVE_MACH)
80+
if(HAVE_MACH)
81+
set(__DARWIN_NON_CANCELABLE 1)
82+
set(USE_MACH_SEM 1)
83+
else()
84+
set(__DARWIN_NON_CANCELABLE 0)
85+
set(USE_MACH_SEM 0)
86+
endif()
87+
check_include_files("malloc/malloc.h" HAVE_MALLOC_MALLOC_H)
88+
check_include_files("memory.h" HAVE_MEMORY_H)
89+
check_include_files("pthread/qos.h" HAVE_PTHREAD_QOS_H)
90+
check_include_files("pthread/workqueue_private.h" HAVE_PTHREAD_WORKQUEUE_PRIVATE_H)
91+
check_include_files("pthread_machdep.h" HAVE_PTHREAD_MACHDEP_H)
92+
check_include_files("pthread_np.h" HAVE_PTHREAD_NP_H)
93+
check_include_files("pthread_workqueue.h" HAVE_PTHREAD_WORKQUEUE_H)
94+
check_include_files("stdint.h" HAVE_STDINT_H)
95+
check_include_files("stdlib.h" HAVE_STDLIB_H)
96+
check_include_files("string.h" HAVE_STRING_H)
97+
check_include_files("strings.h" HAVE_STRINGS_H)
98+
check_include_files("sys/cdefs.h" HAVE_SYS_CDEFS_H)
99+
check_include_files("sys/guarded.h" HAVE_SYS_GUARDED_H)
100+
check_include_files("sys/stat.h" HAVE_SYS_STAT_H)
101+
check_include_files("sys/types.h" HAVE_SYS_TYPES_H)
102+
check_include_files("unistd.h" HAVE_UNISTD_H)
103+
104+
check_library_exists(pthread sem_init "" USE_POSIX_SEM)
105+
106+
check_symbol_exists(CLOCK_UPTIME "time.h" HAVE_DECL_CLOCK_UPTIME)
107+
check_symbol_exists(CLOCK_MONOTONIC "time.h" HAVE_DECL_CLOCK_MONOTONIC)
108+
check_symbol_exists(FD_COPY "sys/select.h" HAVE_DECL_FD_COPY)
109+
check_symbol_exists(NOTE_NONE "sys/event.h" HAVE_DECL_NOTE_NONE)
110+
check_symbol_exists(NOTE_REAP "sys/event.h" HAVE_DECL_NOTE_REAP)
111+
check_symbol_exists(NOTE_REVOKE "sys/event.h" HAVE_DECL_NOTE_REVOKE)
112+
check_symbol_exists(NOTE_SIGNAL "sys/event.h" HAVE_DECL_NOTE_SIGNAL)
113+
check_symbol_exists(SIGEMT "signal.h" HAVE_DECL_SIGEMT)
114+
check_symbol_exists(VQ_QUOTA "sys/mount.h" HAVE_DECL_VQ_QUOTA)
115+
check_symbol_exists(VQ_UPDATE "sys/mount.h" HAVE_DECL_VQ_UPDATE)
116+
check_symbol_exists(VQ_VERYLOWDISK "sys/mount.h" HAVE_DECL_VQ_VERYLOWDISK)
117+
118+
check_symbol_exists(program_invocation_name "errno.h" HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME)
119+
120+
if(APPLE)
121+
add_definitions(-DDISPATCH_USE_DTRACE=1)
122+
else()
123+
add_definitions(-DDISPATCH_USE_DTRACE=0)
124+
endif()
125+
126+
# TODO(compnerd) unify the config.h naming across Darwin and others and rename
127+
# to config.h
128+
configure_file("${CMAKE_SOURCE_DIR}/cmake/config.h.in"
129+
"${CMAKE_BINARY_DIR}/config/config_ac.h")
130+
131+
add_subdirectory(dispatch)
132+
add_subdirectory(man)
133+
add_subdirectory(os)
134+
add_subdirectory(private)
135+
add_subdirectory(src)
136+
if(ENABLE_TESTING)
137+
add_subdirectory(tests)
138+
endif()
139+

cmake/config.h.in

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
/* config/config.h.in. Generated from configure.ac by autoheader. */
2+
3+
/* Define if building pthread work queues from source */
4+
#undef BUILD_OWN_PTHREAD_WORKQUEUES
5+
6+
/* Define to 1 if you have the declaration of `CLOCK_MONOTONIC', and to 0 if
7+
you don't. */
8+
#cmakedefine01 HAVE_DECL_CLOCK_MONOTONIC
9+
10+
/* Define to 1 if you have the declaration of `CLOCK_UPTIME', and to 0 if you
11+
don't. */
12+
#cmakedefine01 HAVE_DECL_CLOCK_UPTIME
13+
14+
/* Define to 1 if you have the declaration of `FD_COPY', and to 0 if you
15+
don't. */
16+
#cmakedefine01 HAVE_DECL_FD_COPY
17+
18+
/* Define to 1 if you have the declaration of `NOTE_NONE', and to 0 if you
19+
don't. */
20+
#cmakedefine01 HAVE_DECL_NOTE_NONE
21+
22+
/* Define to 1 if you have the declaration of `NOTE_REAP', and to 0 if you
23+
don't. */
24+
#cmakedefine01 HAVE_DECL_NOTE_REAP
25+
26+
/* Define to 1 if you have the declaration of `NOTE_REVOKE', and to 0 if you
27+
don't. */
28+
#cmakedefine01 HAVE_DECL_NOTE_REVOKE
29+
30+
/* Define to 1 if you have the declaration of `NOTE_SIGNAL', and to 0 if you
31+
don't. */
32+
#cmakedefine01 HAVE_DECL_NOTE_SIGNAL
33+
34+
/* Define to 1 if you have the declaration of `POSIX_SPAWN_START_SUSPENDED',
35+
and to 0 if you don't. */
36+
#undef HAVE_DECL_POSIX_SPAWN_START_SUSPENDED
37+
38+
/* Define to 1 if you have the declaration of `program_invocation_short_name',
39+
and to 0 if you don't. */
40+
#cmakedefine01 HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
41+
42+
/* Define to 1 if you have the declaration of `SIGEMT', and to 0 if you don't.
43+
*/
44+
#cmakedefine01 HAVE_DECL_SIGEMT
45+
46+
/* Define to 1 if you have the declaration of `VQ_QUOTA', and to 0 if you
47+
don't. */
48+
#cmakedefine01 HAVE_DECL_VQ_QUOTA
49+
50+
/* Define to 1 if you have the declaration of `VQ_UPDATE', and to 0 if you
51+
don't. */
52+
#cmakedefine01 HAVE_DECL_VQ_UPDATE
53+
54+
/* Define to 1 if you have the declaration of `VQ_VERYLOWDISK', and to 0 if
55+
you don't. */
56+
#cmakedefine01 HAVE_DECL_VQ_VERYLOWDISK
57+
58+
/* Define to 1 if you have the <dlfcn.h> header file. */
59+
#cmakedefine01 HAVE_DLFCN_H
60+
61+
/* Define to 1 if you have the <fcntl.h> header file. */
62+
#cmakedefine01 HAVE_FCNTL_H
63+
64+
/* Define to 1 if you have the `getprogname' function. */
65+
#cmakedefine01 HAVE_GETPROGNAME
66+
67+
/* Define to 1 if you have the <inttypes.h> header file. */
68+
#cmakedefine01 HAVE_INTTYPES_H
69+
70+
/* Define if Apple leaks program is present */
71+
#undef HAVE_LEAKS
72+
73+
/* Define to 1 if you have the <libkern/OSAtomic.h> header file. */
74+
#cmakedefine01 HAVE_LIBKERN_OSATOMIC_H
75+
76+
/* Define to 1 if you have the <libkern/OSCrossEndian.h> header file. */
77+
#cmakedefine01 HAVE_LIBKERN_OSCROSSENDIAN_H
78+
79+
/* Define to 1 if you have the <libproc_internal.h> header file. */
80+
#cmakedefine01 HAVE_LIBPROC_INTERNAL_H
81+
82+
/* Define if mach is present */
83+
#cmakedefine01 HAVE_MACH
84+
85+
/* Define to 1 if you have the `mach_absolute_time' function. */
86+
#cmakedefine01 HAVE_MACH_ABSOLUTE_TIME
87+
88+
/* Define to 1 if you have the `mach_port_construct' function. */
89+
#cmakedefine01 HAVE_MACH_PORT_CONSTRUCT
90+
91+
/* Define to 1 if you have the `malloc_create_zone' function. */
92+
#cmakedefine01 HAVE_MALLOC_CREATE_ZONE
93+
94+
/* Define to 1 if you have the <malloc/malloc.h> header file. */
95+
#cmakedefine01 HAVE_MALLOC_MALLOC_H
96+
97+
/* Define to 1 if you have the <memory.h> header file. */
98+
#cmakedefine01 HAVE_MEMORY_H
99+
100+
/* Define if __builtin_trap marked noreturn */
101+
#undef HAVE_NORETURN_BUILTIN_TRAP
102+
103+
/* Define if you have the Objective-C runtime */
104+
#undef HAVE_OBJC
105+
106+
/* Define to 1 if you have the `pthread_key_init_np' function. */
107+
#cmakedefine01 HAVE_PTHREAD_KEY_INIT_NP
108+
109+
/* Define to 1 if you have the <pthread_machdep.h> header file. */
110+
#cmakedefine01 HAVE_PTHREAD_MACHDEP_H
111+
112+
/* Define to 1 if you have the `pthread_main_np' function. */
113+
#cmakedefine01 HAVE_PTHREAD_MAIN_NP
114+
115+
/* Define to 1 if you have the <pthread_np.h> header file. */
116+
#cmakedefine01 HAVE_PTHREAD_NP_H
117+
118+
/* Define to 1 if you have the <pthread/qos.h> header file. */
119+
#cmakedefine01 HAVE_PTHREAD_QOS_H
120+
121+
/* Define if pthread work queues are present */
122+
#undef HAVE_PTHREAD_WORKQUEUES
123+
124+
/* Define to 1 if you have the <pthread_workqueue.h> header file. */
125+
#cmakedefine01 HAVE_PTHREAD_WORKQUEUE_H
126+
127+
/* Define to 1 if you have the <pthread/workqueue_private.h> header file. */
128+
#cmakedefine01 HAVE_PTHREAD_WORKQUEUE_PRIVATE_H
129+
130+
/* Define to 1 if you have the `pthread_workqueue_setdispatch_np' function. */
131+
#cmakedefine01 HAVE_PTHREAD_WORKQUEUE_SETDISPATCH_NP
132+
133+
/* Define to 1 if you have the <stdint.h> header file. */
134+
#cmakedefine HAVE_STDINT_H
135+
136+
/* Define to 1 if you have the <stdlib.h> header file. */
137+
#cmakedefine01 HAVE_STDLIB_H
138+
139+
/* Define to 1 if you have the <strings.h> header file. */
140+
#cmakedefine01 HAVE_STRINGS_H
141+
142+
/* Define to 1 if you have the <string.h> header file. */
143+
#cmakedefine01 HAVE_STRING_H
144+
145+
/* Define to 1 if you have the `strlcpy' function. */
146+
#cmakedefine01 HAVE_STRLCPY
147+
148+
/* Define if building for Swift */
149+
#undef HAVE_SWIFT
150+
151+
/* Define to 1 if you have the `sysconf' function. */
152+
#cmakedefine01 HAVE_SYSCONF
153+
154+
/* Define to 1 if you have the <sys/cdefs.h> header file. */
155+
#cmakedefine01 HAVE_SYS_CDEFS_H
156+
157+
/* Define to 1 if you have the <sys/guarded.h> header file. */
158+
#cmakedefine01 HAVE_SYS_GUARDED_H
159+
160+
/* Define to 1 if you have the <sys/stat.h> header file. */
161+
#cmakedefine01 HAVE_SYS_STAT_H
162+
163+
/* Define to 1 if you have the <sys/types.h> header file. */
164+
#cmakedefine01 HAVE_SYS_TYPES_H
165+
166+
/* Define to 1 if you have the <TargetConditionals.h> header file. */
167+
#cmakedefine01 HAVE_TARGETCONDITIONALS_H
168+
169+
/* Define to 1 if you have the <unistd.h> header file. */
170+
#cmakedefine01 HAVE_UNISTD_H
171+
172+
/* Define to 1 if you have the `_pthread_workqueue_init' function. */
173+
#cmakedefine01 HAVE__PTHREAD_WORKQUEUE_INIT
174+
175+
/* Define to the sub-directory where libtool stores uninstalled libraries. */
176+
#undef LT_OBJDIR
177+
178+
/* Name of package */
179+
#undef PACKAGE
180+
181+
/* Define to the address where bug reports for this package should be sent. */
182+
#undef PACKAGE_BUGREPORT
183+
184+
/* Define to the full name of this package. */
185+
#cmakedefine PACKAGE_NAME
186+
187+
/* Define to the full name and version of this package. */
188+
#define PACKAGE_STRING #PACKAGE_NAME
189+
190+
/* Define to the one symbol short name of this package. */
191+
#undef PACKAGE_TARNAME
192+
193+
/* Define to the home page for this package. */
194+
#undef PACKAGE_URL
195+
196+
/* Define to the version of this package. */
197+
#cmakedefine PACKAGE_VERSION
198+
199+
/* Define to 1 if you have the ANSI C header files. */
200+
#undef STDC_HEADERS
201+
202+
/* Define to use non-portable pthread TSD optimizations for Mac OS X) */
203+
#cmakedefine01 USE_APPLE_TSD_OPTIMIZATIONS
204+
205+
/* Define to use Futex semaphores */
206+
#undef USE_FUTEX_SEM
207+
208+
/* Define to tag libdispatch_init as a constructor */
209+
#undef USE_LIBDISPATCH_INIT_CONSTRUCTOR
210+
211+
/* Define to use Mach semaphores */
212+
#cmakedefine01 USE_MACH_SEM
213+
214+
/* Define to use POSIX semaphores */
215+
#cmakedefine01 USE_POSIX_SEM
216+
217+
/* Enable extensions on AIX 3, Interix. */
218+
#ifndef _ALL_SOURCE
219+
# undef _ALL_SOURCE
220+
#endif
221+
/* Enable GNU extensions on systems that have them. */
222+
#ifndef _GNU_SOURCE
223+
#cmakedefine _GNU_SOURCE
224+
#endif
225+
/* Enable threading extensions on Solaris. */
226+
#ifndef _POSIX_PTHREAD_SEMANTICS
227+
# undef _POSIX_PTHREAD_SEMANTICS
228+
#endif
229+
/* Enable extensions on HP NonStop. */
230+
#ifndef _TANDEM_SOURCE
231+
# undef _TANDEM_SOURCE
232+
#endif
233+
/* Enable general extensions on Solaris. */
234+
#ifndef __EXTENSIONS__
235+
# undef __EXTENSIONS__
236+
#endif
237+
238+
239+
/* Version number of package */
240+
#undef VERSION
241+
242+
/* Define to 1 if on MINIX. */
243+
#undef _MINIX
244+
245+
/* Define to 2 if the system does not provide POSIX.1 features except with
246+
this defined. */
247+
#undef _POSIX_1_SOURCE
248+
249+
/* Define to 1 if you need to in order for `stat' and other things to work. */
250+
#undef _POSIX_SOURCE
251+
252+
/* Define if using Darwin $NOCANCEL */
253+
#cmakedefine01 __DARWIN_NON_CANCELABLE

0 commit comments

Comments
 (0)