1
1
2
- cmake_minimum_required (VERSION 3.4.3 )
2
+ cmake_minimum_required (VERSION 3.15.1 )
3
3
4
- list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /cmake/modules" )
4
+ list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} /cmake/modules )
5
+
6
+ # NOTE(compnerd) enable CMP0091 - select MSVC runtime based on
7
+ # CMAKE_MSVC_RUNTIME_LIBRARY. Requires CMake 3.15 or newer.
8
+ if (POLICY CMP0091 )
9
+ cmake_policy (SET CMP0091 NEW )
10
+ endif ()
5
11
6
12
project (dispatch
7
- VERSION 1.3
8
- LANGUAGES C CXX )
13
+ VERSION 1.3
14
+ LANGUAGES C CXX )
9
15
10
16
if ("${CMAKE_C_SIMULATE_ID} " STREQUAL "MSVC" )
11
17
include (ClangClCompileRules )
12
18
endif ()
13
19
20
+ if (CMAKE_SYSTEM_NAME STREQUAL Windows )
21
+ include (DispatchWindowsSupport )
22
+ dispatch_windows_arch_spelling (${CMAKE_SYSTEM_PROCESSOR} DISPATCH_MSVC_ARCH )
23
+ dispatch_windows_include_for_arch (${DISPATCH_MSVC_ARCH} DISPATCH_INCLUDES )
24
+ include_directories (BEFORE SYSTEM ${DISPATCH_INCLUDES} )
25
+ dispatch_windows_lib_for_arch (${CMAKE_SYSTEM_PROCESSOR} DISPATCH_LIBDIR )
26
+ link_directories (${DISPATCH_LIBDIR} )
27
+ endif ()
28
+
14
29
set (CMAKE_C_STANDARD 11 )
15
30
set (CMAKE_C_STANDARD_REQUIRED YES )
16
31
17
32
set (CMAKE_CXX_STANDARD 11 )
18
33
19
34
set (CMAKE_C_VISIBILITY_PRESET hidden )
35
+ set (CMAKE_C_VISIBILITY_INLINES_HIDDEN YES )
20
36
21
37
# NOTE(compnerd) this is a horrible workaround for Windows to ensure that the
22
38
# tests can run as there is no rpath equivalent and `PATH` is used to lookup the
@@ -28,74 +44,37 @@ set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
28
44
set (THREADS_PREFER_PTHREAD_FLAG TRUE )
29
45
find_package (Threads REQUIRED )
30
46
47
+ include (CheckCCompilerFlag )
31
48
include (CheckCSourceCompiles )
32
49
include (CheckFunctionExists )
33
50
include (CheckIncludeFiles )
34
51
include (CheckLibraryExists )
35
52
include (CheckSymbolExists )
36
53
include (GNUInstallDirs )
37
- include (SwiftSupport )
38
54
include (CTest )
39
55
40
- set (SWIFT_LIBDIR "lib" CACHE PATH "Library folder name, defined by swift main buildscript" )
41
- set (INSTALL_LIBDIR "${SWIFT_LIBDIR} " CACHE PATH "Path where the libraries should be installed" )
42
-
43
56
include (DispatchAppleOptions )
44
57
include (DispatchSanitization )
45
-
46
58
include (DispatchCompilerWarnings )
47
- dispatch_common_warnings ()
48
-
49
- option (ENABLE_DISPATCH_INIT_CONSTRUCTOR "enable libdispatch_init as a constructor" ON )
50
- set (USE_LIBDISPATCH_INIT_CONSTRUCTOR ${ENABLE_DISPATCH_INIT_CONSTRUCTOR} )
59
+ include (DTrace )
60
+ include (SwiftSupport )
51
61
52
62
# NOTE(abdulras) this is the CMake supported way to control whether we generate
53
63
# shared or static libraries. This impacts the behaviour of `add_library` in
54
64
# what type of library it generates.
55
65
option (BUILD_SHARED_LIBS "build shared libraries" ON )
56
66
57
- option (ENABLE_SWIFT "enable libdispatch swift overlay" OFF )
58
- if (ENABLE_SWIFT )
59
- if (NOT CMAKE_SWIFT_COMPILER )
60
- message (FATAL_ERROR "CMAKE_SWIFT_COMPILER must be defined to enable swift" )
61
- endif ()
62
-
63
- string (TOLOWER ${CMAKE_SYSTEM_NAME} swift_os )
64
- get_swift_host_arch (swift_arch )
65
-
66
- if (BUILD_SHARED_LIBS )
67
- set (swift_dir swift )
68
- else ()
69
- set (swift_dir swift_static )
70
- endif ()
71
-
72
- set (INSTALL_TARGET_DIR "${INSTALL_LIBDIR} /${swift_dir} /${swift_os} " CACHE PATH "Path where the libraries will be installed" )
73
- set (INSTALL_DISPATCH_HEADERS_DIR "${INSTALL_LIBDIR} /${swift_dir} /dispatch" CACHE PATH "Path where the headers will be installed for libdispatch" )
74
- set (INSTALL_BLOCK_HEADERS_DIR "${INSTALL_LIBDIR} /${swift_dir} /Block" CACHE PATH "Path where the headers will be installed for the blocks runtime" )
75
- set (INSTALL_OS_HEADERS_DIR "${INSTALL_LIBDIR} /${swift_dir} /os" CACHE PATH "Path where the os/ headers will be installed" )
76
- endif ()
77
-
78
- if (NOT ENABLE_SWIFT )
79
- set (INSTALL_TARGET_DIR "${INSTALL_LIBDIR} " CACHE PATH "Path where the libraries will be installed" )
80
- set (INSTALL_DISPATCH_HEADERS_DIR "include/dispatch" CACHE PATH "Path where the headers will be installed" )
81
- set (INSTALL_BLOCK_HEADERS_DIR "include" CACHE PATH "Path where the headers will be installed for the blocks runtime" )
82
- set (INSTALL_OS_HEADERS_DIR "include/os" CACHE PATH "Path where the headers will be installed" )
83
- endif ()
84
-
85
67
option (DISPATCH_ENABLE_ASSERTS "enable debug assertions" FALSE )
86
68
87
- option (ENABLE_DTRACE "enable dtrace support" "" )
69
+ option (ENABLE_DISPATCH_INIT_CONSTRUCTOR "enable libdispatch_init as a constructor" ON )
70
+ set (USE_LIBDISPATCH_INIT_CONSTRUCTOR ${ENABLE_DISPATCH_INIT_CONSTRUCTOR} )
88
71
89
- option (ENABLE_THREAD_LOCAL_STORAGE "enable usage of thread local storage via _Thread_local" ON )
90
- set (DISPATCH_USE_THREAD_LOCAL_STORAGE ${ENABLE_THREAD_LOCAL_STORAGE} )
72
+ option (ENABLE_DTRACE "enable dtrace support" "" )
91
73
92
- if (CMAKE_SYSTEM_NAME STREQUAL Linux OR
93
- CMAKE_SYSTEM_NAME STREQUAL Android OR
94
- CMAKE_SYSTEM_NAME STREQUAL FreeBSD OR
95
- CMAKE_SYSTEM_NAME STREQUAL Windows )
96
- set (ENABLE_INTERNAL_PTHREAD_WORKQUEUES_DEFAULT ON )
97
- else ()
74
+ if (CMAKE_SYSTEM_NAME STREQUAL Darwin OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD )
98
75
set (ENABLE_INTERNAL_PTHREAD_WORKQUEUES_DEFAULT OFF )
76
+ else ()
77
+ set (ENABLE_INTERNAL_PTHREAD_WORKQUEUES_DEFAULT ON )
99
78
endif ()
100
79
option (ENABLE_INTERNAL_PTHREAD_WORKQUEUES "use libdispatch's own implementation of pthread workqueues" ${ENABLE_INTERNAL_PTHREAD_WORKQUEUES_DEFAULT} )
101
80
if (ENABLE_INTERNAL_PTHREAD_WORKQUEUES )
@@ -114,6 +93,15 @@ endif()
114
93
115
94
option (INSTALL_PRIVATE_HEADERS "installs private headers in the same location as the public ones" OFF )
116
95
96
+ option (ENABLE_SWIFT "enable libdispatch swift overlay" OFF )
97
+ if (ENABLE_SWIFT )
98
+ enable_language (Swift )
99
+ endif ()
100
+
101
+ option (ENABLE_THREAD_LOCAL_STORAGE "enable usage of thread local storage via _Thread_local" ON )
102
+ set (DISPATCH_USE_THREAD_LOCAL_STORAGE ${ENABLE_THREAD_LOCAL_STORAGE} )
103
+
104
+
117
105
check_symbol_exists (__GNU_LIBRARY__ "features.h" _GNU_SOURCE )
118
106
if (_GNU_SOURCE )
119
107
set (CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -D_GNU_SOURCE )
@@ -144,8 +132,6 @@ check_function_exists(strlcpy HAVE_STRLCPY)
144
132
check_function_exists (sysconf HAVE_SYSCONF )
145
133
check_function_exists (arc4random HAVE_ARC4RANDOM )
146
134
147
- find_package (Threads REQUIRED )
148
-
149
135
check_include_files ("TargetConditionals.h" HAVE_TARGETCONDITIONALS_H )
150
136
check_include_files ("dlfcn.h" HAVE_DLFCN_H )
151
137
check_include_files ("fcntl.h" HAVE_FCNTL_H )
@@ -181,7 +167,7 @@ else()
181
167
set (USE_MACH_SEM 0 )
182
168
endif ()
183
169
if (CMAKE_SYSTEM_NAME STREQUAL Windows )
184
- add_definitions ( -DUSE_WIN32_SEM )
170
+ add_compile_definitions ( $< $< OR: $< COMPILE_LANGUAGE:C > , $< COMPILE_LANGUAGE:CXX > > :USE_WIN32_SEM > )
185
171
endif ()
186
172
check_library_exists (pthread sem_init "" USE_POSIX_SEM )
187
173
# NOTE: android has not always provided a libpthread, but uses the pthreads API
@@ -211,7 +197,7 @@ check_symbol_exists(VQ_FREE_SPACE_CHANGE "sys/mount.h" HAVE_DECL_VQ_FREE_SPACE_C
211
197
check_symbol_exists (strlcpy "string.h" HAVE_STRLCPY )
212
198
check_symbol_exists (program_invocation_name "errno.h" HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME )
213
199
if (HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME )
214
- add_definitions ( -D_GNU_SOURCE=1 )
200
+ add_compile_definitions ( $< $< OR: $< COMPILE_LANGUAGE:C > , $< COMPILE_LANGUAGE:CXX > > :_GNU_SOURCE=1 > )
215
201
endif ()
216
202
check_symbol_exists (__printflike "bsd/sys/cdefs.h" HAVE_PRINTFLIKE )
217
203
@@ -220,31 +206,28 @@ if(CMAKE_SYSTEM_NAME STREQUAL Android)
220
206
endif ()
221
207
222
208
if (CMAKE_SYSTEM_NAME STREQUAL FreeBSD )
223
- add_definitions ( -D_WITH_DPRINTF )
209
+ add_compile_definitions ( $< $< OR: $< COMPILE_LANGUAGE:C > , $< COMPILE_LANGUAGE:CXX > > :_WITH_DPRINTF > )
224
210
endif ()
225
211
226
- if (ENABLE_DTRACE STREQUAL "" )
212
+ if (ENABLE_DTRACE )
227
213
find_program (dtrace_EXECUTABLE dtrace )
228
- if (dtrace_EXECUTABLE )
229
- add_definitions (-DDISPATCH_USE_DTRACE=1 )
230
- else ()
231
- add_definitions (-DDISPATCH_USE_DTRACE=0 )
232
- endif ()
233
- elseif (ENABLE_DTRACE )
234
- find_program (dtrace_EXECUTABLE dtrace )
235
- if (NOT dtrace_EXECUTABLE )
214
+ if (NOT dtrace_EXECUTABLE AND NOT ENABLE_DTRACE STREQUAL "" )
236
215
message (FATAL_ERROR "dtrace not found but explicitly requested" )
237
216
endif ()
238
- add_definitions (-DDISPATCH_USE_DTRACE=1 )
217
+ endif ()
218
+
219
+ if (dtrace_EXECUTABLE )
220
+ add_compile_definitions ($< $< OR:$< COMPILE_LANGUAGE:C> ,$< COMPILE_LANGUAGE:CXX> > :DISPATCH_USE_DTRACE=1> )
239
221
else ()
240
- add_definitions ( -DDISPATCH_USE_DTRACE=0 )
222
+ add_compile_definitions ( $< $< OR: $< COMPILE_LANGUAGE:C > , $< COMPILE_LANGUAGE:CXX > > :DISPATCH_USE_DTRACE=0 > )
241
223
endif ()
242
224
243
225
find_program (leaks_EXECUTABLE leaks )
244
226
if (leaks_EXECUTABLE )
245
227
set (HAVE_LEAKS TRUE )
246
228
endif ()
247
229
230
+
248
231
if (CMAKE_SYSTEM_NAME STREQUAL Darwin )
249
232
add_custom_command (OUTPUT
250
233
"${PROJECT_SOURCE_DIR} /dispatch/module.modulemap"
@@ -266,19 +249,25 @@ add_custom_target(module-maps ALL
266
249
DEPENDS
267
250
"${PROJECT_SOURCE_DIR} /dispatch/module.modulemap"
268
251
"${PROJECT_SOURCE_DIR} /private/module.modulemap" )
252
+
269
253
configure_file ("${PROJECT_SOURCE_DIR} /cmake/config.h.in"
270
254
"${PROJECT_BINARY_DIR} /config/config_ac.h" )
271
- add_definitions ( -DHAVE_CONFIG_H )
255
+ add_compile_definitions ( $< $< OR: $< COMPILE_LANGUAGE:C > , $< COMPILE_LANGUAGE:CXX > > :HAVE_CONFIG_H > )
272
256
273
- if (CMAKE_SYSTEM_NAME STREQUAL Windows )
274
- include (DispatchWindowsSupport )
275
- dispatch_windows_arch_spelling (${CMAKE_SYSTEM_PROCESSOR} DISPATCH_MSVC_ARCH )
276
- dispatch_windows_include_for_arch (${DISPATCH_MSVC_ARCH} DISPATCH_INCLUDES )
277
- include_directories (BEFORE SYSTEM ${DISPATCH_INCLUDES} )
278
- dispatch_windows_lib_for_arch (${CMAKE_SYSTEM_PROCESSOR} DISPATCH_LIBDIR )
279
- link_directories (${DISPATCH_LIBDIR} )
257
+
258
+ if (ENABLE_SWIFT )
259
+ set (INSTALL_TARGET_DIR "${CMAKE_INSTALL_LIBDIR} /swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS} >>:_static>/$<LOWER_CASE:${CMAKE_SYSTEM_NAME} >" CACHE PATH "Path where the libraries will be installed" )
260
+ set (INSTALL_DISPATCH_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR} /swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS} >>:_static>/dispatch" CACHE PATH "Path where the headers will be installed for libdispatch" )
261
+ set (INSTALL_BLOCK_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR} /swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS} >>:_static>/Block" CACHE PATH "Path where the headers will be installed for the blocks runtime" )
262
+ set (INSTALL_OS_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR} /swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS} >>:_static>/os" CACHE PATH "Path where the os/ headers will be installed" )
263
+ else ()
264
+ set (INSTALL_TARGET_DIR "${CMAKE_INSTALL_LIBDIR} " CACHE PATH "Path where the libraries will be installed" )
265
+ set (INSTALL_DISPATCH_HEADERS_DIR "include/dispatch" CACHE PATH "Path where the headers will be installed" )
266
+ set (INSTALL_BLOCK_HEADERS_DIR "include" CACHE PATH "Path where the headers will be installed for the blocks runtime" )
267
+ set (INSTALL_OS_HEADERS_DIR "include/os" CACHE PATH "Path where the headers will be installed" )
280
268
endif ()
281
269
270
+
282
271
add_subdirectory (dispatch )
283
272
add_subdirectory (man )
284
273
add_subdirectory (os )
@@ -287,4 +276,3 @@ add_subdirectory(src)
287
276
if (BUILD_TESTING )
288
277
add_subdirectory (tests )
289
278
endif ()
290
-
0 commit comments