1project('harfbuzz', 'c', 'cpp', 2 meson_version: '>= 0.47.0', 3 version: '2.8.1', 4 default_options: [ 5 'cpp_eh=none', # Just to support msvc, we are passing -fno-rtti also anyway 6 'cpp_rtti=false', # Just to support msvc, we are passing -fno-exceptions also anyway 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 12hb_version_arr = meson.project_version().split('.') 13hb_version_major = hb_version_arr[0].to_int() 14hb_version_minor = hb_version_arr[1].to_int() 15hb_version_micro = hb_version_arr[2].to_int() 16 17# libtool versioning 18hb_version_int = hb_version_major*10000 + hb_version_minor*100 + hb_version_micro 19hb_libtool_version_info = '@0@:0:@0@'.format(hb_version_int) 20 21pkgmod = import('pkgconfig') 22cpp = meson.get_compiler('cpp') 23null_dep = dependency('', required: false) 24 25if cpp.get_id() == 'msvc' 26 # Ignore several spurious warnings for things HarfBuzz does very commonly. 27 # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it 28 # If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once 29 # NOTE: Only add warnings here if you are sure they're spurious 30 msvc_args = [ 31 '/wd4018', # implicit signed/unsigned conversion 32 '/wd4146', # unary minus on unsigned (beware INT_MIN) 33 '/wd4244', # lossy type conversion (e.g. double -> int) 34 '/wd4305', # truncating type conversion (e.g. double -> float) 35 cpp.get_supported_arguments(['/utf-8']), # set the input encoding to utf-8 36 ] 37 add_project_arguments(msvc_args, language: ['c', 'cpp']) 38 # Disable SAFESEH with MSVC for libs that use external deps that are built with MinGW 39 # noseh_link_args = ['/SAFESEH:NO'] 40endif 41 42add_project_link_arguments(cpp.get_supported_link_arguments([ 43 '-Bsymbolic-functions' 44]), language: 'c') 45 46add_project_arguments(cpp.get_supported_arguments([ 47 '-fno-exceptions', 48 '-fno-rtti', 49 '-fno-threadsafe-statics', 50 '-fvisibility-inlines-hidden', 51]), language: 'cpp') 52 53if host_machine.cpu_family() == 'arm' and cpp.alignment('struct { char c; }') != 1 54 if cpp.has_argument('-mstructure-size-boundary=8') 55 add_project_arguments('-mstructure-size-boundary=8', language: 'cpp') 56 endif 57endif 58 59check_headers = [ 60 ['unistd.h'], 61 ['sys/mman.h'], 62 ['stdbool.h'], 63] 64 65check_funcs = [ 66 ['atexit'], 67 ['mprotect'], 68 ['sysconf'], 69 ['getpagesize'], 70 ['mmap'], 71 ['isatty'], 72] 73 74m_dep = cpp.find_library('m', required: false) 75 76freetype_dep = null_dep 77if not get_option('freetype').disabled() 78 freetype_dep = dependency('freetype2', required: false) 79 80 if (not freetype_dep.found() and 81 cpp.get_id() == 'msvc' and 82 cpp.has_header('ft2build.h')) 83 freetype_dep = cpp.find_library('freetype', required: false) 84 endif 85 86 if not freetype_dep.found() 87 # https://github.com/harfbuzz/harfbuzz/pull/2498 88 freetype_dep = dependency('freetype2', required: get_option('freetype'), 89 fallback: ['freetype2', 'freetype_dep'], 90 default_options: ['harfbuzz=disabled']) 91 endif 92endif 93 94glib_dep = dependency('glib-2.0', required: get_option('glib'), 95 fallback: ['glib', 'libglib_dep']) 96gobject_dep = dependency('gobject-2.0', required: get_option('gobject'), 97 fallback: ['glib', 'libgobject_dep']) 98graphite2_dep = dependency('graphite2', required: get_option('graphite')) 99 100icu_dep = null_dep 101if not get_option('icu').disabled() 102 icu_dep = dependency('icu-uc', required: false) 103 104 if (not icu_dep.found() and 105 cpp.get_id() == 'msvc' and 106 cpp.has_header('unicode/uchar.h') and 107 cpp.has_header('unicode/unorm2.h') and 108 cpp.has_header('unicode/ustring.h') and 109 cpp.has_header('unicode/utf16.h') and 110 cpp.has_header('unicode/uversion.h') and 111 cpp.has_header('unicode/uscript.h')) 112 if get_option('buildtype') == 'debug' 113 icu_dep = cpp.find_library('icuucd', required: false) 114 else 115 icu_dep = cpp.find_library('icuuc', required: false) 116 endif 117 endif 118 119 if not icu_dep.found() 120 icu_dep = dependency('icu-uc', required: get_option('icu')) 121 endif 122endif 123 124cairo_dep = null_dep 125cairo_ft_dep = null_dep 126if not get_option('cairo').disabled() 127 cairo_dep = dependency('cairo', required: false) 128 cairo_ft_dep = dependency('cairo-ft', required: false) 129 130 if (not cairo_dep.found() and 131 cpp.get_id() == 'msvc' and 132 cpp.has_header('cairo.h')) 133 cairo_dep = cpp.find_library('cairo', required: false) 134 if cairo_dep.found() and cpp.has_function('cairo_ft_font_face_create_for_ft_face', 135 prefix: '#include <cairo-ft.h>', 136 dependencies: cairo_dep) 137 cairo_ft_dep = cairo_dep 138 endif 139 endif 140 141 if not cairo_dep.found() 142 # Requires Meson 0.54.0 to use cairo subproject 143 if meson.version().version_compare('>=0.54.0') 144 # Note that we don't have harfbuzz -> cairo -> freetype2 -> harfbuzz fallback 145 # dependency cycle here because we have configured freetype2 above with 146 # harfbuzz support disabled, so when cairo will lookup freetype2 dependency 147 # it will be forced to use that one. 148 cairo_dep = dependency('cairo', fallback: 'cairo', required: get_option('cairo')) 149 cairo_ft_dep = dependency('cairo-ft', fallback: 'cairo', required: get_option('cairo')) 150 elif get_option('cairo').enabled() 151 error('cairo feature is enabled but it cannot be found on the system and ' + 152 'meson>=0.54.0 is required to build it as subproject') 153 endif 154 endif 155endif 156 157chafa_dep = dependency('chafa', version: '>= 1.6.0', required: get_option('chafa')) 158 159conf = configuration_data() 160incconfig = include_directories('.') 161 162add_project_arguments('-DHAVE_CONFIG_H', language: ['c', 'cpp']) 163 164warn_cflags = [ 165 '-Wno-non-virtual-dtor', 166] 167 168cpp_args = cpp.get_supported_arguments(warn_cflags) 169 170if glib_dep.found() 171 conf.set('HAVE_GLIB', 1) 172endif 173 174if gobject_dep.found() 175 conf.set('HAVE_GOBJECT', 1) 176endif 177 178if cairo_dep.found() 179 conf.set('HAVE_CAIRO', 1) 180endif 181 182if cairo_ft_dep.found() 183 conf.set('HAVE_CAIRO_FT', 1) 184endif 185 186if chafa_dep.found() 187 conf.set('HAVE_CHAFA', 1) 188endif 189 190if graphite2_dep.found() 191 conf.set('HAVE_GRAPHITE2', 1) 192endif 193 194if icu_dep.found() 195 conf.set('HAVE_ICU', 1) 196endif 197 198if get_option('icu_builtin') 199 conf.set('HAVE_ICU_BUILTIN', 1) 200endif 201 202if get_option('experimental_api') 203 conf.set('HB_EXPERIMENTAL_API', 1) 204endif 205 206if freetype_dep.found() 207 conf.set('HAVE_FREETYPE', 1) 208 check_freetype_funcs = [ 209 ['FT_Get_Var_Blend_Coordinates', {'deps': freetype_dep}], 210 ['FT_Set_Var_Blend_Coordinates', {'deps': freetype_dep}], 211 ['FT_Done_MM_Var', {'deps': freetype_dep}], 212 ] 213 214 if freetype_dep.type_name() == 'internal' 215 foreach func: check_freetype_funcs 216 name = func[0] 217 conf.set('HAVE_@0@'.format(name.to_upper()), 1) 218 endforeach 219 else 220 check_funcs += check_freetype_funcs 221 endif 222endif 223 224gdi_uniscribe_deps = [] 225# GDI (Uniscribe) (Windows) 226if host_machine.system() == 'windows' and not get_option('gdi').disabled() 227 if (get_option('directwrite').enabled() and 228 not (cpp.has_header('usp10.h') and cpp.has_header('windows.h'))) 229 error('GDI/Uniscribe was enabled explicitly, but required headers are missing.') 230 endif 231 232 gdi_deps_found = true 233 foreach usplib : ['usp10', 'gdi32', 'rpcrt4'] 234 dep = cpp.find_library(usplib, required: get_option('gdi')) 235 gdi_deps_found = gdi_deps_found and dep.found() 236 gdi_uniscribe_deps += dep 237 endforeach 238 239 if gdi_deps_found 240 conf.set('HAVE_UNISCRIBE', 1) 241 conf.set('HAVE_GDI', 1) 242 endif 243endif 244 245# DirectWrite (Windows) 246directwrite_dep = null_dep 247if host_machine.system() == 'windows' and not get_option('directwrite').disabled() 248 if get_option('directwrite').enabled() and not cpp.has_header('dwrite_1.h') 249 error('DirectWrite was enabled explicitly, but required header is missing.') 250 endif 251 252 directwrite_dep = cpp.find_library('dwrite', required: get_option('directwrite')) 253 254 if directwrite_dep.found() 255 conf.set('HAVE_DIRECTWRITE', 1) 256 endif 257endif 258 259# CoreText (macOS) 260coretext_deps = [] 261if host_machine.system() == 'darwin' and not get_option('coretext').disabled() 262 app_services_dep = dependency('appleframeworks', modules: ['ApplicationServices'], required: false) 263 if cpp.has_type('CTFontRef', prefix: '#include <ApplicationServices/ApplicationServices.h>', dependencies: app_services_dep) 264 coretext_deps += [app_services_dep] 265 conf.set('HAVE_CORETEXT', 1) 266 # On iOS CoreText and CoreGraphics are stand-alone frameworks 267 # Check for a different symbol to avoid getting cached result 268 else 269 coretext_dep = dependency('appleframeworks', modules: ['CoreText'], required: false) 270 coregraphics_dep = dependency('appleframeworks', modules: ['CoreGraphics'], required: false) 271 corefoundation_dep = dependency('appleframeworks', modules: ['CoreFoundation'], required: false) 272 if cpp.has_type('CTRunRef', prefix: '#include <CoreText/CoreText.h>', dependencies: [coretext_dep, coregraphics_dep, corefoundation_dep]) 273 coretext_deps += [coretext_dep, coregraphics_dep, corefoundation_dep] 274 conf.set('HAVE_CORETEXT', 1) 275 elif get_option('coretext').enabled() 276 error('CoreText was enabled explicitly, but required headers or frameworks are missing.') 277 endif 278 endif 279endif 280 281# threads 282thread_dep = null_dep 283if host_machine.system() != 'windows' 284 thread_dep = dependency('threads', required: false) 285 286 if thread_dep.found() 287 conf.set('HAVE_PTHREAD', 1) 288 endif 289endif 290 291conf.set_quoted('PACKAGE_NAME', 'HarfBuzz') 292conf.set_quoted('PACKAGE_VERSION', meson.project_version()) 293 294foreach check : check_headers 295 name = check[0] 296 297 if cpp.has_header(name) 298 conf.set('HAVE_@0@'.format(name.to_upper().underscorify()), 1) 299 endif 300endforeach 301 302harfbuzz_extra_deps = [] 303foreach check : check_funcs 304 name = check[0] 305 opts = check.get(1, {}) 306 link_withs = opts.get('link_with', []) 307 check_deps = opts.get('deps', []) 308 extra_deps = [] 309 found = true 310 311 # First try without linking 312 found = cpp.has_function(name, dependencies: check_deps) 313 314 if not found and link_withs.length() > 0 315 found = true 316 317 foreach link_with : link_withs 318 dep = cpp.find_library(link_with, required: false) 319 if dep.found() 320 extra_deps += dep 321 else 322 found = false 323 endif 324 endforeach 325 326 if found 327 found = cpp.has_function(name, dependencies: check_deps + extra_deps) 328 endif 329 endif 330 331 if found 332 harfbuzz_extra_deps += extra_deps 333 conf.set('HAVE_@0@'.format(name.to_upper()), 1) 334 endif 335endforeach 336 337subdir('src') 338subdir('util') 339 340if not get_option('tests').disabled() 341 subdir('test') 342endif 343 344if not get_option('benchmark').disabled() 345 subdir('perf') 346endif 347 348if not get_option('docs').disabled() 349 subdir('docs') 350endif 351 352configure_file(output: 'config.h', configuration: conf) 353 354build_summary = { 355 'Directories': 356 {'prefix': get_option('prefix'), 357 'bindir': get_option('bindir'), 358 'libdir': get_option('libdir'), 359 'includedir': get_option('includedir'), 360 'datadir': get_option('datadir'), 361 }, 362 'Unicode callbacks (you want at least one)': 363 {'Builtin': true, 364 'Glib': conf.get('HAVE_GLIB', 0) == 1, 365 'ICU': conf.get('HAVE_ICU', 0) == 1, 366 }, 367 'Font callbacks (the more the merrier)': 368 {'FreeType': conf.get('HAVE_FREETYPE', 0) == 1, 369 }, 370 'Dependencies used for command-line utilities': 371 {'Cairo': conf.get('HAVE_CAIRO', 0) == 1, 372 'Chafa': conf.get('HAVE_CHAFA', 0) == 1, 373 }, 374 'Additional shapers': 375 {'Graphite2': conf.get('HAVE_GRAPHITE2', 0) == 1, 376 }, 377 'Platform shapers (not normally needed)': 378 {'CoreText': conf.get('HAVE_CORETEXT', 0) == 1, 379 'DirectWrite': conf.get('HAVE_DIRECTWRITE', 0) == 1, 380 'GDI/Uniscribe': (conf.get('HAVE_GDI', 0) == 1) and (conf.get('HAVE_UNISCRIBE', 0) == 1), 381 }, 382 'Other features': 383 {'Documentation': conf.get('HAVE_GTK_DOC', 0) == 1, 384 'GObject bindings': conf.get('HAVE_GOBJECT', 0) == 1, 385 'Introspection': conf.get('HAVE_INTROSPECTION', 0) == 1, 386 'Experimental APIs': conf.get('HB_EXPERIMENTAL_API', 0) == 1, 387 }, 388 'Testing': 389 {'Tests': get_option('tests').enabled(), 390 'Benchmark': get_option('benchmark').enabled(), 391 }, 392} 393if meson.version().version_compare('>=0.53') 394 foreach section_title, section : build_summary 395 summary(section, bool_yn: true, section: section_title) 396 endforeach 397else 398 summary = [''] 399 foreach section_title, section : build_summary 400 summary += ' @0@:'.format(section_title) 401 foreach feature, value : section 402 summary += ' @0@:'.format(feature) 403 summary += ' @0@'.format(value) 404 endforeach 405 summary += '' 406 endforeach 407 message('\n'.join(summary)) 408endif 409