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