-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmeson.build
345 lines (281 loc) · 8.4 KB
/
meson.build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
project(
'swa',
'c',
version: '0.1.0',
license: 'MIT',
meson_version: '>=0.51.0',
default_options: [
'c_std=c11',
'warning_level=3',
'werror=true',
],
)
examples = get_option('examples')
opt_with_gl = get_option('with-gl')
opt_with_vulkan = get_option('with-vulkan')
opt_link_vulkan = get_option('link-vulkan')
opt_with_wayland = get_option('with-wayland')
opt_with_x11 = get_option('with-x11')
opt_with_kms = get_option('with-kms')
cc = meson.get_compiler('c')
args = cc.get_supported_arguments([
# gcc/clang
'-Wno-unused-parameter',
'-Wno-unused-function',
'-Wno-missing-braces',
'-Wundef',
'-Wvla',
# msvc
'/wd4127', # conditional expression is constant
'/wd4706', # assignment within conditional expression
'/wd4100', # unreferenced formal parameter
'/wd4189', # local variable unused
'/wd4090', # wrong const double pointer warnings
'/wd5105', # needed to fix an issue in winbase.h on a specific windows version (wtf microsoft)
# c99 & c11 compat
'/wd4132', # const object should be initialized (for fwd decl)
'/wd4204', # non-constant aggregate initializer
'/wd4201', # anonymous union extension
])
if meson.get_compiler('c').get_id() == 'clang'
args += '-Wno-missing-braces'
endif
add_project_arguments(args, language: 'c')
swa_src = files('src/swa/swa.c')
source_root = '/'.join(meson.global_source_root().split('\\'))
flag_dlg = '-DDLG_BASE_PATH="' + source_root + '/"'
add_project_arguments(flag_dlg, language: 'c')
dep_threads = dependency('threads', required: false)
dep_dlg = dependency('dlg',
fallback: ['dlg', 'dlg_dep'],
)
shared = (get_option('default_library') == 'shared')
swa_deps = [dep_dlg, dep_threads]
swa_args = []
conf_data = configuration_data()
conf_data.set('SWA_SHARED', shared, description: 'Compiled as shared library')
dep_vulkan_full = dependency('vulkan', required: opt_with_vulkan)
dep_vulkan = dep_vulkan_full
if not opt_link_vulkan
dep_vulkan = dep_vulkan.partial_dependency(
compile_args: true,
includes: true)
endif
swa_inc = [
include_directories('src'),
include_directories('include'),
]
with_x11 = false
with_wl = false
with_win = false
with_android = false
with_kms = false
with_gl = false
with_vk = dep_vulkan.found()
if host_machine.system() == 'android'
dep_egl = cc.find_library('EGL', required: opt_with_gl)
dep_log = cc.find_library('log')
dep_android = cc.find_library('android')
with_android = true
with_gl = dep_egl.found()
swa_src += files('src/swa/android.c')
if with_gl
swa_src += files('src/swa/egl.c')
endif
swa_deps += [
dep_log,
dep_android,
dep_egl,
dep_vulkan,
]
elif host_machine.system() == 'windows'
dep_gl = dependency('gl', required: opt_with_gl)
with_win = true
with_gl = dep_gl.found()
if shared
swa_args += '-DSWA_API=__declspec(dllexport)'
endif
swa_args += '-D_WIN32_WINNT=0x0600'
swa_deps += cc.find_library('Dwmapi')
swa_deps += cc.find_library('Shlwapi')
swa_deps += cc.find_library('Gdi32')
swa_deps += dep_vulkan
swa_deps += dep_gl
swa_src += files('src/swa/winapi.c')
if with_gl
swa_src += files('src/swa/wgl.c')
endif
# embrace, extend, extinguish? meh
swa_args += '-D_CRT_SECURE_NO_WARNINGS'
else # just assume some posix/unix variant
dep_pml = dependency('pml',
fallback: ['pml', 'pml_dep'],
static: true,
default_options: ['examples=false', 'tests=false'],
)
# we require xkbcommon since it's needed by all backends
dep_xkbcommon = dependency('xkbcommon', required: true)
swa_src += files(
'src/swa/xkb.c',
'src/swa/xcursor.c',
)
dep_egl = dependency('egl', required: opt_with_gl, version: '>=1.4')
with_gl = dep_egl.found()
if with_gl
swa_src += files('src/swa/egl.c')
endif
swa_deps += [
dep_xkbcommon,
dep_pml,
dep_vulkan,
dep_egl,
]
# == wayland ==
dep_wl_client = dependency('wayland-client', required: opt_with_wayland)
dep_wl_cursor = dependency('wayland-cursor', required: opt_with_wayland)
wl_protos = dependency('wayland-protocols', version: '>=1.14', required: opt_with_wayland)
wl_scanner = find_program('wayland-scanner', required: opt_with_wayland)
with_wl = dep_wl_client.found() and dep_wl_cursor.found() and wl_protos.found() and wl_scanner.found()
# When wayland and egl is found, wayland-egl must be found as well.
if with_wl
dep_wl_egl = dependency('wayland-egl', required: with_gl and with_wl)
swa_src += files(
'src/swa/wayland.c',
)
wl_protocol_dir = wl_protos.get_pkgconfig_variable('pkgdatadir')
if dep_wl_client.version().version_compare('>=1.14.91')
code_type = 'private-code'
else
code_type = 'code'
endif
wl_scanner_code = generator(
wl_scanner,
output: '@[email protected]',
arguments: [code_type, '@INPUT@', '@OUTPUT@'],
)
wl_scanner_client = generator(
wl_scanner,
output: '@[email protected]',
arguments: ['client-header', '@INPUT@', '@OUTPUT@'],
)
wl_protos_src = []
wl_protos_headers = []
wl_protocols = [
[wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'],
[wl_protocol_dir, 'unstable/xdg-decoration/xdg-decoration-unstable-v1.xml'],
]
foreach p : wl_protocols
xml = join_paths(p)
wl_protos_src += wl_scanner_code.process(xml)
wl_protos_headers += wl_scanner_client.process(xml)
endforeach
lib_wl_protos = static_library(
'client_protos',
wl_protos_src + wl_protos_headers,
dependencies: [dep_wl_client]
) # for the include directory
dep_wl_protos = declare_dependency(
link_with: lib_wl_protos,
sources: wl_protos_headers,
)
swa_deps += [
dep_wl_client,
dep_wl_cursor,
dep_wl_egl,
dep_wl_protos,
]
endif
# == x11 ==
x11_deps = [
dep_xkbcommon,
dependency('x11', required: opt_with_x11),
dependency('x11-xcb', required: opt_with_x11),
dependency('xcursor', required: opt_with_x11),
dependency('xcb', required: opt_with_x11),
dependency('xcb-ewmh', required: opt_with_x11),
dependency('xcb-icccm', required: opt_with_x11),
dependency('xcb-shm', required: opt_with_x11),
dependency('xcb-present', required: opt_with_x11),
dependency('xcb-xinput', required: opt_with_x11),
dependency('xcb-xkb', required: opt_with_x11),
dependency('xkbcommon-x11', required: opt_with_x11),
]
with_x11 = true
foreach dep : x11_deps
if not dep.found()
with_x11 = false
endif
endforeach
if with_x11
swa_src += files(
'src/swa/x11.c',
)
swa_deps += x11_deps
endif
# kms/drm backend
dep_drm = dependency('libdrm', version: '>=2.4.95', required: opt_with_kms)
dep_gbm = dependency('gbm', version: '>=17.1.0', required: opt_with_kms)
dep_libinput = dependency('libinput', version: '>=1.9.0', required: opt_with_kms)
dep_udev = dependency('libudev', required: opt_with_kms)
with_kms = dep_drm.found() and dep_gbm.found() and dep_libinput.found() and dep_udev.found()
if with_kms
if with_vk
if not opt_link_vulkan
error('Combining kms backend and link-vulkan=false does not work')
endif
swa_src += files(
'src/swa/kms/vulkan.c'
)
endif
swa_src += files(
'src/swa/kms/kms.c',
'src/swa/kms/props.c',
'src/swa/kms/xcursor.c',
)
swa_deps += [
dep_drm,
dep_gbm,
dep_libinput,
dep_udev,
]
endif
# check that at least one backend is available
if not with_wl and not with_x11 and not with_kms
error('No backend enabled')
endif
endif
conf_data.set('SWA_WITH_VK', with_vk, description: 'Compiled with Vulkan support')
conf_data.set('SWA_WITH_LINKED_VK', opt_link_vulkan, description: 'Linked to vulkan library')
conf_data.set('SWA_WITH_ANDROID', with_android, description: 'Compiled with Android support')
conf_data.set('SWA_WITH_GL', with_gl, description: 'Compiled with OpenGL support')
conf_data.set('SWA_WITH_WL', with_wl, description: 'Compiled with Wayland support')
conf_data.set('SWA_WITH_X11', with_x11, description: 'Compiled with X11 support')
conf_data.set('SWA_WITH_WIN', with_win, description: 'Compiled with Winapi support')
conf_data.set('SWA_WITH_KMS', with_kms, description: 'Compiled with KMS/DRM support')
subdir('include/swa')
if with_android
swa_lib = shared_module('swa',
swa_src,
include_directories: swa_inc,
dependencies: swa_deps,
c_args: swa_args,
install: true)
exe_type = 'shared_library'
else
swa_lib = library('swa',
swa_src,
include_directories: swa_inc,
dependencies: swa_deps,
c_args: swa_args,
install: true)
exe_type = 'executable'
endif
swa_dep = declare_dependency(
link_with: swa_lib,
include_directories: include_directories('include'))
if examples
subdir('docs/examples')
endif
if with_android and examples
subdir('apk')
endif