2 # Meson project file for FreeType 2
5 # Copyright (C) 2020-2022 by
6 # David Turner, Robert Wilhelm, and Werner Lemberg.
8 # This file is part of the FreeType project, and may only be used, modified,
9 # and distributed under the terms of the FreeType project license,
10 # LICENSE.TXT. By continuing to use, modify, or distribute this file you
11 # indicate that you have read the license and understand and accept it
19 # to see all configuration options and their default values. For example,
20 # to build only a shared version of FreeType, override the default value
23 # meson setup -Ddefault_library=shared
26 project('freetype2', 'c',
27 meson_version: '>= 0.55.0',
28 version: run_command('builds/meson/extract_freetype_version.py',
29 'include/freetype/freetype.h',
30 check: true).stdout().strip(),
34 # Only meson >= 0.57 can read a file and assign its contents to a
35 # variable; we thus use an external command to have this functionality
36 # with older versions, too.
38 python_exe = find_program('python3')
40 ft2_so_version = run_command(python_exe,
41 files('builds/meson/extract_libtool_version.py'),
43 files('builds/unix/configure.raw'),
44 check: true).stdout().strip()
46 ft2_pkgconfig_version = run_command(python_exe,
47 files('builds/meson/extract_libtool_version.py'),
48 files('builds/unix/configure.raw'),
49 check: true).stdout().strip()
51 ft2_includes = include_directories('include')
53 freetype_includedir = join_paths(get_option('includedir'), 'freetype2')
55 # Generate a custom `ftmodule.h` version based on the content of
58 ftmodule_h = custom_target('ftmodule.h',
61 command: [python_exe, files('builds/meson/parse_modules_cfg.py'),
62 '--format=ftmodule.h', '@INPUT@', '--output', '@OUTPUT@'],
64 install_dir: join_paths(freetype_includedir, 'freetype/config'),
66 ft2_sources = [ftmodule_h]
71 ft_main_modules = run_command(python_exe,
72 files('builds/meson/parse_modules_cfg.py'),
73 '--format=main-modules',
75 check: true).stdout().strip().split()
77 ft2_sources += files([
82 foreach mod: ft_main_modules
89 ft2_sources += 'src/@0@/@1@.c'.format(mod, source)
92 # NOTE: The `bzip2` aux module is handled through options.
93 ft_aux_modules = run_command(python_exe,
94 files('builds/meson/parse_modules_cfg.py'),
95 '--format=aux-modules',
97 check: true).stdout().strip().split()
99 foreach auxmod: ft_aux_modules
101 # Most sources are named `src/<module>/<module>.c`, but there are a few
102 # exceptions handled here.
107 elif auxmod == 'gzip'
109 elif auxmod == 'bzip2'
110 # Handled through options instead, see below.
113 ft2_sources += 'src/@0@/@1@.c'.format(auxmod, source)
117 # FreeType 2 base extensions.
118 # To be configured in `modules.cfg`.
120 base_extensions = run_command(python_exe,
121 files('builds/meson/parse_modules_cfg.py'),
122 '--format=base-extensions-list',
123 files('modules.cfg'),
124 check: true).stdout().split()
126 foreach ext: base_extensions
127 ft2_sources += files('src/base/' + ext)
133 ft2_public_headers = files([
134 'include/freetype/freetype.h',
135 'include/freetype/ftadvanc.h',
136 'include/freetype/ftbbox.h',
137 'include/freetype/ftbdf.h',
138 'include/freetype/ftbitmap.h',
139 'include/freetype/ftbzip2.h',
140 'include/freetype/ftcache.h',
141 'include/freetype/ftchapters.h',
142 'include/freetype/ftcid.h',
143 'include/freetype/ftcolor.h',
144 'include/freetype/ftdriver.h',
145 'include/freetype/fterrdef.h',
146 'include/freetype/fterrors.h',
147 'include/freetype/ftfntfmt.h',
148 'include/freetype/ftgasp.h',
149 'include/freetype/ftglyph.h',
150 'include/freetype/ftgxval.h',
151 'include/freetype/ftgzip.h',
152 'include/freetype/ftimage.h',
153 'include/freetype/ftincrem.h',
154 'include/freetype/ftlcdfil.h',
155 'include/freetype/ftlist.h',
156 'include/freetype/ftlzw.h',
157 'include/freetype/ftmac.h',
158 'include/freetype/ftmm.h',
159 'include/freetype/ftmodapi.h',
160 'include/freetype/ftmoderr.h',
161 'include/freetype/ftotval.h',
162 'include/freetype/ftoutln.h',
163 'include/freetype/ftparams.h',
164 'include/freetype/ftpfr.h',
165 'include/freetype/ftrender.h',
166 'include/freetype/ftsizes.h',
167 'include/freetype/ftsnames.h',
168 'include/freetype/ftstroke.h',
169 'include/freetype/ftsynth.h',
170 'include/freetype/ftsystem.h',
171 'include/freetype/fttrigon.h',
172 'include/freetype/fttypes.h',
173 'include/freetype/ftwinfnt.h',
174 'include/freetype/otsvg.h',
175 'include/freetype/t1tables.h',
176 'include/freetype/ttnameid.h',
177 'include/freetype/tttables.h',
178 'include/freetype/tttags.h',
181 ft2_config_headers = files([
182 'include/freetype/config/ftconfig.h',
183 'include/freetype/config/ftheader.h',
184 'include/freetype/config/ftstdlib.h',
185 'include/freetype/config/integer-types.h',
186 'include/freetype/config/mac-support.h',
187 'include/freetype/config/public-macros.h',
190 ft2_defines = ['-DFT2_BUILD_LIBRARY=1']
193 # System support file.
195 cc = meson.get_compiler('c')
197 # NOTE: msys2 on Windows has `unistd.h` and `fcntl.h` but not `sys/mman.h`!
198 has_unistd_h = cc.has_header('unistd.h')
199 has_fcntl_h = cc.has_header('fcntl.h')
200 has_sys_mman_h = cc.has_header('sys/mman.h')
202 mmap_option = get_option('mmap')
204 use_unix_ftsystem_c = false
205 if mmap_option.disabled()
206 ft2_sources += files(['src/base/ftsystem.c',])
207 elif host_machine.system() == 'windows'
208 ft2_sources += files(['builds/windows/ftsystem.c',])
210 if has_unistd_h and has_fcntl_h and has_sys_mman_h
211 # This version of `ftsystem.c` uses `mmap` to read input font files.
212 ft2_sources += files(['builds/unix/ftsystem.c',])
213 use_unix_ftsystem_c = true
214 elif mmap_option.enabled()
215 error('mmap was enabled via options but is not available,'
216 + ' required headers were not found!')
218 ft2_sources += files(['src/base/ftsystem.c',])
225 # NOTE: Some specialized versions exist for other platforms not supported by
226 # Meson. Most implementation differences are extremely minor, i.e., in the
227 # implementation of `FT_Message` and `FT_Panic`, and getting the `FT2_DEBUG`
228 # value from the environment, when this is supported. A smaller refactor
229 # might make these platform-specific files much smaller, and could be moved
230 # into `ftsystem.c` as well.
232 if host_machine.system() == 'windows'
233 winmod = import('windows')
235 'builds/windows/ftdebug.c',
236 winmod.compile_resources('src/base/ftver.rc'),
239 ft2_sources += 'src/base/ftdebug.c'
247 # Correct compatibility version for OS x.
249 # OSX sets the compatibility_version (aka libtools version) differently from
252 if host_machine.system() == 'darwin'
253 # maintain compatibility with autotools on macOS
255 '-compatibility_version', ft2_pkgconfig_version.split('.')[0],
256 '-current_version', ft2_pkgconfig_version
261 # Generate `ftoption.h` based on available dependencies.
263 process_header_command = [python_exe,
264 files('builds/meson/process_ftoption_h.py'),
265 '@INPUT@', '--output=@OUTPUT@']
266 ftoption_command = process_header_command
269 # external GZip support
270 zlib_option = get_option('zlib')
272 # Backwards-compatible aliases.
273 if zlib_option == 'disabled'
275 elif zlib_option == 'enabled'
279 if zlib_option == 'auto'
280 # First try to find a system installation, otherwise fall back to
282 zlib_dep = dependency('zlib',
285 zlib_option = 'system'
287 zlib_option = 'external'
291 if zlib_option == 'none'
292 ftoption_command += [ '--disable=FT_CONFIG_OPTION_USE_ZLIB' ]
293 elif zlib_option == 'internal'
294 ftoption_command += [ '--enable=FT_CONFIG_OPTION_USE_ZLIB' ]
295 elif zlib_option == 'external'
296 ftoption_command += [ '--enable=FT_CONFIG_OPTION_USE_ZLIB' ]
297 zlib_project = subproject('zlib',
299 default_options: 'default_library=static')
300 zlib_dep = zlib_project.get_variable('zlib_dep')
301 ft2_deps += [zlib_dep]
302 elif zlib_option == 'system'
303 zlib_dep = dependency('zlib',
305 assert(zlib_dep.found(), 'Could not find system zlib installation!')
306 ftoption_command += [
307 '--enable=FT_CONFIG_OPTION_USE_ZLIB',
308 '--enable=FT_CONFIG_OPTION_SYSTEM_ZLIB',
310 ft2_deps += [zlib_dep]
312 assert(false, 'Invalid zlib option ' + zlib_option)
316 bzip2_dep = cc.find_library('bz2',
317 required: get_option('bzip2'))
320 ftoption_command += ['--enable=FT_CONFIG_OPTION_USE_BZIP2']
321 ft2_sources += files(['src/bzip2/ftbzip2.c',])
322 ft2_deps += [bzip2_dep]
326 libpng_dep = dependency('libpng',
327 required: get_option('png'),
330 if libpng_dep.found()
331 ftoption_command += ['--enable=FT_CONFIG_OPTION_USE_PNG']
332 ft2_deps += [libpng_dep]
336 harfbuzz_dep = dependency('harfbuzz',
338 required: get_option('harfbuzz'))
340 if harfbuzz_dep.found()
341 ftoption_command += ['--enable=FT_CONFIG_OPTION_USE_HARFBUZZ']
342 ft2_deps += [harfbuzz_dep]
345 # Brotli decompression support
346 brotli_dep = dependency('libbrotlidec',
347 required: get_option('brotli'))
349 if brotli_dep.found()
350 ftoption_command += ['--enable=FT_CONFIG_OPTION_USE_BROTLI']
351 ft2_deps += [brotli_dep]
354 # We can now generate `ftoption.h`.
355 ftoption_h = custom_target('ftoption.h',
356 input: 'include/freetype/config/ftoption.h',
357 output: 'ftoption.h',
358 command: ftoption_command,
360 install_dir: join_paths(freetype_includedir, 'freetype/config'),
362 ft2_sources += ftoption_h
363 ft2_defines += ['-DFT_CONFIG_OPTIONS_H=<ftoption.h>']
365 if host_machine.system() == 'windows'
366 ft2_defines += ['-DDLL_EXPORT=1']
370 # Generate `ftconfig.h`.
372 ftconfig_command = process_header_command
374 ftconfig_command += '--enable=HAVE_UNISTD_H'
377 ftconfig_command += '--enable=HAVE_FCNTL_H'
380 if use_unix_ftsystem_c
381 ftconfig_h_in = files('builds/unix/ftconfig.h.in')
382 ftconfig_h = custom_target('ftconfig.h',
383 input: ftconfig_h_in,
384 output: 'ftconfig.h',
385 command: ftconfig_command,
387 install_dir: join_paths(freetype_includedir, 'freetype/config'),
389 ft2_sources += ftconfig_h
390 ft2_defines += ['-DFT_CONFIG_CONFIG_H=<ftconfig.h>']
394 ft2_lib = library('freetype',
395 sources: ft2_sources + [ftmodule_h],
397 gnu_symbol_visibility: 'hidden',
398 include_directories: ft2_includes,
399 dependencies: ft2_deps,
401 version: ft2_so_version,
402 link_args: common_ldflags,
406 # To be used by other projects including this one through `subproject`.
407 freetype_dep = declare_dependency(
408 include_directories: ft2_includes,
410 version: ft2_pkgconfig_version)
412 meson.override_dependency('freetype2', freetype_dep)
415 # NOTE: Using both `install_dir` and `subdir` doesn't seem to work below,
416 # i.e., the subdir value seems to be ignored, contrary to examples in the
417 # Meson documentation.
418 install_headers('include/ft2build.h',
419 install_dir: freetype_includedir)
420 install_headers(ft2_public_headers,
421 install_dir: join_paths(freetype_includedir, 'freetype'))
422 install_headers(ft2_config_headers,
423 install_dir: join_paths(freetype_includedir, 'freetype/config'))
426 pkgconfig = import('pkgconfig')
428 pkgconfig.generate(ft2_lib,
429 filebase: 'freetype2',
431 description: 'A free, high-quality, and portable font engine.',
432 url: 'https://freetype.org',
433 subdirs: 'freetype2',
434 version: ft2_pkgconfig_version,
437 if get_option('tests').enabled()
441 # NOTE: Unlike the old `make refdoc` command, this generates the
442 # documentation under `$BUILD/docs/` since Meson doesn't support modifying
443 # the source root directory (which is a good thing).
444 gen_docs = custom_target('freetype2 reference documentation',
446 input: ft2_public_headers + ft2_config_headers,
447 command: [python_exe,
448 files('builds/meson/generate_reference_docs.py'),
449 '--version=' + meson.project_version(),
450 '--input-dir=' + meson.current_source_dir(),
451 '--output-dir=@OUTPUT@'
456 summary({'OS': host_machine.system(),
457 }, section: 'Operating System')
459 summary({'Zlib': zlib_option,
460 'Bzip2': bzip2_dep.found() ? 'yes' : 'no',
461 'Png': libpng_dep.found() ? 'yes' : 'no',
462 'Harfbuzz': harfbuzz_dep.found() ? 'yes' : 'no',
463 'Brotli': brotli_dep.found() ? 'yes' : 'no',
464 }, section: 'Used Libraries')