-
Notifications
You must be signed in to change notification settings - Fork 2
/
meson.build
576 lines (483 loc) · 16.2 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
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
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
project('fontconfig', 'c',
version: '2.15.0',
meson_version : '>= 1.6.0',
default_options: [ 'buildtype=debugoptimized', ]
)
fs = import('fs')
fc_version = meson.project_version()
version_arr = fc_version.split('.')
fc_version_major = version_arr[0].to_int()
fc_version_minor = version_arr[1].to_int()
fc_version_micro = version_arr[2].to_int()
# Try and maintain compatibility with the previous libtool versioning
# (this is a bit of a hack, but it should work fine for our case where
# API is added, in which case LT_AGE and LIBT_CURRENT are both increased)
soversion = fc_version_major - 1
curversion = fc_version_minor - 1
libversion = '@0@.@[email protected]'.format(soversion, curversion)
defversion = '@0@.@1@'.format(curversion, fc_version_micro)
osxversion = curversion + 1
freetype_req = '>= 21.0.15'
freetype_req_cmake = '>= 2.8.1'
cc = meson.get_compiler('c')
math_dep = cc.find_library('m', required: false)
conf = configuration_data()
freetype_dep = dependency('freetype2', method: 'pkg-config', version: freetype_req, required: false)
# Give another shot using CMake
if not freetype_dep.found()
freetype_dep = dependency('freetype', method: 'cmake', version: freetype_req_cmake,
fallback: ['freetype2', 'freetype_dep'], default_options: 'werror=false')
endif
if freetype_dep.type_name() == 'internal'
conf.set('FREETYPE_PCF_LONG_FAMILY_NAMES', false)
else
if cc.compiles(files('meson-cc-tests/freetype-pcf-long-family-names.c'),
dependencies: freetype_dep)
conf.set('FREETYPE_PCF_LONG_FAMILY_NAMES', true)
else
conf.set('FREETYPE_PCF_LONG_FAMILY_NAMES', false)
endif
endif
jsonc_dep = dependency('json-c', required: false)
xml_dep = dependency('', required: false)
xmlbackend = get_option('xml-backend')
xmltype = ''
if xmlbackend == 'auto' or xmlbackend == 'expat'
# Linking expat should not be so difficult... see: https://github.com/mesonbuild/meson/issues/10516
xml_dep = dependency('expat', required: false)
if not xml_dep.found()
xml_dep = cc.find_library('expat', required : false)
if not xml_dep.found() and xmlbackend == 'expat'
xml_dep = dependency('expat', method: 'system', required: true, fallback: ['expat', 'expat_dep'])
else
xmltype = 'expat'
endif
endif
endif
if (xmlbackend == 'auto' and not xml_dep.found()) or xmlbackend == 'libxml2'
xml_dep = dependency('libxml-2.0', required: true)
conf.set('ENABLE_LIBXML2', 1)
endif
if xmltype == ''
xmltype = xml_dep.name()
endif
fontations = get_option('fontations')
if (fontations.enabled())
conf.set('ENABLE_FONTATIONS', 1)
add_languages(['rust'], native: false, required : true)
endif
pkgmod = import('pkgconfig')
python3 = import('python').find_installation()
pytest = find_program('pytest', required: false)
check_headers = [
['dirent.h'],
['dlfcn.h'],
['fcntl.h'],
['inttypes.h'],
['stdint.h'],
['stdio.h'],
['stdlib.h'],
['strings.h'],
['string.h'],
['unistd.h'],
['sys/statvfs.h'],
['sys/vfs.h'],
['sys/statfs.h'],
['sys/stat.h'],
['sys/types.h'],
['sys/param.h'],
['sys/mount.h'],
['time.h'],
['wchar.h'],
]
check_funcs = [
['link'],
['mkstemp'],
['mkostemp'],
['_mktemp_s'],
['mkdtemp'],
['getopt'],
['getopt_long'],
['getprogname'],
['getexecname'],
['rand'],
['random'],
['lrand48'],
['random_r'],
['rand_r'],
['readlink'],
['fstatvfs'],
['fstatfs'],
['lstat'],
['strerror'],
['strerror_r'],
['mmap'],
['vprintf'],
['vsnprintf'],
['vsprintf'],
['getpagesize'],
['getpid'],
['dcgettext'],
['gettext'],
['localtime_r'],
]
check_freetype_funcs = [
['FT_Get_BDF_Property', {'dependencies': freetype_dep}],
['FT_Get_PS_Font_Info', {'dependencies': freetype_dep}],
['FT_Has_PS_Glyph_Names', {'dependencies': freetype_dep}],
['FT_Get_X11_Font_Format', {'dependencies': freetype_dep}],
['FT_Done_MM_Var', {'dependencies': freetype_dep}],
]
check_header_symbols = [
['posix_fadvise', 'fcntl.h']
]
check_struct_members = [
['struct statvfs', 'f_basetype', ['sys/statvfs.h']],
['struct statvfs', 'f_fstypename', ['sys/statvfs.h']],
['struct statfs', 'f_flags', ['sys/vfs.h', 'sys/statfs.h', 'sys/param.h', 'sys/mount.h']],
['struct statfs', 'f_fstypename', ['sys/vfs.h', 'sys/statfs.h', 'sys/param.h', 'sys/mount.h']],
['struct stat', 'st_mtim', ['sys/stat.h']],
['struct dirent', 'd_type', ['sys/types.h', 'dirent.h']],
]
check_sizeofs = [
['void *', {'conf-name': 'SIZEOF_VOID_P'}],
]
check_alignofs = [
['void *', {'conf-name': 'ALIGNOF_VOID_P'}],
['double'],
]
add_project_arguments('-DHAVE_CONFIG_H', language: 'c')
c_args = []
deps = [freetype_dep, xml_dep]
incbase = include_directories('.')
# For compatibility to autoconf (regardless of the usage in fontconfig)
conf.set_quoted('PACKAGE_NAME', meson.project_name())
conf.set_quoted('PACKAGE_TARNAME', meson.project_name())
conf.set_quoted('PACKAGE_VERSION', meson.project_version())
conf.set_quoted('PACKAGE_STRING', '@0@ @1@'.format(meson.project_name(), meson.project_version()))
conf.set_quoted('PACKAGE_BUGREPORT', 'https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/new')
conf.set_quoted('PACKAGE_URL', '')
if host_machine.system() == 'windows'
conf.set('EXEEXT', '.exe')
else
conf.set('EXEEXT', '')
endif
i18n = import('i18n')
gettext_args = [ '--msgid-bugs-address=@0@'.format(conf.get('PACKAGE_BUGREPORT')) ]
# Check for libintl.h
opt_nls = get_option('nls')
libintl_dep = dependency('intl', required: false, fallback: ['libintl', 'libintl_dep'])
if libintl_dep.found()
conf.set('ENABLE_NLS', opt_nls.allowed().to_int())
deps += [libintl_dep]
else
opt_nls = opt_nls.require(false)
endif
# Check iconv support
iconv = get_option('iconv')
iconv_dep = dependency('', required: false)
found_iconv = 0
if iconv.allowed()
iconv_dep = cc.find_library('iconv', required: false)
if cc.has_header_symbol('iconv.h', 'libiconv_open', dependencies: libintl_dep)
conf.set('LIBICONV_PLUG', 1)
found_iconv = 1
elif cc.has_header('iconv.h') and cc.has_function('iconv_open', dependencies: iconv_dep)
found_iconv = 1
else
iconv.require(false)
endif
endif
conf.set('USE_ICONV', found_iconv)
deps += [iconv_dep]
# We cannot try compiling against an internal dependency
if freetype_dep.type_name() == 'internal'
foreach func: check_freetype_funcs
name = func[0]
conf.set('HAVE_@0@'.format(name.to_upper()), 1)
endforeach
else
check_funcs += check_freetype_funcs
endif
foreach check : check_headers
name = check[0]
if cc.has_header(name)
conf.set('HAVE_@0@'.format(name.to_upper().underscorify()), 1)
endif
endforeach
foreach check : check_funcs
name = check[0]
opts = check.length() > 1 ? check[1] : {}
extra_deps = opts.get('dependencies', [])
if cc.has_function(name, dependencies: extra_deps)
conf.set('HAVE_@0@'.format(name.to_upper()), 1)
endif
endforeach
foreach check : check_header_symbols
name = check[0]
header = check[1]
if cc.has_header_symbol(header, name)
conf.set('HAVE_@0@'.format(name.to_upper()), 1)
endif
endforeach
foreach check : check_struct_members
struct_name = check[0]
member_name = check[1]
headers = check[2]
prefix = ''
foreach header : headers
prefix += '#include <@0@>\n'.format(header)
endforeach
if cc.has_member(struct_name, member_name, prefix: prefix)
conf.set('HAVE_@0@_@1@'.format(struct_name, member_name).to_upper().underscorify(), 1)
endif
endforeach
foreach check : check_sizeofs
type = check[0]
opts = check.length() > 1 ? check[1] : {}
conf_name = opts.get('conf-name', 'SIZEOF_@0@'.format(type.to_upper()))
conf.set(conf_name, cc.sizeof(type))
endforeach
foreach check : check_alignofs
type = check[0]
opts = check.length() > 1 ? check[1] : {}
conf_name = opts.get('conf-name', 'ALIGNOF_@0@'.format(type.to_upper()))
conf.set(conf_name, cc.alignment(type))
endforeach
if cc.compiles(files('meson-cc-tests/flexible-array-member-test.c'))
conf.set('FLEXIBLE_ARRAY_MEMBER', '/**/')
else
conf.set('FLEXIBLE_ARRAY_MEMBER', 1)
endif
if cc.compiles(files('meson-cc-tests/pthread-prio-inherit-test.c'))
conf.set('HAVE_PTHREAD_PRIO_INHERIT', 1)
endif
if cc.links(files('meson-cc-tests/stdatomic-primitives-test.c'), name: 'stdatomic.h atomics')
conf.set('HAVE_STDATOMIC_PRIMITIVES', 1)
endif
if cc.links(files('meson-cc-tests/intel-atomic-primitives-test.c'), name: 'Intel atomics')
conf.set('HAVE_INTEL_ATOMIC_PRIMITIVES', 1)
endif
if cc.links(files('meson-cc-tests/solaris-atomic-operations.c'), name: 'Solaris atomic ops')
conf.set('HAVE_SOLARIS_ATOMIC_OPS', 1)
endif
prefix = get_option('prefix')
fonts_conf = configuration_data()
default_fonts_dirs = get_option('default-fonts-dirs')
if default_fonts_dirs == ['yes']
if host_machine.system() == 'windows'
fc_fonts_paths = ['WINDOWSFONTDIR', 'WINDOWSUSERFONTDIR']
elif host_machine.system() == 'darwin'
fc_fonts_paths = ['/System/Library/Fonts', '/Library/Fonts', '~/Library/Fonts', '/System/Library/Assets/com_apple_MobileAsset_Font3', '/System/Library/Assets/com_apple_MobileAsset_Font4']
elif host_machine.system() == 'android'
fc_fonts_paths = ['/system/fonts/', '/product/fonts/']
else
fc_fonts_paths = ['/usr/share/fonts', '/usr/local/share/fonts']
endif
else
fc_fonts_paths = default_fonts_dirs
endif
xml_path = ''
escaped_xml_path = ''
foreach p : fc_fonts_paths
s = '\t<dir>' + p + '</dir>\n'
xml_path += s
# No substitution method for string
s = '\\t<dir>' + p + '</dir>\\n'
escaped_xml_path += s
endforeach
conf.set_quoted('FC_DEFAULT_FONTS', escaped_xml_path)
fonts_conf.set('FC_DEFAULT_FONTS', xml_path)
# Add more fonts if available. By default, add only the directories
# with outline fonts; those with bitmaps can be added as desired in
# local.conf or ~/.fonts.conf
fc_add_fonts = []
additional_fonts_dirs = get_option('additional-fonts-dirs')
if additional_fonts_dirs == ['yes']
fs = import('fs')
foreach dir : ['/usr/X11R6/lib/X11', '/usr/X11/lib/X11', '/usr/lib/X11']
if fs.is_dir(dir / 'fonts')
fc_add_fonts += [dir / 'fonts']
endif
endforeach
elif additional_fonts_dirs == ['no']
# nothing to do
else
fc_add_fonts = additional_fonts_dirs
endif
xml_path = ''
escaped_xml_path = ''
foreach p : fc_add_fonts
s = '\t<dir>' + p + '</dir>\n'
xml_path += s
# No substitution method for string
s = '\\t<dir>' + p + '</dir>\\n'
escaped_xml_path += s
endforeach
conf.set_quoted('FC_FONTPATH', escaped_xml_path)
fonts_conf.set('FC_FONTPATH', xml_path)
fc_cachedir = get_option('cache-dir')
if fc_cachedir in ['yes', 'no', 'default']
if host_machine.system() == 'windows'
fc_cachedir = 'LOCAL_APPDATA_FONTCONFIG_CACHE'
else
fc_cachedir = join_paths(prefix, get_option('localstatedir'), 'cache', meson.project_name())
endif
endif
if host_machine.system() != 'windows'
thread_dep = dependency('threads')
conf.set('HAVE_PTHREAD', 1)
deps += [thread_dep]
endif
fc_templatedir = get_option('template-dir')
if fc_templatedir in ['default', 'yes', 'no']
fc_templatedir = prefix / get_option('datadir') / 'fontconfig/conf.avail'
endif
fc_baseconfigdir = get_option('baseconfig-dir')
if fc_baseconfigdir in ['default', 'yes', 'no']
fc_baseconfigdir = prefix / get_option('sysconfdir') / 'fonts'
endif
fc_configdir = get_option('config-dir')
if fc_configdir in ['default', 'yes', 'no']
fc_configdir = fc_baseconfigdir / 'conf.d'
endif
fc_xmldir = get_option('xml-dir')
if fc_xmldir in ['default', 'yes', 'no']
fc_xmldir = prefix / get_option('datadir') / 'xml/fontconfig'
endif
conf.set_quoted('CONFIGDIR', fc_configdir)
conf.set_quoted('FC_CACHEDIR', fc_cachedir)
conf.set_quoted('FC_TEMPLATEDIR', fc_templatedir)
conf.set_quoted('FONTCONFIG_PATH', fc_baseconfigdir)
conf.set_quoted('FC_FONTPATH', '')
fonts_conf.set('FC_FONTPATH', '')
fonts_conf.set('FC_CACHEDIR', fc_cachedir)
fonts_conf.set('CONFIGDIR', fc_configdir)
# strip off fc_baseconfigdir prefix if that is the prefix
if fc_configdir.startswith(fc_baseconfigdir + '/')
fonts_conf.set('CONFIGDIR', fc_configdir.split(fc_baseconfigdir + '/')[1])
endif
gperf = find_program('gperf', required: false)
gperf_len_type = ''
if gperf.found()
gperf_test_format = '''
#include <string.h>
const char * in_word_set(const char *, @0@);
@1@
'''
gperf_snippet = run_command(gperf, '-L', 'ANSI-C', files('meson-cc-tests/gperf.txt'),
check: true).stdout()
foreach type : ['size_t', 'unsigned']
if cc.compiles(gperf_test_format.format(type, gperf_snippet))
gperf_len_type = type
break
endif
endforeach
if gperf_len_type == ''
error('unable to determine gperf len type')
endif
else
# Fallback to subproject
gperf = find_program('gperf')
# assume if we are compiling from the wrap, the size is just size_t
gperf_len_type = 'size_t'
endif
message('gperf len type is @0@'.format(gperf_len_type))
conf.set('FC_GPERF_SIZE_T', gperf_len_type,
description : 'The type of gperf "len" parameter')
conf.set('_GNU_SOURCE', true)
conf.set_quoted('GETTEXT_PACKAGE', meson.project_name())
incsrc = include_directories('src')
# We assume stdint.h is available
foreach t : ['uint64_t', 'int32_t', 'uintptr_t', 'intptr_t']
if not cc.has_type(t, prefix: '#include <stdint.h>')
error('Sanity check failed: type @0@ not provided via stdint.h'.format(t))
endif
endforeach
fcstdint_h = fs.copyfile('src/fcstdint.h.in', 'fcstdint.h')
makealias = files('src/makealias.py')[0]
alias_headers = custom_target('alias_headers',
output: ['fcalias.h', 'fcaliastail.h'],
input: ['fontconfig/fontconfig.h', 'src/fcdeprecate.h', 'fontconfig/fcprivate.h'],
command: [python3, makealias, join_paths(meson.current_source_dir(), 'src'), '@OUTPUT@', '@INPUT@'],
)
ft_alias_headers = custom_target('ft_alias_headers',
output: ['fcftalias.h', 'fcftaliastail.h'],
input: ['fontconfig/fcfreetype.h'],
command: [python3, makealias, join_paths(meson.current_source_dir(), 'src'), '@OUTPUT@', '@INPUT@']
)
tools_man_pages = []
# Do not reorder
subdir('fc-case')
subdir('fc-lang')
subdir('src')
if get_option('fontations').enabled()
subdir('fc-fontations')
endif
if not get_option('tools').disabled()
subdir('fc-cache')
subdir('fc-cat')
subdir('fc-conflist')
subdir('fc-list')
subdir('fc-match')
subdir('fc-pattern')
subdir('fc-query')
subdir('fc-scan')
subdir('fc-validate')
endif
if not get_option('tests').disabled()
subdir('test')
endif
subdir('conf.d')
subdir('its')
# xgettext is optional (on Windows for instance)
if find_program('xgettext', required : opt_nls).found()
subdir('po')
subdir('po-conf')
endif
if not get_option('doc').disabled()
subdir('doc')
endif
configure_file(output: 'config.h', configuration: conf)
configure_file(output: 'fonts.conf',
input: 'fonts.conf.in',
configuration: fonts_conf,
install_dir: fc_baseconfigdir,
install: true,
install_tag: 'runtime')
install_data('fonts.dtd',
install_dir: join_paths(get_option('prefix'), get_option('datadir'), 'xml/fontconfig'),
install_tag: 'runtime')
fc_headers = [
'fontconfig/fontconfig.h',
'fontconfig/fcfreetype.h',
'fontconfig/fcprivate.h',
]
install_headers(fc_headers, subdir: meson.project_name())
if not meson.is_subproject()
meson.add_dist_script('build-aux/meson-dist-docs.py')
meson.add_dist_script('build-aux/meson-dist-autotools.py')
endif
# Summary
doc_targets = get_variable('doc_targets', [])
summary({
'Documentation': (doc_targets.length() > 0 ? doc_targets : false),
'NLS': not opt_nls.disabled(),
'Tests': not get_option('tests').disabled(),
'Tools': not get_option('tools').disabled(),
'iconv': found_iconv == 1,
'XML backend': xmltype,
'Fontations support' : fontations
}, section: 'General', bool_yn: true, list_sep: ', ')
summary({
'Hinting': preferred_hinting,
'Font directories': fc_fonts_paths,
'Additional font directories': fc_add_fonts,
}, section: 'Defaults', bool_yn: true, list_sep: ', ')
summary({
'Cache directory': fc_cachedir,
'Template directory': fc_templatedir,
'Base config directory': fc_baseconfigdir,
'Config directory': fc_configdir,
'XML directory': fc_xmldir,
}, section: 'Paths', bool_yn: true, list_sep: ', ')