-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathmeson.build
More file actions
528 lines (448 loc) · 14 KB
/
meson.build
File metadata and controls
528 lines (448 loc) · 14 KB
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
# Copyright 2021-2025 David Robillard <d@drobilla.net>
# SPDX-License-Identifier: 0BSD OR ISC
project(
'pugl',
['c'],
default_options: [
'b_ndebug=if-release',
'buildtype=release',
'c_std=c99',
'c_winlibs=',
'cpp_std=c++17',
],
license: 'ISC',
meson_version: '>= 0.54.0',
version: '0.5.7',
)
pugl_src_root = meson.current_source_dir()
major_version = meson.project_version().split('.')[0]
version_suffix = '-@0@'.format(major_version)
versioned_name = 'pugl' + version_suffix
#######################
# Compilers and Flags #
#######################
# Required tools
pkg = import('pkgconfig')
cc = meson.get_compiler('c')
# Enable Objective C support if we're building for MacOS
if host_machine.system() == 'darwin'
add_languages(['objc'], native: false)
objcc = meson.get_compiler('objc')
endif
# Set global warning suppressions
subdir('meson/suppressions')
# Set additional suppressions for OpenGL code
opengl_args = []
if host_machine.system() == 'darwin'
opengl_args += ['-DGL_SILENCE_DEPRECATION', '-Wno-deprecated-declarations']
endif
#############
# Platforms #
#############
dl_dep = cc.find_library('dl', required: false)
m_dep = cc.find_library('m', required: false)
platform_link_args = []
if host_machine.system() == 'darwin'
# MacOS
framework_deps = dependency(
'appleframeworks',
modules: ['foundation', 'corevideo'],
required: false,
)
platform = 'mac'
platform_sources = files('src/mac.m')
platform_link_args = ['-Wl,-framework,Cocoa']
core_deps = [framework_deps]
backend_extension = '.m'
soversion = meson.project_version().split('.')[0]
platform_args = ['-DGL_SILENCE_DEPRECATION', '-Wno-deprecated-declarations']
elif host_machine.system() == 'windows'
# Windows
if get_option('default_library') == 'both'
error('default_library=both is not supported on Windows')
endif
platform_args = [
# Set minimum target version
'-DWINVER=0x0500', # Windows 2000
'-D_WIN32_WINNT=0x0500', # Windows 2000
# Disable as many things from windows.h as possible
'-DWIN32_LEAN_AND_MEAN',
'-DNOGDICAPMASKS', # CC_*, LC_*, PC_*, CP_*, TC_*, RC_
'-DNOSYSMETRICS', # SM_*
'-DNOKEYSTATES', # MK_*
'-DOEMRESOURCE', # OEM Resource values
'-DNOATOM', # Atom Manager routines
'-DNOCOLOR', # Screen colors
'-DNODRAWTEXT', # DrawText() and DT_*
'-DNOKERNEL', # All KERNEL defines and routines
'-DNOMB', # MB_* and MessageBox()
'-DNOMEMMGR', # GMEM_*, LMEM_*, GHND, LHND, associated routines
'-DNOMETAFILE', # typedef METAFILEPICT
'-DNOMINMAX', # Macros min(a,b) and max(a,b)
'-DNOOPENFILE', # OpenFile(), OemToAnsi, AnsiToOem, and OF_*
'-DNOSCROLL', # SB_* and scrolling routines
'-DNOSERVICE', # All Service Controller routines, SERVICE_ equates, etc.
'-DNOSOUND', # Sound driver routines
'-DNOWH', # SetWindowsHook and WH_*
'-DNOCOMM', # COMM driver routines
'-DNOKANJI', # Kanji support stuff
'-DNOHELP', # Help engine interface
'-DNOPROFILER', # Profiler interface
'-DNODEFERWINDOWPOS', # DeferWindowPos routines
'-DNOMCX', # Modem Configuration Extensions
# Needed only for Cairo
# '-DNORASTEROPS', # Binary and Tertiary raster ops
# Needed by Pugl
# '-DNOVIRTUALKEYCODES', # VK_*
# '-DNOWINMESSAGES', # WM_*, EM_*, LB_*, CB_*
# '-DNOWINSTYLES', # WS_*, CS_*, ES_*, LBS_*, SBS_*, CBS_*
# '-DNOMENUS', # MF_*
# '-DNOICONS', # IDI_*
# '-DNOSYSCOMMANDS', # SC_*
# '-DNOSHOWWINDOW', # SW_*
# '-DNOCLIPBOARD', # Clipboard routines
# '-DNOCTLMGR', # Control and Dialog routines
# '-DNOGDI', # All GDI defines and routines
# '-DNOUSER', # All USER defines and routines
# '-DNONLS', # All NLS defines and routines
# '-DNOMSG', # typedef MSG and associated routines
# '-DNOWINOFFSETS', # GWL_*, GCL_*, associated routines
]
if cc.get_id() == 'msvc'
platform_args += [
'-DNOTEXTMETRIC', # typedef TEXTMETRIC and associated routines
]
endif
if not get_option('win_wchar').disabled()
platform_args += ['-DUNICODE', '-D_UNICODE']
endif
dwmapi_dep = cc.find_library('dwmapi')
gdi32_dep = cc.find_library('gdi32')
shlwapi_dep = cc.find_library('shlwapi')
user32_dep = cc.find_library('user32')
platform = 'win'
platform_sources = files('src/win.c')
core_deps = [dwmapi_dep, gdi32_dep, shlwapi_dep, user32_dep]
backend_extension = '.c'
soversion = '' # Avoid redundant version in DLL name
else
# X11
x11_dep = cc.find_library('X11')
platform_args = ['-D_POSIX_C_SOURCE=200809L']
xcursor_dep = cc.find_library('Xcursor', required: get_option('xcursor'))
platform_args += ['-DUSE_XCURSOR=@0@'.format(xcursor_dep.found().to_int())]
xrandr_dep = cc.find_library('Xrandr', required: get_option('xrandr'))
platform_args += ['-DUSE_XRANDR=@0@'.format(xrandr_dep.found().to_int())]
use_xsync = false
xext_dep = cc.find_library('Xext', required: get_option('xsync'))
if xext_dep.found()
xsync_fragment = '''#include <X11/Xlib.h>
#include <X11/extensions/sync.h>
int main(void) { XSyncQueryExtension(0, 0, 0); return 0; }'''
use_xsync = cc.compiles(xsync_fragment, name: 'Xsync')
if (not use_xsync) and (get_option('xsync') == 'enabled')
error('C header <X11/extensions/sync.h> not found')
endif
endif
platform_args += ['-DUSE_XSYNC=@0@'.format(use_xsync.to_int())]
x11_suppressions = []
if cc.get_id() == 'clang'
x11_suppressions += [
'-Wno-reserved-identifier', # FD_ZERO
]
endif
platform = 'x11'
platform_sources = files('src/x11.c')
platform_args += cc.get_supported_arguments(x11_suppressions)
core_deps = [x11_dep, xcursor_dep, xext_dep, xrandr_dep]
backend_extension = '.c'
soversion = meson.project_version().split('.')[0]
endif
################
# Core Library #
################
core_name = 'pugl_@0@@1@'.format(platform, version_suffix)
includes = include_directories(['include'])
# "Usage" arguments for libraries and their dependants
usage_args = []
if get_option('default_library') == 'static'
usage_args += ['-DPUGL_STATIC']
endif
# Arguments used when building libraries
library_args = usage_args + platform_args
library_args += ['-DPUGL_INTERNAL']
common_sources = files('src/common.c', 'src/internal.c')
libpugl = library(
core_name,
common_sources + platform_sources,
c_args: c_suppressions + library_args,
dependencies: core_deps,
gnu_symbol_visibility: 'hidden',
implicit_include_directories: false,
include_directories: includes,
install: true,
link_args: platform_link_args,
objc_args: objc_suppressions + library_args,
soversion: soversion,
version: meson.project_version(),
)
pugl_dep = declare_dependency(
compile_args: usage_args,
dependencies: core_deps,
include_directories: includes,
link_with: libpugl,
)
pkg.generate(
libpugl,
description: 'Pugl GUI library core',
filebase: versioned_name,
name: 'Pugl',
subdirs: [versioned_name],
version: meson.project_version(),
)
meson.override_dependency(versioned_name, pugl_dep)
############
# Backends #
############
# Stub Backend #
if get_option('stub')
stub_backend = library(
'pugl_@0@_stub@1@'.format(platform, version_suffix),
files('src' / (platform + '_stub' + backend_extension)),
c_args: c_suppressions + library_args,
dependencies: [pugl_dep],
gnu_symbol_visibility: 'hidden',
implicit_include_directories: false,
include_directories: includes,
install: true,
link_args: platform_link_args,
objc_args: objc_suppressions + library_args,
soversion: soversion,
version: meson.project_version(),
)
pugl_stub_dep = declare_dependency(
compile_args: usage_args,
link_with: stub_backend,
dependencies: [pugl_dep],
)
stub_pkg_name = 'pugl-stub-@0@'.format(major_version)
meson.override_dependency(stub_pkg_name, pugl_stub_dep)
pkg.generate(
stub_backend,
description: 'Pugl GUI library with stub (platform-specific) backend',
filebase: stub_pkg_name,
name: 'Pugl Stub',
subdirs: [versioned_name],
version: meson.project_version(),
)
endif
# OpenGL Backend #
opengl_dep = dependency(
'GL',
include_type: 'system',
required: get_option('opengl'),
)
if opengl_dep.found()
gl_backend = library(
'pugl_@0@_gl@1@'.format(platform, version_suffix),
files('src' / (platform + '_gl' + backend_extension)),
c_args: c_suppressions + library_args,
dependencies: [pugl_dep, opengl_dep],
gnu_symbol_visibility: 'hidden',
implicit_include_directories: false,
include_directories: includes,
install: true,
link_args: platform_link_args,
objc_args: objc_suppressions + library_args,
soversion: soversion,
version: meson.project_version(),
)
pugl_gl_dep = declare_dependency(
compile_args: usage_args,
link_with: gl_backend,
dependencies: [pugl_dep, opengl_dep],
)
gl_pkg_name = 'pugl-gl-@0@'.format(major_version)
meson.override_dependency(gl_pkg_name, pugl_gl_dep)
pkg.generate(
gl_backend,
description: 'Pugl GUI library with OpenGL backend',
filebase: gl_pkg_name,
name: 'Pugl OpenGL',
subdirs: [versioned_name],
version: meson.project_version(),
)
endif
# Cairo Backend #
cairo_dep = dependency(
'cairo',
include_type: 'system',
required: get_option('cairo'),
)
if cairo_dep.found()
cairo_args = []
if cc.get_id() == 'clang'
cairo_args += [
'-Wno-documentation',
'-Wno-documentation-unknown-command',
'-Wno-reserved-identifier',
]
endif
cairo_args = cc.get_supported_arguments(cairo_args)
cairo_args += library_args
cairo_backend = library(
'pugl_@0@_cairo@1@'.format(platform, version_suffix),
files('src' / (platform + '_cairo' + backend_extension)),
c_args: c_suppressions + cairo_args,
dependencies: [pugl_dep, cairo_dep],
gnu_symbol_visibility: 'hidden',
implicit_include_directories: false,
include_directories: includes,
install: true,
link_args: platform_link_args,
objc_args: objc_suppressions + cairo_args,
soversion: soversion,
version: meson.project_version(),
)
pugl_cairo_dep = declare_dependency(
compile_args: usage_args,
dependencies: [pugl_dep, cairo_dep],
link_with: cairo_backend,
)
cairo_pkg_name = 'pugl-cairo-@0@'.format(major_version)
meson.override_dependency(cairo_pkg_name, pugl_cairo_dep)
pkg.generate(
cairo_backend,
description: 'Pugl GUI library with Cairo backend',
filebase: cairo_pkg_name,
name: 'Pugl Cairo',
subdirs: [versioned_name],
version: meson.project_version(),
)
endif
# Vulkan
vulkan_dep = dependency(
'vulkan',
include_type: 'system',
required: get_option('vulkan'),
)
if vulkan_dep.found()
thread_dep = dependency('threads', include_type: 'system')
vulkan_deps = [pugl_dep, vulkan_dep, dl_dep]
if platform == 'mac'
vulkan_deps += [
dependency('Metal', include_type: 'system', modules: 'foundation'),
dependency('QuartzCore', include_type: 'system', modules: 'foundation'),
]
endif
vulkan_args = []
if cc.get_id() == 'gcc' and warning_level in ['everything', '3']
vulkan_args += ['-Wno-pedantic']
endif
vulkan_backend = library(
'pugl_@0@_vulkan@1@'.format(platform, version_suffix),
files('src' / (platform + '_vulkan' + backend_extension)),
c_args: c_suppressions + library_args + vulkan_args,
dependencies: vulkan_deps,
gnu_symbol_visibility: 'hidden',
implicit_include_directories: false,
include_directories: includes,
install: true,
link_args: platform_link_args,
objc_args: objc_suppressions + library_args,
soversion: soversion,
version: meson.project_version(),
)
pugl_vulkan_dep = declare_dependency(
compile_args: usage_args,
dependencies: [pugl_dep, vulkan_dep, thread_dep],
link_with: vulkan_backend,
)
vulkan_pkg_name = 'pugl-vulkan-@0@'.format(major_version)
meson.override_dependency(vulkan_pkg_name, pugl_vulkan_dep)
pkg.generate(
vulkan_backend,
description: 'Pugl GUI library with Vulkan backend',
filebase: vulkan_pkg_name,
name: 'Pugl Vulkan',
subdirs: [versioned_name],
version: meson.project_version(),
)
endif
##################
# Public Headers #
##################
subdir('include')
######################
# Tests and Examples #
######################
if not get_option('tests').disabled() or not get_option('examples').disabled()
puglutil = subproject('puglutil')
puglutil_dep = puglutil.get_variable('puglutil_dep')
endif
if not get_option('tests').disabled()
subdir('test')
endif
if not get_option('examples').disabled()
subdir('examples')
endif
################
# C++ Bindings #
################
subproject('pugl-cpp', required: get_option('bindings_cpp'))
#################
# Documentation #
#################
if not get_option('docs').disabled()
subdir('doc')
else
build_docs = false
endif
if meson.version().version_compare('>=0.53.0')
summary({'Platform': platform}, section: 'Configuration')
if platform == 'x11'
summary(
{
'Cursor support (XCursor)': xcursor_dep.found(),
'Refresh rate support (XRandR)': xrandr_dep.found(),
'Timer support (XSync)': use_xsync,
},
bool_yn: true,
section: 'Configuration',
)
endif
summary(
{
'Cairo': cairo_dep.found(),
'OpenGL': opengl_dep.found(),
'Stub': get_option('stub'),
'Vulkan': vulkan_dep.found(),
},
bool_yn: true,
section: 'Backends',
)
summary(
{
'Tests': not get_option('tests').disabled(),
'Examples': not get_option('examples').disabled(),
'Documentation': build_docs,
'C++ bindings': not get_option('bindings_cpp').disabled(),
},
bool_yn: true,
section: 'Components',
)
summary(
{
'Install prefix': get_option('prefix'),
'Headers': get_option('prefix') / get_option('includedir'),
'Libraries': get_option('prefix') / get_option('libdir'),
},
section: 'Directories',
)
if not get_option('examples').disabled()
summary(
{'Executables': get_option('prefix') / get_option('bindir')},
section: 'Directories',
)
endif
endif