Meson: Fix dependency lookup and generate ftconfig.h [meson] Fix dependency lookup and generate `ftconfig.h`. - zlib: If not found on the system, meson can build it as a subproject. We thus never use the (outdated) zlib support that comes with FreeType. Doing so has the additional advantage that the zlib code can be shared with other projects like GLib if both are subprojects of an application. - harfbuzz: Build as a subproject if not found on the system. - 'QUESTION: What if the compiler doesn't support `-D` but uses `/D` instead as on Windows?' Answer: Meson translate arguments for us. - visibility: Replace self-made code with meson-specific solution. * meson.build (ft2_defines): Rewrite logic to set and handle it. (process_header_command): New variable, previously called `ftoption_command`. (ftoption_command, ftconfig_command): New variables. (zlib_option): Removed. (zlib_dep): New variable. (ft2_deps): Updated. (harfbuzz_dep): Updated. (ftconfig_h_in, ftconfig_h): New variables. (ft2_sources): Updated. (ft2_lib): Updated, handle visibility. (summary): Updted. * meson_options.txt (zlib): Updated.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
diff --git a/ChangeLog b/ChangeLog
index e7095d8..6c37127 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,34 @@
2021-02-09 Xavier Claessens <xavier.claessens@collabora.com>
+ [meson] Fix dependency lookup and generate `ftconfig.h`.
+
+ - zlib: If not found on the system, meson can build it as a
+ subproject. We thus never use the (outdated) zlib support that
+ comes with FreeType. Doing so has the additional advantage that
+ the zlib code can be shared with other projects like GLib if both
+ are subprojects of an application.
+ - harfbuzz: Build as a subproject if not found on the system.
+ - 'QUESTION: What if the compiler doesn't support `-D` but uses `/D`
+ instead as on Windows?' Answer: Meson translate arguments for us.
+ - visibility: Replace self-made code with meson-specific solution.
+
+ * meson.build (ft2_defines): Rewrite logic to set and handle it.
+ (process_header_command): New variable, previously called
+ `ftoption_command`.
+ (ftoption_command, ftconfig_command): New variables.
+ (zlib_option): Removed.
+ (zlib_dep): New variable.
+ (ft2_deps): Updated.
+ (harfbuzz_dep): Updated.
+ (ftconfig_h_in, ftconfig_h): New variables.
+ (ft2_sources): Updated.
+ (ft2_lib): Updated, handle visibility.
+ (summary): Updted.
+
+ * meson_options.txt (zlib): Updated.
+
+2021-02-09 Xavier Claessens <xavier.claessens@collabora.com>
+
* meson.build: Fix resource compilation on Windows.
This is copied from GStreamer's meson port of FreeType.
diff --git a/meson.build b/meson.build
index df61dec..0116572 100644
--- a/meson.build
+++ b/meson.build
@@ -170,7 +170,7 @@ ft2_config_headers = files([
'include/freetype/config/public-macros.h',
])
-ft2_defines = []
+ft2_defines = ['-DFT2_BUILD_LIBRARY=1']
# System support file.
@@ -182,13 +182,6 @@ 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')
-if has_unistd_h
- ft2_defines += ['-DHAVE_UNISTD_H=1']
-endif
-if has_fcntl_h
- ft2_defines += ['-DHAVE_FCNTL_H']
-endif
-
mmap_option = get_option('mmap')
if mmap_option.auto()
use_mmap = has_unistd_h and has_fcntl_h and has_sys_mman_h
@@ -229,27 +222,24 @@ ft2_deps = []
# Generate `ftoption.h` based on available dependencies.
-ftoption_command = [python_exe,
+process_header_command = [python_exe,
files('builds/meson/process_ftoption_h.py'),
'@INPUT@', '--output=@OUTPUT@']
+ftoption_command = process_header_command
+
# GZip support
-have_zlib='no'
-zlib_option = get_option('zlib')
-if zlib_option == 'disabled'
- ftoption_command += ['--disable=FT_CONFIG_OPTION_USE_ZLIB']
-else
- have_zlib='yes'
- 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
+zlib_dep = dependency('zlib', required: get_option('zlib'),
+ fallback: ['zlib', 'zlib_dep'])
+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
+ ftoption_command += ['--disable=FT_CONFIG_OPTION_USE_ZLIB']
endif
# BZip2 support
@@ -270,7 +260,10 @@ endif
# Harfbuzz support
harfbuzz_dep = dependency('harfbuzz',
version: '>= 2.0.0',
- required: get_option('harfbuzz'))
+ required: get_option('harfbuzz'),
+ fallback: ['harfbuzz', 'libharfbuzz_dep'],
+ default_options : ['freetype=disabled',
+ 'fontconfig=disabled'])
if harfbuzz_dep.found()
ftoption_command += ['--enable=FT_CONFIG_OPTION_USE_HARFBUZZ']
ft2_deps += [harfbuzz_dep]
@@ -292,39 +285,43 @@ ftoption_h = custom_target('ftoption.h',
install_dir: 'include/freetype2/freetype/config',
)
ft2_sources += ftoption_h
-
-
-# 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']
+ft2_defines += ['-DFT_CONFIG_OPTIONS_H=<ftoption.h>']
if host_machine.system() == 'windows'
ft2_defines += ['-DDLL_EXPORT=1']
endif
+# Generate `ftconfig.h`
-# 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>']
+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
-ft2_c_args = ft2_defines
-if cc.has_function_attribute('visibility:hidden')
- ft2_c_args += ['-fvisibility=hidden']
+if host_machine.system() in ['linux', 'darwin', 'cygwin']
+ ftconfig_h_in = files('builds/unix/ftconfig.h.in')
+else
+ ftconfig_h_in = files('include/freetype/config/ftconfig.h')
endif
+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_lib = library('freetype',
sources: ft2_sources + [ftmodule_h],
- c_args: ft2_c_args,
+ c_args: ft2_defines,
+ gnu_symbol_visibility: 'hidden',
include_directories: ft2_includes,
dependencies: ft2_deps,
install: true,
@@ -378,7 +375,7 @@ gen_docs = custom_target('freetype2 reference documentation',
summary({'OS': host_machine.system(),
- 'Zlib': have_zlib,
+ 'Zlib': zlib_dep.found() ? 'yes' : 'no',
'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 301acdc..f0fc50a 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -13,8 +13,7 @@
option('zlib',
- type: 'combo',
- choices: ['disabled', 'auto', 'builtin', 'system'],
+ type: 'feature',
value: 'auto',
description: 'Support reading gzip-compressed font files.')