blob: 176eefb39ac2092d09e2a84cb6cc3178ae1f2814 [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',
Mathieu Duponchelle920efc02018-05-17 01:28:53 +02003 version: '1.7.6')
4
Mathieu Duponchelle484313f2018-06-05 02:15:43 +02005pkgmod = import('pkgconfig')
Mathieu Duponchelle920efc02018-05-17 01:28:53 +02006cpp = meson.get_compiler('cpp')
7
Tim-Philipp Müller4a47f1a2018-12-01 11:05:27 +00008if cpp.get_id() == 'msvc'
9 # Ignore several spurious warnings for things HarfBuzz does very commonly.
10 # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it
11 # If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once
12 # NOTE: Only add warnings here if you are sure they're spurious
13 msvc_args = [
14 '/wd4018', # implicit signed/unsigned conversion
15 '/wd4146', # unary minus on unsigned (beware INT_MIN)
16 '/wd4244', # lossy type conversion (e.g. double -> int)
17 '/wd4305', # truncating type conversion (e.g. double -> float)
18 cpp.get_supported_arguments(['/utf-8']), # set the input encoding to utf-8
19 ]
20 add_project_arguments(msvc_args, language : 'c')
21 add_project_arguments(msvc_args, language : 'cpp')
22 # Disable SAFESEH with MSVC for libs that use external deps that are built with MinGW
23 # noseh_link_args = ['/SAFESEH:NO']
24endif
25
Mathieu Duponchelle920efc02018-05-17 01:28:53 +020026python3 = import('python').find_installation('python3')
27
28check_headers = [
29 ['unistd.h'],
30 ['sys/mman.h'],
31 ['xlocale.h'],
32 ['stdbool.h'],
33]
34
35check_funcs = [
36 ['atexit'],
37 ['mprotect'],
38 ['sysconf'],
39 ['getpagesize'],
40 ['mmap'],
41 ['isatty'],
42 ['newlocale'],
43 ['strtod_l'],
44 ['round'],
45]
46
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000047freetype_dep = dependency('freetype2', required: get_option('freetype'),
Nirbheek Chauhanf65def42018-10-12 19:41:49 +053048 fallback: ['freetype2', 'freetype_dep'])
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000049glib_dep = dependency('glib-2.0', required: get_option('glib'),
Nirbheek Chauhanf65def42018-10-12 19:41:49 +053050 fallback: ['glib', 'libglib_dep'])
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000051gobject_dep = dependency('gobject-2.0', required: get_option('gobject'),
Nirbheek Chauhanf65def42018-10-12 19:41:49 +053052 fallback: ['glib', 'libgobject_dep'])
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000053cairo_dep = dependency('cairo', required: get_option('cairo'),
Nirbheek Chauhanf65def42018-10-12 19:41:49 +053054 fallback: ['cairo', 'libcairo_dep'])
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000055fontconfig_dep = dependency('fontconfig', required: get_option('fontconfig'),
Nirbheek Chauhanf65def42018-10-12 19:41:49 +053056 fallback: ['fontconfig', 'fontconfig_dep'])
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000057graphite2_dep = dependency('graphite2', required: get_option('graphite'))
58icu_dep = dependency('icu-uc', required: get_option('icu'))
Mathieu Duponchellefce88f92018-05-17 16:20:10 +020059m_dep = cpp.find_library('m', required: false)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +020060
Nirbheek Chauhanf65def42018-10-12 19:41:49 +053061# Ensure that cairo-ft is fetched from the same library as cairo itself
62if cairo_dep.found()
63 if cairo_dep.type_name() == 'pkgconfig'
Tim-Philipp Müller49ba2112018-11-12 15:36:27 +000064 cairo_ft_dep = dependency('cairo-ft', required: get_option('cairo'))
Nirbheek Chauhanf65def42018-10-12 19:41:49 +053065 else
66 cairo_ft_dep = cairo_dep
67 endif
68else
69 # Not-found dependency
70 cairo_ft_dep = dependency('', required: false)
71endif
72
Mathieu Duponchellefce88f92018-05-17 16:20:10 +020073deps = []
Mathieu Duponchelle920efc02018-05-17 01:28:53 +020074
75conf = configuration_data()
Tim-Philipp Müller618584e2018-11-14 20:19:36 +000076incconfig = include_directories('.')
Mathieu Duponchelle920efc02018-05-17 01:28:53 +020077cpp_args = ['-DHAVE_CONFIG_H']
78
79warn_cflags = [
80 '-Wno-non-virtual-dtor',
81]
82
83cpp_args += cpp.get_supported_arguments(warn_cflags)
84
Mathieu Duponchellefce88f92018-05-17 16:20:10 +020085if m_dep.found()
86 deps += [m_dep]
87endif
88
Mathieu Duponchelle920efc02018-05-17 01:28:53 +020089if glib_dep.found()
90 conf.set('HAVE_GLIB', 1)
91 deps += [glib_dep]
92endif
93
94if gobject_dep.found()
95 conf.set('HAVE_GOBJECT', 1)
96 deps += [gobject_dep]
97endif
98
99if cairo_dep.found()
100 conf.set('HAVE_CAIRO', 1)
101 deps += [cairo_dep]
102endif
103
104if cairo_ft_dep.found()
105 conf.set('HAVE_CAIRO_FT', 1)
106 deps += [cairo_ft_dep]
107endif
108
109if graphite2_dep.found()
110 conf.set('HAVE_GRAPHITE2', 1)
111 deps += [graphite2_dep]
112endif
113
114if icu_dep.found()
115 conf.set('HAVE_ICU', 1)
116 conf.set('HAVE_ICU_BUILTIN', 1)
117 deps += [icu_dep]
118endif
119
120if freetype_dep.found()
121 conf.set('HAVE_FREETYPE', 1)
122 deps += [freetype_dep]
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200123 check_freetype_funcs = [
124 ['FT_Get_Var_Blend_Coordinates', {'deps': freetype_dep}],
125 ['FT_Set_Var_Blend_Coordinates', {'deps': freetype_dep}],
126 ['FT_Done_MM_Var', {'deps': freetype_dep}],
127 ]
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200128
129 if freetype_dep.type_name() == 'internal'
130 foreach func: check_freetype_funcs
131 name = func[0]
132 conf.set('HAVE_@0@'.format(name.to_upper()), 1)
133 endforeach
134 else
135 check_funcs += check_freetype_funcs
136 endif
137endif
138
139if fontconfig_dep.found()
140 conf.set('HAVE_FONTCONFIG', 1)
141 deps += [fontconfig_dep]
142endif
143
Tim-Philipp Müllerb7796a52018-11-12 16:56:56 +0000144# uniscribe (windows) - FIXME: untested
145if host_machine.system() == 'windows' and not get_option('uniscribe').disabled()
146 # TODO: make nicer once we have https://github.com/mesonbuild/meson/issues/3940
147 if cpp.has_header('usp10.h') and cpp.has_header('windows.h')
148 foreach usplib : ['usp10', 'gdi32', 'rpcrt4']
149 deps += [cpp.find_library(usplib, required: true)]
150 endforeach
151 conf.set('HAVE_UNISCRIBE', 1)
152 elif get_option('uniscribe').enabled()
153 error('uniscribe was enabled explicitly, but some required headers are missing.')
154 endif
155endif
156
Tim-Philipp Müller83ebbe42018-11-12 16:56:56 +0000157# DirectWrite (windows) - FIXME: untested
158if host_machine.system() == 'windows' and not get_option('directwrite').disabled()
159 if cpp.has_header('dwrite.h')
160 deps += [cpp.find_library('dwrite', required: true)]
161 conf.set('HAVE_DIRECTWRITE', 1)
162 elif get_option('directwrite').enabled()
163 error('DirectWrite was enabled explicitly, but required header is missing.')
164 endif
165endif
166
Tim-Philipp Müller4840c822018-11-12 16:56:56 +0000167# CoreText (macOS) - FIXME: untested
168if host_machine.system() == 'darwin' and not get_option('coretext').disabled()
169 app_services_dep = dependency('appleframeworks', modules : ['ApplicationServices'], required: false)
170 if cpp.has_type('CTFontRef', prefix: '#include <ApplicationServices/ApplicationServices.h>', dependencies: app_services_dep)
171 deps += [app_services_dep]
172 conf.set('HAVE_CORETEXT', 1)
173 # On iOS CoreText and CoreGraphics are stand-alone frameworks
174 # Check for a different symbol to avoid getting cached result
175 else
176 coretext_dep = dependency('appleframeworks', modules : ['CoreText'], required: false)
177 coregraphics_dep = dependency('appleframeworks', modules : ['CoreGraphics'], required: false)
178 corefoundation_dep = dependency('appleframeworks', modules : ['CoreFoundation'], required: false)
179 if cpp.has_type('CTRunRef', prefix: '#include <CoreText/CoreText.h>', dependencies: [coretext_dep, coregraphics_dep, corefoundation_dep])
180 deps += [coretext_dep, coregraphics_dep, corefoundation_dep]
181 conf.set('HAVE_CORETEXT', 1)
182 elif get_option('coretext').enabled()
183 error('CoreText was enabled explicitly, but required headers or frameworks are missing.')
184 endif
185 endif
186endif
187
Tim-Philipp Müllerb7796a52018-11-12 16:56:56 +0000188# threads
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200189if host_machine.system() != 'windows'
190 thread_dep = dependency('threads', required: false)
191
192 if thread_dep.found()
193 conf.set('HAVE_PTHREAD', 1)
194 deps += [thread_dep]
195 else
196 check_headers += ['sched.h']
197 check_funcs += ['sched_yield', {'link_with': 'rt'}]
198 endif
199endif
200
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200201conf.set('HAVE_OT', 1)
202conf.set('HAVE_FALLBACK', 1)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200203conf.set_quoted('PACKAGE_NAME', 'HarfBuzz')
204conf.set_quoted('PACKAGE_VERSION', meson.project_version())
205
206foreach check : check_headers
207 name = check[0]
208
209 if cpp.has_header(name)
210 conf.set('HAVE_@0@'.format(name.to_upper().underscorify()), 1)
211 endif
212endforeach
213
214foreach check : check_funcs
215 name = check[0]
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200216 opts = check.get(1, {})
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200217 link_withs = opts.get('link_with', [])
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200218 check_deps = opts.get('deps', [])
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200219 extra_deps = []
220 found = true
221
222 # First try without linking
223
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200224 found = cpp.has_function(name, dependencies: check_deps)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200225
226 if not found and link_withs.length() > 0
227 found = true
228
229 foreach link_with : link_withs
230 dep = cpp.find_library(link_with, required: false)
231 if dep.found()
232 extra_deps += dep
233 else
234 found = false
235 endif
236 endforeach
237
238 if found
Mathieu Duponchelle04bcdb92018-06-05 20:59:29 +0200239 found = cpp.has_function(name, dependencies: check_deps + extra_deps)
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200240 endif
241 endif
242
243 if found
244 deps += extra_deps
245 conf.set('HAVE_@0@'.format(name.to_upper()), 1)
246 endif
247endforeach
248
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200249if cpp.links(files('meson-cc-tests/intel-atomic-primitives-test.c'), name: 'Intel atomics')
250 conf.set('HAVE_INTEL_ATOMIC_PRIMITIVES', 1)
251endif
252
253if cpp.links(files('meson-cc-tests/solaris-atomic-operations.c'), name: 'Solaris atomic ops')
254 conf.set('HAVE_SOLARIS_ATOMIC_OPS', 1)
255endif
256
257subdir('src')
258subdir('util')
Tim-Philipp Müller6147df32018-11-14 10:12:40 +0000259
260if not get_option('tests').disabled()
261 subdir('test')
262endif
Mathieu Duponchelle920efc02018-05-17 01:28:53 +0200263
264configure_file(output: 'config.h', configuration: conf)