blob: 1d8e25ee5ec50794d3387cf7a1552123ffdca99c [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
Ebrahim Byagowi22048d52020-06-05 04:09:07 +043044add_project_link_arguments(cpp.get_supported_link_arguments([
45 '-Bsymbolic-functions'
46]), language : 'c')
47
Tim-Philipp Müllerbb8aaa32020-03-14 01:05:38 +000048add_project_arguments(cpp.get_supported_arguments([
Ebrahim Byagowi365d2d32020-03-11 20:16:36 +033049 '-fno-rtti',
50 '-fno-exceptions',
51 '-fno-threadsafe-statics',
52 '-fvisibility-inlines-hidden', # maybe shouldn't be applied for mingw
53]), language : 'cpp')
54
55if host_machine.cpu_family() == 'arm' and cpp.alignment('struct { char c; }') != 1
56 if cpp.has_argument('-mstructure-size-boundary=8')
Tim-Philipp Müllerbb8aaa32020-03-14 01:05:38 +000057 add_project_arguments('-mstructure-size-boundary=8', language : 'cpp')
Ebrahim Byagowi365d2d32020-03-11 20:16:36 +033058 endif
59endif
60
Mathieu Duponchelle920efc02018-05-17 01:28:53 +020061check_headers = [
62 ['unistd.h'],
63 ['sys/mman.h'],
Mathieu Duponchelle920efc02018-05-17 01:28:53 +020064 ['stdbool.h'],
65]
66
67check_funcs = [
68 ['atexit'],
69 ['mprotect'],
70 ['sysconf'],
71 ['getpagesize'],
72 ['mmap'],
73 ['isatty'],
Ebrahim Byagowi1c3f80b2020-03-11 19:29:47 +033074 ['roundf'],
Mathieu Duponchelle920efc02018-05-17 01:28:53 +020075]
76
Ebrahim Byagowib8454c32020-06-11 18:32:13 +043077m_dep = cpp.find_library('m', required: false)
78
Ebrahim Byagowiebab4b82020-06-10 16:52:32 +043079if not get_option('freetype').disabled()
80 freetype_dep = dependency('freetype2', required: false)
Ebrahim Byagowib8454c32020-06-11 18:32:13 +043081
82 if not freetype_dep.found() and cpp.get_id() == 'msvc'
83 if cpp.has_header('ft2build.h')
84 freetype_dep = cpp.find_library('freetype', required: false)
85 endif
86 endif
87
88 if not freetype_dep.found() and get_option('freetype').enabled()
89 freetype_dep = dependency('freetype2', fallback: ['freetype2', 'freetype_dep'])
90 endif
Ebrahim Byagowiebab4b82020-06-10 16:52:32 +043091else
92 freetype_dep = dependency('', required: false)
93endif
Chun-wei Fan733414b2020-03-13 16:15:21 +080094
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000095glib_dep = dependency('glib-2.0', required: get_option('glib'),
Nirbheek Chauhanf65def42018-10-12 19:41:49 +053096 fallback: ['glib', 'libglib_dep'])
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000097gobject_dep = dependency('gobject-2.0', required: get_option('gobject'),
Nirbheek Chauhanf65def42018-10-12 19:41:49 +053098 fallback: ['glib', 'libgobject_dep'])
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000099fontconfig_dep = dependency('fontconfig', required: get_option('fontconfig'),
Nirbheek Chauhanf65def42018-10-12 19:41:49 +0530100 fallback: ['fontconfig', 'fontconfig_dep'])
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +0000101graphite2_dep = dependency('graphite2', required: get_option('graphite'))
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200102
Ebrahim Byagowiebab4b82020-06-10 16:52:32 +0430103if not get_option('icu').disabled()
104 icu_dep = dependency('icu-uc', required: false)
Ebrahim Byagowib8454c32020-06-11 18:32:13 +0430105
106 if not icu_dep.found() and get_option('icu').enabled()
107 icu_dep = dependency('icu-uc', required: cpp.get_id() != 'msvc')
108 endif
109
110 if not icu_dep.found() and cpp.get_id() == 'msvc'
111 if cpp.has_header('unicode/uchar.h') and \
112 cpp.has_header('unicode/unorm2.h') and \
113 cpp.has_header('unicode/ustring.h') and \
114 cpp.has_header('unicode/utf16.h') and \
115 cpp.has_header('unicode/uversion.h') and \
116 cpp.has_header('unicode/uscript.h')
117 if get_option('buildtype') == 'debug'
118 icu_dep = cpp.find_library('icuucd', required: get_option('icu'))
119 else
120 icu_dep = cpp.find_library('icuuc', required: get_option('icu'))
121 endif
Chun-wei Fan5efce602020-03-13 16:40:20 +0800122 else
Ebrahim Byagowib8454c32020-06-11 18:32:13 +0430123 if get_option('icu').enabled()
124 error('ICU headers and libraries must be present to build ICU support')
125 endif
Chun-wei Fan5efce602020-03-13 16:40:20 +0800126 endif
127 endif
Ebrahim Byagowib8454c32020-06-11 18:32:13 +0430128else
129 icu_dep = dependency('', required: false)
Chun-wei Fan5efce602020-03-13 16:40:20 +0800130endif
131
Ebrahim Byagowiebab4b82020-06-10 16:52:32 +0430132if not get_option('cairo').disabled()
133 cairo_dep = dependency('cairo', required: false)
Chun-wei Fan9d0e6ae2020-03-13 16:56:55 +0800134
Ebrahim Byagowib8454c32020-06-11 18:32:13 +0430135 if not cairo_dep.found() and cpp.get_id() == 'msvc'
136 if cpp.has_header('cairo.h')
137 cairo_dep = cpp.find_library('cairo')
Chun-wei Fan9d0e6ae2020-03-13 16:56:55 +0800138 endif
Nirbheek Chauhanf65def42018-10-12 19:41:49 +0530139 endif
Ebrahim Byagowib8454c32020-06-11 18:32:13 +0430140
141 if not cairo_dep.found() and get_option('cairo').enabled()
142 cairo_dep = dependency('cairo', fallback: ['cairo', 'libcairo_dep'])
143 endif
144
145 # Ensure that cairo-ft is fetched from the same library as cairo itself
146 if cairo_dep.found()
147 if cairo_dep.type_name() == 'pkgconfig'
148 cairo_ft_dep = dependency('cairo-ft', required: get_option('cairo'))
149 else
150 if cpp.has_header('cairo-ft.h') and \
151 cpp.has_function('cairo_ft_font_face_create_for_ft_face', dependencies: cairo_dep)
152 cairo_ft_dep = cairo_dep
153 else
154 cairo_ft_dep = dependency('', required: false)
155 endif
156 endif
157 else
158 cairo_ft_dep = dependency('', required: false)
159 endif
Nirbheek Chauhanf65def42018-10-12 19:41:49 +0530160else
Ebrahim Byagowib8454c32020-06-11 18:32:13 +0430161 cairo_dep = dependency('', required: false)
Nirbheek Chauhanf65def42018-10-12 19:41:49 +0530162 cairo_ft_dep = dependency('', required: false)
163endif
164
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200165conf = configuration_data()
Tim-Philipp Müller618584e2018-11-14 20:19:36 +0000166incconfig = include_directories('.')
Tim-Philipp Müllera3892be2020-03-14 01:08:15 +0000167
168add_project_arguments('-DHAVE_CONFIG_H', language: ['c', 'cpp'])
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200169
170warn_cflags = [
171 '-Wno-non-virtual-dtor',
172]
173
Tim-Philipp Müllera3892be2020-03-14 01:08:15 +0000174cpp_args = cpp.get_supported_arguments(warn_cflags)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200175
176if glib_dep.found()
177 conf.set('HAVE_GLIB', 1)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200178endif
179
180if gobject_dep.found()
181 conf.set('HAVE_GOBJECT', 1)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200182endif
183
184if cairo_dep.found()
185 conf.set('HAVE_CAIRO', 1)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200186endif
187
188if cairo_ft_dep.found()
189 conf.set('HAVE_CAIRO_FT', 1)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200190endif
191
192if graphite2_dep.found()
193 conf.set('HAVE_GRAPHITE2', 1)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200194endif
195
196if icu_dep.found()
197 conf.set('HAVE_ICU', 1)
Ebrahim Byagowic6b3f732020-04-19 00:54:24 +0430198endif
199
Ebrahim Byagowicc53fd12020-05-21 19:33:18 +0430200if get_option('icu_builtin')
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200201 conf.set('HAVE_ICU_BUILTIN', 1)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200202endif
203
Ebrahim Byagowicc53fd12020-05-21 19:33:18 +0430204if get_option('experimental_api')
Ebrahim Byagowi750bb732020-04-21 01:13:13 +0430205 conf.set('HB_EXPERIMENTAL_API', 1)
206endif
207
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200208if freetype_dep.found()
209 conf.set('HAVE_FREETYPE', 1)
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200210 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 ]
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200215
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
226if fontconfig_dep.found()
227 conf.set('HAVE_FONTCONFIG', 1)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200228endif
229
Christoph Reiter03bd6ea2020-06-03 23:52:10 +0200230gdi_uniscribe_deps = []
Chun-wei Fan838346c2020-03-13 18:01:17 +0800231# GDI (uniscribe) (windows)
232if host_machine.system() == 'windows' and not get_option('gdi').disabled()
Tim-Philipp Müllerb7796a52018-11-12 16:56:56 +0000233 # TODO: make nicer once we have https://github.com/mesonbuild/meson/issues/3940
234 if cpp.has_header('usp10.h') and cpp.has_header('windows.h')
235 foreach usplib : ['usp10', 'gdi32', 'rpcrt4']
Christoph Reiter03bd6ea2020-06-03 23:52:10 +0200236 gdi_uniscribe_deps += cpp.find_library(usplib, required: true)
Tim-Philipp Müllerb7796a52018-11-12 16:56:56 +0000237 endforeach
238 conf.set('HAVE_UNISCRIBE', 1)
Chun-wei Fan838346c2020-03-13 18:01:17 +0800239 conf.set('HAVE_GDI', 1)
240 elif get_option('gdi').enabled()
241 error('gdi was enabled explicitly, but some required headers are missing.')
Tim-Philipp Müllerb7796a52018-11-12 16:56:56 +0000242 endif
243endif
244
Chun-wei Fan7baa8e02020-03-13 16:21:25 +0800245# DirectWrite (windows)
Christoph Reiter03bd6ea2020-06-03 23:52:10 +0200246directwrite_dep = dependency('', required: false)
Tim-Philipp Müller83ebbe42018-11-12 16:56:56 +0000247if host_machine.system() == 'windows' and not get_option('directwrite').disabled()
Chun-wei Fan7baa8e02020-03-13 16:21:25 +0800248 if cpp.has_header('dwrite_1.h')
Christoph Reiter03bd6ea2020-06-03 23:52:10 +0200249 directwrite_dep = cpp.find_library('dwrite', required: true)
Tim-Philipp Müller83ebbe42018-11-12 16:56:56 +0000250 conf.set('HAVE_DIRECTWRITE', 1)
251 elif get_option('directwrite').enabled()
252 error('DirectWrite was enabled explicitly, but required header is missing.')
253 endif
254endif
255
Tim-Philipp Müller4840c822018-11-12 16:56:56 +0000256# CoreText (macOS) - FIXME: untested
Christoph Reiter03bd6ea2020-06-03 23:52:10 +0200257coretext_deps = []
Tim-Philipp Müller4840c822018-11-12 16:56:56 +0000258if 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)
Christoph Reiter03bd6ea2020-06-03 23:52:10 +0200261 coretext_deps += [app_services_dep]
Tim-Philipp Müller4840c822018-11-12 16:56:56 +0000262 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])
Christoph Reiter03bd6ea2020-06-03 23:52:10 +0200270 coretext_deps += [coretext_dep, coregraphics_dep, corefoundation_dep]
Tim-Philipp Müller4840c822018-11-12 16:56:56 +0000271 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
Tim-Philipp Müllerb7796a52018-11-12 16:56:56 +0000278# threads
Christoph Reiter03bd6ea2020-06-03 23:52:10 +0200279thread_dep = dependency('', required: false)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200280if host_machine.system() != 'windows'
281 thread_dep = dependency('threads', required: false)
282
283 if thread_dep.found()
284 conf.set('HAVE_PTHREAD', 1)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200285 else
286 check_headers += ['sched.h']
287 check_funcs += ['sched_yield', {'link_with': 'rt'}]
288 endif
289endif
290
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200291conf.set('HAVE_OT', 1)
292conf.set('HAVE_FALLBACK', 1)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200293conf.set_quoted('PACKAGE_NAME', 'HarfBuzz')
294conf.set_quoted('PACKAGE_VERSION', meson.project_version())
295
296foreach check : check_headers
297 name = check[0]
298
299 if cpp.has_header(name)
300 conf.set('HAVE_@0@'.format(name.to_upper().underscorify()), 1)
301 endif
302endforeach
303
Christoph Reiter03bd6ea2020-06-03 23:52:10 +0200304harfbuzz_extra_deps = []
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200305foreach check : check_funcs
306 name = check[0]
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200307 opts = check.get(1, {})
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200308 link_withs = opts.get('link_with', [])
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200309 check_deps = opts.get('deps', [])
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200310 extra_deps = []
311 found = true
312
313 # First try without linking
314
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200315 found = cpp.has_function(name, dependencies: check_deps)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200316
317 if not found and link_withs.length() > 0
318 found = true
319
320 foreach link_with : link_withs
321 dep = cpp.find_library(link_with, required: false)
322 if dep.found()
Ebrahim Byagowie8808c12020-03-24 19:15:09 +0430323 extra_deps += dep
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200324 else
Ebrahim Byagowie8808c12020-03-24 19:15:09 +0430325 found = false
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200326 endif
327 endforeach
328
329 if found
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200330 found = cpp.has_function(name, dependencies: check_deps + extra_deps)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200331 endif
332 endif
333
334 if found
Christoph Reiter03bd6ea2020-06-03 23:52:10 +0200335 harfbuzz_extra_deps += extra_deps
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200336 conf.set('HAVE_@0@'.format(name.to_upper()), 1)
337 endif
338endforeach
339
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200340if cpp.links(files('meson-cc-tests/intel-atomic-primitives-test.c'), name: 'Intel atomics')
341 conf.set('HAVE_INTEL_ATOMIC_PRIMITIVES', 1)
342endif
343
344if cpp.links(files('meson-cc-tests/solaris-atomic-operations.c'), name: 'Solaris atomic ops')
345 conf.set('HAVE_SOLARIS_ATOMIC_OPS', 1)
346endif
347
348subdir('src')
349subdir('util')
Tim-Philipp Müller6147df32018-11-14 10:12:40 +0000350
351if not get_option('tests').disabled()
352 subdir('test')
353endif
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200354
Tim-Philipp Müller3dd7b212020-05-17 00:12:08 +0100355if not get_option('gtk_doc').disabled()
356 subdir('docs')
357endif
358
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200359configure_file(output: 'config.h', configuration: conf)
Ebrahim Byagowia9e83282020-05-21 16:28:24 +0430360
361summary({'prefix': get_option('prefix'),
362 'bindir': get_option('bindir'),
363 'libdir': get_option('libdir'),
364 'includedir': get_option('includedir'),
365 'datadir': get_option('datadir'),
366 }, section: 'Directories')
367summary({'Builtin': true,
368 'Glib': conf.get('HAVE_GLIB', 0) == 1,
369 'ICU': conf.get('HAVE_ICU', 0) == 1,
370 }, bool_yn: true, section: 'Unicode callbacks (you want at least one)')
371summary({'FreeType': conf.get('HAVE_FREETYPE', 0) == 1,
372 }, bool_yn: true, section: 'Font callbacks (the more the merrier)')
373summary({'Cairo': conf.get('HAVE_CAIRO', 0) == 1,
374 'Fontconfig': conf.get('HAVE_FONTCONFIG', 0) == 1,
375 }, bool_yn: true, section: 'Tools used for command-line utilities')
376summary({'Graphite2': conf.get('HAVE_GRAPHITE2', 0) == 1,
Ebrahim Byagowi65462c42020-06-05 01:08:08 +0430377 }, bool_yn: true, section: 'Additional shapers')
Ebrahim Byagowia9e83282020-05-21 16:28:24 +0430378summary({'CoreText': conf.get('HAVE_CORETEXT', 0) == 1,
379 'DirectWrite': conf.get('HAVE_DIRECTWRITE', 0) == 1,
380 'GDI': conf.get('HAVE_GDI', 0) == 1,
381 'Uniscribe': conf.get('HAVE_UNISCRIBE', 0) == 1,
382 }, bool_yn: true, section: 'Platform shapers (not normally needed)')
383summary({'Documentation': conf.get('HAVE_GTK_DOC', 0) == 1,
384 'GObject bindings': conf.get('HAVE_GOBJECT', 0) == 1,
385 'Introspection': conf.get('HAVE_INTROSPECTION', 0) == 1,
386 }, bool_yn: true, section: 'Other features')