Mathieu Duponchelle | 920efc0 | 2018-05-17 01:28:53 +0200 | [diff] [blame] | 1 | project('harfbuzz', 'c', 'cpp', |
Mathieu Duponchelle | 07cadc9 | 2018-06-18 17:18:05 +0200 | [diff] [blame] | 2 | meson_version: '>= 0.47.0', |
Ebrahim Byagowi | 31218b4 | 2020-03-11 22:27:32 +0330 | [diff] [blame] | 3 | default_options : ['cpp_std=c++11'], |
Ebrahim Byagowi | 1c3f80b | 2020-03-11 19:29:47 +0330 | [diff] [blame] | 4 | version: '2.6.4') |
Mathieu Duponchelle | 920efc0 | 2018-05-17 01:28:53 +0200 | [diff] [blame] | 5 | |
Tim-Philipp Müller | 535186f | 2018-12-03 20:51:06 +0100 | [diff] [blame] | 6 | hb_version_arr = meson.project_version().split('.') |
| 7 | hb_version_major = hb_version_arr[0].to_int() |
| 8 | hb_version_minor = hb_version_arr[1].to_int() |
| 9 | hb_version_micro = hb_version_arr[2].to_int() |
| 10 | |
| 11 | # libtool versioning |
| 12 | hb_version_int = hb_version_major*10000 + hb_version_minor*100 + hb_version_micro |
| 13 | if hb_version_minor % 2 == 1 |
| 14 | hb_libtool_revision = 0 # for unstable releases |
| 15 | else |
| 16 | hb_libtool_revision = hb_version_micro # for stable releases |
| 17 | endif |
| 18 | hb_libtool_age = hb_version_int - hb_libtool_revision |
| 19 | hb_libtool_current = hb_libtool_age |
| 20 | hb_libtool_version_info = '@0@:@1@:@2@'.format(hb_libtool_current, hb_libtool_revision, hb_libtool_age) |
| 21 | |
Mathieu Duponchelle | 484313f | 2018-06-05 02:15:43 +0200 | [diff] [blame] | 22 | pkgmod = import('pkgconfig') |
Mathieu Duponchelle | 920efc0 | 2018-05-17 01:28:53 +0200 | [diff] [blame] | 23 | cpp = meson.get_compiler('cpp') |
| 24 | |
Tim-Philipp Müller | 4a47f1a | 2018-12-01 11:05:27 +0000 | [diff] [blame] | 25 | if 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') |
| 38 | add_project_arguments(msvc_args, language : 'cpp') |
| 39 | # Disable SAFESEH with MSVC for libs that use external deps that are built with MinGW |
| 40 | # noseh_link_args = ['/SAFESEH:NO'] |
| 41 | endif |
| 42 | |
Ebrahim Byagowi | 365d2d3 | 2020-03-11 20:16:36 +0330 | [diff] [blame] | 43 | add_global_arguments(cpp.get_supported_arguments([ |
| 44 | '-fno-rtti', |
| 45 | '-fno-exceptions', |
| 46 | '-fno-threadsafe-statics', |
| 47 | '-fvisibility-inlines-hidden', # maybe shouldn't be applied for mingw |
| 48 | ]), language : 'cpp') |
| 49 | |
| 50 | if host_machine.cpu_family() == 'arm' and cpp.alignment('struct { char c; }') != 1 |
| 51 | if cpp.has_argument('-mstructure-size-boundary=8') |
| 52 | add_global_arguments('-mstructure-size-boundary=8', language : 'cpp') |
| 53 | endif |
| 54 | endif |
| 55 | |
Mathieu Duponchelle | 920efc0 | 2018-05-17 01:28:53 +0200 | [diff] [blame] | 56 | python3 = import('python').find_installation('python3') |
| 57 | |
| 58 | check_headers = [ |
| 59 | ['unistd.h'], |
| 60 | ['sys/mman.h'], |
| 61 | ['xlocale.h'], |
| 62 | ['stdbool.h'], |
| 63 | ] |
| 64 | |
| 65 | check_funcs = [ |
| 66 | ['atexit'], |
| 67 | ['mprotect'], |
| 68 | ['sysconf'], |
| 69 | ['getpagesize'], |
| 70 | ['mmap'], |
| 71 | ['isatty'], |
| 72 | ['newlocale'], |
| 73 | ['strtod_l'], |
Ebrahim Byagowi | 1c3f80b | 2020-03-11 19:29:47 +0330 | [diff] [blame] | 74 | ['roundf'], |
Mathieu Duponchelle | 920efc0 | 2018-05-17 01:28:53 +0200 | [diff] [blame] | 75 | ] |
| 76 | |
Chun-wei Fan | 733414b | 2020-03-13 16:15:21 +0800 | [diff] [blame] | 77 | freetype_dep = dependency('freetype2', required: false) |
| 78 | |
| 79 | if not freetype_dep.found() and cpp.get_id() == 'msvc' |
| 80 | if cpp.has_header('ft2build.h') |
| 81 | freetype_dep = cpp.find_library('freetype', required: false) |
| 82 | endif |
| 83 | endif |
| 84 | |
| 85 | if not freetype_dep.found() and get_option('freetype').enabled() |
| 86 | freetype_dep = dependency('freetype2', fallback: ['freetype2', 'freetype_dep']) |
| 87 | endif |
| 88 | |
Tim-Philipp Müller | 49ba211 | 2018-11-12 15:36:27 +0000 | [diff] [blame] | 89 | glib_dep = dependency('glib-2.0', required: get_option('glib'), |
Nirbheek Chauhan | f65def4 | 2018-10-12 19:41:49 +0530 | [diff] [blame] | 90 | fallback: ['glib', 'libglib_dep']) |
Tim-Philipp Müller | 49ba211 | 2018-11-12 15:36:27 +0000 | [diff] [blame] | 91 | gobject_dep = dependency('gobject-2.0', required: get_option('gobject'), |
Nirbheek Chauhan | f65def4 | 2018-10-12 19:41:49 +0530 | [diff] [blame] | 92 | fallback: ['glib', 'libgobject_dep']) |
Tim-Philipp Müller | 49ba211 | 2018-11-12 15:36:27 +0000 | [diff] [blame] | 93 | cairo_dep = dependency('cairo', required: get_option('cairo'), |
Nirbheek Chauhan | f65def4 | 2018-10-12 19:41:49 +0530 | [diff] [blame] | 94 | fallback: ['cairo', 'libcairo_dep']) |
Tim-Philipp Müller | 49ba211 | 2018-11-12 15:36:27 +0000 | [diff] [blame] | 95 | fontconfig_dep = dependency('fontconfig', required: get_option('fontconfig'), |
Nirbheek Chauhan | f65def4 | 2018-10-12 19:41:49 +0530 | [diff] [blame] | 96 | fallback: ['fontconfig', 'fontconfig_dep']) |
Tim-Philipp Müller | 49ba211 | 2018-11-12 15:36:27 +0000 | [diff] [blame] | 97 | graphite2_dep = dependency('graphite2', required: get_option('graphite')) |
| 98 | icu_dep = dependency('icu-uc', required: get_option('icu')) |
Mathieu Duponchelle | fce88f9 | 2018-05-17 16:20:10 +0200 | [diff] [blame] | 99 | m_dep = cpp.find_library('m', required: false) |
Mathieu Duponchelle | 920efc0 | 2018-05-17 01:28:53 +0200 | [diff] [blame] | 100 | |
Nirbheek Chauhan | f65def4 | 2018-10-12 19:41:49 +0530 | [diff] [blame] | 101 | # Ensure that cairo-ft is fetched from the same library as cairo itself |
| 102 | if cairo_dep.found() |
| 103 | if cairo_dep.type_name() == 'pkgconfig' |
Tim-Philipp Müller | 49ba211 | 2018-11-12 15:36:27 +0000 | [diff] [blame] | 104 | cairo_ft_dep = dependency('cairo-ft', required: get_option('cairo')) |
Nirbheek Chauhan | f65def4 | 2018-10-12 19:41:49 +0530 | [diff] [blame] | 105 | else |
| 106 | cairo_ft_dep = cairo_dep |
| 107 | endif |
| 108 | else |
| 109 | # Not-found dependency |
| 110 | cairo_ft_dep = dependency('', required: false) |
| 111 | endif |
| 112 | |
Mathieu Duponchelle | fce88f9 | 2018-05-17 16:20:10 +0200 | [diff] [blame] | 113 | deps = [] |
Mathieu Duponchelle | 920efc0 | 2018-05-17 01:28:53 +0200 | [diff] [blame] | 114 | |
| 115 | conf = configuration_data() |
Tim-Philipp Müller | 618584e | 2018-11-14 20:19:36 +0000 | [diff] [blame] | 116 | incconfig = include_directories('.') |
Mathieu Duponchelle | 920efc0 | 2018-05-17 01:28:53 +0200 | [diff] [blame] | 117 | cpp_args = ['-DHAVE_CONFIG_H'] |
| 118 | |
| 119 | warn_cflags = [ |
| 120 | '-Wno-non-virtual-dtor', |
| 121 | ] |
| 122 | |
| 123 | cpp_args += cpp.get_supported_arguments(warn_cflags) |
| 124 | |
Mathieu Duponchelle | fce88f9 | 2018-05-17 16:20:10 +0200 | [diff] [blame] | 125 | if m_dep.found() |
| 126 | deps += [m_dep] |
| 127 | endif |
| 128 | |
Mathieu Duponchelle | 920efc0 | 2018-05-17 01:28:53 +0200 | [diff] [blame] | 129 | if glib_dep.found() |
| 130 | conf.set('HAVE_GLIB', 1) |
| 131 | deps += [glib_dep] |
| 132 | endif |
| 133 | |
| 134 | if gobject_dep.found() |
| 135 | conf.set('HAVE_GOBJECT', 1) |
| 136 | deps += [gobject_dep] |
| 137 | endif |
| 138 | |
| 139 | if cairo_dep.found() |
| 140 | conf.set('HAVE_CAIRO', 1) |
| 141 | deps += [cairo_dep] |
| 142 | endif |
| 143 | |
| 144 | if cairo_ft_dep.found() |
| 145 | conf.set('HAVE_CAIRO_FT', 1) |
| 146 | deps += [cairo_ft_dep] |
| 147 | endif |
| 148 | |
| 149 | if graphite2_dep.found() |
| 150 | conf.set('HAVE_GRAPHITE2', 1) |
| 151 | deps += [graphite2_dep] |
| 152 | endif |
| 153 | |
| 154 | if icu_dep.found() |
| 155 | conf.set('HAVE_ICU', 1) |
| 156 | conf.set('HAVE_ICU_BUILTIN', 1) |
| 157 | deps += [icu_dep] |
| 158 | endif |
| 159 | |
| 160 | if freetype_dep.found() |
| 161 | conf.set('HAVE_FREETYPE', 1) |
| 162 | deps += [freetype_dep] |
Mathieu Duponchelle | 04bcdb9 | 2018-06-05 20:59:29 +0200 | [diff] [blame] | 163 | check_freetype_funcs = [ |
| 164 | ['FT_Get_Var_Blend_Coordinates', {'deps': freetype_dep}], |
| 165 | ['FT_Set_Var_Blend_Coordinates', {'deps': freetype_dep}], |
| 166 | ['FT_Done_MM_Var', {'deps': freetype_dep}], |
| 167 | ] |
Mathieu Duponchelle | 920efc0 | 2018-05-17 01:28:53 +0200 | [diff] [blame] | 168 | |
| 169 | if freetype_dep.type_name() == 'internal' |
| 170 | foreach func: check_freetype_funcs |
| 171 | name = func[0] |
| 172 | conf.set('HAVE_@0@'.format(name.to_upper()), 1) |
| 173 | endforeach |
| 174 | else |
| 175 | check_funcs += check_freetype_funcs |
| 176 | endif |
| 177 | endif |
| 178 | |
| 179 | if fontconfig_dep.found() |
| 180 | conf.set('HAVE_FONTCONFIG', 1) |
| 181 | deps += [fontconfig_dep] |
| 182 | endif |
| 183 | |
Chun-wei Fan | 7baa8e0 | 2020-03-13 16:21:25 +0800 | [diff] [blame^] | 184 | # uniscribe (windows) |
Tim-Philipp Müller | b7796a5 | 2018-11-12 16:56:56 +0000 | [diff] [blame] | 185 | if host_machine.system() == 'windows' and not get_option('uniscribe').disabled() |
| 186 | # TODO: make nicer once we have https://github.com/mesonbuild/meson/issues/3940 |
| 187 | if cpp.has_header('usp10.h') and cpp.has_header('windows.h') |
| 188 | foreach usplib : ['usp10', 'gdi32', 'rpcrt4'] |
| 189 | deps += [cpp.find_library(usplib, required: true)] |
| 190 | endforeach |
| 191 | conf.set('HAVE_UNISCRIBE', 1) |
| 192 | elif get_option('uniscribe').enabled() |
| 193 | error('uniscribe was enabled explicitly, but some required headers are missing.') |
| 194 | endif |
| 195 | endif |
| 196 | |
Chun-wei Fan | 7baa8e0 | 2020-03-13 16:21:25 +0800 | [diff] [blame^] | 197 | # DirectWrite (windows) |
Tim-Philipp Müller | 83ebbe4 | 2018-11-12 16:56:56 +0000 | [diff] [blame] | 198 | if host_machine.system() == 'windows' and not get_option('directwrite').disabled() |
Chun-wei Fan | 7baa8e0 | 2020-03-13 16:21:25 +0800 | [diff] [blame^] | 199 | if cpp.has_header('dwrite_1.h') |
Tim-Philipp Müller | 83ebbe4 | 2018-11-12 16:56:56 +0000 | [diff] [blame] | 200 | deps += [cpp.find_library('dwrite', required: true)] |
| 201 | conf.set('HAVE_DIRECTWRITE', 1) |
| 202 | elif get_option('directwrite').enabled() |
| 203 | error('DirectWrite was enabled explicitly, but required header is missing.') |
| 204 | endif |
| 205 | endif |
| 206 | |
Tim-Philipp Müller | 4840c82 | 2018-11-12 16:56:56 +0000 | [diff] [blame] | 207 | # CoreText (macOS) - FIXME: untested |
| 208 | if host_machine.system() == 'darwin' and not get_option('coretext').disabled() |
| 209 | app_services_dep = dependency('appleframeworks', modules : ['ApplicationServices'], required: false) |
| 210 | if cpp.has_type('CTFontRef', prefix: '#include <ApplicationServices/ApplicationServices.h>', dependencies: app_services_dep) |
| 211 | deps += [app_services_dep] |
| 212 | conf.set('HAVE_CORETEXT', 1) |
| 213 | # On iOS CoreText and CoreGraphics are stand-alone frameworks |
| 214 | # Check for a different symbol to avoid getting cached result |
| 215 | else |
| 216 | coretext_dep = dependency('appleframeworks', modules : ['CoreText'], required: false) |
| 217 | coregraphics_dep = dependency('appleframeworks', modules : ['CoreGraphics'], required: false) |
| 218 | corefoundation_dep = dependency('appleframeworks', modules : ['CoreFoundation'], required: false) |
| 219 | if cpp.has_type('CTRunRef', prefix: '#include <CoreText/CoreText.h>', dependencies: [coretext_dep, coregraphics_dep, corefoundation_dep]) |
| 220 | deps += [coretext_dep, coregraphics_dep, corefoundation_dep] |
| 221 | conf.set('HAVE_CORETEXT', 1) |
| 222 | elif get_option('coretext').enabled() |
| 223 | error('CoreText was enabled explicitly, but required headers or frameworks are missing.') |
| 224 | endif |
| 225 | endif |
| 226 | endif |
| 227 | |
Tim-Philipp Müller | b7796a5 | 2018-11-12 16:56:56 +0000 | [diff] [blame] | 228 | # threads |
Mathieu Duponchelle | 920efc0 | 2018-05-17 01:28:53 +0200 | [diff] [blame] | 229 | if host_machine.system() != 'windows' |
| 230 | thread_dep = dependency('threads', required: false) |
| 231 | |
| 232 | if thread_dep.found() |
| 233 | conf.set('HAVE_PTHREAD', 1) |
| 234 | deps += [thread_dep] |
| 235 | else |
| 236 | check_headers += ['sched.h'] |
| 237 | check_funcs += ['sched_yield', {'link_with': 'rt'}] |
| 238 | endif |
| 239 | endif |
| 240 | |
Mathieu Duponchelle | 04bcdb9 | 2018-06-05 20:59:29 +0200 | [diff] [blame] | 241 | conf.set('HAVE_OT', 1) |
| 242 | conf.set('HAVE_FALLBACK', 1) |
Mathieu Duponchelle | 920efc0 | 2018-05-17 01:28:53 +0200 | [diff] [blame] | 243 | conf.set_quoted('PACKAGE_NAME', 'HarfBuzz') |
| 244 | conf.set_quoted('PACKAGE_VERSION', meson.project_version()) |
| 245 | |
| 246 | foreach check : check_headers |
| 247 | name = check[0] |
| 248 | |
| 249 | if cpp.has_header(name) |
| 250 | conf.set('HAVE_@0@'.format(name.to_upper().underscorify()), 1) |
| 251 | endif |
| 252 | endforeach |
| 253 | |
| 254 | foreach check : check_funcs |
| 255 | name = check[0] |
Mathieu Duponchelle | 04bcdb9 | 2018-06-05 20:59:29 +0200 | [diff] [blame] | 256 | opts = check.get(1, {}) |
Mathieu Duponchelle | 920efc0 | 2018-05-17 01:28:53 +0200 | [diff] [blame] | 257 | link_withs = opts.get('link_with', []) |
Mathieu Duponchelle | 04bcdb9 | 2018-06-05 20:59:29 +0200 | [diff] [blame] | 258 | check_deps = opts.get('deps', []) |
Mathieu Duponchelle | 920efc0 | 2018-05-17 01:28:53 +0200 | [diff] [blame] | 259 | extra_deps = [] |
| 260 | found = true |
| 261 | |
| 262 | # First try without linking |
| 263 | |
Mathieu Duponchelle | 04bcdb9 | 2018-06-05 20:59:29 +0200 | [diff] [blame] | 264 | found = cpp.has_function(name, dependencies: check_deps) |
Mathieu Duponchelle | 920efc0 | 2018-05-17 01:28:53 +0200 | [diff] [blame] | 265 | |
| 266 | if not found and link_withs.length() > 0 |
| 267 | found = true |
| 268 | |
| 269 | foreach link_with : link_withs |
| 270 | dep = cpp.find_library(link_with, required: false) |
| 271 | if dep.found() |
| 272 | extra_deps += dep |
| 273 | else |
| 274 | found = false |
| 275 | endif |
| 276 | endforeach |
| 277 | |
| 278 | if found |
Mathieu Duponchelle | 04bcdb9 | 2018-06-05 20:59:29 +0200 | [diff] [blame] | 279 | found = cpp.has_function(name, dependencies: check_deps + extra_deps) |
Mathieu Duponchelle | 920efc0 | 2018-05-17 01:28:53 +0200 | [diff] [blame] | 280 | endif |
| 281 | endif |
| 282 | |
| 283 | if found |
| 284 | deps += extra_deps |
| 285 | conf.set('HAVE_@0@'.format(name.to_upper()), 1) |
| 286 | endif |
| 287 | endforeach |
| 288 | |
Mathieu Duponchelle | 920efc0 | 2018-05-17 01:28:53 +0200 | [diff] [blame] | 289 | if cpp.links(files('meson-cc-tests/intel-atomic-primitives-test.c'), name: 'Intel atomics') |
| 290 | conf.set('HAVE_INTEL_ATOMIC_PRIMITIVES', 1) |
| 291 | endif |
| 292 | |
| 293 | if cpp.links(files('meson-cc-tests/solaris-atomic-operations.c'), name: 'Solaris atomic ops') |
| 294 | conf.set('HAVE_SOLARIS_ATOMIC_OPS', 1) |
| 295 | endif |
| 296 | |
| 297 | subdir('src') |
| 298 | subdir('util') |
Tim-Philipp Müller | 6147df3 | 2018-11-14 10:12:40 +0000 | [diff] [blame] | 299 | |
| 300 | if not get_option('tests').disabled() |
| 301 | subdir('test') |
| 302 | endif |
Mathieu Duponchelle | 920efc0 | 2018-05-17 01:28:53 +0200 | [diff] [blame] | 303 | |
| 304 | configure_file(output: 'config.h', configuration: conf) |