From 0d34386366c93835501e98d643586eb32dbda1fa Mon Sep 17 00:00:00 2001 From: David Turner Date: Tue, 17 Aug 2021 17:27:36 +0200 Subject: [PATCH] [meson] Change Zlib configuration option. * meson_options.txt, meson.build: Change the format of the 'zlib' meson build configuration option to be a combo with the following choices: - none: Do not support gzip-compressed streams at all. - internal: Support gzip-compressed streams using the copy of the gzip sources under `src/gzip/`; this should only be used during development to ensure these work properly. - external: Support gzip-compressed streams using the 'zlib' Meson subproject, linked as a static library. - system: Support gzip-compressed streams using a system-installed version of zlib. - auto: Support gzip-compressed streams using a system-installed version of zlib, if available, or using the 'zlib' subproject otherwise. This is the default. - disabled: Backward-compatible alias for 'none'. - enabled: Backward-compatible alias for 'auto'. --- meson.build | 48 ++++++++++++++++++++++++++++++++++++++++------- meson_options.txt | 6 ++++-- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/meson.build b/meson.build index 5e8d8ef18..34937bf46 100644 --- a/meson.build +++ b/meson.build @@ -267,15 +267,49 @@ ftoption_command = process_header_command # external GZip support -zlib_dep = dependency('zlib', - required: get_option('zlib'), - fallback: 'zlib') +zlib_option = get_option('zlib') -if zlib_dep.found() - ftoption_command += ['--enable=FT_CONFIG_OPTION_SYSTEM_ZLIB'] +# Backwards-compatible aliases. +if zlib_option == 'disabled' + zlib_option = 'none' +elif zlib_option == 'enabled' + zlib_option = 'auto' +endif + +if zlib_option == 'auto' + # First try to find a system installation, otherwise fall back to + # the subproject. + zlib_dep = dependency('zlib', + required: false) + if zlib_dep.found() + zlib_option = 'system' + else + zlib_option = 'external' + endif +endif + +if zlib_option == 'none' + ftoption_command += [ '--disable=FT_CONFIG_OPTION_USE_ZLIB' ] +elif zlib_option == 'internal' + ftoption_command += [ '--enable=FT_CONFIG_OPTION_USE_ZLIB' ] +elif zlib_option == 'external' + ftoption_command += [ '--enable=FT_CONFIG_OPTION_USE_ZLIB' ] + zlib_project = subproject('zlib', + required: true, + default_options: 'default_library=static') + zlib_dep = zlib_project.get_variable('zlib_dep') + ft2_deps += [zlib_dep] +elif zlib_option == 'system' + zlib_dep = dependency('zlib', + required: true) + assert(zlib_dep.found(), 'Could not find system zlib installation!') + ftoption_command += [ + '--enable=FT_CONFIG_OPTION_USE_ZLIB', + '--enable=FT_CONFIG_OPTION_SYSTEM_ZLIB', + ] ft2_deps += [zlib_dep] else - ftoption_command += ['--disable=FT_CONFIG_OPTION_SYSTEM_ZLIB'] + assert(false, 'Invalid zlib option ' + zlib_option) endif # BZip2 support @@ -422,7 +456,7 @@ gen_docs = custom_target('freetype2 reference documentation', summary({'OS': host_machine.system(), }, section: 'Operating System') -summary({'Zlib': zlib_dep.found() ? 'external' : 'internal', +summary({'Zlib': zlib_option, 'Bzip2': bzip2_dep.found() ? 'yes' : 'no', 'Png': libpng_dep.found() ? 'yes' : 'no', 'Harfbuzz': harfbuzz_dep.found() ? 'yes' : 'no', diff --git a/meson_options.txt b/meson_options.txt index 375eb714e..50ca0f986 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -46,8 +46,10 @@ option('tests', description: 'Enable FreeType unit and regression tests') option('zlib', - type: 'feature', - value: 'auto', + type: 'combo', + choices: [ 'auto', 'none', + 'internal', 'external', 'system', + 'disabled', 'enabled' ], description: 'Support reading gzip-compressed font files') # EOF