blob: 65d31924236bdcd2d3197905cdb97dca3a7533bf [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 Byagowifb46a322020-06-03 12:54:26 +04304 version: '2.6.7')
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 +020057check_headers = [
58 ['unistd.h'],
59 ['sys/mman.h'],
Mathieu Duponchelle920efc02018-05-17 01:28:53 +020060 ['stdbool.h'],
61]
62
63check_funcs = [
64 ['atexit'],
65 ['mprotect'],
66 ['sysconf'],
67 ['getpagesize'],
68 ['mmap'],
69 ['isatty'],
Ebrahim Byagowi1c3f80b2020-03-11 19:29:47 +033070 ['roundf'],
Mathieu Duponchelle920efc02018-05-17 01:28:53 +020071]
72
Chun-wei Fan733414b2020-03-13 16:15:21 +080073freetype_dep = dependency('freetype2', required: false)
74
75if not freetype_dep.found() and cpp.get_id() == 'msvc'
76 if cpp.has_header('ft2build.h')
77 freetype_dep = cpp.find_library('freetype', required: false)
78 endif
79endif
80
81if not freetype_dep.found() and get_option('freetype').enabled()
82 freetype_dep = dependency('freetype2', fallback: ['freetype2', 'freetype_dep'])
83endif
84
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000085glib_dep = dependency('glib-2.0', required: get_option('glib'),
Nirbheek Chauhanf65def42018-10-12 19:41:49 +053086 fallback: ['glib', 'libglib_dep'])
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000087gobject_dep = dependency('gobject-2.0', required: get_option('gobject'),
Nirbheek Chauhanf65def42018-10-12 19:41:49 +053088 fallback: ['glib', 'libgobject_dep'])
Chun-wei Fan9d0e6ae2020-03-13 16:56:55 +080089cairo_dep = dependency('cairo', required: false)
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000090fontconfig_dep = dependency('fontconfig', required: get_option('fontconfig'),
Nirbheek Chauhanf65def42018-10-12 19:41:49 +053091 fallback: ['fontconfig', 'fontconfig_dep'])
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000092graphite2_dep = dependency('graphite2', required: get_option('graphite'))
Christoph Reiter8ae06c92020-04-18 20:22:45 +020093icu_dep = dependency('icu-uc', required: false)
Mathieu Duponchellefce88f92018-05-17 16:20:10 +020094m_dep = cpp.find_library('m', required: false)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +020095
Christoph Reiter8ae06c92020-04-18 20:22:45 +020096if not icu_dep.found() and get_option('icu').enabled()
97 icu_dep = dependency('icu-uc', required: cpp.get_id() != 'msvc')
98endif
99
Chun-wei Fan5efce602020-03-13 16:40:20 +0800100if not icu_dep.found() and cpp.get_id() == 'msvc'
101 if cpp.has_header('unicode/uchar.h') and \
102 cpp.has_header('unicode/unorm2.h') and \
103 cpp.has_header('unicode/ustring.h') and \
104 cpp.has_header('unicode/utf16.h') and \
105 cpp.has_header('unicode/uversion.h') and \
106 cpp.has_header('unicode/uscript.h')
107 if get_option('buildtype') == 'debug'
108 icu_dep = cpp.find_library('icuucd', required: get_option('icu'))
109 else
110 icu_dep = cpp.find_library('icuuc', required: get_option('icu'))
111 endif
112 else
113 if get_option('icu').enabled()
114 error('ICU headers and libraries must be present to build ICU support')
115 endif
116 endif
117endif
118
Chun-wei Fan9d0e6ae2020-03-13 16:56:55 +0800119if not cairo_dep.found() and cpp.get_id() == 'msvc'
120 if cpp.has_header('cairo.h')
121 cairo_dep = cpp.find_library('cairo')
122 endif
123endif
124
125if not cairo_dep.found() and get_option('cairo').enabled()
126 cairo_dep = dependency('cairo', fallback: ['cairo', 'libcairo_dep'])
127endif
128
Nirbheek Chauhanf65def42018-10-12 19:41:49 +0530129# Ensure that cairo-ft is fetched from the same library as cairo itself
130if cairo_dep.found()
131 if cairo_dep.type_name() == 'pkgconfig'
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +0000132 cairo_ft_dep = dependency('cairo-ft', required: get_option('cairo'))
Nirbheek Chauhanf65def42018-10-12 19:41:49 +0530133 else
Chun-wei Fan9d0e6ae2020-03-13 16:56:55 +0800134 if cpp.has_header('cairo-ft.h') and \
135 cpp.has_function('cairo_ft_font_face_create_for_ft_face', dependencies: cairo_dep)
136 cairo_ft_dep = cairo_dep
Ebrahim Byagowi6058ede2020-06-01 12:58:31 +0430137 else
138 # Not-found dependency
139 cairo_ft_dep = dependency('', required: false)
Chun-wei Fan9d0e6ae2020-03-13 16:56:55 +0800140 endif
Nirbheek Chauhanf65def42018-10-12 19:41:49 +0530141 endif
142else
143 # Not-found dependency
144 cairo_ft_dep = dependency('', required: false)
145endif
146
Mathieu Duponchellefce88f92018-05-17 16:20:10 +0200147deps = []
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200148
149conf = configuration_data()
Tim-Philipp Müller618584e2018-11-14 20:19:36 +0000150incconfig = include_directories('.')
Tim-Philipp Müllera3892be2020-03-14 01:08:15 +0000151
152add_project_arguments('-DHAVE_CONFIG_H', language: ['c', 'cpp'])
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200153
154warn_cflags = [
155 '-Wno-non-virtual-dtor',
156]
157
Tim-Philipp Müllera3892be2020-03-14 01:08:15 +0000158cpp_args = cpp.get_supported_arguments(warn_cflags)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200159
Mathieu Duponchellefce88f92018-05-17 16:20:10 +0200160if m_dep.found()
161 deps += [m_dep]
162endif
163
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200164if glib_dep.found()
165 conf.set('HAVE_GLIB', 1)
166 deps += [glib_dep]
167endif
168
169if gobject_dep.found()
170 conf.set('HAVE_GOBJECT', 1)
171 deps += [gobject_dep]
172endif
173
174if cairo_dep.found()
175 conf.set('HAVE_CAIRO', 1)
176 deps += [cairo_dep]
177endif
178
179if cairo_ft_dep.found()
180 conf.set('HAVE_CAIRO_FT', 1)
181 deps += [cairo_ft_dep]
182endif
183
184if graphite2_dep.found()
185 conf.set('HAVE_GRAPHITE2', 1)
186 deps += [graphite2_dep]
187endif
188
189if icu_dep.found()
190 conf.set('HAVE_ICU', 1)
Ebrahim Byagowic6b3f732020-04-19 00:54:24 +0430191endif
192
Ebrahim Byagowicc53fd12020-05-21 19:33:18 +0430193if get_option('icu_builtin')
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200194 conf.set('HAVE_ICU_BUILTIN', 1)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200195endif
196
Ebrahim Byagowicc53fd12020-05-21 19:33:18 +0430197if get_option('experimental_api')
Ebrahim Byagowi750bb732020-04-21 01:13:13 +0430198 conf.set('HB_EXPERIMENTAL_API', 1)
199endif
200
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200201if freetype_dep.found()
202 conf.set('HAVE_FREETYPE', 1)
203 deps += [freetype_dep]
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200204 check_freetype_funcs = [
205 ['FT_Get_Var_Blend_Coordinates', {'deps': freetype_dep}],
206 ['FT_Set_Var_Blend_Coordinates', {'deps': freetype_dep}],
207 ['FT_Done_MM_Var', {'deps': freetype_dep}],
208 ]
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200209
210 if freetype_dep.type_name() == 'internal'
211 foreach func: check_freetype_funcs
212 name = func[0]
213 conf.set('HAVE_@0@'.format(name.to_upper()), 1)
214 endforeach
215 else
216 check_funcs += check_freetype_funcs
217 endif
218endif
219
220if fontconfig_dep.found()
221 conf.set('HAVE_FONTCONFIG', 1)
222 deps += [fontconfig_dep]
223endif
224
Chun-wei Fan838346c2020-03-13 18:01:17 +0800225# GDI (uniscribe) (windows)
226if host_machine.system() == 'windows' and not get_option('gdi').disabled()
Tim-Philipp Müllerb7796a52018-11-12 16:56:56 +0000227 # TODO: make nicer once we have https://github.com/mesonbuild/meson/issues/3940
228 if cpp.has_header('usp10.h') and cpp.has_header('windows.h')
229 foreach usplib : ['usp10', 'gdi32', 'rpcrt4']
230 deps += [cpp.find_library(usplib, required: true)]
231 endforeach
232 conf.set('HAVE_UNISCRIBE', 1)
Chun-wei Fan838346c2020-03-13 18:01:17 +0800233 conf.set('HAVE_GDI', 1)
234 elif get_option('gdi').enabled()
235 error('gdi was enabled explicitly, but some required headers are missing.')
Tim-Philipp Müllerb7796a52018-11-12 16:56:56 +0000236 endif
237endif
238
Chun-wei Fan7baa8e02020-03-13 16:21:25 +0800239# DirectWrite (windows)
Tim-Philipp Müller83ebbe42018-11-12 16:56:56 +0000240if host_machine.system() == 'windows' and not get_option('directwrite').disabled()
Chun-wei Fan7baa8e02020-03-13 16:21:25 +0800241 if cpp.has_header('dwrite_1.h')
Tim-Philipp Müller83ebbe42018-11-12 16:56:56 +0000242 deps += [cpp.find_library('dwrite', required: true)]
243 conf.set('HAVE_DIRECTWRITE', 1)
244 elif get_option('directwrite').enabled()
245 error('DirectWrite was enabled explicitly, but required header is missing.')
246 endif
247endif
248
Tim-Philipp Müller4840c822018-11-12 16:56:56 +0000249# CoreText (macOS) - FIXME: untested
250if host_machine.system() == 'darwin' and not get_option('coretext').disabled()
251 app_services_dep = dependency('appleframeworks', modules : ['ApplicationServices'], required: false)
252 if cpp.has_type('CTFontRef', prefix: '#include <ApplicationServices/ApplicationServices.h>', dependencies: app_services_dep)
253 deps += [app_services_dep]
254 conf.set('HAVE_CORETEXT', 1)
255 # On iOS CoreText and CoreGraphics are stand-alone frameworks
256 # Check for a different symbol to avoid getting cached result
257 else
258 coretext_dep = dependency('appleframeworks', modules : ['CoreText'], required: false)
259 coregraphics_dep = dependency('appleframeworks', modules : ['CoreGraphics'], required: false)
260 corefoundation_dep = dependency('appleframeworks', modules : ['CoreFoundation'], required: false)
261 if cpp.has_type('CTRunRef', prefix: '#include <CoreText/CoreText.h>', dependencies: [coretext_dep, coregraphics_dep, corefoundation_dep])
262 deps += [coretext_dep, coregraphics_dep, corefoundation_dep]
263 conf.set('HAVE_CORETEXT', 1)
264 elif get_option('coretext').enabled()
265 error('CoreText was enabled explicitly, but required headers or frameworks are missing.')
266 endif
267 endif
268endif
269
Tim-Philipp Müllerb7796a52018-11-12 16:56:56 +0000270# threads
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200271if host_machine.system() != 'windows'
272 thread_dep = dependency('threads', required: false)
273
274 if thread_dep.found()
275 conf.set('HAVE_PTHREAD', 1)
276 deps += [thread_dep]
277 else
278 check_headers += ['sched.h']
279 check_funcs += ['sched_yield', {'link_with': 'rt'}]
280 endif
281endif
282
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200283conf.set('HAVE_OT', 1)
284conf.set('HAVE_FALLBACK', 1)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200285conf.set_quoted('PACKAGE_NAME', 'HarfBuzz')
286conf.set_quoted('PACKAGE_VERSION', meson.project_version())
287
288foreach check : check_headers
289 name = check[0]
290
291 if cpp.has_header(name)
292 conf.set('HAVE_@0@'.format(name.to_upper().underscorify()), 1)
293 endif
294endforeach
295
296foreach check : check_funcs
297 name = check[0]
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200298 opts = check.get(1, {})
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200299 link_withs = opts.get('link_with', [])
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200300 check_deps = opts.get('deps', [])
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200301 extra_deps = []
302 found = true
303
304 # First try without linking
305
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200306 found = cpp.has_function(name, dependencies: check_deps)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200307
308 if not found and link_withs.length() > 0
309 found = true
310
311 foreach link_with : link_withs
312 dep = cpp.find_library(link_with, required: false)
313 if dep.found()
Ebrahim Byagowie8808c12020-03-24 19:15:09 +0430314 extra_deps += dep
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200315 else
Ebrahim Byagowie8808c12020-03-24 19:15:09 +0430316 found = false
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200317 endif
318 endforeach
319
320 if found
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200321 found = cpp.has_function(name, dependencies: check_deps + extra_deps)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200322 endif
323 endif
324
325 if found
326 deps += extra_deps
327 conf.set('HAVE_@0@'.format(name.to_upper()), 1)
328 endif
329endforeach
330
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200331if cpp.links(files('meson-cc-tests/intel-atomic-primitives-test.c'), name: 'Intel atomics')
332 conf.set('HAVE_INTEL_ATOMIC_PRIMITIVES', 1)
333endif
334
335if cpp.links(files('meson-cc-tests/solaris-atomic-operations.c'), name: 'Solaris atomic ops')
336 conf.set('HAVE_SOLARIS_ATOMIC_OPS', 1)
337endif
338
339subdir('src')
340subdir('util')
Tim-Philipp Müller6147df32018-11-14 10:12:40 +0000341
342if not get_option('tests').disabled()
343 subdir('test')
344endif
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200345
Tim-Philipp Müller3dd7b212020-05-17 00:12:08 +0100346if not get_option('gtk_doc').disabled()
347 subdir('docs')
348endif
349
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200350configure_file(output: 'config.h', configuration: conf)
Ebrahim Byagowia9e83282020-05-21 16:28:24 +0430351
352summary({'prefix': get_option('prefix'),
353 'bindir': get_option('bindir'),
354 'libdir': get_option('libdir'),
355 'includedir': get_option('includedir'),
356 'datadir': get_option('datadir'),
357 }, section: 'Directories')
358summary({'Builtin': true,
359 'Glib': conf.get('HAVE_GLIB', 0) == 1,
360 'ICU': conf.get('HAVE_ICU', 0) == 1,
361 }, bool_yn: true, section: 'Unicode callbacks (you want at least one)')
362summary({'FreeType': conf.get('HAVE_FREETYPE', 0) == 1,
363 }, bool_yn: true, section: 'Font callbacks (the more the merrier)')
364summary({'Cairo': conf.get('HAVE_CAIRO', 0) == 1,
365 'Fontconfig': conf.get('HAVE_FONTCONFIG', 0) == 1,
366 }, bool_yn: true, section: 'Tools used for command-line utilities')
367summary({'Graphite2': conf.get('HAVE_GRAPHITE2', 0) == 1,
368 }, bool_yn: true, section: 'Additional shapers (the more the merrier)')
369summary({'CoreText': conf.get('HAVE_CORETEXT', 0) == 1,
370 'DirectWrite': conf.get('HAVE_DIRECTWRITE', 0) == 1,
371 'GDI': conf.get('HAVE_GDI', 0) == 1,
372 'Uniscribe': conf.get('HAVE_UNISCRIBE', 0) == 1,
373 }, bool_yn: true, section: 'Platform shapers (not normally needed)')
374summary({'Documentation': conf.get('HAVE_GTK_DOC', 0) == 1,
375 'GObject bindings': conf.get('HAVE_GOBJECT', 0) == 1,
376 'Introspection': conf.get('HAVE_INTROSPECTION', 0) == 1,
377 }, bool_yn: true, section: 'Other features')