diff options
Diffstat (limited to 'Build/source/libs/freetype2/freetype-src/meson.build')
-rw-r--r-- | Build/source/libs/freetype2/freetype-src/meson.build | 231 |
1 files changed, 95 insertions, 136 deletions
diff --git a/Build/source/libs/freetype2/freetype-src/meson.build b/Build/source/libs/freetype2/freetype-src/meson.build index 0eb780bfd6c..ea304954e1b 100644 --- a/Build/source/libs/freetype2/freetype-src/meson.build +++ b/Build/source/libs/freetype2/freetype-src/meson.build @@ -2,7 +2,7 @@ # Meson project file for FreeType 2 # -# Copyright (C) 2020-2021 by +# Copyright (C) 2020 by # David Turner, Robert Wilhelm, and Werner Lemberg. # # This file is part of the FreeType project, and may only be used, modified, @@ -11,40 +11,30 @@ # indicate that you have read the license and understand and accept it # fully. -# -# Say -# -# meson configure -# -# to see all configuration options and their default values. For example, -# to build only a shared version of FreeType, override the default value -# with -# -# meson setup -Ddefault_library=shared -# project('freetype2', 'c', meson_version: '>= 0.55.0', default_options: ['default_library=both'], - version: run_command('builds/meson/extract_freetype_version.py', - 'include/freetype/freetype.h').stdout().strip(), ) +# +# Rules to compile the FreeType 2 library itself +# + -# Only meson >= 0.57 can read a file and assign its contents to a -# variable; we thus use an external command to have this functionality -# with older versions, too. +# Apparently meson doesn't provide a read_file() function, so instead +# running an external command is required. python = import('python') python_exe = python.find_installation(required: true) -ft2_so_version = run_command(python_exe, - files('builds/meson/extract_libtool_version.py'), - '--soversion', - files('builds/unix/configure.raw')).stdout().strip() +ft2_version = run_command(python_exe, + files('builds/meson/extract_freetype_version.py'), + files('include/freetype/freetype.h')).stdout().strip() -ft2_pkgconfig_version = run_command(python_exe, +ft2_libtool_version = run_command(python_exe, files('builds/meson/extract_libtool_version.py'), + '--soversion', files('builds/unix/configure.raw')).stdout().strip() ft2_includes = include_directories('include') @@ -109,7 +99,7 @@ endforeach # FreeType 2 base extensions. -# To be configured in `modules.cfg`. +# Normally configured through `modules.cfg`. base_extensions = run_command(python_exe, files('builds/meson/parse_modules_cfg.py'), @@ -132,7 +122,6 @@ ft2_public_headers = files([ 'include/freetype/ftbzip2.h', 'include/freetype/ftcache.h', 'include/freetype/ftchapters.h', - 'include/freetype/ftcid.h', 'include/freetype/ftcolor.h', 'include/freetype/ftdriver.h', 'include/freetype/fterrdef.h', @@ -179,7 +168,7 @@ ft2_config_headers = files([ 'include/freetype/config/public-macros.h', ]) -ft2_defines = ['-DFT2_BUILD_LIBRARY=1'] +ft2_defines = [] # System support file. @@ -191,24 +180,24 @@ has_unistd_h = cc.has_header('unistd.h') has_fcntl_h = cc.has_header('fcntl.h') has_sys_mman_h = cc.has_header('sys/mman.h') -mmap_option = get_option('mmap') +if has_unistd_h + ft2_defines += ['-DHAVE_UNISTD_H=1'] +endif +if has_fcntl_h + ft2_defines += ['-DHAVE_FCNTL_H'] +endif -use_unix_ftsystem_c = false -if mmap_option.disabled() - ft2_sources += files(['src/base/ftsystem.c',]) -elif host_machine.system() == 'windows' - ft2_sources += files(['builds/windows/ftsystem.c',]) +mmap_option = get_option('mmap') +if mmap_option.auto() + use_mmap = has_unistd_h and has_fcntl_h and has_sys_mman_h else - if has_unistd_h and has_fcntl_h and has_sys_mman_h - # This version of `ftsystem.c` uses `mmap` to read input font files. - ft2_sources += files(['builds/unix/ftsystem.c',]) - use_unix_ftsystem_c = true - elif mmap_option.enabled() - error('mmap was enabled via options but is not available,' - + ' required headers were not found!') - else - ft2_sources += files(['src/base/ftsystem.c',]) - endif + use_mmap = mmap_option.enabled() +endif +if use_mmap + # This version of ftsystem.c uses mmap() to read input font files. + ft2_sources += files(['builds/unix/ftsystem.c',]) +else + ft2_sources += files(['src/base/ftsystem.c',]) endif @@ -216,52 +205,53 @@ endif # # NOTE: Some specialized versions exist for other platforms not supported by # Meson. Most implementation differences are extremely minor, i.e., in the -# implementation of `FT_Message` and `FT_Panic`, and getting the `FT2_DEBUG` +# implementation of FT_Message() and FT_Panic(), and getting the `FT2_DEBUG` # value from the environment, when this is supported. A smaller refactor # might make these platform-specific files much smaller, and could be moved # into `ftsystem.c` as well. # if host_machine.system() == 'windows' - winmod = import('windows') - ft2_sources += [ - 'builds/windows/ftdebug.c', - winmod.compile_resources('src/base/ftver.rc'), - ] + ft2_debug_src = 'builds/windows/ftdebug.c' else - ft2_sources += 'src/base/ftdebug.c' + ft2_debug_src = 'src/base/ftdebug.c' endif +ft2_sources += files([ft2_debug_src]) ft2_deps = [] # Generate `ftoption.h` based on available dependencies. -process_header_command = [python_exe, +ftoption_command = [python_exe, files('builds/meson/process_ftoption_h.py'), '@INPUT@', '--output=@OUTPUT@'] -ftoption_command = process_header_command - # GZip support -zlib_dep = dependency('zlib', - required: get_option('zlib'), - fallback: 'zlib') - -if zlib_dep.found() - ftoption_command += [ - '--enable=FT_CONFIG_OPTION_USE_ZLIB', - '--enable=FT_CONFIG_OPTION_SYSTEM_ZLIB', - ] - ft2_sources += files(['src/gzip/ftgzip.c',]) - ft2_deps += [zlib_dep] -else +zlib_option = get_option('zlib') +if zlib_option == 'disabled' ftoption_command += ['--disable=FT_CONFIG_OPTION_USE_ZLIB'] +else + ftoption_command += ['--enable=FT_CONFIG_OPTION_USE_ZLIB'] + if zlib_option == 'builtin' + ftoption_command += ['--disable=FT_CONFIG_OPTION_SYSTEM_ZLIB'] + else + # Probe for the system version. + zlib_system = dependency('zlib', required: zlib_option == 'system') + ft2_deps += [zlib_system] + ftoption_command += ['--enable=FT_CONFIG_OPTION_SYSTEM_ZLIB'] + endif + ft2_sources += files(['src/gzip/ftgzip.c',]) endif # BZip2 support -bzip2_dep = cc.find_library('bz2', - required: get_option('bzip2')) - +# +# IMPORTANT NOTE: Without `static: false` here, Meson will find both the +# static library version and the shared library version when they are +# installed on the system, and will try to link them *both* to the final +# library! +bzip2_dep = meson.get_compiler('c').find_library('bz2', + static: false, + required: get_option('bzip2')) if bzip2_dep.found() ftoption_command += ['--enable=FT_CONFIG_OPTION_USE_BZIP2'] ft2_sources += files(['src/bzip2/ftbzip2.c',]) @@ -269,33 +259,21 @@ if bzip2_dep.found() endif # PNG support -libpng_dep = dependency('libpng', - required: get_option('png'), - fallback: 'libpng') - -if libpng_dep.found() - ftoption_command += ['--enable=FT_CONFIG_OPTION_USE_PNG'] - ft2_deps += [libpng_dep] -endif +libpng_dep = dependency('libpng', required: get_option('png')) +ftoption_command += ['--enable=FT_CONFIG_OPTION_USE_PNG'] +ft2_deps += [libpng_dep] # Harfbuzz support harfbuzz_dep = dependency('harfbuzz', - version: '>= 2.0.0', - required: get_option('harfbuzz')) - -if harfbuzz_dep.found() - ftoption_command += ['--enable=FT_CONFIG_OPTION_USE_HARFBUZZ'] - ft2_deps += [harfbuzz_dep] -endif + version: '>= 1.8.0', + required: get_option('harfbuzz')) +ftoption_command += ['--enable=FT_CONFIG_OPTION_USE_HARFBUZZ'] +ft2_deps += [harfbuzz_dep] # Brotli decompression support -brotli_dep = dependency('libbrotlidec', - required: get_option('brotli')) - -if brotli_dep.found() - ftoption_command += ['--enable=FT_CONFIG_OPTION_USE_BROTLI'] - ft2_deps += [brotli_dep] -endif +brotli_dep = dependency('libbrotlidec', required: get_option('brotli')) +ftoption_command += ['--enable=FT_CONFIG_OPTION_USE_BROTLI'] +ft2_deps += [brotli_dep] # We can now generate `ftoption.h`. ftoption_h = custom_target('ftoption.h', @@ -306,82 +284,72 @@ ftoption_h = custom_target('ftoption.h', install_dir: 'include/freetype2/freetype/config', ) ft2_sources += ftoption_h -ft2_defines += ['-DFT_CONFIG_OPTIONS_H=<ftoption.h>'] -if host_machine.system() == 'windows' - ft2_defines += ['-DDLL_EXPORT=1'] -endif +# QUESTION: What if the compiler doesn't support `-D` but uses `/D` instead +# as on Windows? +# +# Other build systems have something like c_defines to list defines in a +# more portable way. For now assume the compiler supports `-D` (hint: Visual +# Studio does). +ft2_defines += ['-DFT2_BUILD_LIBRARY=1'] -# Generate `ftconfig.h`. -ftconfig_command = process_header_command -if has_unistd_h - ftconfig_command += '--enable=HAVE_UNISTD_H' -endif -if has_fcntl_h - ftconfig_command += '--enable=HAVE_FCNTL_H' -endif +# Ensure that the `ftoption.h` file generated above will be used to build +# FreeType. Unfortunately, and very surprisingly, configure_file() does not +# support putting the output file in a sub-directory, so we have to override +# the default which is `<freetype/config/ftoption.h>`. +# +# It would be cleaner to generate the file directly into +# `${MESON_BUILD_DIR}/freetype/config/ftoption.h`. See +# 'https://github.com/mesonbuild/meson/issues/2320' for details. +ft2_defines += ['-DFT_CONFIG_OPTIONS_H=<ftoption.h>'] -if use_unix_ftsystem_c - ftconfig_h_in = files('builds/unix/ftconfig.h.in') - ftconfig_h = custom_target('ftconfig.h', - input: ftconfig_h_in, - output: 'ftconfig.h', - command: ftconfig_command, - install: true, - install_dir: 'include/freetype2/freetype/config', - ) - ft2_sources += ftconfig_h - ft2_defines += ['-DFT_CONFIG_CONFIG_H=<ftconfig.h>'] +ft2_c_args = ft2_defines +if cc.has_function_attribute('visibility:hidden') + ft2_c_args += ['-fvisibility=hidden'] endif - ft2_lib = library('freetype', sources: ft2_sources + [ftmodule_h], - c_args: ft2_defines, - gnu_symbol_visibility: 'hidden', + c_args: ft2_c_args, include_directories: ft2_includes, dependencies: ft2_deps, install: true, - version: ft2_so_version, + version: ft2_libtool_version, ) -# To be used by other projects including this one through `subproject`. -freetype_dep = declare_dependency( +# To be used by other projects including this one through subproject(). +freetype2_dep = declare_dependency( include_directories: ft2_includes, link_with: ft2_lib, - version: ft2_pkgconfig_version) - -meson.override_dependency('freetype2', freetype_dep) + version: ft2_libtool_version) # NOTE: Using both `install_dir` and `subdir` doesn't seem to work below, # i.e., the subdir value seems to be ignored, contrary to examples in the # Meson documentation. install_headers('include/ft2build.h', - install_dir: 'include/freetype2') + install_dir: 'include/freetype2') install_headers(ft2_public_headers, install_dir: 'include/freetype2/freetype') install_headers(ft2_config_headers, install_dir: 'include/freetype2/freetype/config') +# TODO(david): Declare_dependency() for using this in a Meson subproject +# pkgconfig = import('pkgconfig') - pkgconfig.generate(ft2_lib, filebase: 'freetype2', name: 'FreeType 2', description: 'A free, high-quality, and portable font engine.', url: 'https://freetype.org', subdirs: 'freetype2', - version: ft2_pkgconfig_version, + version: ft2_libtool_version, ) -if get_option('tests').enabled() - subdir('tests') -endif # NOTE: Unlike the old `make refdoc` command, this generates the # documentation under `$BUILD/docs/` since Meson doesn't support modifying @@ -391,19 +359,10 @@ gen_docs = custom_target('freetype2 reference documentation', input: ft2_public_headers + ft2_config_headers, command: [python_exe, files('builds/meson/generate_reference_docs.py'), - '--version=' + meson.project_version(), + '--version=' + ft2_version, '--input-dir=' + meson.source_root(), '--output-dir=@OUTPUT@' ], ) - -summary({'OS': host_machine.system(), - 'Zlib': zlib_dep.found() ? 'yes' : 'no', - 'Bzip2': bzip2_dep.found() ? 'yes' : 'no', - 'Png': libpng_dep.found() ? 'yes' : 'no', - 'Harfbuzz': harfbuzz_dep.found() ? 'yes' : 'no', - 'Brotli': brotli_dep.found() ? 'yes' : 'no', - }, section: 'Configuration Options Summary:') - # EOF |