1project('harfbuzz', 'c', 'cpp', 2 meson_version: '>= 0.55.0', 3 version: '10.1.0', 4 default_options: [ 5 'cpp_eh=none', # Just to support msvc, we are passing -fno-exceptions also anyway 6 # 'cpp_rtti=false', # Do NOT enable, wraps inherit it and ICU needs RTTI 7 'cpp_std=c++11', 8 'wrap_mode=nofallback', # Use --wrap-mode=default to revert, https://github.com/harfbuzz/harfbuzz/pull/2548 9 ], 10) 11 12glib_min_version = '>= 2.30.0' 13cairo_min_version = '>= 1.10.0' 14chafa_min_version = '>= 1.6.0' 15icu_min_version = '>= 49.0' 16graphite2_min_version = '>= 1.2.0' 17 18freetype_min_version_actual = '>= 2.4.2' 19freetype_min_version = '>= 12.0.6' # Corresponds to `freetype_min_version_actual` 20 21hb_version_arr = meson.project_version().split('.') 22hb_version_major = hb_version_arr[0].to_int() 23hb_version_minor = hb_version_arr[1].to_int() 24hb_version_micro = hb_version_arr[2].to_int() 25 26# libtool versioning 27hb_version_int = 60000 + hb_version_major*100 + hb_version_minor*10 + hb_version_micro 28hb_libtool_version_info = '@0@:0:@0@'.format(hb_version_int) 29 30pkgmod = import('pkgconfig') 31cpp = meson.get_compiler('cpp') 32null_dep = dependency('', required: false) 33 34# Only perform these checks if cpp_std is c++11 as setting -std directly 35# produces a warning from meson. 36if get_option('cpp_std') == 'c++11' 37 # Enforce C++14 requirement for MSVC STL 38 if cpp.get_id() == 'clang' and cpp.get_define('_MSC_FULL_VER') != '' 39 add_project_arguments('-std=c++14', language: 'cpp') 40 elif cpp.get_id() == 'clang-cl' 41 # Clang-cl produces a warning when using -std=c++14, but not when using /std:c++14 42 add_project_arguments('/std:c++14', language : 'cpp') 43 endif 44endif 45 46if cpp.get_argument_syntax() == 'msvc' 47 # Ignore several spurious warnings for things HarfBuzz does very commonly. 48 # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it 49 # If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once 50 # NOTE: Only add warnings here if you are sure they're spurious 51 msvc_args = [ 52 '/wd4244', # lossy type conversion (e.g. double -> int) 53 '/bigobj', # hb-subset.cc -- compile error C1128: number of sections exceeded object file format limit 54 cpp.get_supported_arguments(['/utf-8']), # set the input encoding to utf-8 55 ] 56 add_project_arguments(msvc_args, language: ['c', 'cpp']) 57 # Disable SAFESEH with MSVC for libs that use external deps that are built with MinGW 58 # noseh_link_args = ['/SAFESEH:NO'] 59endif 60 61add_project_link_arguments(cpp.get_supported_link_arguments([ 62 '-Bsymbolic-functions' 63]), language: 'c') 64 65add_project_arguments(cpp.get_supported_arguments([ 66 '-fno-exceptions', 67 '-fno-rtti', 68 '-fno-threadsafe-statics', 69 '-fvisibility-inlines-hidden', 70]), language: 'cpp') 71 72if host_machine.cpu_family() == 'arm' and cpp.alignment('struct { char c; }') != 1 73 if cpp.has_argument('-mstructure-size-boundary=8') 74 add_project_arguments('-mstructure-size-boundary=8', language: 'cpp') 75 endif 76endif 77 78if host_machine.system() == 'windows' 79 add_project_arguments(cpp.get_supported_arguments([ 80 '-Wa,-mbig-obj' 81 ]), language : 'cpp') 82endif 83 84check_headers = [ 85 ['unistd.h'], 86 ['sys/mman.h'], 87 ['stdbool.h'], 88 ['xlocale.h'], 89] 90 91check_funcs = [ 92 ['atexit', {'prefix': '#include <stdlib.h>'}], 93 ['mprotect', {'prefix': '#include <sys/mman.h>'}], 94 ['sysconf', {'prefix': '#include <unistd.h>'}], 95 ['getpagesize', {'prefix': '#include <unistd.h>'}], 96 ['mmap', {'prefix': '#include <sys/mman.h>'}], 97 ['isatty', {'prefix': '#include <unistd.h>'}], 98 ['uselocale', {'prefix': '#include <locale.h>'}], 99 ['newlocale', {'prefix': '#include <locale.h>'}], 100 ['sincosf', {'prefix': '#define _GNU_SOURCE\n#include <math.h>'}], 101] 102 103m_dep = cpp.find_library('m', required: false) 104 105if meson.version().version_compare('>=0.60.0') 106 # Sadly, FreeType's versioning schemes are different between pkg-config and CMake 107 # pkg-config: freetype2, cmake: Freetype 108 freetype_dep = dependency('freetype2', 109 version: freetype_min_version, 110 method: 'pkg-config', 111 required: false, 112 allow_fallback: false) 113 if not freetype_dep.found() 114 freetype_dep = dependency('FreeType', 115 version: freetype_min_version_actual, 116 method: 'cmake', 117 required: get_option('freetype'), 118 default_options: ['harfbuzz=disabled'], 119 allow_fallback: true) 120 endif 121else 122 # painful hack to handle multiple dependencies but also respect options 123 freetype_opt = get_option('freetype') 124 # we want to handle enabled manually after fallbacks, but also handle disabled normally 125 if freetype_opt.enabled() 126 freetype_opt = false 127 endif 128 # try pkg-config name 129 freetype_dep = dependency('freetype2', version: freetype_min_version, method: 'pkg-config', required: freetype_opt) 130 # when disabled, leave it not-found 131 if not freetype_dep.found() and not get_option('freetype').disabled() 132 # Try cmake name 133 freetype_dep = dependency('Freetype', version: freetype_min_version_actual, method: 'cmake', required: false) 134 # Subproject fallback, `allow_fallback: true` means the fallback will be 135 # tried even if the freetype option is set to `auto`. 136 if not freetype_dep.found() 137 freetype_dep = dependency('freetype2', 138 version: freetype_min_version, 139 method: 'pkg-config', 140 required: get_option('freetype'), 141 default_options: ['harfbuzz=disabled'], 142 allow_fallback: true) 143 endif 144 endif 145endif 146 147glib_dep = dependency('glib-2.0', version: glib_min_version, required: get_option('glib')) 148gobject_dep = dependency('gobject-2.0', version: glib_min_version, required: get_option('gobject')) 149graphite2_dep = dependency('graphite2', version: graphite2_min_version, required: get_option('graphite2')) 150graphite_dep = dependency('graphite2', version: graphite2_min_version, required: get_option('graphite')) 151wasm_dep = cpp.find_library('iwasm', required: get_option('wasm')) 152# How to check whether iwasm was built, and hence requires, LLVM? 153#llvm_dep = cpp.find_library('LLVM-15', required: get_option('wasm')) 154 155if meson.version().version_compare('>=0.60.0') 156 # pkg-config: icu-uc, cmake: ICU but with components 157 icu_dep = dependency('icu-uc', 'ICU', 158 version: icu_min_version, 159 components: 'uc', 160 required: get_option('icu'), 161 allow_fallback: true) 162else 163 # painful hack to handle multiple dependencies but also respect options 164 icu_opt = get_option('icu') 165 # we want to handle enabled manually after fallbacks, but also handle disabled normally 166 if icu_opt.enabled() 167 icu_opt = false 168 endif 169 # try pkg-config name 170 icu_dep = dependency('icu-uc', version: icu_min_version, method: 'pkg-config', required: icu_opt) 171 # when disabled, leave it not-found 172 if not icu_dep.found() and not get_option('icu').disabled() 173 # Try cmake name 174 icu_dep = dependency('ICU', version: icu_min_version, method: 'cmake', components: 'uc', required: false) 175 # Try again with subproject fallback. `allow_fallback: true` means the 176 # fallback will be tried even if the icu option is set to `auto`, but 177 # we cannot pass this option until Meson 0.59.0, because no wrap file 178 # is checked into git. 179 if not icu_dep.found() 180 icu_dep = dependency('icu-uc', 181 version: icu_min_version, 182 method: 'pkg-config', 183 required: get_option('icu')) 184 endif 185 endif 186endif 187 188if icu_dep.found() and icu_dep.version().version_compare('>=75.1') and (get_option('cpp_std') == 'c++11' or get_option('cpp_std') == 'c++14') 189 cpp17_arg = cpp.get_argument_syntax() == 'msvc' ? '/std:c++17' : '-std=c++17' 190 add_project_arguments(cpp17_arg, language: 'cpp') 191endif 192 193if icu_dep.found() and icu_dep.type_name() == 'pkgconfig' 194 icu_defs = icu_dep.get_variable(pkgconfig: 'DEFS', default_value: '').split() 195 if icu_defs.length() > 0 196 add_project_arguments(icu_defs, language: ['c', 'cpp']) 197 endif 198endif 199 200cairo_dep = null_dep 201cairo_ft_dep = null_dep 202if not get_option('cairo').disabled() 203 cairo_dep = dependency('cairo', version: cairo_min_version, required: false) 204 cairo_ft_dep = dependency('cairo-ft', version: cairo_min_version, required: false) 205 206 if (not cairo_dep.found() and 207 cpp.get_argument_syntax() == 'msvc' and 208 cpp.has_header('cairo.h')) 209 cairo_dep = cpp.find_library('cairo', required: false) 210 if cairo_dep.found() and cpp.has_function('cairo_ft_font_face_create_for_ft_face', 211 prefix: '#include <cairo-ft.h>', 212 dependencies: cairo_dep) 213 cairo_ft_dep = cairo_dep 214 endif 215 endif 216 217 if not cairo_dep.found() 218 # Note that we don't have harfbuzz -> cairo -> freetype2 -> harfbuzz fallback 219 # dependency cycle here because we have configured freetype2 above with 220 # harfbuzz support disabled, so when cairo will lookup freetype2 dependency 221 # it will be forced to use that one. 222 cairo_dep = dependency('cairo', version: cairo_min_version, required: get_option('cairo')) 223 cairo_ft_required = get_option('cairo').enabled() and get_option('freetype').enabled() 224 cairo_ft_dep = dependency('cairo-ft', version: cairo_min_version, required: cairo_ft_required) 225 endif 226endif 227 228chafa_dep = dependency('chafa', version: chafa_min_version, required: get_option('chafa')) 229 230conf = configuration_data() 231incconfig = include_directories('.') 232 233add_project_arguments('-DHAVE_CONFIG_H', language: ['c', 'cpp']) 234 235warn_cflags = [ 236 '-Wno-non-virtual-dtor', 237] 238 239cpp_args = cpp.get_supported_arguments(warn_cflags) 240 241if glib_dep.found() 242 conf.set('HAVE_GLIB', 1) 243endif 244 245if gobject_dep.found() 246 conf.set('HAVE_GOBJECT', 1) 247endif 248 249if cairo_dep.found() 250 conf.set('HAVE_CAIRO', 1) 251 check_cairo_funcs = [ 252 ['cairo_user_font_face_set_render_color_glyph_func', {'deps': cairo_dep}], 253 ['cairo_font_options_get_custom_palette_color', {'deps': cairo_dep}], 254 ['cairo_user_scaled_font_get_foreground_source', {'deps': cairo_dep}], 255 ] 256 257 if cairo_dep.type_name() == 'internal' 258 foreach func: check_cairo_funcs 259 name = func[0] 260 conf.set('HAVE_@0@'.format(name.to_upper()), 1) 261 endforeach 262 else 263 check_funcs += check_cairo_funcs 264 endif 265endif 266 267if cairo_ft_dep.found() 268 conf.set('HAVE_CAIRO_FT', 1) 269endif 270 271if chafa_dep.found() 272 conf.set('HAVE_CHAFA', 1) 273endif 274 275if wasm_dep.found() 276 conf.set('HAVE_WASM', 1) 277 conf.set('HB_WASM_MODULE_DIR', '"'+get_option('prefix')+'/'+get_option('libdir')+'/harfbuzz/wasm"') 278endif 279 280if graphite2_dep.found() or graphite_dep.found() 281 conf.set('HAVE_GRAPHITE2', 1) 282endif 283 284if icu_dep.found() 285 conf.set('HAVE_ICU', 1) 286endif 287 288if get_option('icu_builtin') 289 conf.set('HAVE_ICU_BUILTIN', 1) 290endif 291 292if get_option('experimental_api') 293 conf.set('HB_EXPERIMENTAL_API', 1) 294endif 295 296if freetype_dep.found() 297 conf.set('HAVE_FREETYPE', 1) 298 check_freetype_funcs = [ 299 ['FT_Get_Var_Blend_Coordinates', {'deps': freetype_dep}], 300 ['FT_Set_Var_Blend_Coordinates', {'deps': freetype_dep}], 301 ['FT_Done_MM_Var', {'deps': freetype_dep}], 302 ['FT_Get_Transform', {'deps': freetype_dep}], 303 ] 304 305 if freetype_dep.type_name() == 'internal' 306 foreach func: check_freetype_funcs 307 name = func[0] 308 conf.set('HAVE_@0@'.format(name.to_upper()), 1) 309 endforeach 310 else 311 check_funcs += check_freetype_funcs 312 endif 313endif 314 315gdi_uniscribe_deps = [] 316# GDI (Uniscribe) (Windows) 317if host_machine.system() == 'windows' and not get_option('gdi').disabled() 318 if (get_option('directwrite').enabled() and 319 not (cpp.has_header('usp10.h') and cpp.has_header('windows.h'))) 320 error('GDI/Uniscribe was enabled explicitly, but required headers are missing.') 321 endif 322 323 gdi_deps_found = true 324 foreach usplib : ['usp10', 'gdi32', 'rpcrt4'] 325 dep = cpp.find_library(usplib, required: get_option('gdi')) 326 gdi_deps_found = gdi_deps_found and dep.found() 327 gdi_uniscribe_deps += dep 328 endforeach 329 330 if gdi_deps_found 331 conf.set('HAVE_UNISCRIBE', 1) 332 conf.set('HAVE_GDI', 1) 333 endif 334endif 335 336# DirectWrite (Windows) 337if host_machine.system() == 'windows' and not get_option('directwrite').disabled() 338 if get_option('directwrite').enabled() and not cpp.has_header('dwrite_1.h') 339 error('DirectWrite was enabled explicitly, but required header is missing.') 340 endif 341 342 conf.set('HAVE_DIRECTWRITE', 1) 343endif 344 345# CoreText (macOS) 346coretext_deps = [] 347if host_machine.system() == 'darwin' and not get_option('coretext').disabled() 348 app_services_dep = dependency('appleframeworks', modules: ['ApplicationServices'], required: false) 349 if cpp.has_type('CTFontRef', prefix: '#include <ApplicationServices/ApplicationServices.h>', dependencies: app_services_dep) 350 coretext_deps += [app_services_dep] 351 conf.set('HAVE_CORETEXT', 1) 352 # On iOS CoreText and CoreGraphics are stand-alone frameworks 353 # Check for a different symbol to avoid getting cached result 354 else 355 coretext_dep = dependency('appleframeworks', modules: ['CoreText'], required: false) 356 coregraphics_dep = dependency('appleframeworks', modules: ['CoreGraphics'], required: false) 357 corefoundation_dep = dependency('appleframeworks', modules: ['CoreFoundation'], required: false) 358 if cpp.has_type('CTRunRef', prefix: '#include <CoreText/CoreText.h>', dependencies: [coretext_dep, coregraphics_dep, corefoundation_dep]) 359 coretext_deps += [coretext_dep, coregraphics_dep, corefoundation_dep] 360 conf.set('HAVE_CORETEXT', 1) 361 elif get_option('coretext').enabled() 362 error('CoreText was enabled explicitly, but required headers or frameworks are missing.') 363 endif 364 endif 365endif 366 367# threads 368thread_dep = null_dep 369if host_machine.system() != 'windows' 370 thread_dep = dependency('threads', required: false) 371 372 if thread_dep.found() 373 conf.set('HAVE_PTHREAD', 1) 374 endif 375endif 376 377conf.set_quoted('PACKAGE_NAME', 'HarfBuzz') 378conf.set_quoted('PACKAGE_VERSION', meson.project_version()) 379 380foreach check : check_headers 381 name = check[0] 382 383 if cpp.has_header(name) 384 conf.set('HAVE_@0@'.format(name.to_upper().underscorify()), 1) 385 endif 386endforeach 387 388harfbuzz_extra_deps = [] 389foreach check : check_funcs 390 name = check[0] 391 opts = check.get(1, {}) 392 link_withs = opts.get('link_with', []) 393 check_deps = opts.get('deps', []) 394 check_prefix = opts.get('prefix', '') 395 extra_deps = [] 396 found = true 397 398 # First try without linking 399 found = cpp.has_function(name, prefix: check_prefix, dependencies: check_deps) 400 401 if not found and link_withs.length() > 0 402 found = true 403 404 foreach link_with : link_withs 405 dep = cpp.find_library(link_with, required: false) 406 if dep.found() 407 extra_deps += dep 408 else 409 found = false 410 endif 411 endforeach 412 413 if found 414 found = cpp.has_function(name, prefix: check_prefix, dependencies: check_deps + extra_deps) 415 endif 416 endif 417 418 if found 419 harfbuzz_extra_deps += extra_deps 420 conf.set('HAVE_@0@'.format(name.to_upper()), 1) 421 endif 422endforeach 423 424# CMake support (package install dir) 425 426# Equivalent to configure_package_config_file(INSTALL_DESTINATION ...), see 427# https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html#command:configure_package_config_file. 428# In certain unusual packaging layouts such as Nixpkgs, the Harfbuzz package 429# is installed into two Nix store paths, "out" and "dev", where "out" contains 430# libraries only (i.e. lib/libharfbuzz.so) and "dev" contains development 431# files, i.e. include and lib/cmake. If CMake package files are installed to 432# "out", Nixpkgs will move them to "dev", which breaks assumptions about 433# our file paths. Since we need to figure out relative install paths here 434# to make a relocatable package, we do need to know the final path of our 435# CMake files to calculate the correct relative paths. 436# Of course, this still defaults to $libdir/cmake if unset, which works for 437# most packaging layouts. 438cmake_package_install_dir = get_option('cmakepackagedir') 439 440if cmake_package_install_dir == '' 441 cmake_package_install_dir = get_option('libdir') / 'cmake' 442endif 443 444subdir('src') 445 446if not get_option('utilities').disabled() 447 subdir('util') 448endif 449 450if not get_option('tests').disabled() 451 subdir('test') 452endif 453 454if not get_option('benchmark').disabled() 455 subdir('perf') 456endif 457 458if not get_option('docs').disabled() 459 subdir('docs') 460endif 461 462configure_file(output: 'config.h', configuration: conf) 463 464alias_target('lib', libharfbuzz) 465alias_target('libs', libharfbuzz, libharfbuzz_subset) 466 467build_summary = { 468 'Directories': 469 {'prefix': get_option('prefix'), 470 'bindir': get_option('bindir'), 471 'libdir': get_option('libdir'), 472 'includedir': get_option('includedir'), 473 'datadir': get_option('datadir'), 474 'cmakepackagedir': cmake_package_install_dir 475 }, 476 'Unicode callbacks (you want at least one)': 477 {'Builtin': true, 478 'Glib': conf.get('HAVE_GLIB', 0) == 1, 479 'ICU': conf.get('HAVE_ICU', 0) == 1, 480 }, 481 'Font callbacks (the more the merrier)': 482 {'Builtin' : true, 483 'FreeType': conf.get('HAVE_FREETYPE', 0) == 1, 484 }, 485 'Dependencies used for command-line utilities': 486 {'Cairo': conf.get('HAVE_CAIRO', 0) == 1, 487 'Chafa': conf.get('HAVE_CHAFA', 0) == 1, 488 }, 489 'Additional shapers': 490 {'Graphite2': conf.get('HAVE_GRAPHITE2', 0) == 1, 491 'WebAssembly (experimental)': conf.get('HAVE_WASM', 0) == 1, 492 }, 493 'Platform shapers (not normally needed)': 494 {'CoreText': conf.get('HAVE_CORETEXT', 0) == 1, 495 'DirectWrite (experimental)': conf.get('HAVE_DIRECTWRITE', 0) == 1, 496 'GDI/Uniscribe': (conf.get('HAVE_GDI', 0) == 1) and (conf.get('HAVE_UNISCRIBE', 0) == 1), 497 }, 498 'Other features': 499 {'Documentation': conf.get('HAVE_GTK_DOC', 0) == 1, 500 'GObject bindings': conf.get('HAVE_GOBJECT', 0) == 1, 501 'Cairo integration': conf.get('HAVE_CAIRO', 0) == 1, 502 'Introspection': conf.get('HAVE_INTROSPECTION', 0) == 1, 503 'Experimental APIs': conf.get('HB_EXPERIMENTAL_API', 0) == 1, 504 }, 505 'Testing': 506 {'Tests': get_option('tests').enabled(), 507 'Benchmark': get_option('benchmark').enabled(), 508 }, 509} 510foreach section_title, section : build_summary 511 summary(section, bool_yn: true, section: section_title) 512endforeach 513