1 project('fontconfig', 'c',
3 meson_version : '>= 0.57.0',
4 default_options: [ 'buildtype=debugoptimized'],
7 fc_version = meson.project_version()
8 version_arr = fc_version.split('.')
9 fc_version_major = version_arr[0].to_int()
10 fc_version_minor = version_arr[1].to_int()
11 fc_version_micro = version_arr[2].to_int()
13 # Try and maintain compatibility with the previous libtool versioning
14 # (this is a bit of a hack, but it should work fine for our case where
15 # API is added, in which case LT_AGE and LIBT_CURRENT are both increased)
16 soversion = fc_version_major - 1
17 curversion = fc_version_minor - 1
18 libversion = '@0@.@1@.0'.format(soversion, curversion)
19 defversion = '@0@.@1@'.format(curversion, fc_version_micro)
20 osxversion = curversion + 1
22 freetype_req = '>= 21.0.15'
23 freetype_req_cmake = '>= 2.8.1'
25 cc = meson.get_compiler('c')
28 freetype_dep = dependency('freetype2', method: 'pkg-config', version: freetype_req, required: false)
30 # Give another shot using CMake
31 if not freetype_dep.found()
32 freetype_dep = dependency('freetype', method: 'cmake', version: freetype_req_cmake,
33 fallback: ['freetype2', 'freetype_dep'], default_options: 'werror=false')
36 # Linking expat should not be so difficult... see: https://github.com/mesonbuild/meson/issues/10516
37 expat_dep = dependency('expat', required: false)
38 if not expat_dep.found()
39 expat_dep = cc.find_library('expat', required : false)
40 if not expat_dep.found()
41 expat_dep = dependency('expat', method: 'system', fallback: ['expat', 'expat_dep'])
46 pkgmod = import('pkgconfig')
47 python3 = import('python').find_installation()
85 check_freetype_funcs = [
86 ['FT_Get_BDF_Property', {'dependencies': freetype_dep}],
87 ['FT_Get_PS_Font_Info', {'dependencies': freetype_dep}],
88 ['FT_Has_PS_Glyph_Names', {'dependencies': freetype_dep}],
89 ['FT_Get_X11_Font_Format', {'dependencies': freetype_dep}],
90 ['FT_Done_MM_Var', {'dependencies': freetype_dep}],
93 check_header_symbols = [
94 ['posix_fadvise', 'fcntl.h']
97 check_struct_members = [
98 ['struct statvfs', 'f_basetype', ['sys/statvfs.h']],
99 ['struct statvfs', 'f_fstypename', ['sys/statvfs.']],
100 ['struct statfs', 'f_flags', []],
101 ['struct statfs', 'f_fstypename', []],
102 ['struct dirent', 'd_type', ['sys/types.h', 'dirent.h']],
106 ['void *', {'conf-name': 'SIZEOF_VOID_P'}],
110 ['void *', {'conf-name': 'ALIGNOF_VOID_P'}],
114 add_project_arguments('-DHAVE_CONFIG_H', language: 'c')
118 conf = configuration_data()
119 deps = [freetype_dep, expat_dep]
120 incbase = include_directories('.')
122 # We cannot try compiling against an internal dependency
123 if freetype_dep.type_name() == 'internal'
124 foreach func: check_freetype_funcs
126 conf.set('HAVE_@0@'.format(name.to_upper()), 1)
129 check_funcs += check_freetype_funcs
132 foreach check : check_headers
135 if cc.has_header(name)
136 conf.set('HAVE_@0@'.format(name.to_upper().underscorify()), 1)
140 foreach check : check_funcs
142 opts = check.length() > 1 ? check[1] : {}
143 extra_deps = opts.get('dependencies', [])
145 if cc.has_function(name, dependencies: extra_deps)
146 conf.set('HAVE_@0@'.format(name.to_upper()), 1)
150 foreach check : check_header_symbols
154 if cc.has_header_symbol(header, name)
155 conf.set('HAVE_@0@'.format(name.to_upper()), 1)
159 foreach check : check_struct_members
160 struct_name = check[0]
161 member_name = check[1]
166 foreach header : headers
167 prefix += '#include <@0@>\n'.format(header)
170 if cc.has_member(struct_name, member_name, prefix: prefix)
171 conf.set('HAVE_@0@_@1@'.format(struct_name, member_name).to_upper().underscorify(), 1)
175 foreach check : check_sizeofs
177 opts = check.length() > 1 ? check[1] : {}
179 conf_name = opts.get('conf-name', 'SIZEOF_@0@'.format(type.to_upper()))
181 conf.set(conf_name, cc.sizeof(type))
184 foreach check : check_alignofs
186 opts = check.length() > 1 ? check[1] : {}
188 conf_name = opts.get('conf-name', 'ALIGNOF_@0@'.format(type.to_upper()))
190 conf.set(conf_name, cc.alignment(type))
193 if cc.compiles(files('meson-cc-tests/flexible-array-member-test.c'))
194 conf.set('FLEXIBLE_ARRAY_MEMBER', true)
196 conf.set('FLEXIBLE_ARRAY_MEMBER', 1)
199 if cc.links(files('meson-cc-tests/stdatomic-primitives-test.c'), name: 'stdatomic.h atomics')
200 conf.set('HAVE_STDATOMIC_PRIMITIVES', 1)
203 if cc.links(files('meson-cc-tests/intel-atomic-primitives-test.c'), name: 'Intel atomics')
204 conf.set('HAVE_INTEL_ATOMIC_PRIMITIVES', 1)
207 if cc.links(files('meson-cc-tests/solaris-atomic-operations.c'), name: 'Solaris atomic ops')
208 conf.set('HAVE_SOLARIS_ATOMIC_OPS', 1)
212 prefix = get_option('prefix')
214 fonts_conf = configuration_data()
216 default_fonts_dirs = get_option('default-fonts-dirs')
217 if default_fonts_dirs == ['yes']
218 if host_machine.system() == 'windows'
219 fc_fonts_paths = ['WINDOWSFONTDIR', 'WINDOWSUSERFONTDIR']
220 elif host_machine.system() == 'darwin'
221 fc_fonts_paths = ['/System/Library/Fonts', '/Library/Fonts', '~/Library/Fonts', '/System/Library/Assets/com_apple_MobileAsset_Font3', '/System/Library/Assets/com_apple_MobileAsset_Font4']
223 fc_fonts_paths = ['/usr/share/fonts', '/usr/local/share/fonts']
226 fc_fonts_paths = default_fonts_dirs
229 escaped_xml_path = ''
230 foreach p : fc_fonts_paths
231 s = '\t<dir>' + p + '</dir>\n'
233 # No substitution method for string
234 s = '\\t<dir>' + p + '</dir>\\n'
235 escaped_xml_path += s
237 conf.set_quoted('FC_DEFAULT_FONTS', escaped_xml_path)
238 fonts_conf.set('FC_DEFAULT_FONTS', xml_path)
240 # Add more fonts if available. By default, add only the directories
241 # with outline fonts; those with bitmaps can be added as desired in
242 # local.conf or ~/.fonts.conf
244 additional_fonts_dirs = get_option('additional-fonts-dirs')
245 if additional_fonts_dirs == ['yes']
247 foreach dir : ['/usr/X11R6/lib/X11', '/usr/X11/lib/X11', '/usr/lib/X11']
248 if fs.is_dir(dir / 'fonts')
249 fc_add_fonts += [dir / 'fonts']
252 elif additional_fonts_dirs == ['no']
255 fc_add_fonts = additional_fonts_dirs
258 escaped_xml_path = ''
259 foreach p : fc_add_fonts
260 s = '\t<dir>' + p + '</dir>\n'
262 # No substitution method for string
263 s = '\\t<dir>' + p + '</dir>\\n'
264 escaped_xml_path += s
266 conf.set_quoted('FC_FONTPATH', escaped_xml_path)
267 fonts_conf.set('FC_FONTPATH', xml_path)
269 fc_cachedir = get_option('cache-dir')
270 if fc_cachedir in ['yes', 'no', 'default']
271 if host_machine.system() == 'windows'
272 fc_cachedir = 'LOCAL_APPDATA_FONTCONFIG_CACHE'
274 fc_cachedir = join_paths(prefix, get_option('localstatedir'), 'cache', meson.project_name())
278 if host_machine.system() != 'windows'
279 thread_dep = dependency('threads')
280 conf.set('HAVE_PTHREAD', 1)
284 fc_templatedir = get_option('template-dir')
285 if fc_templatedir in ['default', 'yes', 'no']
286 fc_templatedir = prefix / get_option('datadir') / 'fontconfig/conf.avail'
289 fc_baseconfigdir = get_option('baseconfig-dir')
290 if fc_baseconfigdir in ['default', 'yes', 'no']
291 fc_baseconfigdir = prefix / get_option('sysconfdir') / 'fonts'
294 fc_configdir = get_option('config-dir')
295 if fc_configdir in ['default', 'yes', 'no']
296 fc_configdir = fc_baseconfigdir / 'conf.d'
299 fc_xmldir = get_option('xml-dir')
300 if fc_xmldir in ['default', 'yes', 'no']
301 fc_xmldir = prefix / get_option('datadir') / 'xml/fontconfig'
304 conf.set_quoted('CONFIGDIR', fc_configdir)
305 conf.set_quoted('FC_CACHEDIR', fc_cachedir)
306 conf.set_quoted('FC_TEMPLATEDIR', fc_templatedir)
307 conf.set_quoted('FONTCONFIG_PATH', fc_baseconfigdir)
308 conf.set_quoted('FC_FONTPATH', '')
310 fonts_conf.set('FC_FONTPATH', '')
311 fonts_conf.set('FC_CACHEDIR', fc_cachedir)
312 fonts_conf.set('CONFIGDIR', fc_configdir)
313 # strip off fc_baseconfigdir prefix if that is the prefix
314 if fc_configdir.startswith(fc_baseconfigdir + '/')
315 fonts_conf.set('CONFIGDIR', fc_configdir.split(fc_baseconfigdir + '/')[1])
318 gperf = find_program('gperf', required: false)
322 gperf_test_format = '''
324 const char * in_word_set(const char *, @0@);
327 gperf_snippet = run_command(gperf, '-L', 'ANSI-C', files('meson-cc-tests/gperf.txt'),
328 check: true).stdout()
330 foreach type : ['size_t', 'unsigned']
331 if cc.compiles(gperf_test_format.format(type, gperf_snippet))
332 gperf_len_type = type
337 if gperf_len_type == ''
338 error('unable to determine gperf len type')
341 # Fallback to subproject
342 gperf = find_program('gperf')
343 # assume if we are compiling from the wrap, the size is just size_t
344 gperf_len_type = 'size_t'
347 message('gperf len type is @0@'.format(gperf_len_type))
349 conf.set('FC_GPERF_SIZE_T', gperf_len_type,
350 description : 'The type of gperf "len" parameter')
352 conf.set('_GNU_SOURCE', true)
354 conf.set_quoted('GETTEXT_PACKAGE', meson.project_name())
356 incsrc = include_directories('src')
358 # We assume stdint.h is available
359 foreach t : ['uint64_t', 'int32_t', 'uintptr_t', 'intptr_t']
360 if not cc.has_type(t, prefix: '#include <stdint.h>')
361 error('Sanity check failed: type @0@ not provided via stdint.h'.format(t))
365 fcstdint_h = configure_file(
366 input: 'src/fcstdint.h.in',
367 output: 'fcstdint.h',
370 makealias = files('src/makealias.py')[0]
372 alias_headers = custom_target('alias_headers',
373 output: ['fcalias.h', 'fcaliastail.h'],
374 input: ['fontconfig/fontconfig.h', 'src/fcdeprecate.h', 'fontconfig/fcprivate.h'],
375 command: [python3, makealias, join_paths(meson.current_source_dir(), 'src'), '@OUTPUT@', '@INPUT@'],
378 ft_alias_headers = custom_target('ft_alias_headers',
379 output: ['fcftalias.h', 'fcftaliastail.h'],
380 input: ['fontconfig/fcfreetype.h'],
381 command: [python3, makealias, join_paths(meson.current_source_dir(), 'src'), '@OUTPUT@', '@INPUT@']
391 if not get_option('tools').disabled()
394 subdir('fc-conflist')
400 subdir('fc-validate')
403 if not get_option('tests').disabled()
410 # xgettext is optional (on Windows for instance)
411 if find_program('xgettext', required : get_option('nls')).found()
416 if not get_option('doc').disabled()
420 configure_file(output: 'config.h', configuration: conf)
422 configure_file(output: 'fonts.conf',
423 input: 'fonts.conf.in',
424 configuration: fonts_conf,
425 install_dir: fc_baseconfigdir,
428 install_data('fonts.dtd',
429 install_dir: join_paths(get_option('prefix'), get_option('datadir'), 'xml/fontconfig')
433 'fontconfig/fontconfig.h',
434 'fontconfig/fcfreetype.h',
435 'fontconfig/fcprivate.h',
438 install_headers(fc_headers, subdir: meson.project_name())
441 doc_targets = get_variable('doc_targets', [])
444 'Documentation': (doc_targets.length() > 0 ? doc_targets : false),
445 'NLS': not get_option('nls').disabled(),
446 'Tests': not get_option('tests').disabled(),
447 'Tools': not get_option('tools').disabled(),
448 }, section: 'General', bool_yn: true, list_sep: ', ')
450 'Hinting': preferred_hinting,
451 'Font directories': fc_fonts_paths,
452 'Additional font directories': fc_add_fonts,
453 }, section: 'Defaults', bool_yn: true, list_sep: ', ')
455 'Cache directory': fc_cachedir,
456 'Template directory': fc_templatedir,
457 'Base config directory': fc_baseconfigdir,
458 'Config directory': fc_configdir,
459 'XML directory': fc_xmldir,
460 }, section: 'Paths', bool_yn: true, list_sep: ', ')