blob: 8ca46b9643574e1f22cd7062ff34eb7cdfab6d9c [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
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'],
62 ['xlocale.h'],
63 ['stdbool.h'],
64]
65
66check_funcs = [
67 ['atexit'],
68 ['mprotect'],
69 ['sysconf'],
70 ['getpagesize'],
71 ['mmap'],
72 ['isatty'],
73 ['newlocale'],
74 ['strtod_l'],
Ebrahim Byagowi1c3f80b2020-03-11 19:29:47 +033075 ['roundf'],
Mathieu Duponchelle920efc02018-05-17 01:28:53 +020076]
77
Chun-wei Fan733414b2020-03-13 16:15:21 +080078freetype_dep = dependency('freetype2', required: false)
79
80if not freetype_dep.found() and cpp.get_id() == 'msvc'
81 if cpp.has_header('ft2build.h')
82 freetype_dep = cpp.find_library('freetype', required: false)
83 endif
84endif
85
86if not freetype_dep.found() and get_option('freetype').enabled()
87 freetype_dep = dependency('freetype2', fallback: ['freetype2', 'freetype_dep'])
88endif
89
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000090glib_dep = dependency('glib-2.0', required: get_option('glib'),
Nirbheek Chauhanf65def42018-10-12 19:41:49 +053091 fallback: ['glib', 'libglib_dep'])
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000092gobject_dep = dependency('gobject-2.0', required: get_option('gobject'),
Nirbheek Chauhanf65def42018-10-12 19:41:49 +053093 fallback: ['glib', 'libgobject_dep'])
Chun-wei Fan9d0e6ae2020-03-13 16:56:55 +080094cairo_dep = dependency('cairo', required: false)
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'))
Chun-wei Fan5efce602020-03-13 16:40:20 +080098icu_dep = dependency('icu-uc', required: get_option('icu').enabled() and cpp.get_id() != 'msvc')
Mathieu Duponchellefce88f92018-05-17 16:20:10 +020099m_dep = cpp.find_library('m', required: false)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200100
Chun-wei Fan5efce602020-03-13 16:40:20 +0800101if not icu_dep.found() and cpp.get_id() == 'msvc'
102 if cpp.has_header('unicode/uchar.h') and \
103 cpp.has_header('unicode/unorm2.h') and \
104 cpp.has_header('unicode/ustring.h') and \
105 cpp.has_header('unicode/utf16.h') and \
106 cpp.has_header('unicode/uversion.h') and \
107 cpp.has_header('unicode/uscript.h')
108 if get_option('buildtype') == 'debug'
109 icu_dep = cpp.find_library('icuucd', required: get_option('icu'))
110 else
111 icu_dep = cpp.find_library('icuuc', required: get_option('icu'))
112 endif
113 else
114 if get_option('icu').enabled()
115 error('ICU headers and libraries must be present to build ICU support')
116 endif
117 endif
118endif
119
Chun-wei Fan9d0e6ae2020-03-13 16:56:55 +0800120if not cairo_dep.found() and cpp.get_id() == 'msvc'
121 if cpp.has_header('cairo.h')
122 cairo_dep = cpp.find_library('cairo')
123 endif
124endif
125
126if not cairo_dep.found() and get_option('cairo').enabled()
127 cairo_dep = dependency('cairo', fallback: ['cairo', 'libcairo_dep'])
128endif
129
Nirbheek Chauhanf65def42018-10-12 19:41:49 +0530130# Ensure that cairo-ft is fetched from the same library as cairo itself
131if cairo_dep.found()
132 if cairo_dep.type_name() == 'pkgconfig'
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +0000133 cairo_ft_dep = dependency('cairo-ft', required: get_option('cairo'))
Nirbheek Chauhanf65def42018-10-12 19:41:49 +0530134 else
Chun-wei Fan9d0e6ae2020-03-13 16:56:55 +0800135 if cpp.has_header('cairo-ft.h') and \
136 cpp.has_function('cairo_ft_font_face_create_for_ft_face', dependencies: cairo_dep)
137 cairo_ft_dep = cairo_dep
138 endif
Nirbheek Chauhanf65def42018-10-12 19:41:49 +0530139 endif
140else
141 # Not-found dependency
142 cairo_ft_dep = dependency('', required: false)
143endif
144
Mathieu Duponchellefce88f92018-05-17 16:20:10 +0200145deps = []
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200146
147conf = configuration_data()
Tim-Philipp Müller618584e2018-11-14 20:19:36 +0000148incconfig = include_directories('.')
Tim-Philipp Müllera3892be2020-03-14 01:08:15 +0000149
150add_project_arguments('-DHAVE_CONFIG_H', language: ['c', 'cpp'])
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200151
152warn_cflags = [
153 '-Wno-non-virtual-dtor',
154]
155
Tim-Philipp Müllera3892be2020-03-14 01:08:15 +0000156cpp_args = cpp.get_supported_arguments(warn_cflags)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200157
Mathieu Duponchellefce88f92018-05-17 16:20:10 +0200158if m_dep.found()
159 deps += [m_dep]
160endif
161
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200162if glib_dep.found()
163 conf.set('HAVE_GLIB', 1)
164 deps += [glib_dep]
165endif
166
167if gobject_dep.found()
168 conf.set('HAVE_GOBJECT', 1)
169 deps += [gobject_dep]
170endif
171
172if cairo_dep.found()
173 conf.set('HAVE_CAIRO', 1)
174 deps += [cairo_dep]
175endif
176
177if cairo_ft_dep.found()
178 conf.set('HAVE_CAIRO_FT', 1)
179 deps += [cairo_ft_dep]
180endif
181
182if graphite2_dep.found()
183 conf.set('HAVE_GRAPHITE2', 1)
184 deps += [graphite2_dep]
185endif
186
187if icu_dep.found()
188 conf.set('HAVE_ICU', 1)
189 conf.set('HAVE_ICU_BUILTIN', 1)
190 deps += [icu_dep]
191endif
192
193if freetype_dep.found()
194 conf.set('HAVE_FREETYPE', 1)
195 deps += [freetype_dep]
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200196 check_freetype_funcs = [
197 ['FT_Get_Var_Blend_Coordinates', {'deps': freetype_dep}],
198 ['FT_Set_Var_Blend_Coordinates', {'deps': freetype_dep}],
199 ['FT_Done_MM_Var', {'deps': freetype_dep}],
200 ]
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200201
202 if freetype_dep.type_name() == 'internal'
203 foreach func: check_freetype_funcs
204 name = func[0]
205 conf.set('HAVE_@0@'.format(name.to_upper()), 1)
206 endforeach
207 else
208 check_funcs += check_freetype_funcs
209 endif
210endif
211
212if fontconfig_dep.found()
213 conf.set('HAVE_FONTCONFIG', 1)
214 deps += [fontconfig_dep]
215endif
216
Chun-wei Fan838346c2020-03-13 18:01:17 +0800217# GDI (uniscribe) (windows)
218if host_machine.system() == 'windows' and not get_option('gdi').disabled()
Tim-Philipp Müllerb7796a52018-11-12 16:56:56 +0000219 # TODO: make nicer once we have https://github.com/mesonbuild/meson/issues/3940
220 if cpp.has_header('usp10.h') and cpp.has_header('windows.h')
221 foreach usplib : ['usp10', 'gdi32', 'rpcrt4']
222 deps += [cpp.find_library(usplib, required: true)]
223 endforeach
224 conf.set('HAVE_UNISCRIBE', 1)
Chun-wei Fan838346c2020-03-13 18:01:17 +0800225 conf.set('HAVE_GDI', 1)
226 elif get_option('gdi').enabled()
227 error('gdi was enabled explicitly, but some required headers are missing.')
Tim-Philipp Müllerb7796a52018-11-12 16:56:56 +0000228 endif
229endif
230
Chun-wei Fan7baa8e02020-03-13 16:21:25 +0800231# DirectWrite (windows)
Tim-Philipp Müller83ebbe42018-11-12 16:56:56 +0000232if host_machine.system() == 'windows' and not get_option('directwrite').disabled()
Chun-wei Fan7baa8e02020-03-13 16:21:25 +0800233 if cpp.has_header('dwrite_1.h')
Tim-Philipp Müller83ebbe42018-11-12 16:56:56 +0000234 deps += [cpp.find_library('dwrite', required: true)]
235 conf.set('HAVE_DIRECTWRITE', 1)
236 elif get_option('directwrite').enabled()
237 error('DirectWrite was enabled explicitly, but required header is missing.')
238 endif
239endif
240
Tim-Philipp Müller4840c822018-11-12 16:56:56 +0000241# CoreText (macOS) - FIXME: untested
242if host_machine.system() == 'darwin' and not get_option('coretext').disabled()
243 app_services_dep = dependency('appleframeworks', modules : ['ApplicationServices'], required: false)
244 if cpp.has_type('CTFontRef', prefix: '#include <ApplicationServices/ApplicationServices.h>', dependencies: app_services_dep)
245 deps += [app_services_dep]
246 conf.set('HAVE_CORETEXT', 1)
247 # On iOS CoreText and CoreGraphics are stand-alone frameworks
248 # Check for a different symbol to avoid getting cached result
249 else
250 coretext_dep = dependency('appleframeworks', modules : ['CoreText'], required: false)
251 coregraphics_dep = dependency('appleframeworks', modules : ['CoreGraphics'], required: false)
252 corefoundation_dep = dependency('appleframeworks', modules : ['CoreFoundation'], required: false)
253 if cpp.has_type('CTRunRef', prefix: '#include <CoreText/CoreText.h>', dependencies: [coretext_dep, coregraphics_dep, corefoundation_dep])
254 deps += [coretext_dep, coregraphics_dep, corefoundation_dep]
255 conf.set('HAVE_CORETEXT', 1)
256 elif get_option('coretext').enabled()
257 error('CoreText was enabled explicitly, but required headers or frameworks are missing.')
258 endif
259 endif
260endif
261
Tim-Philipp Müllerb7796a52018-11-12 16:56:56 +0000262# threads
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200263if host_machine.system() != 'windows'
264 thread_dep = dependency('threads', required: false)
265
266 if thread_dep.found()
267 conf.set('HAVE_PTHREAD', 1)
268 deps += [thread_dep]
269 else
270 check_headers += ['sched.h']
271 check_funcs += ['sched_yield', {'link_with': 'rt'}]
272 endif
273endif
274
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200275conf.set('HAVE_OT', 1)
276conf.set('HAVE_FALLBACK', 1)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200277conf.set_quoted('PACKAGE_NAME', 'HarfBuzz')
278conf.set_quoted('PACKAGE_VERSION', meson.project_version())
279
280foreach check : check_headers
281 name = check[0]
282
283 if cpp.has_header(name)
284 conf.set('HAVE_@0@'.format(name.to_upper().underscorify()), 1)
285 endif
286endforeach
287
288foreach check : check_funcs
289 name = check[0]
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200290 opts = check.get(1, {})
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200291 link_withs = opts.get('link_with', [])
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200292 check_deps = opts.get('deps', [])
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200293 extra_deps = []
294 found = true
295
296 # First try without linking
297
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200298 found = cpp.has_function(name, dependencies: check_deps)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200299
300 if not found and link_withs.length() > 0
301 found = true
302
303 foreach link_with : link_withs
304 dep = cpp.find_library(link_with, required: false)
305 if dep.found()
Ebrahim Byagowie8808c12020-03-24 19:15:09 +0430306 extra_deps += dep
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200307 else
Ebrahim Byagowie8808c12020-03-24 19:15:09 +0430308 found = false
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200309 endif
310 endforeach
311
312 if found
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200313 found = cpp.has_function(name, dependencies: check_deps + extra_deps)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200314 endif
315 endif
316
317 if found
318 deps += extra_deps
319 conf.set('HAVE_@0@'.format(name.to_upper()), 1)
320 endif
321endforeach
322
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200323if cpp.links(files('meson-cc-tests/intel-atomic-primitives-test.c'), name: 'Intel atomics')
324 conf.set('HAVE_INTEL_ATOMIC_PRIMITIVES', 1)
325endif
326
327if cpp.links(files('meson-cc-tests/solaris-atomic-operations.c'), name: 'Solaris atomic ops')
328 conf.set('HAVE_SOLARIS_ATOMIC_OPS', 1)
329endif
330
331subdir('src')
332subdir('util')
Tim-Philipp Müller6147df32018-11-14 10:12:40 +0000333
334if not get_option('tests').disabled()
335 subdir('test')
336endif
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200337
338configure_file(output: 'config.h', configuration: conf)