broadcom/vc5: Fix CLIF dumping of lists that aren't capped by a HALT.
[mesa.git] / meson.build
1 # 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
21 project('mesa', ['c', 'cpp'], version : '17.3.0-devel', license : 'MIT',
22 default_options : ['c_std=c99', 'cpp_std=c++11'])
23
24 # Arguments for the preprocessor, put these in a separate array from the C and
25 # C++ (cpp in meson terminology) arguments since they need to be added to the
26 # default arguments for both C and C++.
27 pre_args = [
28 '-D__STDC_CONSTANT_MACROS',
29 '-D__STDC_FORMAT_MACROS',
30 '-D__STDC_LIMIT_MACROS',
31 '-DVERSION="@0@"'.format(meson.project_version()),
32 '-DPACKAGE_VERSION=VERSION',
33 '-DPACKAGE_BUGREPORT="https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa"',
34 ]
35
36 with_vulkan_icd_dir = get_option('vulkan-icd-dir')
37 with_tests = get_option('build-tests')
38 with_valgrind = get_option('valgrind')
39 with_asm = get_option('asm')
40
41 # XXX: yeah, do these
42 with_appledri = false
43 with_windowsdri = false
44
45 dri_drivers_path = get_option('dri-drivers-path')
46 if dri_drivers_path == ''
47 dri_drivers_path = join_paths(get_option('libdir'), 'dri')
48 endif
49
50 with_gles1 = get_option('gles1')
51 with_gles2 = get_option('gles2')
52 with_opengl = get_option('opengl')
53 with_any_opengl = with_opengl or with_gles1 or with_gles2
54 # Only build shared_glapi if at least one OpenGL API is enabled
55 with_shared_glapi = get_option('shared-glapi') and with_any_opengl
56
57 # TODO: these will need options, but at the moment they just control header
58 # installs
59 with_osmesa = false
60
61 # shared-glapi is required if at least two OpenGL APIs are being built
62 if not with_shared_glapi
63 if ((with_gles1 and with_gles2) or (with_gles1 and with_opengl)
64 or (with_gles2 and with_opengl))
65 error('shared-glapi required for building two or more of OpenGL, OpenGL ES 1.x, OpenGL ES 2.x')
66 endif
67 endif
68
69 # We require OpenGL for OpenGL ES
70 if (with_gles1 or with_gles2) and not with_opengl
71 error('building OpenGL ES without OpenGL is not supported.')
72 endif
73
74 with_dri = false
75 with_dri_i965 = false
76 with_dri_swrast = false
77 _drivers = get_option('dri-drivers')
78 if _drivers != ''
79 _split = _drivers.split(',')
80 with_dri_i965 = _split.contains('i965')
81 with_dri_swrast = _split.contains('swrast')
82 with_dri = true
83 endif
84
85 if not with_dri
86 with_gles1 = false
87 with_gles2 = false
88 with_opengl = false
89 with_any_opengl = false
90 with_shared_glapi = false
91 endif
92
93 # TODO: other OSes
94 with_dri_platform = 'drm'
95
96 with_gallium = false
97 # TODO: gallium drivers
98
99 # TODO: conditionalize libdrm requirement
100 dep_libdrm = dependency('libdrm', version : '>= 2.4.75')
101 pre_args += '-DHAVE_LIBDRM'
102
103 with_dri2 = with_dri_platform == 'drm' and dep_libdrm.found()
104 with_dri3 = get_option('dri3')
105 if with_dri3 == 'auto'
106 if host_machine.system() == 'linux' and with_dri2
107 with_dri3 = true
108 else
109 with_dri3 = false
110 endif
111 elif with_dri3 == 'yes'
112 if not with_dri2
113 error('dri3 support requires libdrm')
114 endif
115 with_dri3 = true
116 else
117 with_dri3 = false
118 endif
119
120 # TODO: there are more platforms required for non-vulkan drivers
121 with_platform_wayland = false
122 with_platform_x11 = false
123 _platforms = get_option('platforms')
124 if _platforms != ''
125 _split = _platforms.split(',')
126 with_platform_x11 = _split.contains('x11')
127 with_platform_wayland = _split.contains('wayland')
128 endif
129
130 with_gbm = get_option('gbm')
131 if with_gbm == 'auto' and with_dri # TODO: or gallium
132 with_gbm = host_machine.system() == 'linux'
133 elif with_gbm == 'yes'
134 if not ['linux', 'bsd'].contains(host_machine.system())
135 error('GBM only supports unix-like platforms')
136 endif
137 with_gbm = true
138 else
139 with_gbm = false
140 endif
141
142 with_glx = get_option('glx')
143 if with_glx != 'disabled'
144 pre_args += '-DGLX_USE_TLS'
145 if not (with_platform_x11 and with_any_opengl) and with_glx != 'auto'
146 error('Cannot build GLX support without X11 platform support and at least one OpenGL API')
147 elif with_glx == 'gallium-xlib'
148 if not with_gallium
149 error('Gallium-xlib based GLX requires at least one gallium driver')
150 elif with_dri
151 error('gallium-xlib conflicts with any dri driver')
152 endif
153 elif with_glx == 'dri' and not with_dri
154 error('dri based GLX requires at least one DRI driver')
155 elif with_glx == 'auto'
156 if with_dri
157 with_glx = 'dri'
158 elif with_gallium
159 with_glx = 'gallium-xlib'
160 elif with_platform_x11 and with_any_opengl
161 with_glx = 'xlib'
162 else
163 with_glx = 'disabled'
164 endif
165 endif
166 endif
167
168 with_glvnd = get_option('glvnd')
169 if with_glvnd and with_glx != 'dri'
170 message('glvnd requires dri based glx')
171 endif
172
173 # TODO: toggle for this
174 with_glx_direct = true
175
176 if with_vulkan_icd_dir == ''
177 with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
178 endif
179
180 with_intel_vk = false
181 with_amd_vk = false
182 with_any_vk = false
183 _vulkan_drivers = get_option('vulkan-drivers')
184 if _vulkan_drivers != ''
185 _split = _vulkan_drivers.split(',')
186 with_intel_vk = _split.contains('intel')
187 with_amd_vk = _split.contains('amd')
188 with_any_vk = with_amd_vk or with_intel_vk
189 if not (with_platform_x11 or with_platform_wayland)
190 error('Vulkan requires at least one platform (x11, wayland)')
191 endif
192 if with_platform_x11 and not with_dri3
193 error('Vulkan drivers require dri3 for X11 support')
194 endif
195 endif
196
197 if with_dri # TODO: or gallium
198 if with_glx == 'disabled' # TODO: or egl
199 error('building dri or gallium drivers require at least one window system')
200 endif
201 endif
202
203 prog_python2 = find_program('python2')
204 has_mako = run_command(prog_python2, '-c', 'import mako')
205 if has_mako.returncode() != 0
206 error('Python (2.x) mako module required to build mesa.')
207 endif
208
209 cc = meson.get_compiler('c')
210 if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
211 error('When using GCC, version 4.4.6 or later is required.')
212 endif
213
214 # Define DEBUG for debug and debugoptimized builds
215 if get_option('buildtype').startswith('debug')
216 pre_args += '-DDEBUG'
217 endif
218
219 if get_option('shader-cache')
220 pre_args += '-DENABLE_SHADER_CACHE'
221 elif with_amd_vk
222 error('Radv requires shader cache support')
223 endif
224
225 # Check for GCC style builtins
226 foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
227 'ffsll', 'popcount', 'popcountll', 'unreachable']
228 if cc.has_function(b)
229 pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
230 endif
231 endforeach
232
233 # check for GCC __attribute__
234 foreach a : ['const', 'flatten', 'malloc', 'pure', 'unused',
235 'warn_unused_result', 'weak',]
236 if cc.compiles('int foo(void) __attribute__((@0@));'.format(a),
237 name : '__attribute__((@0@))'.format(a))
238 pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
239 endif
240 endforeach
241 if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
242 name : '__attribute__((format(...)))')
243 pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
244 endif
245 if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
246 name : '__attribute__((packed))')
247 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
248 endif
249 if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
250 name : '__attribute__((returns_nonnull))')
251 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NONNULL'
252 endif
253 if cc.compiles('''int foo_def(void) __attribute__((visibility("default")));
254 int foo_hid(void) __attribute__((visibility("hidden")));
255 int foo_int(void) __attribute__((visibility("internal")));
256 int foo_pro(void) __attribute__((visibility("protected")));''',
257 name : '__attribute__((visibility(...)))')
258 pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISBILITY'
259 endif
260 if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
261 name : '__attribute__((alias(...)))')
262 pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
263 endif
264
265 # TODO: this is very incomplete
266 if host_machine.system() == 'linux'
267 pre_args += '-D_GNU_SOURCE'
268 endif
269
270 # Check for generic C arguments
271 c_args = []
272 foreach a : ['-Wall', '-Werror=implicit-function-declaration',
273 '-Werror=missing-prototypes', '-fno-math-errno',
274 '-fno-trapping-math', '-Qunused-arguments']
275 if cc.has_argument(a)
276 c_args += a
277 endif
278 endforeach
279 c_vis_args = []
280 if cc.has_argument('-fvisibility=hidden')
281 c_vis_args += '-fvisibility=hidden'
282 endif
283
284 # Check for generic C++ arguments
285 cpp = meson.get_compiler('cpp')
286 cpp_args = []
287 foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math',
288 '-Qunused-arguments', '-Wno-non-virtual-dtor']
289 if cpp.has_argument(a)
290 cpp_args += a
291 endif
292 endforeach
293 cpp_vis_args = []
294 if cpp.has_argument('-fvisibility=hidden')
295 cpp_vis_args += '-fvisibility=hidden'
296 endif
297
298 # Check for C and C++ arguments for MSVC2013 compatibility. These are only used
299 # in parts of the mesa code base that need to compile with old versions of
300 # MSVC, mainly common code
301 c_msvc_compat_args = []
302 cpp_msvc_compat_args = []
303 foreach a : ['-Werror=pointer-arith', '-Werror=vla']
304 if cc.has_argument(a)
305 c_msvc_compat_args += a
306 endif
307 if cpp.has_argument(a)
308 cpp_msvc_compat_args += a
309 endif
310 endforeach
311
312 no_override_init_args = []
313 foreach a : ['-Wno-override-init', '-Wno-initializer-overrides']
314 if cc.has_argument(a)
315 no_override_init_args += a
316 endif
317 endforeach
318
319 # TODO: SSE41 (which is only required for core mesa)
320
321 # Check for GCC style atomics
322 if cc.compiles('int main() { int n; return __atomic_load_n(&n, __ATOMIC_ACQUIRE); }',
323 name : 'GCC atomic builtins')
324 pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
325 endif
326 if not cc.links('''#include <stdint.h>
327 uint64_t v;
328 int main() {
329 return __sync_add_and_fetch(&v, (uint64_t)1);
330 }''',
331 name : 'GCC 64bit atomics')
332 pre_args += '-DMISSING_64_BIT_ATOMICS'
333 endif
334
335 # TODO: endian
336 # TODO: powr8
337 # TODO: shared/static? Is this even worth doing?
338
339 # I don't think that I need to set any of the debug stuff, I think meson
340 # handles that for us
341
342 # TODO: ldflags
343
344 # TODO: texture-float (gallium/mesa only)
345
346 # TODO: cross-compiling. I don't think this is relavent to meson
347
348 # FIXME: enable asm when cross compiler
349 # This is doable (autotools does it), but it's not of immediate concern
350 if meson.is_cross_build()
351 message('Cross compiling, disabling asm')
352 with_asm = false
353 endif
354
355 with_asm_arch = ''
356 if with_asm
357 # TODO: SPARC and PPC
358 if host_machine.cpu_family() == 'x86'
359 if ['linux', 'bsd'].contains(host_machine.system()) # FIXME: hurd?
360 with_asm_arch = 'x86'
361 pre_args += ['-DUSE_X86_ASM', '-DUSE_MMX_ASM', '-DUSE_3DNOW_ASM',
362 '-DUSE_SSE_ASM']
363 endif
364 elif host_machine.cpu_family() == 'x86_64'
365 if host_machine.system() == 'linux'
366 with_asm_arch = 'x86_64'
367 pre_args += ['-DUSE_X86_64_ASM']
368 endif
369 elif host_machine.cpu_family() == 'arm'
370 if host_machine.system() == 'linux'
371 with_asm_arch = 'arm'
372 pre_args += ['-DUSE_ARM_ASM']
373 endif
374 elif host_machine.cpu_family() == 'aarch64'
375 if host_machine.system() == 'linux'
376 with_asm_arch = 'aarch64'
377 pre_args += ['-DUSE_AARCH64_ASM']
378 endif
379 endif
380 endif
381
382 # Check for standard headers and functions
383 if cc.has_header_symbol('sys/sysmacros.h', 'major')
384 pre_args += '-DMAJOR_IN_SYSMACROS'
385 elif cc.has_header_symbol('sys/mkdev.h', 'major')
386 pre_args += '-DMAJOR_IN_MKDEV'
387 endif
388
389 foreach h : ['xlocale.h', 'sys/sysctl.h']
390 if cc.has_header(h)
391 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
392 endif
393 endforeach
394
395 foreach f : ['strtof', 'mkostemp', 'posix_memalign']
396 if cc.has_function(f)
397 pre_args += '-DHAVE_@0@'.format(f.to_upper())
398 endif
399 endforeach
400
401 # strtod locale support
402 if cc.links('''
403 #define _GNU_SOURCE
404 #include <stdlib.h>
405 #include <locale.h>
406 #ifdef HAVE_XLOCALE_H
407 #include <xlocale.h>
408 #endif
409 int main() {
410 locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
411 const char *s = "1.0";
412 char *end;
413 double d = strtod_l(s, end, loc);
414 float f = strtod_l(s, end, loc);
415 freelocale(loc);
416 return 0;
417 }''',
418 extra_args : pre_args,
419 name : 'strtod has locale support')
420 pre_args += '-DHAVE_STRTOD_L'
421 endif
422
423 # Check for some linker flags
424 ld_args_bsymbolic = []
425 if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic')
426 ld_args_bsymbolic += '-Wl,-Bsymbolic'
427 endif
428 ld_args_gc_sections = []
429 if cc.links('static char unused() { return 5; } int main() { return 0; }',
430 args : '-Wl,--gc-sections')
431 ld_args_gc_sections += '-Wl,--gc-sections'
432 endif
433
434 # check for dl support
435 if cc.has_function('dlopen')
436 dep_dl = []
437 else
438 dep_dl = cc.find_library('dl')
439 endif
440 if cc.has_function('dladdr', dependencies : dep_dl)
441 # This is really only required for megadrivers
442 pre_args += '-DHAVE_DLADDR'
443 endif
444
445 if cc.has_function('dl_iterate_phdr')
446 pre_args += '-DHAVE_DL_ITERATE_PHDR'
447 else
448 # TODO: this is required for vulkan
449 endif
450
451 # Determine whether or not the rt library is needed for time functions
452 if cc.has_function('clock_gettime')
453 dep_clock = []
454 else
455 dep_clock = cc.find_library('rt')
456 endif
457
458 # TODO: some of these may be conditional
459 dep_zlib = dependency('zlib', version : '>= 1.2.3')
460 dep_thread = dependency('threads')
461 pre_args += '-DHAVE_PTHREAD'
462 dep_elf = dependency('libelf', required : false)
463 if not dep_elf.found()
464 dep_elf = cc.find_library('elf', required : with_amd_vk) # TODO: clover, r600, radeonsi
465 endif
466 dep_expat = dependency('expat')
467 # this only exists on linux so either this is linux and it will be found, or
468 # its not linux and and wont
469 dep_m = cc.find_library('m', required : false)
470
471 dep_libdrm_amdgpu = []
472 if with_amd_vk
473 dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.82')
474 endif
475
476 llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
477 if with_amd_vk
478 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
479 endif
480 dep_llvm = dependency(
481 'llvm', version : '>= 3.9.0', required : false, modules : llvm_modules,
482 )
483 if not dep_llvm.found()
484 if with_amd_vk
485 error('Radv requires llvm.')
486 endif
487 else
488 _llvm_version = dep_llvm.version().split('.')
489 # Development versions of LLVM have an 'svn' suffix, we don't want that for
490 # our version checks.
491 _llvm_patch = _llvm_version[2]
492 if _llvm_patch.endswith('svn')
493 _llvm_patch = _llvm_patch.split('s')[0]
494 endif
495 pre_args += [
496 '-DHAVE_LLVM=0x0@0@@1@@2@'.format(_llvm_version[0], _llvm_version[1], _llvm_patch),
497 '-DMESA_LLVM_VERSION_PATCH=@0@'.format(_llvm_patch),
498 ]
499 endif
500
501 dep_glvnd = []
502 if with_glvnd
503 dep_glvnd = dependency('libglvnd', version : '>= 0.2.0')
504 pre_args += '-DUSE_LIBGLVND=1'
505 endif
506
507 # TODO: make this conditional
508 dep_valgrind = dependency('valgrind', required : false)
509 if dep_valgrind.found() and with_valgrind
510 pre_args += '-DHAVE_VALGRIND'
511 endif
512
513 # pthread stubs. Lets not and say we didn't
514
515 prog_bison = find_program('bison', required : with_any_opengl)
516 prog_flex = find_program('flex', required : with_any_opengl)
517
518 # TODO: selinux
519 dep_selinux = []
520
521 # TODO: llvm-prefix and llvm-shared-libs
522
523 # TODO: unwind (llvm [radeon, gallivm] and gallium)
524
525 # TODO: flags for opengl, gles, dri
526
527 # TODO: gallium-hud
528
529 # TODO: glx provider
530
531 # TODO: osmesa provider
532
533 # TODO: flags for xa, egl, gbm, nin, xvmc, vdpau, omx, va, opencl,
534 # gallium-tests,
535
536 # TODO: gallium drivers
537
538 # TODO: symbol mangling
539
540 # TODO: egl configuration
541
542 if with_platform_wayland
543 prog_wl_scanner = find_program('wayland-scanner')
544 dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8')
545 dep_wayland_client = dependency('wayland-client', version : '>=1.11')
546 dep_wayland_server = dependency('wayland-server', version : '>=1.11')
547 else
548 prog_wl_scanner = []
549 dep_wl_protocols = []
550 dep_wayland_client = []
551 dep_wayland_server = []
552 endif
553
554 dep_xcb_dri2 = []
555 dep_xcb_dri3 = []
556 dep_dri2proto = []
557 dep_glproto = []
558 dep_x11 = []
559 dep_xf86vm = []
560 if with_platform_x11
561 if with_glx == 'xlib'
562 # TODO
563 error('TODO')
564 elif with_glx == 'gallium-xlib'
565 # TODO
566 error('TODO')
567 else
568 pre_args += '-DGLX_INDIRECT_RENDERING'
569 if with_glx_direct
570 pre_args += '-DGLX_DIRECT_RENDERING'
571 endif
572 if with_dri_platform == 'drm'
573 pre_args += '-DGLX_USE_DRM'
574 dep_dri2proto = dependency('dri2proto', version : '>= 2.8')
575 dep_x11 = [
576 dependency('x11'),
577 dependency('xext'),
578 dependency('xdamage', version : '>= 1.1'),
579 dependency('xfixes'),
580 dependency('x11-xcb'),
581 dependency('xcb'),
582 dependency('xcb-glx', version : '>= 1.8.1'),
583 ]
584
585 dep_xf86vm = dependency('xf86vm', required : false)
586 endif
587 # TODO: XF86VIDMODE
588 endif
589 if with_glx != 'disabled'
590 dep_glproto = dependency('glproto', version : '>= 1.4.14')
591 endif
592 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
593 dep_xcb_dri2 = [
594 dependency('x11-xcb'),
595 dependency('xcb'),
596 dependency('xcb-dri2', version : '>= 1.8'),
597 dependency('xcb-xfixes'),
598 ]
599 pre_args += '-DHAVE_X11_PLATFORM'
600 if with_dri3
601 pre_args += '-DHAVE_DRI3'
602 dep_xcb_dri3 = [
603 dep_xcb_dri2,
604 dependency('xcb-dri3'),
605 dependency('xcb-present'),
606 dependency('xcb-sync'),
607 dependency('xshmfence', version : '>= 1.1'),
608 ]
609 endif
610 endif
611 endif
612
613 # TODO: platforms for !vulkan
614
615 # TODO: osmesa
616
617 # TODO: egl
618
619 # TODO: xa
620
621 # TODO: vallium G3DVL
622
623 # TODO: nine
624
625 # TODO: clover
626
627 # TODO: egl sans x11
628
629 # TODO: xvmc
630
631 # TODO: gallium tests
632
633 # TODO: various libdirs
634
635 # TODO: swr
636
637 # TODO: gallium driver dirs
638
639 # FIXME: this is a workaround for #2326
640 prog_touch = find_program('touch')
641 dummy_cpp = custom_target(
642 'dummy_cpp',
643 output : 'dummy.cpp',
644 command : [prog_touch, '@OUTPUT@'],
645 )
646
647 foreach a : pre_args
648 add_project_arguments(a, language : ['c', 'cpp'])
649 endforeach
650 foreach a : c_args
651 add_project_arguments(a, language : ['c'])
652 endforeach
653 foreach a : cpp_args
654 add_project_arguments(a, language : ['cpp'])
655 endforeach
656
657 inc_include = include_directories('include')
658
659 pkg = import('pkgconfig')
660
661 subdir('include')
662 subdir('src')