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