intel/blorp: Add fast-clear to the special case in MSAA resolves
[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(
22 'mesa',
23 ['c', 'cpp'],
24 version : run_command(
25 [find_program('python', 'python2', 'python3'), 'bin/meson_get_version.py']
26 ).stdout(),
27 license : 'MIT',
28 meson_version : '>= 0.42',
29 default_options : ['buildtype=debugoptimized', 'c_std=c99', 'cpp_std=c++11']
30 )
31
32 # Arguments for the preprocessor, put these in a separate array from the C and
33 # C++ (cpp in meson terminology) arguments since they need to be added to the
34 # default arguments for both C and C++.
35 pre_args = [
36 '-D__STDC_CONSTANT_MACROS',
37 '-D__STDC_FORMAT_MACROS',
38 '-D__STDC_LIMIT_MACROS',
39 '-DVERSION="@0@"'.format(meson.project_version()),
40 '-DPACKAGE_VERSION=VERSION',
41 '-DPACKAGE_BUGREPORT="https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa"',
42 ]
43
44 with_vulkan_icd_dir = get_option('vulkan-icd-dir')
45 with_tests = get_option('build-tests')
46 with_valgrind = get_option('valgrind')
47 with_libunwind = get_option('libunwind')
48 with_asm = get_option('asm')
49 with_osmesa = get_option('osmesa')
50 if get_option('texture-float')
51 pre_args += '-DTEXTURE_FLOAT_ENABLED'
52 message('WARNING: Floating-point texture enabled. Please consult docs/patents.txt and your lawyer before building mesa.')
53 endif
54
55 dri_drivers_path = get_option('dri-drivers-path')
56 if dri_drivers_path == ''
57 dri_drivers_path = join_paths(get_option('libdir'), 'dri')
58 endif
59
60 with_gles1 = get_option('gles1')
61 with_gles2 = get_option('gles2')
62 with_opengl = get_option('opengl')
63 with_any_opengl = with_opengl or with_gles1 or with_gles2
64 # Only build shared_glapi if at least one OpenGL API is enabled
65 with_shared_glapi = get_option('shared-glapi') and with_any_opengl
66
67
68 # shared-glapi is required if at least two OpenGL APIs are being built
69 if not with_shared_glapi
70 if ((with_gles1 and with_gles2) or (with_gles1 and with_opengl)
71 or (with_gles2 and with_opengl))
72 error('shared-glapi required for building two or more of OpenGL, OpenGL ES 1.x, OpenGL ES 2.x')
73 endif
74 endif
75
76 # We require OpenGL for OpenGL ES
77 if (with_gles1 or with_gles2) and not with_opengl
78 error('building OpenGL ES without OpenGL is not supported.')
79 endif
80
81 with_dri = false
82 with_dri_i915 = false
83 with_dri_i965 = false
84 with_dri_r100 = false
85 with_dri_r200 = false
86 with_dri_nouveau = false
87 with_dri_swrast = false
88 _drivers = get_option('dri-drivers')
89 if _drivers == 'auto'
90 # TODO: PPC, Sparc
91 if not ['darwin', 'windows'].contains(host_machine.system())
92 if ['x86', 'x86_64'].contains(host_machine.cpu_family())
93 _drivers = 'i915,i965,r100,r200,nouveau'
94 else
95 error('Unknown architecture. Please pass -Ddri-drivers to set driver options. Patches gladly accepted to fix this.')
96 endif
97 else
98 error('Unknown OS. Please pass -Ddri-drivers to set driver options. Patches gladly accepted to fix this.')
99 endif
100 endif
101 if _drivers != ''
102 _split = _drivers.split(',')
103 with_dri_i915 = _split.contains('i915')
104 with_dri_i965 = _split.contains('i965')
105 with_dri_r100 = _split.contains('r100')
106 with_dri_r200 = _split.contains('r200')
107 with_dri_nouveau = _split.contains('nouveau')
108 with_dri_swrast = _split.contains('swrast')
109 with_dri = true
110 endif
111
112 with_gallium = false
113 with_gallium_pl111 = false
114 with_gallium_radeonsi = false
115 with_gallium_nouveau = false
116 with_gallium_freedreno = false
117 with_gallium_softpipe = false
118 with_gallium_vc4 = false
119 with_gallium_vc5 = false
120 with_gallium_etnaviv = false
121 with_gallium_imx = false
122 _drivers = get_option('gallium-drivers')
123 if _drivers == 'auto'
124 if not ['darwin', 'windows'].contains(host_machine.system())
125 # TODO: PPC, Sparc
126 if ['x86', 'x86_64'].contains(host_machine.cpu_family())
127 _drivers = 'radeonsi,nouveau,swrast'
128 elif ['arm', 'aarch64'].contains(host_machine.cpu_family())
129 _drivers = 'pl111,vc4,vc5,freedreno,etnaviv,imx,swrast'
130 else
131 error('Unknown architecture. Please pass -Dgallium-drivers to set driver options. Patches gladly accepted to fix this.')
132 endif
133 else
134 error('Unknown OS. Please pass -Dgallium-drivers to set driver options. Patches gladly accepted to fix this.')
135 endif
136 endif
137 if _drivers != ''
138 _split = _drivers.split(',')
139 with_gallium_pl111 = _split.contains('pl111')
140 with_gallium_radeonsi = _split.contains('radeonsi')
141 with_gallium_nouveau = _split.contains('nouveau')
142 with_gallium_freedreno = _split.contains('freedreno')
143 with_gallium_softpipe = _split.contains('swrast')
144 with_gallium_vc4 = _split.contains('vc4')
145 with_gallium_vc5 = _split.contains('vc5')
146 with_gallium_etnaviv = _split.contains('etnaviv')
147 with_gallium_imx = _split.contains('imx')
148 with_gallium = true
149 endif
150
151 with_intel_vk = false
152 with_amd_vk = false
153 with_any_vk = false
154 _vulkan_drivers = get_option('vulkan-drivers')
155 if _vulkan_drivers == 'auto'
156 if not ['darwin', 'windows'].contains(host_machine.system())
157 if host_machine.cpu_family().startswith('x86')
158 _vulkan_drivers = 'amd,intel'
159 else
160 error('Unknown architecture. Please pass -Dvulkan-drivers to set driver options. Patches gladly accepted to fix this.')
161 endif
162 else
163 # No vulkan driver supports windows or macOS currently
164 _vulkan_drivers = ''
165 endif
166 endif
167 if _vulkan_drivers != ''
168 _split = _vulkan_drivers.split(',')
169 with_intel_vk = _split.contains('intel')
170 with_amd_vk = _split.contains('amd')
171 with_any_vk = with_amd_vk or with_intel_vk
172 endif
173
174 if with_dri_swrast and with_gallium_softpipe
175 error('Only one swrast provider can be built')
176 endif
177 if with_gallium_imx and not with_gallium_etnaviv
178 error('IMX driver requires etnaviv driver')
179 endif
180
181 dep_libdrm_intel = []
182 if with_dri_i915
183 dep_libdrm_intel = dependency('libdrm_intel', version : '>= 2.4.75')
184 endif
185
186 if host_machine.system() == 'darwin'
187 with_dri_platform = 'apple'
188 elif ['windows', 'cygwin'].contains(host_machine.system())
189 with_dri_platform = 'windows'
190 elif host_machine.system() == 'linux'
191 # FIXME: This should include BSD and possibly other systems
192 with_dri_platform = 'drm'
193 else
194 # FIXME: haiku doesn't use dri, and xlib doesn't use dri, probably should
195 # assert here that one of those cases has been met.
196 # FIXME: GNU (hurd) ends up here as well, but meson doesn't officially
197 # support Hurd at time of writing (2017/11)
198 with_dri_platform = 'none'
199 endif
200
201 with_platform_android = false
202 with_platform_wayland = false
203 with_platform_x11 = false
204 with_platform_drm = false
205 with_platform_surfaceless = false
206 egl_native_platform = ''
207 _platforms = get_option('platforms')
208 if _platforms == 'auto'
209 if ['linux'].contains(host_machine.system())
210 _platforms = 'x11,wayland,drm,surfaceless'
211 else
212 error('Unknown OS, no platforms enabled. Patches gladly accepted to fix this.')
213 endif
214 endif
215 if _platforms != ''
216 _split = _platforms.split(',')
217 with_platform_android = _split.contains('android')
218 with_platform_x11 = _split.contains('x11')
219 with_platform_wayland = _split.contains('wayland')
220 with_platform_drm = _split.contains('drm')
221 with_platform_surfaceless = _split.contains('surfaceless')
222 egl_native_platform = _split[0]
223 endif
224
225 with_glx = get_option('glx')
226 if with_glx == 'auto'
227 if with_dri
228 with_glx = 'dri'
229 elif with_gallium
230 # Even when building just gallium drivers the user probably wants dri
231 with_glx = 'dri'
232 with_dri = true
233 elif with_platform_x11 and with_any_opengl and not with_any_vk
234 # The automatic behavior should not be to turn on xlib based glx when
235 # building only vulkan drivers
236 with_glx = 'xlib'
237 else
238 with_glx = 'disabled'
239 endif
240 endif
241
242 if not (with_dri or with_gallium or with_glx == 'xlib' or with_glx == 'gallium-xlib')
243 with_gles1 = false
244 with_gles2 = false
245 with_opengl = false
246 with_any_opengl = false
247 with_shared_glapi = false
248 endif
249
250 with_gbm = get_option('gbm')
251 if with_gbm == 'auto' and with_dri # TODO: or gallium
252 with_gbm = host_machine.system() == 'linux'
253 elif with_gbm == 'true'
254 if not ['linux', 'bsd'].contains(host_machine.system())
255 error('GBM only supports unix-like platforms')
256 endif
257 with_gbm = true
258 else
259 with_gbm = false
260 endif
261
262 _egl = get_option('egl')
263 if _egl == 'auto'
264 with_egl = with_dri and with_shared_glapi and egl_native_platform != ''
265 elif _egl == 'true'
266 if not with_dri
267 error('EGL requires dri')
268 elif not with_shared_glapi
269 error('EGL requires shared-glapi')
270 elif egl_native_platform == ''
271 error('No platforms specified, consider -Dplatforms=drm,x11 at least')
272 endif
273 with_egl = true
274 else
275 with_egl = false
276 endif
277
278 # TODO: or virgl
279 if with_egl and with_gallium_radeonsi and not (with_platform_drm or with_platform_surfaceless)
280 error('RadeonSI requires drm or surfaceless platform when using EGL')
281 endif
282
283 pre_args += '-DGLX_USE_TLS'
284 if with_glx != 'disabled'
285 if not (with_platform_x11 and with_any_opengl)
286 if with_glx == 'auto'
287 with_glx = 'disabled'
288 else
289 error('Cannot build GLX support without X11 platform support and at least one OpenGL API')
290 endif
291 elif with_glx == 'gallium-xlib'
292 if not with_gallium
293 error('Gallium-xlib based GLX requires at least one gallium driver')
294 elif not with_gallium_softpipe
295 error('Gallium-xlib based GLX requires softpipe or llvmpipe.')
296 elif with_dri
297 error('gallium-xlib conflicts with any dri driver')
298 endif
299 elif with_glx == 'xlib'
300 if with_dri
301 error('xlib conflicts with any dri driver')
302 endif
303 elif with_glx == 'dri' and not with_dri
304 error('dri based GLX requires at least one DRI driver')
305 endif
306 endif
307
308 with_glvnd = get_option('glvnd')
309 if with_glvnd
310 if with_glx == 'xlib' or with_glx == 'gallium-xlib'
311 error('Cannot build glvnd support for GLX that is not DRI based.')
312 elif with_glx == 'disabled' and not with_egl
313 error('glvnd requires DRI based GLX and/or EGL')
314 endif
315 endif
316
317 # TODO: toggle for this
318 with_glx_direct = true
319
320 if with_vulkan_icd_dir == ''
321 with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
322 endif
323
324 with_dri2 = (with_dri or with_any_vk) and with_dri_platform == 'drm'
325 with_dri3 = get_option('dri3')
326 if with_dri3 == 'auto'
327 if host_machine.system() == 'linux' and with_dri2
328 with_dri3 = true
329 else
330 with_dri3 = false
331 endif
332 elif with_dri3 == 'true'
333 with_dri3 = true
334 else
335 with_dri3 = false
336 endif
337
338 if with_any_vk and (with_platform_x11 and not with_dri3)
339 error('Vulkan drivers require dri3 for X11 support')
340 endif
341 if with_dri or with_gallium
342 if with_glx == 'disabled' and not with_egl
343 error('building dri or gallium drivers require at least one window system')
344 endif
345 endif
346
347 with_gallium_xvmc = false
348 with_gallium_vdpau = false
349 with_gallium_omx = false # this is bellagio
350 with_gallium_va = false
351 with_gallium_media = false
352 dep_va = []
353 _drivers = get_option('gallium-media')
354 if _drivers != ''
355 _split = _drivers.split(',')
356 with_gallium_xvmc = _split.contains('xvmc')
357 with_gallium_vdpau = _split.contains('vdpau')
358 with_gallium_omx = _split.contains('omx')
359 with_gallium_va = _split.contains('va')
360 with_gallium_media = (with_gallium_xvmc or with_gallium_vdpau or
361 with_gallium_omx or with_gallium_va)
362 endif
363
364 gl_pkgconfig_c_flags = []
365 if with_platform_x11
366 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
367 pre_args += '-DHAVE_X11_PLATFORM'
368 endif
369 if with_glx == 'xlib' or with_glx == 'gallium-xlib'
370 pre_args += '-DUSE_XSHM'
371 else
372 pre_args += '-DGLX_INDIRECT_RENDERING'
373 if with_glx_direct
374 pre_args += '-DGLX_DIRECT_RENDERING'
375 endif
376 if with_dri_platform == 'drm'
377 pre_args += '-DGLX_USE_DRM'
378 endif
379 endif
380 else
381 pre_args += '-DMESA_EGL_NO_X11_HEADERS'
382 gl_pkgconfig_c_flags += '-DMESA_EGL_NO_X11_HEADERS'
383 endif
384 if with_platform_drm
385 if with_egl and not with_gbm
386 error('EGL drm platform requires gbm')
387 endif
388 pre_args += '-DHAVE_DRM_PLATFORM'
389 endif
390 if with_platform_surfaceless
391 pre_args += '-DHAVE_SURFACELESS_PLATFORM'
392 endif
393 if with_platform_android
394 dep_android = [
395 dependency('cutils'),
396 dependency('hardware'),
397 dependency('sync'),
398 ]
399 pre_args += '-DHAVE_ANDROID_PLATFORM'
400 endif
401
402 prog_python2 = find_program('python2')
403 has_mako = run_command(prog_python2, '-c', 'import mako')
404 if has_mako.returncode() != 0
405 error('Python (2.x) mako module required to build mesa.')
406 endif
407
408 cc = meson.get_compiler('c')
409 if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
410 error('When using GCC, version 4.4.6 or later is required.')
411 endif
412
413 # Define DEBUG for debug builds only (debugoptimized is not included on this one)
414 if get_option('buildtype') == 'debug'
415 pre_args += '-DDEBUG'
416 endif
417
418 if get_option('shader-cache')
419 pre_args += '-DENABLE_SHADER_CACHE'
420 elif with_amd_vk
421 error('Radv requires shader cache support')
422 endif
423
424 # Check for GCC style builtins
425 foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
426 'ffsll', 'popcount', 'popcountll', 'unreachable']
427 if cc.has_function(b)
428 pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
429 endif
430 endforeach
431
432 # check for GCC __attribute__
433 foreach a : ['const', 'flatten', 'malloc', 'pure', 'unused',
434 'warn_unused_result', 'weak',]
435 if cc.compiles('int foo(void) __attribute__((@0@));'.format(a),
436 name : '__attribute__((@0@))'.format(a))
437 pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
438 endif
439 endforeach
440 if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
441 name : '__attribute__((format(...)))')
442 pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
443 endif
444 if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
445 name : '__attribute__((packed))')
446 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
447 endif
448 if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
449 name : '__attribute__((returns_nonnull))')
450 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NONNULL'
451 endif
452 if cc.compiles('''int foo_def(void) __attribute__((visibility("default")));
453 int foo_hid(void) __attribute__((visibility("hidden")));
454 int foo_int(void) __attribute__((visibility("internal")));
455 int foo_pro(void) __attribute__((visibility("protected")));''',
456 name : '__attribute__((visibility(...)))')
457 pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISBILITY'
458 endif
459 if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
460 name : '__attribute__((alias(...)))')
461 pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
462 endif
463
464 # TODO: this is very incomplete
465 if host_machine.system() == 'linux'
466 pre_args += '-D_GNU_SOURCE'
467 endif
468
469 # Check for generic C arguments
470 c_args = []
471 foreach a : ['-Wall', '-Werror=implicit-function-declaration',
472 '-Werror=missing-prototypes', '-fno-math-errno',
473 '-fno-trapping-math', '-Qunused-arguments']
474 if cc.has_argument(a)
475 c_args += a
476 endif
477 endforeach
478 c_vis_args = []
479 if cc.has_argument('-fvisibility=hidden')
480 c_vis_args += '-fvisibility=hidden'
481 endif
482
483 # Check for generic C++ arguments
484 cpp = meson.get_compiler('cpp')
485 cpp_args = []
486 foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math',
487 '-Qunused-arguments', '-Wno-non-virtual-dtor']
488 if cpp.has_argument(a)
489 cpp_args += a
490 endif
491 endforeach
492 cpp_vis_args = []
493 if cpp.has_argument('-fvisibility=hidden')
494 cpp_vis_args += '-fvisibility=hidden'
495 endif
496
497 # Check for C and C++ arguments for MSVC2013 compatibility. These are only used
498 # in parts of the mesa code base that need to compile with old versions of
499 # MSVC, mainly common code
500 c_msvc_compat_args = []
501 cpp_msvc_compat_args = []
502 foreach a : ['-Werror=pointer-arith', '-Werror=vla']
503 if cc.has_argument(a)
504 c_msvc_compat_args += a
505 endif
506 if cpp.has_argument(a)
507 cpp_msvc_compat_args += a
508 endif
509 endforeach
510
511 no_override_init_args = []
512 foreach a : ['-Wno-override-init', '-Wno-initializer-overrides']
513 if cc.has_argument(a)
514 no_override_init_args += a
515 endif
516 endforeach
517
518 if host_machine.cpu_family().startswith('x86')
519 pre_args += '-DHAVE_SSE41'
520 with_sse41 = true
521 sse41_args = ['-msse4.1']
522
523 # GCC on x86 (not x86_64) with -msse* assumes a 16 byte aligned stack, but
524 # that's not guaranteed
525 if host_machine.cpu_family() == 'x86'
526 sse41_args += '-mstackrealign'
527 endif
528 else
529 with_sse41 = false
530 sse41_args = []
531 endif
532
533 # Check for GCC style atomics
534 if cc.compiles('int main() { int n; return __atomic_load_n(&n, __ATOMIC_ACQUIRE); }',
535 name : 'GCC atomic builtins')
536 pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
537 endif
538 if not cc.links('''#include <stdint.h>
539 uint64_t v;
540 int main() {
541 return __sync_add_and_fetch(&v, (uint64_t)1);
542 }''',
543 name : 'GCC 64bit atomics')
544 pre_args += '-DMISSING_64_BIT_ATOMICS'
545 endif
546
547 # TODO: endian
548 # TODO: powr8
549 # TODO: shared/static? Is this even worth doing?
550
551 # Building x86 assembly code requires running x86 binaries. It is possible for
552 # x86_64 OSes to run x86 binaries, so don't disable asm in those cases
553 # TODO: it should be possible to use an exe_wrapper to run the binary during
554 # the build.
555 if meson.is_cross_build()
556 if not (build_machine.cpu_family() == 'x86_64' and host_machine.cpu_family() == 'x86'
557 and build_machine.system() == host_machine.system())
558 message('Cross compiling to x86 from non-x86, disabling asm')
559 with_asm = false
560 endif
561 endif
562
563 with_asm_arch = ''
564 if with_asm
565 # TODO: SPARC and PPC
566 if host_machine.cpu_family() == 'x86'
567 if ['linux', 'bsd'].contains(host_machine.system()) # FIXME: hurd?
568 with_asm_arch = 'x86'
569 pre_args += ['-DUSE_X86_ASM', '-DUSE_MMX_ASM', '-DUSE_3DNOW_ASM',
570 '-DUSE_SSE_ASM']
571 endif
572 elif host_machine.cpu_family() == 'x86_64'
573 if host_machine.system() == 'linux'
574 with_asm_arch = 'x86_64'
575 pre_args += ['-DUSE_X86_64_ASM']
576 endif
577 elif host_machine.cpu_family() == 'arm'
578 if host_machine.system() == 'linux'
579 with_asm_arch = 'arm'
580 pre_args += ['-DUSE_ARM_ASM']
581 endif
582 elif host_machine.cpu_family() == 'aarch64'
583 if host_machine.system() == 'linux'
584 with_asm_arch = 'aarch64'
585 pre_args += ['-DUSE_AARCH64_ASM']
586 endif
587 endif
588 endif
589
590 # Check for standard headers and functions
591 if cc.has_header_symbol('sys/sysmacros.h', 'major')
592 pre_args += '-DMAJOR_IN_SYSMACROS'
593 elif cc.has_header_symbol('sys/mkdev.h', 'major')
594 pre_args += '-DMAJOR_IN_MKDEV'
595 endif
596
597 foreach h : ['xlocale.h', 'sys/sysctl.h', 'linux/futex.h']
598 if cc.has_header(h)
599 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
600 endif
601 endforeach
602
603 foreach f : ['strtof', 'mkostemp', 'posix_memalign', 'timespec_get']
604 if cc.has_function(f)
605 pre_args += '-DHAVE_@0@'.format(f.to_upper())
606 endif
607 endforeach
608
609 # strtod locale support
610 if cc.links('''
611 #define _GNU_SOURCE
612 #include <stdlib.h>
613 #include <locale.h>
614 #ifdef HAVE_XLOCALE_H
615 #include <xlocale.h>
616 #endif
617 int main() {
618 locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
619 const char *s = "1.0";
620 char *end;
621 double d = strtod_l(s, end, loc);
622 float f = strtof_l(s, end, loc);
623 freelocale(loc);
624 return 0;
625 }''',
626 extra_args : pre_args,
627 name : 'strtod has locale support')
628 pre_args += '-DHAVE_STRTOD_L'
629 endif
630
631 # Check for some linker flags
632 ld_args_bsymbolic = []
633 if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic', name : 'Bsymbolic')
634 ld_args_bsymbolic += '-Wl,-Bsymbolic'
635 endif
636 ld_args_gc_sections = []
637 if cc.links('static char unused() { return 5; } int main() { return 0; }',
638 args : '-Wl,--gc-sections', name : 'gc-sections')
639 ld_args_gc_sections += '-Wl,--gc-sections'
640 endif
641 with_ld_version_script = false
642 if cc.links('int main() { return 0; }',
643 args : '-Wl,--version-script=@0@'.format(
644 join_paths(meson.source_root(), 'build-support/conftest.map')),
645 name : 'version-script')
646 with_ld_version_script = true
647 endif
648 with_ld_dynamic_list = false
649 if cc.links('int main() { return 0; }',
650 args : '-Wl,--dynamic-list=@0@'.format(
651 join_paths(meson.source_root(), 'build-support/conftest.dyn')),
652 name : 'dynamic-list')
653 with_ld_dynamic_list = true
654 endif
655
656 # check for dl support
657 if cc.has_function('dlopen')
658 dep_dl = []
659 else
660 dep_dl = cc.find_library('dl')
661 endif
662 if cc.has_function('dladdr', dependencies : dep_dl)
663 # This is really only required for megadrivers
664 pre_args += '-DHAVE_DLADDR'
665 endif
666
667 if cc.has_function('dl_iterate_phdr')
668 pre_args += '-DHAVE_DL_ITERATE_PHDR'
669 elif with_intel_vk
670 error('Intel "Anvil" Vulkan driver requires the dl_iterate_phdr function')
671 elif with_dri_i965 and get_option('shader-cache')
672 error('Intel i965 GL driver requires dl_iterate_phdr when built with shader caching.')
673 endif
674
675 # Determine whether or not the rt library is needed for time functions
676 if cc.has_function('clock_gettime')
677 dep_clock = []
678 else
679 dep_clock = cc.find_library('rt')
680 endif
681
682 with_gallium_drisw_kms = false
683 dep_libdrm = dependency('libdrm', version : '>= 2.4.75',
684 required : with_dri2 or with_dri3)
685 if dep_libdrm.found()
686 pre_args += '-DHAVE_LIBDRM'
687 if with_dri_platform == 'drm' and with_dri
688 with_gallium_drisw_kms = true
689 endif
690 endif
691
692 # TODO: some of these may be conditional
693 dep_zlib = dependency('zlib', version : '>= 1.2.3')
694 dep_thread = dependency('threads')
695 if dep_thread.found() and host_machine.system() != 'windows'
696 pre_args += '-DHAVE_PTHREAD'
697 endif
698 dep_elf = dependency('libelf', required : false)
699 if not dep_elf.found() and (with_amd_vk or with_gallium_radeonsi) # TODO: clover, r600
700 dep_elf = cc.find_library('elf')
701 endif
702 dep_expat = dependency('expat')
703 # this only exists on linux so either this is linux and it will be found, or
704 # its not linux and and wont
705 dep_m = cc.find_library('m', required : false)
706
707 dep_libdrm_amdgpu = []
708 dep_libdrm_radeon = []
709 dep_libdrm_nouveau = []
710 dep_libdrm_etnaviv = []
711 dep_libdrm_freedreno = []
712 if with_amd_vk or with_gallium_radeonsi
713 dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.88')
714 endif
715 if with_gallium_radeonsi or with_dri_r100 or with_dri_r200
716 dep_libdrm_radeon = dependency('libdrm_radeon', version : '>= 2.4.71')
717 endif
718 if with_gallium_nouveau or with_dri_nouveau
719 dep_libdrm_nouveau = dependency('libdrm_nouveau', version : '>= 2.4.66')
720 endif
721 if with_gallium_etnaviv
722 dep_libdrm_etnaviv = dependency('libdrm_etnaviv', version : '>= 2.4.82')
723 endif
724 if with_gallium_freedreno
725 dep_libdrm_freedreno = dependency('libdrm_freedreno', version : '>= 2.4.74')
726 endif
727
728 llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
729 if with_amd_vk or with_gallium_radeonsi
730 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
731 endif
732
733 _llvm = get_option('llvm')
734 if _llvm == 'auto'
735 dep_llvm = dependency(
736 'llvm', version : '>= 3.9.0', modules : llvm_modules,
737 required : with_amd_vk or with_gallium_radeonsi,
738 )
739 with_llvm = dep_llvm.found()
740 elif _llvm == 'true'
741 dep_llvm = dependency('llvm', version : '>= 3.9.0', modules : llvm_modules)
742 with_llvm = true
743 else
744 dep_llvm = []
745 with_llvm = false
746 endif
747 if with_llvm
748 _llvm_version = dep_llvm.version().split('.')
749 # Development versions of LLVM have an 'svn' suffix, we don't want that for
750 # our version checks.
751 _llvm_patch = _llvm_version[2]
752 if _llvm_patch.endswith('svn')
753 _llvm_patch = _llvm_patch.split('s')[0]
754 endif
755 pre_args += [
756 '-DHAVE_LLVM=0x0@0@@1@@2@'.format(_llvm_version[0], _llvm_version[1], _llvm_patch),
757 '-DMESA_LLVM_VERSION_PATCH=@0@'.format(_llvm_patch),
758 ]
759 elif with_amd_vk or with_gallium_radeonsi
760 error('The following drivers requires LLVM: Radv, RadeonSI. One of these is enabled, but LLVM is disabled.')
761 endif
762
763 dep_glvnd = []
764 if with_glvnd
765 dep_glvnd = dependency('libglvnd', version : '>= 0.2.0')
766 pre_args += '-DUSE_LIBGLVND=1'
767 endif
768
769 if with_valgrind != 'false'
770 dep_valgrind = dependency('valgrind', required : with_valgrind == 'true')
771 if dep_valgrind.found()
772 pre_args += '-DHAVE_VALGRIND'
773 endif
774 else
775 dep_valgrind = []
776 endif
777
778 # pthread stubs. Lets not and say we didn't
779
780 prog_bison = find_program('bison', required : with_any_opengl)
781 prog_flex = find_program('flex', required : with_any_opengl)
782
783 dep_selinux = []
784 if get_option('selinux')
785 dep_selinux = dependency('libselinux')
786 pre_args += '-DMESA_SELINUX'
787 endif
788
789 # TODO: llvm-prefix and llvm-shared-libs
790
791 if with_libunwind != 'false'
792 dep_unwind = dependency('libunwind', required : with_libunwind == 'true')
793 if dep_unwind.found()
794 pre_args += '-DHAVE_LIBUNWIND'
795 endif
796 else
797 dep_unwind = []
798 endif
799
800 # TODO: gallium-hud
801
802 if with_osmesa != 'none'
803 if with_osmesa == 'classic' and not with_dri_swrast
804 error('OSMesa classic requires dri (classic) swrast.')
805 endif
806 if with_osmesa == 'gallium' and not with_gallium_softpipe
807 error('OSMesa gallium requires gallium softpipe or llvmpipe.')
808 endif
809 osmesa_lib_name = 'OSMesa'
810 osmesa_bits = get_option('osmesa-bits')
811 if osmesa_bits != '8'
812 if with_dri or with_glx != 'disabled'
813 error('OSMesa bits must be 8 if building glx or dir based drivers')
814 endif
815 osmesa_lib_name = osmesa_lib_name + osmesa_bits
816 pre_args += [
817 '-DCHAN_BITS=@0@'.format(osmesa_bits), '-DDEFAULT_SOFTWARE_DEPTH_BITS=31'
818 ]
819 endif
820 endif
821
822 # TODO: symbol mangling
823
824 if with_platform_wayland
825 prog_wl_scanner = find_program('wayland-scanner')
826 dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8')
827 dep_wayland_client = dependency('wayland-client', version : '>=1.11')
828 dep_wayland_server = dependency('wayland-server', version : '>=1.11')
829 wayland_dmabuf_xml = join_paths(
830 dep_wl_protocols.get_pkgconfig_variable('pkgdatadir'), 'unstable',
831 'linux-dmabuf', 'linux-dmabuf-unstable-v1.xml'
832 )
833 pre_args += ['-DHAVE_WAYLAND_PLATFORM', '-DWL_HIDE_DEPRECATED']
834 else
835 prog_wl_scanner = []
836 dep_wl_protocols = []
837 dep_wayland_client = []
838 dep_wayland_server = []
839 wayland_dmabuf_xml = ''
840 endif
841
842 dep_x11 = []
843 dep_xext = []
844 dep_xdamage = []
845 dep_xfixes = []
846 dep_x11_xcb = []
847 dep_xcb = []
848 dep_xcb_glx = []
849 dep_xcb_dri2 = []
850 dep_xcb_dri3 = []
851 dep_dri2proto = []
852 dep_glproto = []
853 dep_xxf86vm = []
854 dep_xcb_dri3 = []
855 dep_xcb_present = []
856 dep_xcb_sync = []
857 dep_xcb_xfixes = []
858 dep_xshmfence = []
859 if with_platform_x11
860 if with_glx == 'xlib' or with_glx == 'gallium-xlib'
861 dep_x11 = dependency('x11')
862 dep_xext = dependency('xext')
863 dep_xcb = dependency('xcb')
864 elif with_glx == 'dri' and with_dri_platform == 'drm'
865 dep_x11 = dependency('x11')
866 dep_xext = dependency('xext')
867 dep_xdamage = dependency('xdamage', version : '>= 1.1')
868 dep_xfixes = dependency('xfixes')
869 dep_xcb_glx = dependency('xcb-glx', version : '>= 1.8.1')
870 dep_xxf86vm = dependency('xxf86vm', required : false)
871 endif
872 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
873 dep_xcb = dependency('xcb')
874 dep_x11_xcb = dependency('x11-xcb')
875 dep_xcb_dri2 = dependency('xcb-dri2', version : '>= 1.8')
876
877 if with_dri3
878 pre_args += '-DHAVE_DRI3'
879 dep_xcb_dri3 = dependency('xcb-dri3')
880 dep_xcb_present = dependency('xcb-present')
881 dep_xcb_sync = dependency('xcb-sync')
882 dep_xshmfence = dependency('xshmfence', version : '>= 1.1')
883 endif
884 endif
885 if with_glx == 'dri'
886 dep_dri2proto = dependency('dri2proto', version : '>= 2.8')
887 dep_glproto = dependency('glproto', version : '>= 1.4.14')
888 endif
889 if with_egl
890 dep_xcb_xfixes = dependency('xcb-xfixes')
891 endif
892 endif
893
894 # TODO: nine
895
896 # TODO: clover
897
898 # TODO: gallium tests
899
900 # TODO: various libdirs
901
902 # TODO: swr
903
904 # TODO: gallium driver dirs
905
906 # FIXME: this is a workaround for #2326
907 prog_touch = find_program('touch')
908 dummy_cpp = custom_target(
909 'dummy_cpp',
910 output : 'dummy.cpp',
911 command : [prog_touch, '@OUTPUT@'],
912 )
913
914 foreach a : pre_args
915 add_project_arguments(a, language : ['c', 'cpp'])
916 endforeach
917 foreach a : c_args
918 add_project_arguments(a, language : ['c'])
919 endforeach
920 foreach a : cpp_args
921 add_project_arguments(a, language : ['cpp'])
922 endforeach
923
924 inc_include = include_directories('include')
925
926 gl_priv_reqs = [
927 'x11', 'xext', 'xdamage >= 1.1', 'xfixes', 'x11-xcb', 'xcb',
928 'xcb-glx >= 1.8.1', 'libdrm >= 2.4.75',
929 ]
930 if dep_xxf86vm != [] and dep_xxf86vm.found()
931 gl_priv_reqs += 'xxf86vm'
932 endif
933 if with_dri_platform == 'drm'
934 gl_priv_reqs += 'xcb-dri2 >= 1.8'
935 endif
936
937 gl_priv_libs = []
938 if dep_thread.found()
939 gl_priv_libs += ['-lpthread', '-pthread']
940 endif
941 if dep_m.found()
942 gl_priv_libs += '-lm'
943 endif
944 if dep_dl != [] and dep_dl.found()
945 gl_priv_libs += '-ldl'
946 endif
947
948 pkg = import('pkgconfig')
949
950 subdir('include')
951 subdir('bin')
952 subdir('src')