blob: 0f5198bac72609301c5aa1057ed4d808f71f90f9 [file] [log] [blame]
Dylan Bakerd1992252017-09-14 17:57:17 -07001# Copyright © 2017 Intel Corporation
2
3# Permission is hereby granted, free of charge, to any person obtaining a copy
4# of this software and associated documentation files (the "Software"), to deal
5# in the Software without restriction, including without limitation the rights
6# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7# copies of the Software, and to permit persons to whom the Software is
8# furnished to do so, subject to the following conditions:
9
10# The above copyright notice and this permission notice shall be included in
11# all copies or substantial portions of the Software.
12
13# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19# SOFTWARE.
20
21project('mesa', ['c', 'cpp'], version : '17.3.0-devel', license : 'MIT',
22 default_options : ['c_std=c99'])
23
24with_dri3 = true # XXX: need a switch for this
25with_vulkan_icd_dir = get_option('vulkan_icd_dir')
26with_tests = get_option('build-tests')
27with_valgrind = get_option('valgrind')
28
29# TODO: there are more platforms required for non-vulkan drivers
30with_platform_wayland = false
31with_platform_x11 = false
32_platforms = get_option('platforms')
33if _platforms != ''
34 _split = _platforms.split(',')
35 with_platform_x11 = _split.contains('x11')
36 with_platform_wayland = _split.contains('wayland')
37endif
38
39if with_vulkan_icd_dir == ''
40 with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
41endif
42
43with_intel_vk = false
44with_amd_vk = false
45_vulkan_drivers = get_option('vulkan-drivers')
46if _vulkan_drivers != ''
47 _split = _vulkan_drivers.split(',')
48 with_intel_vk = _split.contains('intel')
49 with_amd_vk = _split.contains('amd')
50 if not (with_platform_x11 or with_platform_wayland)
51 error('Vulkan requires at least one platform (x11, wayland)')
52 endif
53endif
54
55prog_python2 = find_program('python2')
56
57cc = meson.get_compiler('c')
58if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
59 error('When using GCC version 4.2.0 or later required.')
60endif
61
62# Arguments for the preprocessor, put these in a separate array from the C and
63# C++ (cpp in meson terminology) arguments since they need to be added to the
64# default arguments for both C and C++.
65pre_args = ['-D__STDC_CONSTANT_MACROS', '-D__STDC_FORMAT_MACROS',
66 '-D__STDC_LIMIT_MACROS',
67 '-DVERSION="@0@"'.format(meson.project_version())]
68
69# Define DEBUG for debug and debugoptimized builds
70if get_option('buildtype').startswith('debug')
71 pre_args += '-DDEBUG'
72endif
73
74# Check for GCC style builtins
75foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
76 'ffsll', 'popcount', 'popcountll', 'unreachable']
77 if cc.has_function(b)
78 pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
79 endif
80endforeach
81
82# check for GCC __attribute__ s
83foreach a : ['const', 'flatten', 'malloc', 'pure', 'unused',
84 'warn_unused_result', 'weak',]
85 if cc.compiles('int foo(void) __attribute__((@0@));'.format(a),
86 name : '__attribute__((@0@))'.format(a))
87 pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
88 endif
89endforeach
90if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
91 name : '__attribute__((format(...)))')
92 pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
93endif
94if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
95 name : '__attribute__((packed))')
96 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
97endif
98if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
99 name : '__attribute__((returns_nonnull))')
100 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NONNULL'
101endif
102if cc.compiles('''int foo_def(void) __attribute__((visibility("default")));
103 int foo_hid(void) __attribute__((visibility("hidden")));
104 int foo_int(void) __attribute__((visibility("internal")));
105 int foo_pro(void) __attribute__((visibility("protected")));''',
106 name : '__attribute__((visibility(...)))')
107 pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISBILITY'
108endif
109if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
110 name : '__attribute__((alias(...)))')
111 pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
112endif
113
114# TODO: this is very incomplete
115if host_machine.system() == 'linux'
116 pre_args += '-D_GNU_SOURCE'
117endif
118
119# Check for generic C arguments
120c_args = []
121foreach a : ['-Wall', '-Werror=implicit-function-declaration',
122 '-Werror=missing-prototypes', '-fno-math-errno',
123 '-fno-trapping-math', '-Qunused-arguments']
124 if cc.has_argument(a)
125 c_args += a
126 endif
127endforeach
128c_vis_args = []
129if cc.has_argument('-fvisibility=hidden')
130 c_vis_args += '-fvisibility=hidden'
131endif
132
133# Check for generic C++ arguments
134cpp = meson.get_compiler('cpp')
135cpp_args = []
136foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math',
137 '-Qunused-arguments', '-Wno-non-virtual-dtor']
138 if cpp.has_argument(a)
139 cpp_args += a
140 endif
141endforeach
142cpp_vis_args = []
143if cpp.has_argument('-fvisibility=hidden')
144 cpp_vis_args += '-fvisibility=hidden'
145endif
146
147# Check for C and C++ arguments for MSVC2013 compatibility. These are only used
148# in parts of the mesa code base that need to compile with old versions of
149# MSVC, mainly common code
150c_msvc_compat_args = []
151cpp_msvc_compat_args = []
152foreach a : ['-Werror=pointer-arith', '-Werror=vla']
153 if cc.has_argument(a)
154 c_msvc_compat_args += a
155 endif
156 if cpp.has_argument(a)
157 cpp_msvc_compat_args += a
158 endif
159endforeach
160
161no_override_init_args = []
162foreach a : ['-Wno-override-init', '-Wno-initializer-overrides']
163 if cc.has_argument(a)
164 no_override_init_args += a
165 endif
166endforeach
167
168# TODO: SSE41 (which is only required for core mesa)
169
170# Check for GCC style atomics
171if cc.compiles('int main() { int n; return __atomic_load_n(&n, __ATOMIC_ACQUIRE); }',
172 name : 'GCC atomic builtins')
173 pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
174endif
175if not cc.links('''#include <stdint.h>
176 uint64_t v;
177 int main() {
178 return __sync_add_and_fetch(&v, (uint64_t)1);
179 }''',
180 name : 'GCC 64bit atomics')
181 pre_args += '-DMISSING_64_BIT_ATOMICS'
182endif
183
184# TODO: endian
185# TODO: powr8
186# TODO: shared/static? Is this even worth doing?
187
188# I don't think that I need to set any of the debug stuff, I think meson
189# handles that for us
190
191# TODO: ldflags
192
193# TODO: texture-float (gallium/mesa only)
194
195# TODO: cross-compiling. I don't think this is relavent to meson
196
197# TODO: assembly support. mesa and vc4
198
199# Check for standard headers and functions
200if cc.has_header_symbol('sys/sysmacros.h', 'major')
201 pre_args += '-DMAJOR_IN_SYSMACROS'
202elif cc.has_header_symbol('sys/mkdev.h', 'major')
203 pre_args += '-DMAJOR_IN_MKDEV'
204endif
205
206foreach h : ['xlocale.h', 'sys/sysctl.h']
207 if cc.has_header(h)
208 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
209 endif
210endforeach
211
212foreach f : ['strtof', 'mkostemp', 'posix_memalign']
213 if cc.has_function(f)
214 pre_args += '-DHAVE_@0@'.format(f.to_upper())
215 endif
216endforeach
217
218# strtod locale support
219if cc.links('''
220 #define _GNU_SOURCE
221 #include <stdlib.h>
222 #include <locale.h>
223 #ifdef HAVE_XLOCALE_H
224 #include <xlocale.h>
225 #endif
226 int main() {
227 locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
228 const char *s = "1.0";
229 char *end;
230 double d = strtod_l(s, end, loc);
231 float f = strtod_l(s, end, loc);
232 freelocale(loc);
233 return 0;
234 }''',
235 extra_args : pre_args,
236 name : 'strtod has locale support')
237 pre_args += '-DHAVE_STRTOD_L'
238endif
239
240# Check for some linker flags
241ld_args_bsymbolic = []
242if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic')
243 ld_args_bsymbolic += '-Wl,-Bsymbolic'
244endif
245ld_args_gc_sections = []
246if cc.links('static char unused() { return 5; } int main() { return 0; }',
247 args : '-Wl,--gc-sections')
248 ld_args_gc_sections += '-Wl,--gc-sections'
249endif
250
251# check for dl support
252if cc.has_function('dlopen')
253 dep_dl = []
254else
255 dep_dl = cc.find_library('dl')
256endif
257pre_args += '-DHAVE_DLOPEN'
258
259if not cc.has_function('dladdr', dependencies : dep_dl)
260 error('dl library doesn\'t have dladdr')
261endif
262
263if cc.has_function('dl_iterate_phdr')
264 pre_args += '-DHAVE_DL_ITERATE_PHDR'
265else
266 # TODO: this is required for vulkan
267endif
268
269# Determine whether or not the rt library is needed for time functions
270if cc.has_function('clock_gettime')
271 dep_clock = []
272else
273 dep_clock = cc.find_library('rt')
274endif
275
276# TODO: some of these may be conditional
277dep_zlib = dependency('zlib', version : '>= 1.2.3')
278dep_thread = dependency('threads')
279pre_args += '-DHAVE_PTHREAD'
280dep_elf = dependency('libelf')
281dep_expat = dependency('expat')
282# this only exists on linux so either this is linux and it will be found, or
283# its not linux and and wont
284dep_m = cc.find_library('m', required : false)
285
286# TODO: conditionalize libdrm requirement
287dep_libdrm = dependency('libdrm', version : '>= 2.4.75')
288pre_args += '-DHAVE_LIBDRM'
289
290# TODO: make this conditional
291dep_valgrind = dependency('valgrind', required : false)
292if dep_valgrind.found() and with_valgrind
293 pre_args += '-DHAVE_VALGRIND'
294endif
295
296# pthread stubs. Lets not and say we didn't
297
298# TODO: selinux
299
300# TODO: llvm-prefix and llvm-shared-libs
301
302# TODO: llvm dependency (that's all native now, yay!)
303
304# TODO: unwind (llvm [radeon, gallivm] and gallium)
305
306# TODO: flags for opengl, gles, dri
307
308# TODO: gallium-hud
309
310# TODO: glx provider
311
312# TODO: osmesa provider
313
314# TODO: flags for xa, egl, gbm, nin, xvmc, vdpau, omx, va, opencl,
315# gallium-tests,
316
317# TODO: gallium drivers
318
319# TODO: libglvnd
320
321# TODO: symbol mangling
322
323# TODO: dri handling
324
325# TODO: shared-glapi
326
327# TODO: libgl requirements
328
329# TODO: GLX configuration
330
331# TODO: egl configuration
332
333if with_platform_wayland
334 prog_wl_scanner = find_program('wayland-scanner')
335 dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8')
336 dep_wayland_client = dependency('wayland-client', version : '>=1.11')
337 dep_wayland_server = dependency('wayland-server', version : '>=1.11')
338else
339 prog_wl_scanner = []
340 dep_wl_protocols = []
341 dep_wayland_client = []
342 dep_wayland_server = []
343endif
344
345dep_xcb_dri2 = []
346dep_xcb_dri3 = []
347if with_platform_x11
348 dep_xcb_dri2 = [
349 dependency('x11-xcb'),
350 dependency('xcb'),
351 dependency('xcb-dri2', version : '>= 1.8'),
352 dependency('xcb-xfixes'),
353 ]
354 if with_dri3
355 dep_xcb_dri3 = [
356 dep_xcb_dri2,
357 dependency('xcb-dri3'),
358 dependency('xcb-present'),
359 dependency('xcb-sync'),
360 dependency('xshmfence', version : '>= 1.1'),
361 ]
362 else
363 # TODO: dri3 is required for vulkan
364 endif
365endif
366
367# TODO: platforms for !vulkan
368
369# TODO: dri paths
370
371# TODO: dri drivers
372
373# TODO: osmesa
374
375# TODO: egl
376
377# TODO: xa
378
379# TODO: vallium G3DVL
380
381# TODO: nine
382
383# TODO: clover
384
385# TODO: egl sans x11
386
387# TODO: xvmc
388
389# TODO: gallium tests
390
391# TODO: various libdirs
392
393# TODO: swr
394
395# TODO: gallium driver dirs
396
397# FIXME: this is a workaround for #2326
398prog_touch = find_program('touch')
399dummy_cpp = custom_target(
400 'dummy_cpp',
401 output : 'dummy.cpp',
402 command : [prog_touch, '@OUTPUT@'],
403)
404
405foreach a : pre_args
406 add_project_arguments(a, language : ['c', 'cpp'])
407endforeach
408foreach a : c_args
409 add_project_arguments(a, language : ['c'])
410endforeach
411foreach a : cpp_args
412 add_project_arguments(a, language : ['cpp'])
413endforeach
414
415inc_include = include_directories('include')
416
417subdir('include')
418subdir('src')