blob: 8e192d7ab9d8ab30129e678e77eb7dc21a7c0439 [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 ]
37 add_project_arguments(msvc_args, language : 'c')
38 add_project_arguments(msvc_args, language : 'cpp')
39 # Disable SAFESEH with MSVC for libs that use external deps that are built with MinGW
40 # noseh_link_args = ['/SAFESEH:NO']
41endif
42
Ebrahim Byagowi365d2d32020-03-11 20:16:36 +033043add_global_arguments(cpp.get_supported_arguments([
44 '-fno-rtti',
45 '-fno-exceptions',
46 '-fno-threadsafe-statics',
47 '-fvisibility-inlines-hidden', # maybe shouldn't be applied for mingw
48]), language : 'cpp')
49
50if host_machine.cpu_family() == 'arm' and cpp.alignment('struct { char c; }') != 1
51 if cpp.has_argument('-mstructure-size-boundary=8')
52 add_global_arguments('-mstructure-size-boundary=8', language : 'cpp')
53 endif
54endif
55
Mathieu Duponchelle920efc02018-05-17 01:28:53 +020056python3 = import('python').find_installation('python3')
57
58check_headers = [
59 ['unistd.h'],
60 ['sys/mman.h'],
61 ['xlocale.h'],
62 ['stdbool.h'],
63]
64
65check_funcs = [
66 ['atexit'],
67 ['mprotect'],
68 ['sysconf'],
69 ['getpagesize'],
70 ['mmap'],
71 ['isatty'],
72 ['newlocale'],
73 ['strtod_l'],
Ebrahim Byagowi1c3f80b2020-03-11 19:29:47 +033074 ['roundf'],
Mathieu Duponchelle920efc02018-05-17 01:28:53 +020075]
76
Chun-wei Fan733414b2020-03-13 16:15:21 +080077freetype_dep = dependency('freetype2', required: false)
78
79if not freetype_dep.found() and cpp.get_id() == 'msvc'
80 if cpp.has_header('ft2build.h')
81 freetype_dep = cpp.find_library('freetype', required: false)
82 endif
83endif
84
85if not freetype_dep.found() and get_option('freetype').enabled()
86 freetype_dep = dependency('freetype2', fallback: ['freetype2', 'freetype_dep'])
87endif
88
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000089glib_dep = dependency('glib-2.0', required: get_option('glib'),
Nirbheek Chauhanf65def42018-10-12 19:41:49 +053090 fallback: ['glib', 'libglib_dep'])
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000091gobject_dep = dependency('gobject-2.0', required: get_option('gobject'),
Nirbheek Chauhanf65def42018-10-12 19:41:49 +053092 fallback: ['glib', 'libgobject_dep'])
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000093cairo_dep = dependency('cairo', required: get_option('cairo'),
Nirbheek Chauhanf65def42018-10-12 19:41:49 +053094 fallback: ['cairo', 'libcairo_dep'])
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000095fontconfig_dep = dependency('fontconfig', required: get_option('fontconfig'),
Nirbheek Chauhanf65def42018-10-12 19:41:49 +053096 fallback: ['fontconfig', 'fontconfig_dep'])
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000097graphite2_dep = dependency('graphite2', required: get_option('graphite'))
98icu_dep = dependency('icu-uc', required: get_option('icu'))
Mathieu Duponchellefce88f92018-05-17 16:20:10 +020099m_dep = cpp.find_library('m', required: false)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200100
Nirbheek Chauhanf65def42018-10-12 19:41:49 +0530101# Ensure that cairo-ft is fetched from the same library as cairo itself
102if cairo_dep.found()
103 if cairo_dep.type_name() == 'pkgconfig'
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +0000104 cairo_ft_dep = dependency('cairo-ft', required: get_option('cairo'))
Nirbheek Chauhanf65def42018-10-12 19:41:49 +0530105 else
106 cairo_ft_dep = cairo_dep
107 endif
108else
109 # Not-found dependency
110 cairo_ft_dep = dependency('', required: false)
111endif
112
Mathieu Duponchellefce88f92018-05-17 16:20:10 +0200113deps = []
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200114
115conf = configuration_data()
Tim-Philipp Müller618584e2018-11-14 20:19:36 +0000116incconfig = include_directories('.')
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200117cpp_args = ['-DHAVE_CONFIG_H']
118
119warn_cflags = [
120 '-Wno-non-virtual-dtor',
121]
122
123cpp_args += cpp.get_supported_arguments(warn_cflags)
124
Mathieu Duponchellefce88f92018-05-17 16:20:10 +0200125if m_dep.found()
126 deps += [m_dep]
127endif
128
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200129if glib_dep.found()
130 conf.set('HAVE_GLIB', 1)
131 deps += [glib_dep]
132endif
133
134if gobject_dep.found()
135 conf.set('HAVE_GOBJECT', 1)
136 deps += [gobject_dep]
137endif
138
139if cairo_dep.found()
140 conf.set('HAVE_CAIRO', 1)
141 deps += [cairo_dep]
142endif
143
144if cairo_ft_dep.found()
145 conf.set('HAVE_CAIRO_FT', 1)
146 deps += [cairo_ft_dep]
147endif
148
149if graphite2_dep.found()
150 conf.set('HAVE_GRAPHITE2', 1)
151 deps += [graphite2_dep]
152endif
153
154if icu_dep.found()
155 conf.set('HAVE_ICU', 1)
156 conf.set('HAVE_ICU_BUILTIN', 1)
157 deps += [icu_dep]
158endif
159
160if freetype_dep.found()
161 conf.set('HAVE_FREETYPE', 1)
162 deps += [freetype_dep]
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200163 check_freetype_funcs = [
164 ['FT_Get_Var_Blend_Coordinates', {'deps': freetype_dep}],
165 ['FT_Set_Var_Blend_Coordinates', {'deps': freetype_dep}],
166 ['FT_Done_MM_Var', {'deps': freetype_dep}],
167 ]
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200168
169 if freetype_dep.type_name() == 'internal'
170 foreach func: check_freetype_funcs
171 name = func[0]
172 conf.set('HAVE_@0@'.format(name.to_upper()), 1)
173 endforeach
174 else
175 check_funcs += check_freetype_funcs
176 endif
177endif
178
179if fontconfig_dep.found()
180 conf.set('HAVE_FONTCONFIG', 1)
181 deps += [fontconfig_dep]
182endif
183
Chun-wei Fan7baa8e02020-03-13 16:21:25 +0800184# uniscribe (windows)
Tim-Philipp Müllerb7796a52018-11-12 16:56:56 +0000185if host_machine.system() == 'windows' and not get_option('uniscribe').disabled()
186 # TODO: make nicer once we have https://github.com/mesonbuild/meson/issues/3940
187 if cpp.has_header('usp10.h') and cpp.has_header('windows.h')
188 foreach usplib : ['usp10', 'gdi32', 'rpcrt4']
189 deps += [cpp.find_library(usplib, required: true)]
190 endforeach
191 conf.set('HAVE_UNISCRIBE', 1)
192 elif get_option('uniscribe').enabled()
193 error('uniscribe was enabled explicitly, but some required headers are missing.')
194 endif
195endif
196
Chun-wei Fan7baa8e02020-03-13 16:21:25 +0800197# DirectWrite (windows)
Tim-Philipp Müller83ebbe42018-11-12 16:56:56 +0000198if host_machine.system() == 'windows' and not get_option('directwrite').disabled()
Chun-wei Fan7baa8e02020-03-13 16:21:25 +0800199 if cpp.has_header('dwrite_1.h')
Tim-Philipp Müller83ebbe42018-11-12 16:56:56 +0000200 deps += [cpp.find_library('dwrite', required: true)]
201 conf.set('HAVE_DIRECTWRITE', 1)
202 elif get_option('directwrite').enabled()
203 error('DirectWrite was enabled explicitly, but required header is missing.')
204 endif
205endif
206
Tim-Philipp Müller4840c822018-11-12 16:56:56 +0000207# CoreText (macOS) - FIXME: untested
208if host_machine.system() == 'darwin' and not get_option('coretext').disabled()
209 app_services_dep = dependency('appleframeworks', modules : ['ApplicationServices'], required: false)
210 if cpp.has_type('CTFontRef', prefix: '#include <ApplicationServices/ApplicationServices.h>', dependencies: app_services_dep)
211 deps += [app_services_dep]
212 conf.set('HAVE_CORETEXT', 1)
213 # On iOS CoreText and CoreGraphics are stand-alone frameworks
214 # Check for a different symbol to avoid getting cached result
215 else
216 coretext_dep = dependency('appleframeworks', modules : ['CoreText'], required: false)
217 coregraphics_dep = dependency('appleframeworks', modules : ['CoreGraphics'], required: false)
218 corefoundation_dep = dependency('appleframeworks', modules : ['CoreFoundation'], required: false)
219 if cpp.has_type('CTRunRef', prefix: '#include <CoreText/CoreText.h>', dependencies: [coretext_dep, coregraphics_dep, corefoundation_dep])
220 deps += [coretext_dep, coregraphics_dep, corefoundation_dep]
221 conf.set('HAVE_CORETEXT', 1)
222 elif get_option('coretext').enabled()
223 error('CoreText was enabled explicitly, but required headers or frameworks are missing.')
224 endif
225 endif
226endif
227
Tim-Philipp Müllerb7796a52018-11-12 16:56:56 +0000228# threads
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200229if host_machine.system() != 'windows'
230 thread_dep = dependency('threads', required: false)
231
232 if thread_dep.found()
233 conf.set('HAVE_PTHREAD', 1)
234 deps += [thread_dep]
235 else
236 check_headers += ['sched.h']
237 check_funcs += ['sched_yield', {'link_with': 'rt'}]
238 endif
239endif
240
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200241conf.set('HAVE_OT', 1)
242conf.set('HAVE_FALLBACK', 1)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200243conf.set_quoted('PACKAGE_NAME', 'HarfBuzz')
244conf.set_quoted('PACKAGE_VERSION', meson.project_version())
245
246foreach check : check_headers
247 name = check[0]
248
249 if cpp.has_header(name)
250 conf.set('HAVE_@0@'.format(name.to_upper().underscorify()), 1)
251 endif
252endforeach
253
254foreach check : check_funcs
255 name = check[0]
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200256 opts = check.get(1, {})
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200257 link_withs = opts.get('link_with', [])
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200258 check_deps = opts.get('deps', [])
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200259 extra_deps = []
260 found = true
261
262 # First try without linking
263
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200264 found = cpp.has_function(name, dependencies: check_deps)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200265
266 if not found and link_withs.length() > 0
267 found = true
268
269 foreach link_with : link_withs
270 dep = cpp.find_library(link_with, required: false)
271 if dep.found()
272 extra_deps += dep
273 else
274 found = false
275 endif
276 endforeach
277
278 if found
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200279 found = cpp.has_function(name, dependencies: check_deps + extra_deps)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200280 endif
281 endif
282
283 if found
284 deps += extra_deps
285 conf.set('HAVE_@0@'.format(name.to_upper()), 1)
286 endif
287endforeach
288
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200289if cpp.links(files('meson-cc-tests/intel-atomic-primitives-test.c'), name: 'Intel atomics')
290 conf.set('HAVE_INTEL_ATOMIC_PRIMITIVES', 1)
291endif
292
293if cpp.links(files('meson-cc-tests/solaris-atomic-operations.c'), name: 'Solaris atomic ops')
294 conf.set('HAVE_SOLARIS_ATOMIC_OPS', 1)
295endif
296
297subdir('src')
298subdir('util')
Tim-Philipp Müller6147df32018-11-14 10:12:40 +0000299
300if not get_option('tests').disabled()
301 subdir('test')
302endif
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200303
304configure_file(output: 'config.h', configuration: conf)