forked from libass/libass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeson.build
399 lines (351 loc) · 10.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
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
project(
'libass',
'c',
license: 'ISC',
meson_version: '>= 0.64.0',
default_options: [
'c_std=c99',
'buildtype=debugoptimized',
'warning_level=2',
'default_library=static',
],
version: files('RELEASEVERSION'),
)
conf = configuration_data()
deps = []
test_deps = []
host_system = host_machine.system()
# Compiler setup
cc = meson.get_compiler('c')
cc_warnings = []
cc_features = []
if cc.get_id() == 'clang-cl'
cc_features += '/clang:-fno-math-errno'
elif cc.get_id() != 'msvc'
cc_features += ['-D_POSIX_C_SOURCE=200809L', '-fno-math-errno']
endif
if cc.get_argument_syntax() == 'gcc'
cc_warnings += [
'-Wno-sign-compare',
'-Wno-unused-parameter',
'-Werror-implicit-function-declaration',
'-Wstrict-prototypes',
'-Wpointer-arith',
'-Wredundant-decls',
'-Wno-missing-field-initializers',
'-Wformat-non-iso',
'-Werror=format-non-iso',
]
endif
add_project_arguments(
cc.get_supported_arguments(cc_warnings + cc_features),
language: 'c',
)
# Configuration
str_check_functions = ['strdup', 'strndup']
foreach name : str_check_functions
if (
cc.has_function(name)
and cc.has_header_symbol('string.h', name, args: cc_features)
)
conf.set('HAVE_@0@'.format(name.to_upper()), 1)
endif
endforeach
if (
cc.has_function('fstat')
and cc.has_header_symbol(
'sys/stat.h',
'fstat',
args: cc_features,
prefix: '#include <sys/types.h>',
)
)
conf.set('HAVE_FSTAT', 1)
endif
# Dependencies
deps += cc.find_library('m', required: false)
iconv_dep = dependency('iconv', required: false)
if iconv_dep.found()
deps += iconv_dep
conf.set('CONFIG_ICONV', 1)
endif
deps += dependency(
'freetype2',
version: '>= 9.17.3',
default_options: ['harfbuzz=disabled'],
)
deps += dependency(
'fribidi',
version: '>= 0.19.1',
default_options: ['docs=false', 'tests=false'],
)
harfbuzz_options = [
'tests=disabled',
'cairo=disabled',
'gobject=disabled',
'glib=disabled',
'freetype=disabled',
]
deps += dependency(
'harfbuzz',
version: '>= 1.2.3',
default_options: harfbuzz_options,
)
libunibreak_dep = dependency(
'libunibreak',
version: '>= 1.1',
required: get_option('libunibreak'),
)
if libunibreak_dep.found()
deps += libunibreak_dep
conf.set('CONFIG_UNIBREAK', 1)
endif
if get_option('test')
test_deps += dependency('libpng', version: '>= 1.2.0')
conf.set('CONFIG_LIBPNG', 1)
endif
font_providers = []
fontconfig_dep = dependency(
'fontconfig',
version: '>= 2.10.92',
required: get_option('fontconfig'),
)
fontconfig = fontconfig_dep.found()
if fontconfig
deps += fontconfig_dep
conf.set('CONFIG_FONTCONFIG', 1)
font_providers += ['Fontconfig']
endif
# CoreText
coretext = false
if not get_option('coretext').disabled()
appservices_dep = dependency(
'appleframeworks',
modules: ['ApplicationServices', 'CoreFoundation'],
required: false,
)
# this intentionally includes a leading newline
coretext_check = '''
int main(void) {
CTFontDescriptorCopyAttribute(NULL, kCTFontNameAttribute);
return 0;
}
'''
appservices_snippet = (
'#include <ApplicationServices/ApplicationServices.h>' + coretext_check
)
if appservices_dep.found() and cc.compiles(appservices_snippet)
deps += appservices_dep
conf.set('CONFIG_CORETEXT', 1)
coretext = true
font_providers += ['CoreText']
else
coretext_dep = dependency(
'appleframeworks',
modules: ['CoreText', 'CoreFoundation'],
required: false,
)
coretext_snippet = '#include <CoreText/CoreText.h>' + coretext_check
if coretext_dep.found() and cc.compiles(coretext_snippet)
deps += coretext_dep
conf.set('CONFIG_CORETEXT', 1)
coretext = true
font_providers += ['CoreText']
endif
endif
endif
# DirectWrite
directwrite = false
if not get_option('directwrite').disabled()
if cc.has_header('windows.h', required: false)
directwrite = true
conf.set('CONFIG_DIRECTWRITE', 1)
code = '''#include <windows.h>
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
#error Win32 desktop APIs are available
#endif'''
if cc.compiles(code)
# WinRT/UWP/app build: GDI and LoadLibrary are unavailable,
# but DirectWrite is always present
deps += cc.find_library('dwrite', required: true)
font_providers += ['DirectWrite (WinRT/UWP)']
else
# Win32/desktop build: GDI is always present;
# DirectWrite is optional but can be loaded via LoadLibrary
deps += cc.find_library('gdi32', required: true)
font_providers += ['DirectWrite and GDI (Win32)']
endif
endif
endif
if get_option('directwrite').enabled() and directwrite == false
error(
'DirectWrite support was requested, but it was not found.',
)
endif
if get_option('coretext').enabled() and coretext == false
error(
'CoreText support was requested, but it was not found.',
)
endif
if get_option('require-system-font-provider')
if font_providers.length() == 0
error(
'Either DirectWrite (on Windows), CoreText (on OSX), or Fontconfig (Linux, ' +
'other) is required. If you really want to compile without a system font ' +
'provider, set -Drequire-system-font-provider=false',
)
endif
else
if font_providers.length() == 0
font_providers += 'none'
endif
endif
# ASM
enable_asm = false
# used in libass/meson.build
asm_is_nasm = false
asm_args = []
# ASM architecture variables
asm_option = get_option('asm')
cpu_family = host_machine.cpu_family()
if cpu_family.startswith('x86')
generic_cpu_family = 'x86'
else
generic_cpu_family = cpu_family
endif
if not asm_option.disabled()
if generic_cpu_family == 'x86'
asm_is_nasm = add_languages(
'nasm',
required: false,
native: false,
)
if not asm_is_nasm or meson.get_compiler('nasm').get_id() != 'nasm'
warning(
'nasm was not found; ASM functions are disabled. Install nasm ' +
'>= 2.10 for a significantly faster libass build.',
)
else
nasm_ver = meson.get_compiler('nasm').version()
if nasm_ver.version_compare('< 2.10')
warning(
'nasm is too old (found @0@); ASM functions are disabled. '.format(
nasm_ver,
) + 'Install nasm >= 2.10 for a significantly faster libass build.',
)
asm_is_nasm = false
endif
endif
enable_asm = asm_is_nasm
if enable_asm
conf.set('ARCH_X86', 1)
nasm_args = ['-Dprivate_prefix=ass', '-DPIC=1']
if cpu_family == 'x86_64'
conf.set('ARCH_X86_64', 1)
nasm_args += '-DARCH_X86_64=1'
else
nasm_args += '-DARCH_X86_64=0'
endif
if host_system in ['windows', 'cygwin']
if cpu_family == 'x86'
nasm_args += '-DPREFIX'
endif
elif host_system == 'darwin'
nasm_args += ['-DPREFIX', '-DSTACK_ALIGNMENT=16']
elif host_system in ['linux', 'sunos', 'haiku', 'gnu', 'android']
nasm_args += ['-DSTACK_ALIGNMENT=16']
elif host_system == 'dragonfly' or host_system.endswith('bsd')
nasm_args += []
else
error(
'Please contact libass upstream to figure out if ASM support ' +
'for your platform @0@ can be added. '.format(host_system) +
'In the meantime you will need to use -Dasm=disabled.',
)
endif
add_project_arguments(nasm_args, language: 'nasm')
endif
elif generic_cpu_family == 'aarch64'
enable_asm = true
conf.set('ARCH_AARCH64', 1)
if host_system == 'darwin'
asm_args += '-DPREFIX'
endif
else
warning(
'Assembly optimizations are not yet supported for the "@0@" architecture; disabling.'.format(
cpu_family,
),
)
endif
if enable_asm
conf.set('CONFIG_ASM', 1)
elif asm_option.enabled()
error(
'Assembly was requested, but cannot be built; see prior messages.',
)
endif
endif
conf.set('CONFIG_LARGE_TILES', get_option('large-tiles').to_int())
conf.set('CONFIG_SOURCEVERSION', '"meson, commit: @VCS_TAG@"')
config_h_in = configure_file(output: 'config.h.in.in', configuration: conf)
config_h_intermediate = vcs_tag(
command: [
'git',
'describe',
'--tags',
'--long',
'--always',
'--broken',
'--abbrev=40',
],
fallback: '@VCS_TAG_FALLBACK@',
input: config_h_in,
output: 'config.h.in',
)
# Fallback command for older git versions (< 2.13.0) that don't support --broken
config_h = vcs_tag(
command: [
'git',
'describe',
'--tags',
'--long',
'--always',
'--dirty',
'--abbrev=40',
],
replace_string: '@VCS_TAG_FALLBACK@',
fallback: 'failed to determine (>= @0@)'.format(meson.project_version()),
input: config_h_intermediate,
output: 'config.h',
)
incs = include_directories('.', 'libass')
subdir('libass')
default_library = get_option('default_library')
if default_library == 'both'
libass_for_tools = libass.get_static_lib()
else
libass_for_tools = libass
endif
if get_option('test')
subdir('test')
endif
if get_option('profile')
subdir('profile')
endif
# libass.pc
pkg = import('pkgconfig')
pkg.generate(
libass,
name: 'libass',
description: 'libass is an SSA/ASS subtitles rendering library',
)
# `libass_dep` comes from subdir('libass')
meson.override_dependency('libass', libass_dep)
if default_library != 'static' and host_system != 'windows'
warning(
'this build does not properly support symbol visibility and the resulting shared lib is not suitable for distribution!',
)
endif
summary('Font providers', font_providers)
summary('ASM optimizations', enable_asm, bool_yn: true)