blob: 1e0b95fcb160e20d4b6952e226a5b959974137cb [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
Dylan Bakere915b8d2017-09-28 14:02:51 -070025with_vulkan_icd_dir = get_option('vulkan-icd-dir')
Dylan Bakerd1992252017-09-14 17:57:17 -070026with_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')
Dylan Baker9342a7d2017-09-28 10:48:30 -070056has_mako = run_command(prog_python2, '-c', 'import mako')
57if has_mako.returncode() != 0
58 error('Python (2.x) mako module required to build mesa.')
59endif
Dylan Bakerd1992252017-09-14 17:57:17 -070060
61cc = meson.get_compiler('c')
62if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
Eric Engestrom1262e822017-09-29 15:25:18 +010063 error('When using GCC, version 4.4.6 or later is required.')
Dylan Bakerd1992252017-09-14 17:57:17 -070064endif
65
66# Arguments for the preprocessor, put these in a separate array from the C and
67# C++ (cpp in meson terminology) arguments since they need to be added to the
68# default arguments for both C and C++.
69pre_args = ['-D__STDC_CONSTANT_MACROS', '-D__STDC_FORMAT_MACROS',
70 '-D__STDC_LIMIT_MACROS',
71 '-DVERSION="@0@"'.format(meson.project_version())]
72
73# Define DEBUG for debug and debugoptimized builds
74if get_option('buildtype').startswith('debug')
75 pre_args += '-DDEBUG'
76endif
77
Dylan Baker673dda82017-09-20 11:53:29 -070078if get_option('shader-cache')
79 pre_args += '-DENABLE_SHADER_CACHE'
80elif with_amd_vk
81 error('Radv requires shader cache support')
82endif
83
Dylan Bakerd1992252017-09-14 17:57:17 -070084# Check for GCC style builtins
85foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
86 'ffsll', 'popcount', 'popcountll', 'unreachable']
87 if cc.has_function(b)
88 pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
89 endif
90endforeach
91
Dylan Baker673dda82017-09-20 11:53:29 -070092# check for GCC __attribute__
Dylan Bakerd1992252017-09-14 17:57:17 -070093foreach a : ['const', 'flatten', 'malloc', 'pure', 'unused',
94 'warn_unused_result', 'weak',]
95 if cc.compiles('int foo(void) __attribute__((@0@));'.format(a),
96 name : '__attribute__((@0@))'.format(a))
97 pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
98 endif
99endforeach
100if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
101 name : '__attribute__((format(...)))')
102 pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
103endif
104if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
105 name : '__attribute__((packed))')
106 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
107endif
108if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
109 name : '__attribute__((returns_nonnull))')
110 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NONNULL'
111endif
112if cc.compiles('''int foo_def(void) __attribute__((visibility("default")));
113 int foo_hid(void) __attribute__((visibility("hidden")));
114 int foo_int(void) __attribute__((visibility("internal")));
115 int foo_pro(void) __attribute__((visibility("protected")));''',
116 name : '__attribute__((visibility(...)))')
117 pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISBILITY'
118endif
119if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
120 name : '__attribute__((alias(...)))')
121 pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
122endif
123
124# TODO: this is very incomplete
125if host_machine.system() == 'linux'
126 pre_args += '-D_GNU_SOURCE'
127endif
128
129# Check for generic C arguments
130c_args = []
131foreach a : ['-Wall', '-Werror=implicit-function-declaration',
132 '-Werror=missing-prototypes', '-fno-math-errno',
133 '-fno-trapping-math', '-Qunused-arguments']
134 if cc.has_argument(a)
135 c_args += a
136 endif
137endforeach
138c_vis_args = []
139if cc.has_argument('-fvisibility=hidden')
140 c_vis_args += '-fvisibility=hidden'
141endif
142
143# Check for generic C++ arguments
144cpp = meson.get_compiler('cpp')
145cpp_args = []
146foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math',
147 '-Qunused-arguments', '-Wno-non-virtual-dtor']
148 if cpp.has_argument(a)
149 cpp_args += a
150 endif
151endforeach
152cpp_vis_args = []
153if cpp.has_argument('-fvisibility=hidden')
154 cpp_vis_args += '-fvisibility=hidden'
155endif
156
157# Check for C and C++ arguments for MSVC2013 compatibility. These are only used
158# in parts of the mesa code base that need to compile with old versions of
159# MSVC, mainly common code
160c_msvc_compat_args = []
161cpp_msvc_compat_args = []
162foreach a : ['-Werror=pointer-arith', '-Werror=vla']
163 if cc.has_argument(a)
164 c_msvc_compat_args += a
165 endif
166 if cpp.has_argument(a)
167 cpp_msvc_compat_args += a
168 endif
169endforeach
170
171no_override_init_args = []
172foreach a : ['-Wno-override-init', '-Wno-initializer-overrides']
173 if cc.has_argument(a)
174 no_override_init_args += a
175 endif
176endforeach
177
178# TODO: SSE41 (which is only required for core mesa)
179
180# Check for GCC style atomics
181if cc.compiles('int main() { int n; return __atomic_load_n(&n, __ATOMIC_ACQUIRE); }',
182 name : 'GCC atomic builtins')
183 pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
184endif
185if not cc.links('''#include <stdint.h>
186 uint64_t v;
187 int main() {
188 return __sync_add_and_fetch(&v, (uint64_t)1);
189 }''',
190 name : 'GCC 64bit atomics')
191 pre_args += '-DMISSING_64_BIT_ATOMICS'
192endif
193
194# TODO: endian
195# TODO: powr8
196# TODO: shared/static? Is this even worth doing?
197
198# I don't think that I need to set any of the debug stuff, I think meson
199# handles that for us
200
201# TODO: ldflags
202
203# TODO: texture-float (gallium/mesa only)
204
205# TODO: cross-compiling. I don't think this is relavent to meson
206
207# TODO: assembly support. mesa and vc4
208
209# Check for standard headers and functions
210if cc.has_header_symbol('sys/sysmacros.h', 'major')
211 pre_args += '-DMAJOR_IN_SYSMACROS'
212elif cc.has_header_symbol('sys/mkdev.h', 'major')
213 pre_args += '-DMAJOR_IN_MKDEV'
214endif
215
216foreach h : ['xlocale.h', 'sys/sysctl.h']
217 if cc.has_header(h)
218 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
219 endif
220endforeach
221
222foreach f : ['strtof', 'mkostemp', 'posix_memalign']
223 if cc.has_function(f)
224 pre_args += '-DHAVE_@0@'.format(f.to_upper())
225 endif
226endforeach
227
228# strtod locale support
229if cc.links('''
230 #define _GNU_SOURCE
231 #include <stdlib.h>
232 #include <locale.h>
233 #ifdef HAVE_XLOCALE_H
234 #include <xlocale.h>
235 #endif
236 int main() {
237 locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
238 const char *s = "1.0";
239 char *end;
240 double d = strtod_l(s, end, loc);
241 float f = strtod_l(s, end, loc);
242 freelocale(loc);
243 return 0;
244 }''',
245 extra_args : pre_args,
246 name : 'strtod has locale support')
247 pre_args += '-DHAVE_STRTOD_L'
248endif
249
250# Check for some linker flags
251ld_args_bsymbolic = []
252if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic')
253 ld_args_bsymbolic += '-Wl,-Bsymbolic'
254endif
255ld_args_gc_sections = []
256if cc.links('static char unused() { return 5; } int main() { return 0; }',
257 args : '-Wl,--gc-sections')
258 ld_args_gc_sections += '-Wl,--gc-sections'
259endif
260
261# check for dl support
262if cc.has_function('dlopen')
263 dep_dl = []
264else
265 dep_dl = cc.find_library('dl')
266endif
267pre_args += '-DHAVE_DLOPEN'
268
269if not cc.has_function('dladdr', dependencies : dep_dl)
270 error('dl library doesn\'t have dladdr')
271endif
272
273if cc.has_function('dl_iterate_phdr')
274 pre_args += '-DHAVE_DL_ITERATE_PHDR'
275else
276 # TODO: this is required for vulkan
277endif
278
279# Determine whether or not the rt library is needed for time functions
280if cc.has_function('clock_gettime')
281 dep_clock = []
282else
283 dep_clock = cc.find_library('rt')
284endif
285
286# TODO: some of these may be conditional
287dep_zlib = dependency('zlib', version : '>= 1.2.3')
288dep_thread = dependency('threads')
289pre_args += '-DHAVE_PTHREAD'
290dep_elf = dependency('libelf')
291dep_expat = dependency('expat')
292# this only exists on linux so either this is linux and it will be found, or
293# its not linux and and wont
294dep_m = cc.find_library('m', required : false)
295
296# TODO: conditionalize libdrm requirement
297dep_libdrm = dependency('libdrm', version : '>= 2.4.75')
298pre_args += '-DHAVE_LIBDRM'
Dylan Baker673dda82017-09-20 11:53:29 -0700299dep_libdrm_amdgpu = []
300if with_amd_vk
301 dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.82')
302endif
303
304llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
305if with_amd_vk
306 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
307endif
308dep_llvm = dependency(
309 'llvm', version : '>= 3.9.0', required : false, modules : llvm_modules,
310)
311if not dep_llvm.found()
312 if with_amd_vk
313 error('Radv requires llvm.')
314 endif
315else
316 _llvm_version = dep_llvm.version().split('.')
317 # Development versions of LLVM have an 'svn' suffix, we don't want that for
318 # our version checks.
319 _llvm_patch = _llvm_version[2]
320 if _llvm_patch.endswith('svn')
321 _llvm_patch = _llvm_patch.split('s')[0]
322 endif
323 pre_args += [
324 '-DHAVE_LLVM=0x0@0@@1@@2@'.format(_llvm_version[0], _llvm_version[1], _llvm_patch),
325 '-DMESA_LLVM_VERSION_PATCH=@0@'.format(_llvm_patch),
326 ]
327endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700328
329# TODO: make this conditional
330dep_valgrind = dependency('valgrind', required : false)
331if dep_valgrind.found() and with_valgrind
332 pre_args += '-DHAVE_VALGRIND'
333endif
334
335# pthread stubs. Lets not and say we didn't
336
337# TODO: selinux
338
339# TODO: llvm-prefix and llvm-shared-libs
340
Dylan Bakerd1992252017-09-14 17:57:17 -0700341# TODO: unwind (llvm [radeon, gallivm] and gallium)
342
343# TODO: flags for opengl, gles, dri
344
345# TODO: gallium-hud
346
347# TODO: glx provider
348
349# TODO: osmesa provider
350
351# TODO: flags for xa, egl, gbm, nin, xvmc, vdpau, omx, va, opencl,
352# gallium-tests,
353
354# TODO: gallium drivers
355
356# TODO: libglvnd
357
358# TODO: symbol mangling
359
360# TODO: dri handling
361
362# TODO: shared-glapi
363
364# TODO: libgl requirements
365
366# TODO: GLX configuration
367
368# TODO: egl configuration
369
370if with_platform_wayland
371 prog_wl_scanner = find_program('wayland-scanner')
372 dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8')
373 dep_wayland_client = dependency('wayland-client', version : '>=1.11')
374 dep_wayland_server = dependency('wayland-server', version : '>=1.11')
375else
376 prog_wl_scanner = []
377 dep_wl_protocols = []
378 dep_wayland_client = []
379 dep_wayland_server = []
380endif
381
382dep_xcb_dri2 = []
383dep_xcb_dri3 = []
384if with_platform_x11
385 dep_xcb_dri2 = [
386 dependency('x11-xcb'),
387 dependency('xcb'),
388 dependency('xcb-dri2', version : '>= 1.8'),
389 dependency('xcb-xfixes'),
390 ]
391 if with_dri3
392 dep_xcb_dri3 = [
393 dep_xcb_dri2,
394 dependency('xcb-dri3'),
395 dependency('xcb-present'),
396 dependency('xcb-sync'),
397 dependency('xshmfence', version : '>= 1.1'),
398 ]
399 else
400 # TODO: dri3 is required for vulkan
401 endif
402endif
403
404# TODO: platforms for !vulkan
405
406# TODO: dri paths
407
408# TODO: dri drivers
409
410# TODO: osmesa
411
412# TODO: egl
413
414# TODO: xa
415
416# TODO: vallium G3DVL
417
418# TODO: nine
419
420# TODO: clover
421
422# TODO: egl sans x11
423
424# TODO: xvmc
425
426# TODO: gallium tests
427
428# TODO: various libdirs
429
430# TODO: swr
431
432# TODO: gallium driver dirs
433
434# FIXME: this is a workaround for #2326
435prog_touch = find_program('touch')
436dummy_cpp = custom_target(
437 'dummy_cpp',
438 output : 'dummy.cpp',
439 command : [prog_touch, '@OUTPUT@'],
440)
441
442foreach a : pre_args
443 add_project_arguments(a, language : ['c', 'cpp'])
444endforeach
445foreach a : c_args
446 add_project_arguments(a, language : ['c'])
447endforeach
448foreach a : cpp_args
449 add_project_arguments(a, language : ['cpp'])
450endforeach
451
452inc_include = include_directories('include')
453
454subdir('include')
455subdir('src')