meson.build revision a4e54154
1a4e54154Smrgproject('fontconfig', 'c',
2a4e54154Smrg  version: '2.14.0',
3a4e54154Smrg  meson_version : '>= 0.56.0',
4a4e54154Smrg  default_options: [ 'buildtype=debugoptimized'],
5a4e54154Smrg)
6a4e54154Smrg
7a4e54154Smrgfc_version = meson.project_version()
8a4e54154Smrgversion_arr = fc_version.split('.')
9a4e54154Smrgfc_version_major = version_arr[0].to_int()
10a4e54154Smrgfc_version_minor = version_arr[1].to_int()
11a4e54154Smrgfc_version_micro = version_arr[2].to_int()
12a4e54154Smrg
13a4e54154Smrg# Try and maintain compatibility with the previous libtool versioning
14a4e54154Smrg# (this is a bit of a hack, but it should work fine for our case where
15a4e54154Smrg# API is added, in which case LT_AGE and LIBT_CURRENT are both increased)
16a4e54154Smrgsoversion = fc_version_major - 1
17a4e54154Smrgcurversion = fc_version_minor - 1
18a4e54154Smrglibversion = '@0@.@1@.0'.format(soversion, curversion)
19a4e54154Smrgdefversion = '@0@.@1@'.format(curversion, fc_version_micro)
20a4e54154Smrgosxversion = curversion + 1
21a4e54154Smrg
22a4e54154Smrgfreetype_req = '>= 21.0.15'
23a4e54154Smrgfreetype_req_cmake = '>= 2.8.1'
24a4e54154Smrg
25a4e54154Smrgcc = meson.get_compiler('c')
26a4e54154Smrg
27a4e54154Smrg
28a4e54154Smrgfreetype_dep = dependency('freetype2', method: 'pkg-config', version: freetype_req, required: false)
29a4e54154Smrg
30a4e54154Smrg# Give another shot using CMake
31a4e54154Smrgif not freetype_dep.found()
32a4e54154Smrg  freetype_dep = dependency('freetype', method: 'cmake', version: freetype_req_cmake,
33a4e54154Smrg    fallback: ['freetype2', 'freetype_dep'])
34a4e54154Smrgendif
35a4e54154Smrg
36a4e54154Smrgexpat_dep = dependency('expat',
37a4e54154Smrg  fallback: ['expat', 'expat_dep'])
38a4e54154Smrg
39a4e54154Smrgi18n = import('i18n')
40a4e54154Smrgpkgmod = import('pkgconfig')
41a4e54154Smrgpython3 = import('python').find_installation()
42a4e54154Smrg
43a4e54154Smrgcheck_headers = [
44a4e54154Smrg  ['dirent.h'],
45a4e54154Smrg  ['fcntl.h'],
46a4e54154Smrg  ['stdlib.h'],
47a4e54154Smrg  ['string.h'],
48a4e54154Smrg  ['unistd.h'],
49a4e54154Smrg  ['sys/statvfs.h'],
50a4e54154Smrg  ['sys/vfs.h'],
51a4e54154Smrg  ['sys/statfs.h'],
52a4e54154Smrg  ['sys/param.h'],
53a4e54154Smrg  ['sys/mount.h'],
54a4e54154Smrg]
55a4e54154Smrg
56a4e54154Smrgcheck_funcs = [
57a4e54154Smrg  ['link'],
58a4e54154Smrg  ['mkstemp'],
59a4e54154Smrg  ['mkostemp'],
60a4e54154Smrg  ['_mktemp_s'],
61a4e54154Smrg  ['mkdtemp'],
62a4e54154Smrg  ['getopt'],
63a4e54154Smrg  ['getopt_long'],
64a4e54154Smrg  ['getprogname'],
65a4e54154Smrg  ['getexecname'],
66a4e54154Smrg  ['rand'],
67a4e54154Smrg  ['random'],
68a4e54154Smrg  ['lrand48'],
69a4e54154Smrg  ['random_r'],
70a4e54154Smrg  ['rand_r'],
71a4e54154Smrg  ['readlink'],
72a4e54154Smrg  ['fstatvfs'],
73a4e54154Smrg  ['fstatfs'],
74a4e54154Smrg  ['lstat'],
75a4e54154Smrg  ['mmap'],
76a4e54154Smrg  ['vprintf'],
77a4e54154Smrg]
78a4e54154Smrg
79a4e54154Smrgcheck_freetype_funcs = [
80a4e54154Smrg  ['FT_Get_BDF_Property', {'dependencies': freetype_dep}],
81a4e54154Smrg  ['FT_Get_PS_Font_Info', {'dependencies': freetype_dep}],
82a4e54154Smrg  ['FT_Has_PS_Glyph_Names', {'dependencies': freetype_dep}],
83a4e54154Smrg  ['FT_Get_X11_Font_Format', {'dependencies': freetype_dep}],
84a4e54154Smrg  ['FT_Done_MM_Var', {'dependencies': freetype_dep}],
85a4e54154Smrg]
86a4e54154Smrg
87a4e54154Smrgcheck_header_symbols = [
88a4e54154Smrg  ['posix_fadvise', 'fcntl.h']
89a4e54154Smrg]
90a4e54154Smrg
91a4e54154Smrgcheck_struct_members = [
92a4e54154Smrg  ['struct statvfs', 'f_basetype', ['sys/statvfs.h']],
93a4e54154Smrg  ['struct statvfs', 'f_fstypename', ['sys/statvfs.']],
94a4e54154Smrg  ['struct statfs', 'f_flags', []],
95a4e54154Smrg  ['struct statfs', 'f_fstypename', []],
96a4e54154Smrg  ['struct dirent', 'd_type', ['sys/types.h', 'dirent.h']],
97a4e54154Smrg]
98a4e54154Smrg
99a4e54154Smrgcheck_sizeofs = [
100a4e54154Smrg  ['void *', {'conf-name': 'SIZEOF_VOID_P'}],
101a4e54154Smrg]
102a4e54154Smrg
103a4e54154Smrgcheck_alignofs = [
104a4e54154Smrg  ['void *', {'conf-name': 'ALIGNOF_VOID_P'}],
105a4e54154Smrg  ['double'],
106a4e54154Smrg]
107a4e54154Smrg
108a4e54154Smrgadd_project_arguments('-DHAVE_CONFIG_H', language: 'c')
109a4e54154Smrg
110a4e54154Smrgc_args = []
111a4e54154Smrg
112a4e54154Smrgconf = configuration_data()
113a4e54154Smrgdeps = [freetype_dep, expat_dep]
114a4e54154Smrgincbase = include_directories('.')
115a4e54154Smrg
116a4e54154Smrg# We cannot try compiling against an internal dependency
117a4e54154Smrgif freetype_dep.type_name() == 'internal'
118a4e54154Smrg  foreach func: check_freetype_funcs
119a4e54154Smrg    name = func[0]
120a4e54154Smrg    conf.set('HAVE_@0@'.format(name.to_upper()), 1)
121a4e54154Smrg  endforeach
122a4e54154Smrgelse
123a4e54154Smrg  check_funcs += check_freetype_funcs
124a4e54154Smrgendif
125a4e54154Smrg
126a4e54154Smrgforeach check : check_headers
127a4e54154Smrg  name = check[0]
128a4e54154Smrg
129a4e54154Smrg  if cc.has_header(name)
130a4e54154Smrg    conf.set('HAVE_@0@'.format(name.to_upper().underscorify()), 1)
131a4e54154Smrg  endif
132a4e54154Smrgendforeach
133a4e54154Smrg
134a4e54154Smrgforeach check : check_funcs
135a4e54154Smrg  name = check[0]
136a4e54154Smrg  opts = check.length() > 1 ? check[1] : {}
137a4e54154Smrg  extra_deps = opts.get('dependencies', [])
138a4e54154Smrg
139a4e54154Smrg  if cc.has_function(name, dependencies: extra_deps)
140a4e54154Smrg    conf.set('HAVE_@0@'.format(name.to_upper()), 1)
141a4e54154Smrg  endif
142a4e54154Smrgendforeach
143a4e54154Smrg
144a4e54154Smrgforeach check : check_header_symbols
145a4e54154Smrg  name = check[0]
146a4e54154Smrg  header = check[1]
147a4e54154Smrg
148a4e54154Smrg  if cc.has_header_symbol(header, name)
149a4e54154Smrg    conf.set('HAVE_@0@'.format(name.to_upper()), 1)
150a4e54154Smrg  endif
151a4e54154Smrgendforeach
152a4e54154Smrg
153a4e54154Smrgforeach check : check_struct_members
154a4e54154Smrg  struct_name = check[0]
155a4e54154Smrg  member_name = check[1]
156a4e54154Smrg  headers = check[2]
157a4e54154Smrg
158a4e54154Smrg  prefix = ''
159a4e54154Smrg
160a4e54154Smrg  foreach header : headers
161a4e54154Smrg    prefix += '#include <@0@>\n'.format(header)
162a4e54154Smrg  endforeach
163a4e54154Smrg
164a4e54154Smrg  if cc.has_member(struct_name, member_name, prefix: prefix)
165a4e54154Smrg    conf.set('HAVE_@0@_@1@'.format(struct_name, member_name).to_upper().underscorify(), 1)
166a4e54154Smrg  endif
167a4e54154Smrgendforeach
168a4e54154Smrg
169a4e54154Smrgforeach check : check_sizeofs
170a4e54154Smrg  type = check[0]
171a4e54154Smrg  opts = check.length() > 1 ? check[1] : {}
172a4e54154Smrg
173a4e54154Smrg  conf_name = opts.get('conf-name', 'SIZEOF_@0@'.format(type.to_upper()))
174a4e54154Smrg
175a4e54154Smrg  conf.set(conf_name, cc.sizeof(type))
176a4e54154Smrgendforeach
177a4e54154Smrg
178a4e54154Smrgforeach check : check_alignofs
179a4e54154Smrg  type = check[0]
180a4e54154Smrg  opts = check.length() > 1 ? check[1] : {}
181a4e54154Smrg
182a4e54154Smrg  conf_name = opts.get('conf-name', 'ALIGNOF_@0@'.format(type.to_upper()))
183a4e54154Smrg
184a4e54154Smrg  conf.set(conf_name, cc.alignment(type))
185a4e54154Smrgendforeach
186a4e54154Smrg
187a4e54154Smrgif cc.compiles(files('meson-cc-tests/flexible-array-member-test.c'))
188a4e54154Smrg  conf.set('FLEXIBLE_ARRAY_MEMBER', true)
189a4e54154Smrgelse
190a4e54154Smrg  conf.set('FLEXIBLE_ARRAY_MEMBER', 1)
191a4e54154Smrgendif
192a4e54154Smrg
193a4e54154Smrgif cc.links(files('meson-cc-tests/stdatomic-primitives-test.c'), name: 'stdatomic.h atomics')
194a4e54154Smrg  conf.set('HAVE_STDATOMIC_PRIMITIVES', 1)
195a4e54154Smrgendif
196a4e54154Smrg
197a4e54154Smrgif cc.links(files('meson-cc-tests/intel-atomic-primitives-test.c'), name: 'Intel atomics')
198a4e54154Smrg  conf.set('HAVE_INTEL_ATOMIC_PRIMITIVES', 1)
199a4e54154Smrgendif
200a4e54154Smrg
201a4e54154Smrgif cc.links(files('meson-cc-tests/solaris-atomic-operations.c'), name: 'Solaris atomic ops')
202a4e54154Smrg  conf.set('HAVE_SOLARIS_ATOMIC_OPS', 1)
203a4e54154Smrgendif
204a4e54154Smrg
205a4e54154Smrg
206a4e54154Smrgprefix = get_option('prefix')
207a4e54154Smrg
208a4e54154Smrgfonts_conf = configuration_data()
209a4e54154Smrg
210a4e54154Smrgif host_machine.system() == 'windows'
211a4e54154Smrg  fc_fonts_path = ['WINDOWSFONTDIR', 'WINDOWSUSERFONTDIR']
212a4e54154Smrg  fc_cachedir = 'LOCAL_APPDATA_FONTCONFIG_CACHE'
213a4e54154Smrgelse
214a4e54154Smrg  if host_machine.system() == 'darwin'
215a4e54154Smrg    fc_fonts_path = ['/System/Library/Fonts', '/Library/Fonts', '~/Library/Fonts', '/System/Library/Assets/com_apple_MobileAsset_Font3', '/System/Library/Assets/com_apple_MobileAsset_Font4']
216a4e54154Smrg  else
217a4e54154Smrg    fc_fonts_path = ['/usr/share/fonts', '/usr/local/share/fonts']
218a4e54154Smrg  endif
219a4e54154Smrg  fc_cachedir = join_paths(prefix, get_option('localstatedir'), 'cache', meson.project_name())
220a4e54154Smrg  thread_dep = dependency('threads')
221a4e54154Smrg  conf.set('HAVE_PTHREAD', 1)
222a4e54154Smrg  deps += [thread_dep]
223a4e54154Smrgendif
224a4e54154Smrgxml_path = ''
225a4e54154Smrgescaped_xml_path = ''
226a4e54154Smrgforeach p : fc_fonts_path
227a4e54154Smrg  s = '\t<dir>' + p + '</dir>\n'
228a4e54154Smrg  xml_path += s
229a4e54154Smrg  # No substitution method for string
230a4e54154Smrg  s = '\\t<dir>' + p + '</dir>\\n'
231a4e54154Smrg  escaped_xml_path += s
232a4e54154Smrgendforeach
233a4e54154Smrgconf.set_quoted('FC_DEFAULT_FONTS', escaped_xml_path)
234a4e54154Smrgfonts_conf.set('FC_DEFAULT_FONTS', xml_path)
235a4e54154Smrg
236a4e54154Smrgfc_templatedir = join_paths(prefix, get_option('datadir'), 'fontconfig/conf.avail')
237a4e54154Smrgfc_baseconfigdir = join_paths(prefix, get_option('sysconfdir'), 'fonts')
238a4e54154Smrgfc_configdir = join_paths(fc_baseconfigdir, 'conf.d')
239a4e54154Smrgfc_xmldir = join_paths(prefix, get_option('datadir'), 'xml/fontconfig')
240a4e54154Smrg
241a4e54154Smrg
242a4e54154Smrgconf.set_quoted('CONFIGDIR', fc_configdir)
243a4e54154Smrgconf.set_quoted('FC_CACHEDIR', fc_cachedir)
244a4e54154Smrgconf.set_quoted('FC_TEMPLATEDIR', fc_templatedir)
245a4e54154Smrgconf.set_quoted('FONTCONFIG_PATH', fc_baseconfigdir)
246a4e54154Smrgconf.set_quoted('FC_FONTPATH', '')
247a4e54154Smrg
248a4e54154Smrgfonts_conf.set('FC_FONTPATH', '')
249a4e54154Smrgfonts_conf.set('FC_CACHEDIR', fc_cachedir)
250a4e54154Smrgfonts_conf.set('CONFIGDIR', fc_configdir)
251a4e54154Smrg# strip off fc_baseconfigdir prefix if that is the prefix
252a4e54154Smrgif fc_configdir.startswith(fc_baseconfigdir + '/')
253a4e54154Smrg  fonts_conf.set('CONFIGDIR', fc_configdir.split(fc_baseconfigdir + '/')[1])
254a4e54154Smrgendif
255a4e54154Smrg
256a4e54154Smrg# It will automatically fallback to subproject if not found on system
257a4e54154Smrggperf = find_program('gperf')
258a4e54154Smrg
259a4e54154Smrgsh = find_program('sh', required : false)
260a4e54154Smrg
261a4e54154Smrgif not sh.found() # host_machine.system() == 'windows' or not sh.found()
262a4e54154Smrg  # TODO: This is not always correct
263a4e54154Smrg  if cc.get_id() == 'msvc'
264a4e54154Smrg    gperf_len_type = 'size_t'
265a4e54154Smrg  else
266a4e54154Smrg    gperf_len_type = 'unsigned'
267a4e54154Smrg  endif
268a4e54154Smrgelse
269a4e54154Smrg  gperf_test_format = '''
270a4e54154Smrg  #include <string.h>
271a4e54154Smrg  const char * in_word_set(const char *, @0@);
272a4e54154Smrg  @1@
273a4e54154Smrg  '''
274a4e54154Smrg  gperf_snippet_format = 'echo foo,bar | @0@ -L ANSI-C'
275a4e54154Smrg  gperf_snippet = run_command(sh, '-c', gperf_snippet_format.format(gperf.path()))
276a4e54154Smrg  gperf_test = gperf_test_format.format('size_t', gperf_snippet.stdout())
277a4e54154Smrg
278a4e54154Smrg  if cc.compiles(gperf_test)
279a4e54154Smrg    gperf_len_type = 'size_t'
280a4e54154Smrg  else
281a4e54154Smrg    gperf_test = gperf_test_format.format('unsigned', gperf_snippet.stdout())
282a4e54154Smrg    if cc.compiles(gperf_test)
283a4e54154Smrg      gperf_len_type = 'unsigned'
284a4e54154Smrg    else
285a4e54154Smrg      error('unable to determine gperf len type')
286a4e54154Smrg    endif
287a4e54154Smrg  endif
288a4e54154Smrgendif
289a4e54154Smrg
290a4e54154Smrgmessage('gperf len type is @0@'.format(gperf_len_type))
291a4e54154Smrg
292a4e54154Smrgconf.set('FC_GPERF_SIZE_T', gperf_len_type,
293a4e54154Smrg  description : 'The type of gperf "len" parameter')
294a4e54154Smrg
295a4e54154Smrgconf.set('_GNU_SOURCE', true)
296a4e54154Smrg
297a4e54154Smrgconf.set_quoted('GETTEXT_PACKAGE', meson.project_name())
298a4e54154Smrg
299a4e54154Smrgincsrc = include_directories('src')
300a4e54154Smrg
301a4e54154Smrg# We assume stdint.h is available
302a4e54154Smrgforeach t : ['uint64_t', 'int32_t', 'uintptr_t', 'intptr_t']
303a4e54154Smrg  if not cc.has_type(t, prefix: '#include <stdint.h>')
304a4e54154Smrg    error('Sanity check failed: type @0@ not provided via stdint.h'.format(t))
305a4e54154Smrg  endif
306a4e54154Smrgendforeach
307a4e54154Smrg
308a4e54154Smrgfcstdint_h = configure_file(
309a4e54154Smrg  input: 'src/fcstdint.h.in',
310a4e54154Smrg  output: 'fcstdint.h',
311a4e54154Smrg  copy: true)
312a4e54154Smrg
313a4e54154Smrgmakealias = files('src/makealias.py')[0]
314a4e54154Smrg
315a4e54154Smrgalias_headers = custom_target('alias_headers',
316a4e54154Smrg  output: ['fcalias.h', 'fcaliastail.h'],
317a4e54154Smrg  input: ['fontconfig/fontconfig.h', 'src/fcdeprecate.h', 'fontconfig/fcprivate.h'],
318a4e54154Smrg  command: [python3, makealias, join_paths(meson.current_source_dir(), 'src'), '@OUTPUT@', '@INPUT@'],
319a4e54154Smrg)
320a4e54154Smrg
321a4e54154Smrgft_alias_headers = custom_target('ft_alias_headers',
322a4e54154Smrg  output: ['fcftalias.h', 'fcftaliastail.h'],
323a4e54154Smrg  input: ['fontconfig/fcfreetype.h'],
324a4e54154Smrg  command: [python3, makealias, join_paths(meson.current_source_dir(), 'src'), '@OUTPUT@', '@INPUT@']
325a4e54154Smrg)
326a4e54154Smrg
327a4e54154Smrgtools_man_pages = []
328a4e54154Smrg
329a4e54154Smrg# Do not reorder
330a4e54154Smrgsubdir('fc-case')
331a4e54154Smrgsubdir('fc-lang')
332a4e54154Smrgsubdir('src')
333a4e54154Smrg
334a4e54154Smrgif not get_option('tools').disabled()
335a4e54154Smrg  subdir('fc-cache')
336a4e54154Smrg  subdir('fc-cat')
337a4e54154Smrg  subdir('fc-conflist')
338a4e54154Smrg  subdir('fc-list')
339a4e54154Smrg  subdir('fc-match')
340a4e54154Smrg  subdir('fc-pattern')
341a4e54154Smrg  subdir('fc-query')
342a4e54154Smrg  subdir('fc-scan')
343a4e54154Smrg  subdir('fc-validate')
344a4e54154Smrgendif
345a4e54154Smrg
346a4e54154Smrgif not get_option('tests').disabled()
347a4e54154Smrg  subdir('test')
348a4e54154Smrgendif
349a4e54154Smrg
350a4e54154Smrgsubdir('conf.d')
351a4e54154Smrgsubdir('its')
352a4e54154Smrg
353a4e54154Smrg# xgettext is optional (on Windows for instance)
354a4e54154Smrgif find_program('xgettext', required : get_option('nls')).found()
355a4e54154Smrg  subdir('po')
356a4e54154Smrg  subdir('po-conf')
357a4e54154Smrgendif
358a4e54154Smrg
359a4e54154Smrgif not get_option('doc').disabled()
360a4e54154Smrg  subdir('doc')
361a4e54154Smrgendif
362a4e54154Smrg
363a4e54154Smrgconfigure_file(output: 'config.h', configuration: conf)
364a4e54154Smrg
365a4e54154Smrgconfigure_file(output: 'fonts.conf',
366a4e54154Smrg  input: 'fonts.conf.in',
367a4e54154Smrg  configuration: fonts_conf,
368a4e54154Smrg  install_dir: fc_baseconfigdir,
369a4e54154Smrg  install: true)
370a4e54154Smrg
371a4e54154Smrginstall_data('fonts.dtd',
372a4e54154Smrg  install_dir: join_paths(get_option('prefix'), get_option('datadir'), 'xml/fontconfig')
373a4e54154Smrg)
374a4e54154Smrg
375a4e54154Smrgfc_headers = [
376a4e54154Smrg  'fontconfig/fontconfig.h',
377a4e54154Smrg  'fontconfig/fcfreetype.h',
378a4e54154Smrg  'fontconfig/fcprivate.h',
379a4e54154Smrg]
380a4e54154Smrg
381a4e54154Smrginstall_headers(fc_headers, subdir: meson.project_name())
382a4e54154Smrg
383a4e54154Smrg# Summary
384a4e54154Smrgdoc_targets = get_variable('doc_targets', [])
385a4e54154Smrg
386a4e54154Smrgsummary({
387a4e54154Smrg       'Documentation': (doc_targets.length() > 0 ? doc_targets : false),
388a4e54154Smrg       'NLS': not get_option('nls').disabled(),
389a4e54154Smrg       'Tests': not get_option('tests').disabled(),
390a4e54154Smrg       'Tools': not get_option('tools').disabled(),
391a4e54154Smrg       }, section: 'General', bool_yn: true, list_sep: ', ')
392