blob: fc4c16f6e7b883f9a0481b7ddd965f10baf0fc1d [file] [log] [blame]
Mathieu Duponchelle920efc02018-05-17 01:28:53 +02001project('harfbuzz', 'c', 'cpp',
Ebrahim Byagowif7562672020-05-21 17:01:04 +04302 meson_version: '>= 0.53.0',
Ebrahim Byagowi31218b42020-03-11 22:27:32 +03303 default_options : ['cpp_std=c++11'],
Ebrahim Byagowi42025682020-05-12 00:14:33 +04304 version: '2.6.6')
Mathieu Duponchelle920efc02018-05-17 01:28:53 +02005
Ebrahim Byagowi466dbaa2020-03-24 19:52:43 +04306warning('Meson is not our main build system yet, don\'t use it for packaging HarfBuzz for *nix distros for now')
7
Tim-Philipp Müller535186f2018-12-03 20:51:06 +01008hb_version_arr = meson.project_version().split('.')
9hb_version_major = hb_version_arr[0].to_int()
10hb_version_minor = hb_version_arr[1].to_int()
11hb_version_micro = hb_version_arr[2].to_int()
12
13# libtool versioning
14hb_version_int = hb_version_major*10000 + hb_version_minor*100 + hb_version_micro
15if hb_version_minor % 2 == 1
16 hb_libtool_revision = 0 # for unstable releases
17else
18 hb_libtool_revision = hb_version_micro # for stable releases
19endif
20hb_libtool_age = hb_version_int - hb_libtool_revision
21hb_libtool_current = hb_libtool_age
22hb_libtool_version_info = '@0@:@1@:@2@'.format(hb_libtool_current, hb_libtool_revision, hb_libtool_age)
23
Mathieu Duponchelle484313f2018-06-05 02:15:43 +020024pkgmod = import('pkgconfig')
Mathieu Duponchelle920efc02018-05-17 01:28:53 +020025cpp = meson.get_compiler('cpp')
26
Tim-Philipp Müller4a47f1a2018-12-01 11:05:27 +000027if cpp.get_id() == 'msvc'
28 # Ignore several spurious warnings for things HarfBuzz does very commonly.
29 # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it
30 # If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once
31 # NOTE: Only add warnings here if you are sure they're spurious
32 msvc_args = [
33 '/wd4018', # implicit signed/unsigned conversion
34 '/wd4146', # unary minus on unsigned (beware INT_MIN)
35 '/wd4244', # lossy type conversion (e.g. double -> int)
36 '/wd4305', # truncating type conversion (e.g. double -> float)
37 cpp.get_supported_arguments(['/utf-8']), # set the input encoding to utf-8
38 ]
Tim-Philipp Müllerbb8aaa32020-03-14 01:05:38 +000039 add_project_arguments(msvc_args, language : ['c', 'cpp'])
Tim-Philipp Müller4a47f1a2018-12-01 11:05:27 +000040 # Disable SAFESEH with MSVC for libs that use external deps that are built with MinGW
41 # noseh_link_args = ['/SAFESEH:NO']
42endif
43
Tim-Philipp Müllerbb8aaa32020-03-14 01:05:38 +000044add_project_arguments(cpp.get_supported_arguments([
Ebrahim Byagowi365d2d32020-03-11 20:16:36 +033045 '-fno-rtti',
46 '-fno-exceptions',
47 '-fno-threadsafe-statics',
48 '-fvisibility-inlines-hidden', # maybe shouldn't be applied for mingw
49]), language : 'cpp')
50
51if host_machine.cpu_family() == 'arm' and cpp.alignment('struct { char c; }') != 1
52 if cpp.has_argument('-mstructure-size-boundary=8')
Tim-Philipp Müllerbb8aaa32020-03-14 01:05:38 +000053 add_project_arguments('-mstructure-size-boundary=8', language : 'cpp')
Ebrahim Byagowi365d2d32020-03-11 20:16:36 +033054 endif
55endif
56
Mathieu Duponchelle920efc02018-05-17 01:28:53 +020057python3 = import('python').find_installation('python3')
58
59check_headers = [
60 ['unistd.h'],
61 ['sys/mman.h'],
Mathieu Duponchelle920efc02018-05-17 01:28:53 +020062 ['stdbool.h'],
63]
64
65check_funcs = [
66 ['atexit'],
67 ['mprotect'],
68 ['sysconf'],
69 ['getpagesize'],
70 ['mmap'],
71 ['isatty'],
Ebrahim Byagowi1c3f80b2020-03-11 19:29:47 +033072 ['roundf'],
Mathieu Duponchelle920efc02018-05-17 01:28:53 +020073]
74
Chun-wei Fan733414b2020-03-13 16:15:21 +080075freetype_dep = dependency('freetype2', required: false)
76
77if not freetype_dep.found() and cpp.get_id() == 'msvc'
78 if cpp.has_header('ft2build.h')
79 freetype_dep = cpp.find_library('freetype', required: false)
80 endif
81endif
82
83if not freetype_dep.found() and get_option('freetype').enabled()
84 freetype_dep = dependency('freetype2', fallback: ['freetype2', 'freetype_dep'])
85endif
86
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000087glib_dep = dependency('glib-2.0', required: get_option('glib'),
Nirbheek Chauhanf65def42018-10-12 19:41:49 +053088 fallback: ['glib', 'libglib_dep'])
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000089gobject_dep = dependency('gobject-2.0', required: get_option('gobject'),
Nirbheek Chauhanf65def42018-10-12 19:41:49 +053090 fallback: ['glib', 'libgobject_dep'])
Chun-wei Fan9d0e6ae2020-03-13 16:56:55 +080091cairo_dep = dependency('cairo', required: false)
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000092fontconfig_dep = dependency('fontconfig', required: get_option('fontconfig'),
Nirbheek Chauhanf65def42018-10-12 19:41:49 +053093 fallback: ['fontconfig', 'fontconfig_dep'])
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000094graphite2_dep = dependency('graphite2', required: get_option('graphite'))
Christoph Reiter8ae06c92020-04-18 20:22:45 +020095icu_dep = dependency('icu-uc', required: false)
Mathieu Duponchellefce88f92018-05-17 16:20:10 +020096m_dep = cpp.find_library('m', required: false)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +020097
Christoph Reiter8ae06c92020-04-18 20:22:45 +020098if not icu_dep.found() and get_option('icu').enabled()
99 icu_dep = dependency('icu-uc', required: cpp.get_id() != 'msvc')
100endif
101
Chun-wei Fan5efce602020-03-13 16:40:20 +0800102if not icu_dep.found() and cpp.get_id() == 'msvc'
103 if cpp.has_header('unicode/uchar.h') and \
104 cpp.has_header('unicode/unorm2.h') and \
105 cpp.has_header('unicode/ustring.h') and \
106 cpp.has_header('unicode/utf16.h') and \
107 cpp.has_header('unicode/uversion.h') and \
108 cpp.has_header('unicode/uscript.h')
109 if get_option('buildtype') == 'debug'
110 icu_dep = cpp.find_library('icuucd', required: get_option('icu'))
111 else
112 icu_dep = cpp.find_library('icuuc', required: get_option('icu'))
113 endif
114 else
115 if get_option('icu').enabled()
116 error('ICU headers and libraries must be present to build ICU support')
117 endif
118 endif
119endif
120
Chun-wei Fan9d0e6ae2020-03-13 16:56:55 +0800121if not cairo_dep.found() and cpp.get_id() == 'msvc'
122 if cpp.has_header('cairo.h')
123 cairo_dep = cpp.find_library('cairo')
124 endif
125endif
126
127if not cairo_dep.found() and get_option('cairo').enabled()
128 cairo_dep = dependency('cairo', fallback: ['cairo', 'libcairo_dep'])
129endif
130
Nirbheek Chauhanf65def42018-10-12 19:41:49 +0530131# Ensure that cairo-ft is fetched from the same library as cairo itself
132if cairo_dep.found()
133 if cairo_dep.type_name() == 'pkgconfig'
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +0000134 cairo_ft_dep = dependency('cairo-ft', required: get_option('cairo'))
Nirbheek Chauhanf65def42018-10-12 19:41:49 +0530135 else
Chun-wei Fan9d0e6ae2020-03-13 16:56:55 +0800136 if cpp.has_header('cairo-ft.h') and \
137 cpp.has_function('cairo_ft_font_face_create_for_ft_face', dependencies: cairo_dep)
138 cairo_ft_dep = cairo_dep
139 endif
Nirbheek Chauhanf65def42018-10-12 19:41:49 +0530140 endif
141else
142 # Not-found dependency
143 cairo_ft_dep = dependency('', required: false)
144endif
145
Mathieu Duponchellefce88f92018-05-17 16:20:10 +0200146deps = []
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200147
148conf = configuration_data()
Tim-Philipp Müller618584e2018-11-14 20:19:36 +0000149incconfig = include_directories('.')
Tim-Philipp Müllera3892be2020-03-14 01:08:15 +0000150
151add_project_arguments('-DHAVE_CONFIG_H', language: ['c', 'cpp'])
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200152
153warn_cflags = [
154 '-Wno-non-virtual-dtor',
155]
156
Tim-Philipp Müllera3892be2020-03-14 01:08:15 +0000157cpp_args = cpp.get_supported_arguments(warn_cflags)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200158
Mathieu Duponchellefce88f92018-05-17 16:20:10 +0200159if m_dep.found()
160 deps += [m_dep]
161endif
162
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200163if glib_dep.found()
164 conf.set('HAVE_GLIB', 1)
165 deps += [glib_dep]
166endif
167
168if gobject_dep.found()
169 conf.set('HAVE_GOBJECT', 1)
170 deps += [gobject_dep]
171endif
172
173if cairo_dep.found()
174 conf.set('HAVE_CAIRO', 1)
175 deps += [cairo_dep]
176endif
177
178if cairo_ft_dep.found()
179 conf.set('HAVE_CAIRO_FT', 1)
180 deps += [cairo_ft_dep]
181endif
182
183if graphite2_dep.found()
184 conf.set('HAVE_GRAPHITE2', 1)
185 deps += [graphite2_dep]
186endif
187
188if icu_dep.found()
189 conf.set('HAVE_ICU', 1)
Ebrahim Byagowic6b3f732020-04-19 00:54:24 +0430190endif
191
192if get_option('icu-builtin')
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200193 conf.set('HAVE_ICU_BUILTIN', 1)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200194endif
195
Ebrahim Byagowi750bb732020-04-21 01:13:13 +0430196if get_option('experimental-api')
197 conf.set('HB_EXPERIMENTAL_API', 1)
198endif
199
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200200if freetype_dep.found()
201 conf.set('HAVE_FREETYPE', 1)
202 deps += [freetype_dep]
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200203 check_freetype_funcs = [
204 ['FT_Get_Var_Blend_Coordinates', {'deps': freetype_dep}],
205 ['FT_Set_Var_Blend_Coordinates', {'deps': freetype_dep}],
206 ['FT_Done_MM_Var', {'deps': freetype_dep}],
207 ]
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200208
209 if freetype_dep.type_name() == 'internal'
210 foreach func: check_freetype_funcs
211 name = func[0]
212 conf.set('HAVE_@0@'.format(name.to_upper()), 1)
213 endforeach
214 else
215 check_funcs += check_freetype_funcs
216 endif
217endif
218
219if fontconfig_dep.found()
220 conf.set('HAVE_FONTCONFIG', 1)
221 deps += [fontconfig_dep]
222endif
223
Chun-wei Fan838346c2020-03-13 18:01:17 +0800224# GDI (uniscribe) (windows)
225if host_machine.system() == 'windows' and not get_option('gdi').disabled()
Tim-Philipp Müllerb7796a52018-11-12 16:56:56 +0000226 # TODO: make nicer once we have https://github.com/mesonbuild/meson/issues/3940
227 if cpp.has_header('usp10.h') and cpp.has_header('windows.h')
228 foreach usplib : ['usp10', 'gdi32', 'rpcrt4']
229 deps += [cpp.find_library(usplib, required: true)]
230 endforeach
231 conf.set('HAVE_UNISCRIBE', 1)
Chun-wei Fan838346c2020-03-13 18:01:17 +0800232 conf.set('HAVE_GDI', 1)
233 elif get_option('gdi').enabled()
234 error('gdi was enabled explicitly, but some required headers are missing.')
Tim-Philipp Müllerb7796a52018-11-12 16:56:56 +0000235 endif
236endif
237
Chun-wei Fan7baa8e02020-03-13 16:21:25 +0800238# DirectWrite (windows)
Tim-Philipp Müller83ebbe42018-11-12 16:56:56 +0000239if host_machine.system() == 'windows' and not get_option('directwrite').disabled()
Chun-wei Fan7baa8e02020-03-13 16:21:25 +0800240 if cpp.has_header('dwrite_1.h')
Tim-Philipp Müller83ebbe42018-11-12 16:56:56 +0000241 deps += [cpp.find_library('dwrite', required: true)]
242 conf.set('HAVE_DIRECTWRITE', 1)
243 elif get_option('directwrite').enabled()
244 error('DirectWrite was enabled explicitly, but required header is missing.')
245 endif
246endif
247
Tim-Philipp Müller4840c822018-11-12 16:56:56 +0000248# CoreText (macOS) - FIXME: untested
249if host_machine.system() == 'darwin' and not get_option('coretext').disabled()
250 app_services_dep = dependency('appleframeworks', modules : ['ApplicationServices'], required: false)
251 if cpp.has_type('CTFontRef', prefix: '#include <ApplicationServices/ApplicationServices.h>', dependencies: app_services_dep)
252 deps += [app_services_dep]
253 conf.set('HAVE_CORETEXT', 1)
254 # On iOS CoreText and CoreGraphics are stand-alone frameworks
255 # Check for a different symbol to avoid getting cached result
256 else
257 coretext_dep = dependency('appleframeworks', modules : ['CoreText'], required: false)
258 coregraphics_dep = dependency('appleframeworks', modules : ['CoreGraphics'], required: false)
259 corefoundation_dep = dependency('appleframeworks', modules : ['CoreFoundation'], required: false)
260 if cpp.has_type('CTRunRef', prefix: '#include <CoreText/CoreText.h>', dependencies: [coretext_dep, coregraphics_dep, corefoundation_dep])
261 deps += [coretext_dep, coregraphics_dep, corefoundation_dep]
262 conf.set('HAVE_CORETEXT', 1)
263 elif get_option('coretext').enabled()
264 error('CoreText was enabled explicitly, but required headers or frameworks are missing.')
265 endif
266 endif
267endif
268
Tim-Philipp Müllerb7796a52018-11-12 16:56:56 +0000269# threads
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200270if host_machine.system() != 'windows'
271 thread_dep = dependency('threads', required: false)
272
273 if thread_dep.found()
274 conf.set('HAVE_PTHREAD', 1)
275 deps += [thread_dep]
276 else
277 check_headers += ['sched.h']
278 check_funcs += ['sched_yield', {'link_with': 'rt'}]
279 endif
280endif
281
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200282conf.set('HAVE_OT', 1)
283conf.set('HAVE_FALLBACK', 1)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200284conf.set_quoted('PACKAGE_NAME', 'HarfBuzz')
285conf.set_quoted('PACKAGE_VERSION', meson.project_version())
286
287foreach check : check_headers
288 name = check[0]
289
290 if cpp.has_header(name)
291 conf.set('HAVE_@0@'.format(name.to_upper().underscorify()), 1)
292 endif
293endforeach
294
295foreach check : check_funcs
296 name = check[0]
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200297 opts = check.get(1, {})
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200298 link_withs = opts.get('link_with', [])
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200299 check_deps = opts.get('deps', [])
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200300 extra_deps = []
301 found = true
302
303 # First try without linking
304
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200305 found = cpp.has_function(name, dependencies: check_deps)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200306
307 if not found and link_withs.length() > 0
308 found = true
309
310 foreach link_with : link_withs
311 dep = cpp.find_library(link_with, required: false)
312 if dep.found()
Ebrahim Byagowie8808c12020-03-24 19:15:09 +0430313 extra_deps += dep
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200314 else
Ebrahim Byagowie8808c12020-03-24 19:15:09 +0430315 found = false
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200316 endif
317 endforeach
318
319 if found
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200320 found = cpp.has_function(name, dependencies: check_deps + extra_deps)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200321 endif
322 endif
323
324 if found
325 deps += extra_deps
326 conf.set('HAVE_@0@'.format(name.to_upper()), 1)
327 endif
328endforeach
329
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200330if cpp.links(files('meson-cc-tests/intel-atomic-primitives-test.c'), name: 'Intel atomics')
331 conf.set('HAVE_INTEL_ATOMIC_PRIMITIVES', 1)
332endif
333
334if cpp.links(files('meson-cc-tests/solaris-atomic-operations.c'), name: 'Solaris atomic ops')
335 conf.set('HAVE_SOLARIS_ATOMIC_OPS', 1)
336endif
337
338subdir('src')
339subdir('util')
Tim-Philipp Müller6147df32018-11-14 10:12:40 +0000340
341if not get_option('tests').disabled()
342 subdir('test')
343endif
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200344
Tim-Philipp Müller3dd7b212020-05-17 00:12:08 +0100345if not get_option('gtk_doc').disabled()
346 subdir('docs')
347endif
348
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200349configure_file(output: 'config.h', configuration: conf)
Ebrahim Byagowia9e83282020-05-21 16:28:24 +0430350
351summary({'prefix': get_option('prefix'),
352 'bindir': get_option('bindir'),
353 'libdir': get_option('libdir'),
354 'includedir': get_option('includedir'),
355 'datadir': get_option('datadir'),
356 }, section: 'Directories')
357summary({'Builtin': true,
358 'Glib': conf.get('HAVE_GLIB', 0) == 1,
359 'ICU': conf.get('HAVE_ICU', 0) == 1,
360 }, bool_yn: true, section: 'Unicode callbacks (you want at least one)')
361summary({'FreeType': conf.get('HAVE_FREETYPE', 0) == 1,
362 }, bool_yn: true, section: 'Font callbacks (the more the merrier)')
363summary({'Cairo': conf.get('HAVE_CAIRO', 0) == 1,
364 'Fontconfig': conf.get('HAVE_FONTCONFIG', 0) == 1,
365 }, bool_yn: true, section: 'Tools used for command-line utilities')
366summary({'Graphite2': conf.get('HAVE_GRAPHITE2', 0) == 1,
367 }, bool_yn: true, section: 'Additional shapers (the more the merrier)')
368summary({'CoreText': conf.get('HAVE_CORETEXT', 0) == 1,
369 'DirectWrite': conf.get('HAVE_DIRECTWRITE', 0) == 1,
370 'GDI': conf.get('HAVE_GDI', 0) == 1,
371 'Uniscribe': conf.get('HAVE_UNISCRIBE', 0) == 1,
372 }, bool_yn: true, section: 'Platform shapers (not normally needed)')
373summary({'Documentation': conf.get('HAVE_GTK_DOC', 0) == 1,
374 'GObject bindings': conf.get('HAVE_GOBJECT', 0) == 1,
375 'Introspection': conf.get('HAVE_INTROSPECTION', 0) == 1,
376 }, bool_yn: true, section: 'Other features')