blob: c22e926266e4e69def96e8f02c78ee4d6294cf90 [file] [log] [blame]
Mathieu Duponchelle920efc02018-05-17 01:28:53 +02001project('harfbuzz', 'c', 'cpp',
Mathieu Duponchelle07cadc92018-06-18 17:18:05 +02002 meson_version: '>= 0.47.0',
Ebrahim Byagowi31218b42020-03-11 22:27:32 +03303 default_options : ['cpp_std=c++11'],
Ebrahim Byagowi1c3f80b2020-03-11 19:29:47 +03304 version: '2.6.4')
Mathieu Duponchelle920efc02018-05-17 01:28:53 +02005
Tim-Philipp Müller535186f2018-12-03 20:51:06 +01006hb_version_arr = meson.project_version().split('.')
7hb_version_major = hb_version_arr[0].to_int()
8hb_version_minor = hb_version_arr[1].to_int()
9hb_version_micro = hb_version_arr[2].to_int()
10
11# libtool versioning
12hb_version_int = hb_version_major*10000 + hb_version_minor*100 + hb_version_micro
13if hb_version_minor % 2 == 1
14 hb_libtool_revision = 0 # for unstable releases
15else
16 hb_libtool_revision = hb_version_micro # for stable releases
17endif
18hb_libtool_age = hb_version_int - hb_libtool_revision
19hb_libtool_current = hb_libtool_age
20hb_libtool_version_info = '@0@:@1@:@2@'.format(hb_libtool_current, hb_libtool_revision, hb_libtool_age)
21
Mathieu Duponchelle484313f2018-06-05 02:15:43 +020022pkgmod = import('pkgconfig')
Mathieu Duponchelle920efc02018-05-17 01:28:53 +020023cpp = meson.get_compiler('cpp')
24
Tim-Philipp Müller4a47f1a2018-12-01 11:05:27 +000025if cpp.get_id() == 'msvc'
26 # Ignore several spurious warnings for things HarfBuzz does very commonly.
27 # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it
28 # If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once
29 # NOTE: Only add warnings here if you are sure they're spurious
30 msvc_args = [
31 '/wd4018', # implicit signed/unsigned conversion
32 '/wd4146', # unary minus on unsigned (beware INT_MIN)
33 '/wd4244', # lossy type conversion (e.g. double -> int)
34 '/wd4305', # truncating type conversion (e.g. double -> float)
35 cpp.get_supported_arguments(['/utf-8']), # set the input encoding to utf-8
36 ]
Tim-Philipp Müllerbb8aaa32020-03-14 01:05:38 +000037 add_project_arguments(msvc_args, language : ['c', 'cpp'])
Tim-Philipp Müller4a47f1a2018-12-01 11:05:27 +000038 # Disable SAFESEH with MSVC for libs that use external deps that are built with MinGW
39 # noseh_link_args = ['/SAFESEH:NO']
40endif
41
Tim-Philipp Müllerbb8aaa32020-03-14 01:05:38 +000042add_project_arguments(cpp.get_supported_arguments([
Ebrahim Byagowi365d2d32020-03-11 20:16:36 +033043 '-fno-rtti',
44 '-fno-exceptions',
45 '-fno-threadsafe-statics',
46 '-fvisibility-inlines-hidden', # maybe shouldn't be applied for mingw
47]), language : 'cpp')
48
49if host_machine.cpu_family() == 'arm' and cpp.alignment('struct { char c; }') != 1
50 if cpp.has_argument('-mstructure-size-boundary=8')
Tim-Philipp Müllerbb8aaa32020-03-14 01:05:38 +000051 add_project_arguments('-mstructure-size-boundary=8', language : 'cpp')
Ebrahim Byagowi365d2d32020-03-11 20:16:36 +033052 endif
53endif
54
Mathieu Duponchelle920efc02018-05-17 01:28:53 +020055python3 = import('python').find_installation('python3')
56
57check_headers = [
58 ['unistd.h'],
59 ['sys/mman.h'],
60 ['xlocale.h'],
61 ['stdbool.h'],
62]
63
64check_funcs = [
65 ['atexit'],
66 ['mprotect'],
67 ['sysconf'],
68 ['getpagesize'],
69 ['mmap'],
70 ['isatty'],
71 ['newlocale'],
72 ['strtod_l'],
Ebrahim Byagowi1c3f80b2020-03-11 19:29:47 +033073 ['roundf'],
Mathieu Duponchelle920efc02018-05-17 01:28:53 +020074]
75
Chun-wei Fan733414b2020-03-13 16:15:21 +080076freetype_dep = dependency('freetype2', required: false)
77
78if not freetype_dep.found() and cpp.get_id() == 'msvc'
79 if cpp.has_header('ft2build.h')
80 freetype_dep = cpp.find_library('freetype', required: false)
81 endif
82endif
83
84if not freetype_dep.found() and get_option('freetype').enabled()
85 freetype_dep = dependency('freetype2', fallback: ['freetype2', 'freetype_dep'])
86endif
87
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000088glib_dep = dependency('glib-2.0', required: get_option('glib'),
Nirbheek Chauhanf65def42018-10-12 19:41:49 +053089 fallback: ['glib', 'libglib_dep'])
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000090gobject_dep = dependency('gobject-2.0', required: get_option('gobject'),
Nirbheek Chauhanf65def42018-10-12 19:41:49 +053091 fallback: ['glib', 'libgobject_dep'])
Chun-wei Fan9d0e6ae2020-03-13 16:56:55 +080092cairo_dep = dependency('cairo', required: false)
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000093fontconfig_dep = dependency('fontconfig', required: get_option('fontconfig'),
Nirbheek Chauhanf65def42018-10-12 19:41:49 +053094 fallback: ['fontconfig', 'fontconfig_dep'])
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000095graphite2_dep = dependency('graphite2', required: get_option('graphite'))
Chun-wei Fan5efce602020-03-13 16:40:20 +080096icu_dep = dependency('icu-uc', required: get_option('icu').enabled() and cpp.get_id() != 'msvc')
Mathieu Duponchellefce88f92018-05-17 16:20:10 +020097m_dep = cpp.find_library('m', required: false)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +020098
Chun-wei Fan5efce602020-03-13 16:40:20 +080099if not icu_dep.found() and cpp.get_id() == 'msvc'
100 if cpp.has_header('unicode/uchar.h') and \
101 cpp.has_header('unicode/unorm2.h') and \
102 cpp.has_header('unicode/ustring.h') and \
103 cpp.has_header('unicode/utf16.h') and \
104 cpp.has_header('unicode/uversion.h') and \
105 cpp.has_header('unicode/uscript.h')
106 if get_option('buildtype') == 'debug'
107 icu_dep = cpp.find_library('icuucd', required: get_option('icu'))
108 else
109 icu_dep = cpp.find_library('icuuc', required: get_option('icu'))
110 endif
111 else
112 if get_option('icu').enabled()
113 error('ICU headers and libraries must be present to build ICU support')
114 endif
115 endif
116endif
117
Chun-wei Fan9d0e6ae2020-03-13 16:56:55 +0800118if not cairo_dep.found() and cpp.get_id() == 'msvc'
119 if cpp.has_header('cairo.h')
120 cairo_dep = cpp.find_library('cairo')
121 endif
122endif
123
124if not cairo_dep.found() and get_option('cairo').enabled()
125 cairo_dep = dependency('cairo', fallback: ['cairo', 'libcairo_dep'])
126endif
127
Nirbheek Chauhanf65def42018-10-12 19:41:49 +0530128# Ensure that cairo-ft is fetched from the same library as cairo itself
129if cairo_dep.found()
130 if cairo_dep.type_name() == 'pkgconfig'
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +0000131 cairo_ft_dep = dependency('cairo-ft', required: get_option('cairo'))
Nirbheek Chauhanf65def42018-10-12 19:41:49 +0530132 else
Chun-wei Fan9d0e6ae2020-03-13 16:56:55 +0800133 if cpp.has_header('cairo-ft.h') and \
134 cpp.has_function('cairo_ft_font_face_create_for_ft_face', dependencies: cairo_dep)
135 cairo_ft_dep = cairo_dep
136 endif
Nirbheek Chauhanf65def42018-10-12 19:41:49 +0530137 endif
138else
139 # Not-found dependency
140 cairo_ft_dep = dependency('', required: false)
141endif
142
Mathieu Duponchellefce88f92018-05-17 16:20:10 +0200143deps = []
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200144
145conf = configuration_data()
Tim-Philipp Müller618584e2018-11-14 20:19:36 +0000146incconfig = include_directories('.')
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200147cpp_args = ['-DHAVE_CONFIG_H']
148
149warn_cflags = [
150 '-Wno-non-virtual-dtor',
151]
152
153cpp_args += cpp.get_supported_arguments(warn_cflags)
154
Mathieu Duponchellefce88f92018-05-17 16:20:10 +0200155if m_dep.found()
156 deps += [m_dep]
157endif
158
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200159if glib_dep.found()
160 conf.set('HAVE_GLIB', 1)
161 deps += [glib_dep]
162endif
163
164if gobject_dep.found()
165 conf.set('HAVE_GOBJECT', 1)
166 deps += [gobject_dep]
167endif
168
169if cairo_dep.found()
170 conf.set('HAVE_CAIRO', 1)
171 deps += [cairo_dep]
172endif
173
174if cairo_ft_dep.found()
175 conf.set('HAVE_CAIRO_FT', 1)
176 deps += [cairo_ft_dep]
177endif
178
179if graphite2_dep.found()
180 conf.set('HAVE_GRAPHITE2', 1)
181 deps += [graphite2_dep]
182endif
183
184if icu_dep.found()
185 conf.set('HAVE_ICU', 1)
186 conf.set('HAVE_ICU_BUILTIN', 1)
187 deps += [icu_dep]
188endif
189
190if freetype_dep.found()
191 conf.set('HAVE_FREETYPE', 1)
192 deps += [freetype_dep]
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200193 check_freetype_funcs = [
194 ['FT_Get_Var_Blend_Coordinates', {'deps': freetype_dep}],
195 ['FT_Set_Var_Blend_Coordinates', {'deps': freetype_dep}],
196 ['FT_Done_MM_Var', {'deps': freetype_dep}],
197 ]
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200198
199 if freetype_dep.type_name() == 'internal'
200 foreach func: check_freetype_funcs
201 name = func[0]
202 conf.set('HAVE_@0@'.format(name.to_upper()), 1)
203 endforeach
204 else
205 check_funcs += check_freetype_funcs
206 endif
207endif
208
209if fontconfig_dep.found()
210 conf.set('HAVE_FONTCONFIG', 1)
211 deps += [fontconfig_dep]
212endif
213
Chun-wei Fan838346c2020-03-13 18:01:17 +0800214# GDI (uniscribe) (windows)
215if host_machine.system() == 'windows' and not get_option('gdi').disabled()
Tim-Philipp Müllerb7796a52018-11-12 16:56:56 +0000216 # TODO: make nicer once we have https://github.com/mesonbuild/meson/issues/3940
217 if cpp.has_header('usp10.h') and cpp.has_header('windows.h')
218 foreach usplib : ['usp10', 'gdi32', 'rpcrt4']
219 deps += [cpp.find_library(usplib, required: true)]
220 endforeach
221 conf.set('HAVE_UNISCRIBE', 1)
Chun-wei Fan838346c2020-03-13 18:01:17 +0800222 conf.set('HAVE_GDI', 1)
223 elif get_option('gdi').enabled()
224 error('gdi was enabled explicitly, but some required headers are missing.')
Tim-Philipp Müllerb7796a52018-11-12 16:56:56 +0000225 endif
226endif
227
Chun-wei Fan7baa8e02020-03-13 16:21:25 +0800228# DirectWrite (windows)
Tim-Philipp Müller83ebbe42018-11-12 16:56:56 +0000229if host_machine.system() == 'windows' and not get_option('directwrite').disabled()
Chun-wei Fan7baa8e02020-03-13 16:21:25 +0800230 if cpp.has_header('dwrite_1.h')
Tim-Philipp Müller83ebbe42018-11-12 16:56:56 +0000231 deps += [cpp.find_library('dwrite', required: true)]
232 conf.set('HAVE_DIRECTWRITE', 1)
233 elif get_option('directwrite').enabled()
234 error('DirectWrite was enabled explicitly, but required header is missing.')
235 endif
236endif
237
Tim-Philipp Müller4840c822018-11-12 16:56:56 +0000238# CoreText (macOS) - FIXME: untested
239if host_machine.system() == 'darwin' and not get_option('coretext').disabled()
240 app_services_dep = dependency('appleframeworks', modules : ['ApplicationServices'], required: false)
241 if cpp.has_type('CTFontRef', prefix: '#include <ApplicationServices/ApplicationServices.h>', dependencies: app_services_dep)
242 deps += [app_services_dep]
243 conf.set('HAVE_CORETEXT', 1)
244 # On iOS CoreText and CoreGraphics are stand-alone frameworks
245 # Check for a different symbol to avoid getting cached result
246 else
247 coretext_dep = dependency('appleframeworks', modules : ['CoreText'], required: false)
248 coregraphics_dep = dependency('appleframeworks', modules : ['CoreGraphics'], required: false)
249 corefoundation_dep = dependency('appleframeworks', modules : ['CoreFoundation'], required: false)
250 if cpp.has_type('CTRunRef', prefix: '#include <CoreText/CoreText.h>', dependencies: [coretext_dep, coregraphics_dep, corefoundation_dep])
251 deps += [coretext_dep, coregraphics_dep, corefoundation_dep]
252 conf.set('HAVE_CORETEXT', 1)
253 elif get_option('coretext').enabled()
254 error('CoreText was enabled explicitly, but required headers or frameworks are missing.')
255 endif
256 endif
257endif
258
Tim-Philipp Müllerb7796a52018-11-12 16:56:56 +0000259# threads
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200260if host_machine.system() != 'windows'
261 thread_dep = dependency('threads', required: false)
262
263 if thread_dep.found()
264 conf.set('HAVE_PTHREAD', 1)
265 deps += [thread_dep]
266 else
267 check_headers += ['sched.h']
268 check_funcs += ['sched_yield', {'link_with': 'rt'}]
269 endif
270endif
271
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200272conf.set('HAVE_OT', 1)
273conf.set('HAVE_FALLBACK', 1)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200274conf.set_quoted('PACKAGE_NAME', 'HarfBuzz')
275conf.set_quoted('PACKAGE_VERSION', meson.project_version())
276
277foreach check : check_headers
278 name = check[0]
279
280 if cpp.has_header(name)
281 conf.set('HAVE_@0@'.format(name.to_upper().underscorify()), 1)
282 endif
283endforeach
284
285foreach check : check_funcs
286 name = check[0]
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200287 opts = check.get(1, {})
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200288 link_withs = opts.get('link_with', [])
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200289 check_deps = opts.get('deps', [])
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200290 extra_deps = []
291 found = true
292
293 # First try without linking
294
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200295 found = cpp.has_function(name, dependencies: check_deps)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200296
297 if not found and link_withs.length() > 0
298 found = true
299
300 foreach link_with : link_withs
301 dep = cpp.find_library(link_with, required: false)
302 if dep.found()
303 extra_deps += dep
304 else
305 found = false
306 endif
307 endforeach
308
309 if found
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200310 found = cpp.has_function(name, dependencies: check_deps + extra_deps)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200311 endif
312 endif
313
314 if found
315 deps += extra_deps
316 conf.set('HAVE_@0@'.format(name.to_upper()), 1)
317 endif
318endforeach
319
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200320if cpp.links(files('meson-cc-tests/intel-atomic-primitives-test.c'), name: 'Intel atomics')
321 conf.set('HAVE_INTEL_ATOMIC_PRIMITIVES', 1)
322endif
323
324if cpp.links(files('meson-cc-tests/solaris-atomic-operations.c'), name: 'Solaris atomic ops')
325 conf.set('HAVE_SOLARIS_ATOMIC_OPS', 1)
326endif
327
328subdir('src')
329subdir('util')
Tim-Philipp Müller6147df32018-11-14 10:12:40 +0000330
331if not get_option('tests').disabled()
332 subdir('test')
333endif
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200334
335configure_file(output: 'config.h', configuration: conf)