Fix coredump for swrast
[platform/upstream/mesa.git] / meson.build
1 # Copyright © 2017-2020 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('python3', 'python'), 'bin/meson_get_version.py'],
26     check : true
27   ).stdout(),
28   license : 'MIT',
29   meson_version : '>= 0.53',
30   default_options : ['buildtype=debugoptimized', 'b_ndebug=if-release', 'c_std=c11', 'cpp_std=c++17', 'rust_std=2021']
31 )
32
33 # In recent versions, meson can inject some extra arguments to get richer
34 # results from gtest based tests.  Feature was added in 0.55, but requiring
35 # 0.59.2 to include an important fix.  See https://github.com/mesonbuild/meson/pull/9283.
36 gtest_test_protocol = 'exitcode'
37 if meson.version().version_compare('>= 0.59.2')
38   gtest_test_protocol = 'gtest'
39 endif
40
41 cc = meson.get_compiler('c')
42 cpp = meson.get_compiler('cpp')
43
44 null_dep = dependency('', required : false)
45
46 if get_option('layout') != 'mirror'
47   error('`mirror` is the only build directory layout supported')
48 endif
49
50 # Arguments for the preprocessor, put these in a separate array from the C and
51 # C++ (cpp in meson terminology) arguments since they need to be added to the
52 # default arguments for both C and C++.
53 pre_args = [
54   '-D__STDC_CONSTANT_MACROS',
55   '-D__STDC_FORMAT_MACROS',
56   '-D__STDC_LIMIT_MACROS',
57   '-DPACKAGE_VERSION="@0@"'.format(meson.project_version()),
58   '-DPACKAGE_BUGREPORT="https://gitlab.freedesktop.org/mesa/mesa/-/issues"',
59 ]
60 c_args = []
61 cpp_args = []
62
63 with_moltenvk_dir = get_option('moltenvk-dir')
64 with_vulkan_icd_dir = get_option('vulkan-icd-dir')
65 with_tests = get_option('build-tests')
66 with_glcpp_tests = get_option('enable-glcpp-tests')
67 with_aco_tests = get_option('build-aco-tests')
68 with_glx_read_only_text = get_option('glx-read-only-text')
69 with_glx_direct = get_option('glx-direct')
70 with_osmesa = get_option('osmesa')
71 with_vulkan_overlay_layer = get_option('vulkan-layers').contains('overlay')
72 with_vulkan_device_select_layer = get_option('vulkan-layers').contains('device-select')
73 with_tools = get_option('tools')
74 if with_tools.contains('all')
75   with_tools = [
76     'drm-shim',
77     'dlclose-skip',
78     'etnaviv',
79     'freedreno',
80     'glsl',
81     'intel',
82     'intel-ui',
83     'lima',
84     'nir',
85     'nouveau',
86     'asahi',
87     'imagination',
88   ]
89 endif
90
91 with_any_vulkan_layers = get_option('vulkan-layers').length() != 0
92 with_intel_tools = with_tools.contains('intel') or with_tools.contains('intel-ui')
93 with_imgui = with_intel_tools or with_vulkan_overlay_layer
94
95 dri_drivers_path = get_option('dri-drivers-path')
96 if dri_drivers_path == ''
97   dri_drivers_path = join_paths(get_option('prefix'), get_option('libdir'), 'dri')
98 endif
99 dri_search_path = get_option('dri-search-path')
100 if dri_search_path == ''
101   dri_search_path = dri_drivers_path
102 endif
103
104 gbm_backends_path = get_option('gbm-backends-path')
105 if gbm_backends_path == ''
106   gbm_backends_path = join_paths(get_option('prefix'), get_option('libdir'), 'gbm')
107 endif
108
109 with_gles1 = get_option('gles1')
110 if with_gles1 == 'true'
111   with_gles1 = 'enabled'
112   warning('gles1 option "true" deprecated, please use "enabled" instead.')
113 elif with_gles1 == 'false'
114   with_gles1 = 'disabled'
115   warning('gles1 option "false" deprecated, please use "disabled" instead.')
116 endif
117 with_gles2 = get_option('gles2')
118 if with_gles2 == 'true'
119   with_gles2 = 'enabled'
120   warning('gles2 option "true" deprecated, please use "enabled" instead.')
121 elif with_gles2 == 'false'
122   with_gles2 = 'disabled'
123   warning('gles2 option "false" deprecated, please use "disabled" instead.')
124 endif
125 if host_machine.system() == 'windows'
126   if with_gles1 == 'auto'
127     with_gles1 = 'disabled'
128   endif
129   if with_gles2 == 'auto'
130     with_gles2 = 'disabled'
131   endif
132 endif
133 with_opengl = get_option('opengl')
134
135 # Default shared glapi off for windows, on elsewhere.
136 _sg = get_option('shared-glapi')
137 if _sg == 'true'
138   _sg = 'enabled'
139   warning('shared-glapi option "true" deprecated, please use "enabled" instead.')
140 elif _sg == 'false'
141   _sg = 'disabled'
142   warning('shared-glapi option "false" deprecated, please use "disabled" instead.')
143 endif
144 if _sg == 'auto'
145   with_shared_glapi = host_machine.system() != 'windows'
146 else
147   with_shared_glapi = _sg == 'enabled'
148 endif
149
150 # shared-glapi is required if at least two OpenGL APIs are being built
151 if not with_shared_glapi
152   if ((with_gles1 == 'enabled' and with_gles2 == 'enabled') or
153       (with_gles1 == 'enabled' and with_opengl) or
154       (with_gles2 == 'enabled' and with_opengl))
155     error('shared-glapi required for building two or more of OpenGL, OpenGL ES 1.x, OpenGL ES 2.x')
156   endif
157   with_gles1 = 'disabled'
158   with_gles2 = 'disabled'
159 endif
160
161 # We require OpenGL for OpenGL ES
162 if not with_opengl
163   if (with_gles1 == 'enabled' or with_gles2 == 'enabled') and not with_opengl
164     error('building OpenGL ES without OpenGL is not supported.')
165   endif
166   with_gles1 = 'disabled'
167   with_gles2 = 'disabled'
168 endif
169
170 with_gles1 = with_gles1 != 'disabled'
171 with_gles2 = with_gles2 != 'disabled'
172 with_any_opengl = with_opengl or with_gles1 or with_gles2
173 # Only build shared_glapi if at least one OpenGL API is enabled
174 with_shared_glapi = with_shared_glapi and with_any_opengl
175
176 system_has_kms_drm = ['openbsd', 'netbsd', 'freebsd', 'gnu/kfreebsd', 'dragonfly', 'linux', 'sunos', 'android'].contains(host_machine.system())
177
178 with_freedreno_kgsl = get_option('freedreno-kgsl')
179 if with_freedreno_kgsl
180   system_has_kms_drm = false
181 endif
182
183 dri_drivers = get_option('dri-drivers')
184 if dri_drivers.length() != 0
185   error('Mesa\'s main branch no longer has any "classic" drivers, use the "amber" branch instead.')
186 endif
187
188 gallium_drivers = get_option('gallium-drivers')
189 if gallium_drivers.contains('auto')
190   if system_has_kms_drm
191     # TODO: PPC, Sparc
192     if ['x86', 'x86_64'].contains(host_machine.cpu_family())
193       gallium_drivers = [
194         'r300', 'r600', 'radeonsi', 'nouveau', 'virgl', 'svga', 'swrast',
195         'iris', 'crocus', 'i915'
196       ]
197     elif ['arm', 'aarch64'].contains(host_machine.cpu_family())
198       gallium_drivers = [
199         'v3d', 'vc4', 'freedreno', 'etnaviv', 'nouveau', 'svga',
200         'tegra', 'virgl', 'lima', 'panfrost', 'swrast'
201       ]
202     elif ['mips', 'mips64', 'riscv32', 'riscv64'].contains(host_machine.cpu_family())
203       gallium_drivers = [
204         'r300', 'r600', 'radeonsi', 'nouveau', 'virgl', 'swrast'
205       ]
206     else
207       error('Unknown architecture @0@. Please pass -Dgallium-drivers to set driver options. Patches gladly accepted to fix this.'.format(
208             host_machine.cpu_family()))
209     endif
210   elif ['darwin', 'windows', 'cygwin', 'haiku'].contains(host_machine.system())
211     gallium_drivers = ['swrast']
212   else
213     error('Unknown OS @0@. Please pass -Dgallium-drivers to set driver options. Patches gladly accepted to fix this.'.format(
214           host_machine.system()))
215   endif
216 endif
217 with_gallium_radeonsi = gallium_drivers.contains('radeonsi')
218 with_gallium_r300 = gallium_drivers.contains('r300')
219 with_gallium_r600 = gallium_drivers.contains('r600')
220 with_gallium_nouveau = gallium_drivers.contains('nouveau')
221 with_gallium_freedreno = gallium_drivers.contains('freedreno')
222 with_gallium_softpipe = gallium_drivers.contains('swrast')
223 with_gallium_vc4 = gallium_drivers.contains('vc4')
224 with_gallium_v3d = gallium_drivers.contains('v3d')
225 with_gallium_panfrost = gallium_drivers.contains('panfrost')
226 with_gallium_etnaviv = gallium_drivers.contains('etnaviv')
227 with_gallium_tegra = gallium_drivers.contains('tegra')
228 with_gallium_crocus = gallium_drivers.contains('crocus')
229 with_gallium_iris = gallium_drivers.contains('iris')
230 with_gallium_i915 = gallium_drivers.contains('i915')
231 with_gallium_svga = gallium_drivers.contains('svga')
232 with_gallium_virgl = gallium_drivers.contains('virgl')
233 with_gallium_lima = gallium_drivers.contains('lima')
234 with_gallium_zink = gallium_drivers.contains('zink')
235 with_gallium_d3d12 = gallium_drivers.contains('d3d12')
236 with_gallium_asahi = gallium_drivers.contains('asahi')
237 foreach gallium_driver : gallium_drivers
238   pre_args += '-DHAVE_@0@'.format(gallium_driver.to_upper())
239 endforeach
240
241 with_gallium = gallium_drivers.length() != 0
242 with_gallium_kmsro = with_gallium_v3d or with_gallium_vc4 or with_gallium_etnaviv or with_gallium_panfrost or with_gallium_lima or with_gallium_freedreno or with_gallium_asahi
243
244 if not system_has_kms_drm
245    with_gallium_kmsro = false
246 endif
247
248 with_dri = false
249 if with_gallium and system_has_kms_drm
250   _glx = get_option('glx')
251   _egl = get_option('egl')
252   if _glx == 'dri' or _egl == 'enabled' or (_glx == 'disabled' and _egl != 'disabled')
253     with_dri = true
254   endif
255 endif
256
257 _vulkan_drivers = get_option('vulkan-drivers')
258 if _vulkan_drivers.contains('auto')
259   if system_has_kms_drm
260     if host_machine.cpu_family().startswith('x86')
261       _vulkan_drivers = ['amd', 'intel', 'intel_hasvk', 'swrast']
262     elif ['arm', 'aarch64'].contains(host_machine.cpu_family())
263       _vulkan_drivers = ['swrast']
264     elif ['mips', 'mips64', 'riscv32', 'riscv64'].contains(host_machine.cpu_family())
265       _vulkan_drivers = ['amd', 'swrast']
266     else
267       error('Unknown architecture @0@. Please pass -Dvulkan-drivers to set driver options. Patches gladly accepted to fix this.'.format(
268             host_machine.cpu_family()))
269     endif
270   elif ['darwin', 'windows', 'cygwin', 'haiku'].contains(host_machine.system())
271     # No vulkan driver supports windows or macOS currently
272     _vulkan_drivers = []
273   else
274     error('Unknown OS @0@. Please pass -Dvulkan-drivers to set driver options. Patches gladly accepted to fix this.'.format(
275           host_machine.system()))
276   endif
277 endif
278
279 with_intel_vk = _vulkan_drivers.contains('intel')
280 with_intel_hasvk = _vulkan_drivers.contains('intel_hasvk')
281 with_amd_vk = _vulkan_drivers.contains('amd')
282 with_freedreno_vk = _vulkan_drivers.contains('freedreno')
283 with_panfrost_vk = _vulkan_drivers.contains('panfrost')
284 with_swrast_vk = _vulkan_drivers.contains('swrast')
285 with_virtio_vk = _vulkan_drivers.contains('virtio-experimental')
286 with_freedreno_virtio = get_option('freedreno-virtio')
287 with_broadcom_vk = _vulkan_drivers.contains('broadcom')
288 with_imagination_vk = _vulkan_drivers.contains('imagination-experimental')
289 with_imagination_srv = get_option('imagination-srv')
290 with_microsoft_vk = _vulkan_drivers.contains('microsoft-experimental')
291 with_any_vk = _vulkan_drivers.length() != 0
292
293 with_any_broadcom = with_gallium_vc4 or with_gallium_v3d or with_broadcom_vk
294 with_any_intel = with_intel_vk or with_intel_hasvk or with_gallium_iris or with_gallium_crocus or with_intel_tools
295
296 if with_swrast_vk and not with_gallium_softpipe
297   error('swrast vulkan requires gallium swrast')
298 endif
299 if with_gallium_tegra and not with_gallium_nouveau
300   error('tegra driver requires nouveau driver')
301 endif
302 if with_aco_tests and not with_amd_vk
303   error('ACO tests require Radv')
304 endif
305
306 with_microsoft_clc = get_option('microsoft-clc').enabled()
307 if ['x86_64'].contains(host_machine.cpu_family())
308   with_intel_clc = get_option('intel-clc').enabled()
309   with_intel_vk_rt = with_intel_vk and with_intel_clc
310 else
311   with_intel_clc = false
312   with_intel_vk_rt = false
313 endif
314 with_clc = with_microsoft_clc or with_intel_clc
315 with_libclc = with_clc
316 with_spirv_to_dxil = get_option('spirv-to-dxil')
317
318 if host_machine.system() == 'darwin'
319   with_dri_platform = 'apple'
320   pre_args += '-DBUILDING_MESA'
321 elif ['windows', 'cygwin'].contains(host_machine.system())
322   with_dri_platform = 'windows'
323 elif system_has_kms_drm
324   with_dri_platform = 'drm'
325 else
326   # FIXME: haiku doesn't use dri, and xlib doesn't use dri, probably should
327   # assert here that one of those cases has been met.
328   # FIXME: illumos ends up here as well
329   with_dri_platform = 'none'
330 endif
331
332 with_vulkan_beta = get_option('vulkan-beta')
333 if with_vulkan_beta
334   pre_args += '-DVK_ENABLE_BETA_EXTENSIONS'
335 endif
336
337 _codecs = get_option('video-codecs')
338 foreach c : ['vc1dec', 'h264dec', 'h264enc', 'h265dec', 'h265enc']
339    pre_args += '-DVIDEO_CODEC_@0@=@1@'.format(c.to_upper(), _codecs.contains(c).to_int())
340 endforeach
341
342 _platforms = get_option('platforms')
343 if _platforms.contains('auto')
344   if system_has_kms_drm
345     _platforms = ['x11', 'wayland', 'tizen']
346   elif ['darwin', 'cygwin'].contains(host_machine.system())
347     _platforms = ['x11']
348   elif ['haiku'].contains(host_machine.system())
349     _platforms = ['haiku']
350   elif host_machine.system() == 'windows'
351     _platforms = ['windows']
352   else
353     error('Unknown OS @0@. Please pass -Dplatforms to set platforms. Patches gladly accepted to fix this.'.format(
354           host_machine.system()))
355   endif
356 endif
357
358 with_platform_android = _platforms.contains('android')
359 with_platform_x11 = _platforms.contains('x11')
360 with_platform_wayland = _platforms.contains('wayland')
361 with_platform_tizen = _platforms.contains('tizen')
362 with_platform_haiku = _platforms.contains('haiku')
363 with_platform_windows = _platforms.contains('windows')
364
365 with_glx = get_option('glx')
366 if with_glx == 'auto'
367   if with_platform_android
368     with_glx = 'disabled'
369   elif with_dri
370     with_glx = 'dri'
371   elif with_platform_haiku
372     with_glx = 'disabled'
373   elif host_machine.system() == 'windows'
374     with_glx = 'disabled'
375   elif with_gallium
376     # Even when building just gallium drivers the user probably wants dri
377     with_glx = 'dri'
378   elif with_platform_x11 and with_any_opengl and not with_any_vk
379     # The automatic behavior should not be to turn on xlib based glx when
380     # building only vulkan drivers
381     with_glx = 'xlib'
382   else
383     with_glx = 'disabled'
384   endif
385 endif
386 if with_glx == 'dri'
387    if with_gallium
388       with_dri = true
389    endif
390 endif
391
392 if not (with_dri or with_gallium or with_glx != 'disabled')
393   with_gles1 = false
394   with_gles2 = false
395   with_opengl = false
396   with_any_opengl = false
397   with_shared_glapi = false
398 endif
399
400 _gbm = get_option('gbm')
401 if _gbm == 'true'
402   _gbm = 'enabled'
403   warning('gbm option "true" deprecated, please use "enabled" instead.')
404 elif _gbm == 'false'
405   _gbm = 'disabled'
406   warning('gbm option "false" deprecated, please use "disabled" instead.')
407 endif
408 if _gbm == 'auto'
409   with_gbm = system_has_kms_drm and with_dri
410 else
411   with_gbm = _gbm == 'enabled'
412 endif
413 if with_gbm and not system_has_kms_drm
414   error('GBM only supports DRM/KMS platforms')
415 endif
416
417 _xlib_lease = get_option('xlib-lease')
418 if _xlib_lease == 'true'
419   _xlib_lease = 'enabled'
420   warning('xlib_lease option "true" deprecated, please use "enabled" instead.')
421 elif _xlib_lease == 'false'
422   _xlib_lease = 'disabled'
423   warning('xlib_lease option "false" deprecated, please use "disabled" instead.')
424 endif
425 if _xlib_lease == 'auto'
426   with_xlib_lease = with_platform_x11 and system_has_kms_drm
427 else
428   with_xlib_lease = _xlib_lease == 'enabled'
429 endif
430
431 if with_platform_wayland
432   c_args += '-DVK_USE_PLATFORM_WAYLAND_KHR'
433   #add this once aco and other places can build with it
434   #cpp_args += '-DVK_USE_PLATFORM_WAYLAND_KHR'
435 endif
436 if with_platform_x11
437   c_args += ['-DVK_USE_PLATFORM_XCB_KHR', '-DVK_USE_PLATFORM_XLIB_KHR']
438   #add this once aco and other places can build with it
439   #cpp_args += ['-DVK_USE_PLATFORM_XCB_KHR', '-DVK_USE_PLATFORM_XLIB_KHR']
440 endif
441 if with_platform_windows
442   c_args += '-DVK_USE_PLATFORM_WIN32_KHR'
443   #add this once aco and other places can build with it
444   #cpp_args += '-DVK_USE_PLATFORM_WIN32_KHR'
445 endif
446 if with_platform_android
447   c_args += '-DVK_USE_PLATFORM_ANDROID_KHR'
448   cpp_args += '-DVK_USE_PLATFORM_ANDROID_KHR'
449 endif
450 if with_xlib_lease
451   c_args += '-DVK_USE_PLATFORM_XLIB_XRANDR_EXT'
452   #add this once aco and other places can build with it
453   #cpp_args += '-DVK_USE_PLATFORM_XLIB_XRANDR_EXT'
454 endif
455 if system_has_kms_drm and not with_platform_android
456   c_args += '-DVK_USE_PLATFORM_DISPLAY_KHR'
457   cpp_args += '-DVK_USE_PLATFORM_DISPLAY_KHR'
458 endif
459 if host_machine.system() == 'darwin'
460   c_args += '-DVK_USE_PLATFORM_MACOS_MVK'
461   cpp_args += '-DVK_USE_PLATFORM_MACOS_MVK'
462   c_args += '-DVK_USE_PLATFORM_METAL_EXT'
463   cpp_args += '-DVK_USE_PLATFORM_METAL_EXT'
464   #macOS seems to need beta extensions to build for now:
465   c_args += '-DVK_ENABLE_BETA_EXTENSIONS'
466   cpp_args += '-DVK_ENABLE_BETA_EXTENSIONS'
467 endif
468
469 _egl = get_option('egl')
470 if _egl == 'true'
471   _egl = 'enabled'
472   warning('egl option "true" deprecated, please use "enabled" instead.')
473 elif _egl == 'false'
474   _egl = 'disabled'
475   warning('egl option "false" deprecated, please use "disabled" instead.')
476 endif
477 if _egl == 'auto'
478   with_egl = (
479     host_machine.system() != 'darwin' and
480     (with_platform_windows or with_dri) and
481     with_shared_glapi
482   )
483 elif _egl == 'enabled'
484   if not with_dri and not with_platform_haiku and not with_platform_windows
485     error('EGL requires dri, haiku, or windows')
486   elif not with_shared_glapi
487     error('EGL requires shared-glapi')
488   elif not ['disabled', 'dri'].contains(with_glx)
489     error('EGL requires dri, but a GLX is being built without dri')
490   elif host_machine.system() == 'darwin'
491     error('EGL is not available on MacOS')
492   endif
493   with_egl = true
494 else
495   with_egl = false
496 endif
497
498 if with_egl
499   _platforms += 'surfaceless'
500   if with_gbm and not with_platform_android
501     _platforms += 'drm'
502   endif
503
504   egl_native_platform = get_option('egl-native-platform')
505   if egl_native_platform.contains('auto')
506     egl_native_platform = _platforms[0]
507   endif
508 endif
509
510 if with_egl and not _platforms.contains(egl_native_platform)
511   error('-Degl-native-platform does not specify an enabled platform')
512 endif
513
514 if 'x11' in _platforms
515   _platforms += 'xcb'
516 endif
517
518 foreach platform : _platforms
519   pre_args += '-DHAVE_@0@_PLATFORM'.format(platform.to_upper())
520 endforeach
521
522 if with_platform_android and get_option('platform-sdk-version') >= 29
523   # By default the NDK compiler, at least, emits emutls references instead of
524   # ELF TLS, even when building targeting newer API levels.  Make it actually do
525   # ELF TLS instead.
526   c_args += '-fno-emulated-tls'
527   cpp_args += '-fno-emulated-tls'
528 endif
529
530 # -mtls-dialect=gnu2 speeds up non-initial-exec TLS significantly but requires
531 # full toolchain (including libc) support.
532 have_mtls_dialect = false
533 foreach c_arg : get_option('c_args')
534   if c_arg.startswith('-mtls-dialect=')
535     have_mtls_dialect = true
536     break
537   endif
538 endforeach
539 if not have_mtls_dialect
540   # need .run to check libc support. meson aborts when calling .run when
541   # cross-compiling, but because this is just an optimization we can skip it
542   if meson.is_cross_build() and not meson.has_exe_wrapper()
543     warning('cannot auto-detect -mtls-dialect when cross-compiling, using compiler default')
544   else
545     # -fpic to force dynamic tls, otherwise TLS relaxation defeats check
546     gnu2_test = cc.run('int __thread x; int main() { return x; }',
547                        args: ['-mtls-dialect=gnu2', '-fpic'],
548                        name: '-mtls-dialect=gnu2')
549     if gnu2_test.returncode() == 0 and (
550           # check for lld 13 bug: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5665
551           host_machine.cpu_family() != 'x86_64' or
552           # get_linker_id misses LDFLAGS=-fuse-ld=lld: https://github.com/mesonbuild/meson/issues/6377
553           #cc.get_linker_id() != 'ld.lld' or
554           cc.links('''int __thread x; int y; int main() { __asm__(
555                 "leaq x@TLSDESC(%rip), %rax\n"
556                 "movq y@GOTPCREL(%rip), %rdx\n"
557                 "call *x@TLSCALL(%rax)\n"); }''', name: 'split TLSDESC')
558           )
559       c_args += '-mtls-dialect=gnu2'
560       cpp_args += '-mtls-dialect=gnu2'
561     endif
562   endif
563 endif
564
565 if with_glx != 'disabled'
566   if not (with_platform_x11 and with_any_opengl)
567     error('Cannot build GLX support without X11 platform support and at least one OpenGL API')
568   elif with_glx == 'xlib'
569     if not with_gallium
570       error('xlib based GLX requires at least one gallium driver')
571     elif not with_gallium_softpipe
572       error('xlib based GLX requires softpipe or llvmpipe.')
573     elif with_dri
574       error('xlib conflicts with any dri driver')
575     endif
576   elif with_glx == 'dri'
577     if not with_shared_glapi
578       error('dri based GLX requires shared-glapi')
579     endif
580   endif
581 endif
582
583 with_glvnd = get_option('glvnd')
584 glvnd_vendor_name = get_option('glvnd-vendor-name')
585 if with_glvnd
586   if with_platform_windows
587     error('glvnd cannot be used on Windows')
588   elif with_glx == 'xlib'
589     error('Cannot build glvnd support for GLX that is not DRI based.')
590   elif with_glx == 'disabled' and not with_egl
591     error('glvnd requires DRI based GLX and/or EGL')
592   endif
593   if get_option('egl-lib-suffix') != ''
594     error('''EGL lib suffix can't be used with libglvnd''')
595   endif
596 endif
597
598 if with_vulkan_icd_dir == ''
599   with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
600 endif
601
602 # GNU/Hurd includes egl_dri2, without drm.
603 with_dri2 = (with_dri or with_any_vk) and (with_dri_platform == 'drm' or
604   host_machine.system() == 'gnu')
605 _dri3 = get_option('dri3')
606 if _dri3 == 'true'
607   _dri3 = 'enabled'
608   warning('dri3 option "true" deprecated, please use "enabled" instead.')
609 elif _dri3 == 'false'
610   _dri3 = 'disabled'
611   warning('dri3 option "false" deprecated, please use "disabled" instead.')
612 endif
613 if _dri3 == 'auto'
614   with_dri3 = system_has_kms_drm and with_dri2
615 else
616   with_dri3 = _dri3 == 'enabled'
617 endif
618
619 if with_any_vk and (with_platform_x11 and not with_dri3)
620   error('Vulkan drivers require dri3 for X11 support')
621 endif
622 if with_dri
623   if with_glx == 'disabled' and not with_egl and not with_gbm
624     error('building dri drivers require at least one windowing system')
625   endif
626 endif
627
628 if with_gallium_kmsro and (with_platform_x11 and not with_dri3)
629   error('kmsro requires dri3 for X11 support')
630 endif
631
632 dep_dxheaders = null_dep
633 if with_gallium_d3d12 or with_microsoft_clc or with_microsoft_vk
634   dep_dxheaders = dependency('directx-headers', required : false)
635   if not dep_dxheaders.found()
636     dep_dxheaders = dependency('DirectX-Headers',
637       version : '>= 1.606.4',
638       fallback : ['DirectX-Headers', 'dep_dxheaders'],
639       required : with_gallium_d3d12 or with_microsoft_vk
640     )
641   endif
642 endif
643
644 _with_gallium_d3d12_video = get_option('gallium-d3d12-video')
645 with_gallium_d3d12_video = false
646 if with_gallium_d3d12 and not _with_gallium_d3d12_video.disabled()
647   with_gallium_d3d12_video = true
648   pre_args += '-DHAVE_GALLIUM_D3D12_VIDEO'
649 endif
650
651 _vdpau = get_option('gallium-vdpau')
652 if _vdpau == 'true'
653   _vdpau = 'enabled'
654   warning('gallium-vdpau option "true" deprecated, please use "enabled" instead.')
655 elif _vdpau == 'false'
656   _vdpau = 'disabled'
657   warning('gallium-vdpau option "false" deprecated, please use "disabled" instead.')
658 endif
659 if not system_has_kms_drm
660   if _vdpau == 'enabled'
661     error('VDPAU state tracker can only be build on unix-like OSes.')
662   else
663     _vdpau = 'disabled'
664   endif
665 elif not with_platform_x11
666   if _vdpau == 'enabled'
667     error('VDPAU state tracker requires X11 support.')
668   else
669     _vdpau = 'disabled'
670   endif
671 elif not (with_gallium_r300 or with_gallium_r600 or with_gallium_radeonsi or
672           with_gallium_nouveau or with_gallium_d3d12_video or with_gallium_virgl)
673   if _vdpau == 'enabled'
674     error('VDPAU state tracker requires at least one of the following gallium drivers: r300, r600, radeonsi, nouveau, d3d12 (with option gallium-d3d12-video, virgl).')
675   else
676     _vdpau = 'disabled'
677   endif
678 endif
679 dep_vdpau = null_dep
680 with_gallium_vdpau = false
681 if _vdpau != 'disabled'
682   dep_vdpau = dependency('vdpau', version : '>= 1.1', required : _vdpau == 'enabled')
683   if dep_vdpau.found()
684     dep_vdpau = dep_vdpau.partial_dependency(compile_args : true)
685     with_gallium_vdpau = true
686   endif
687 endif
688
689 if with_gallium_vdpau
690   pre_args += '-DHAVE_ST_VDPAU'
691 endif
692 vdpau_drivers_path = get_option('vdpau-libs-path')
693 if vdpau_drivers_path == ''
694   vdpau_drivers_path = join_paths(get_option('libdir'), 'vdpau')
695 endif
696
697 if with_vulkan_overlay_layer or with_aco_tests or with_amd_vk
698   prog_glslang = find_program('glslangValidator')
699   if run_command(prog_glslang, [ '--quiet', '--version' ], check : false).returncode() == 0
700     glslang_quiet = ['--quiet']
701   else
702     glslang_quiet = []
703   endif
704 endif
705
706 dep_xv = null_dep
707 _omx = get_option('gallium-omx')
708 if not system_has_kms_drm
709   if ['auto', 'disabled'].contains(_omx)
710     _omx = 'disabled'
711   else
712     error('OMX state tracker can only be built on unix-like OSes.')
713   endif
714 elif not (with_gallium_r600 or with_gallium_radeonsi or with_gallium_nouveau)
715   if ['auto', 'disabled'].contains(_omx)
716     _omx = 'disabled'
717   else
718     error('OMX state tracker requires at least one of the following gallium drivers: r600, radeonsi, nouveau.')
719   endif
720 endif
721 with_gallium_omx = _omx
722 dep_omx = null_dep
723 dep_omx_other = []
724 if ['auto', 'bellagio'].contains(_omx)
725   dep_omx = dependency(
726     'libomxil-bellagio', required : _omx == 'bellagio'
727   )
728   if dep_omx.found()
729     with_gallium_omx = 'bellagio'
730   endif
731 endif
732 if ['auto', 'tizonia'].contains(_omx)
733   if with_dri and with_egl
734     dep_omx = dependency(
735       'libtizonia', version : '>= 0.10.0',
736       required : _omx == 'tizonia',
737     )
738     dep_omx_other = [
739       dependency('libtizplatform', required : _omx == 'tizonia'),
740       dependency('tizilheaders', required : _omx == 'tizonia'),
741     ]
742     if dep_omx.found() and dep_omx_other[0].found() and dep_omx_other[1].found()
743       with_gallium_omx = 'tizonia'
744     endif
745   elif _omx == 'tizonia'
746     error('OMX-Tizonia state tracker requires dri and egl')
747   endif
748 endif
749 if _omx == 'auto'
750   with_gallium_omx = 'disabled'
751 else
752   with_gallium_omx = _omx
753 endif
754
755 pre_args += [
756   '-DENABLE_ST_OMX_BELLAGIO=' + (with_gallium_omx == 'bellagio' ? '1' : '0'),
757   '-DENABLE_ST_OMX_TIZONIA=' + (with_gallium_omx == 'tizonia' ? '1' : '0'),
758 ]
759
760
761 omx_drivers_path = get_option('omx-libs-path')
762
763 if with_gallium_omx != 'disabled'
764   # Figure out where to put the omx driver.
765   # FIXME: this could all be vastly simplified by adding a 'defined_variable'
766   # argument to meson's get_variable method.
767   if omx_drivers_path == ''
768     _omx_libdir = dep_omx.get_variable(pkgconfig : 'libdir')
769     _omx_drivers_dir = dep_omx.get_variable(pkgconfig : 'pluginsdir')
770     if _omx_libdir == get_option('libdir')
771       omx_drivers_path = _omx_drivers_dir
772     else
773       _omx_base_dir = []
774       # This will fail on windows. Does OMX run on windows?
775       _omx_libdir = _omx_libdir.split('/')
776       _omx_drivers_dir = _omx_drivers_dir.split('/')
777       foreach o : _omx_drivers_dir
778         if not _omx_libdir.contains(o)
779           _omx_base_dir += o
780         endif
781       endforeach
782       omx_drivers_path = join_paths(get_option('libdir'), _omx_base_dir)
783     endif
784   endif
785 endif
786
787 _va = get_option('gallium-va')
788 if _va == 'true'
789   _va = 'enabled'
790   warning('gallium-va option "true" deprecated, please use "enabled" instead.')
791 elif _va == 'false'
792   _va = 'disabled'
793   warning('gallium-va option "false" deprecated, please use "disabled" instead.')
794 endif
795 if not (with_gallium_r600 or with_gallium_radeonsi or with_gallium_nouveau or with_gallium_d3d12_video or with_gallium_virgl)
796   if _va == 'enabled'
797     error('VA state tracker requires at least one of the following gallium drivers: r600, radeonsi, nouveau, d3d12 (with option gallium-d3d12-video), virgl.')
798   else
799     _va = 'disabled'
800   endif
801 endif
802 with_gallium_va = false
803 dep_va = null_dep
804 if _va != 'disabled'
805   _dep_va_name = 'libva'
806   if host_machine.system() == 'windows'
807     _dep_va_name = 'libva-win32'
808   endif
809   dep_va = dependency(_dep_va_name, version : '>= 1.8.0', required : _va == 'enabled')
810   if dep_va.found()
811     dep_va_headers = dep_va.partial_dependency(compile_args : true)
812     with_gallium_va = true
813     if cc.has_header_symbol('va/va.h', 'VASurfaceAttribDRMFormatModifiers',
814                             dependencies: dep_va_headers)
815       pre_args += '-DHAVE_VA_SURFACE_ATTRIB_DRM_FORMAT_MODIFIERS'
816     endif
817   endif
818 endif
819
820 va_drivers_path = get_option('va-libs-path')
821 if va_drivers_path == ''
822   va_drivers_path = join_paths(get_option('libdir'), 'dri')
823 endif
824
825 _xa = get_option('gallium-xa')
826 if _xa == 'true'
827   _xa = 'enabled'
828   warning('gallium-xa option "true" deprecated, please use "enabled" instead.')
829 elif _xa == 'false'
830   _xa = 'disabled'
831   warning('gallium-xa option "false" deprecated, please use "disabled" instead.')
832 endif
833 if not system_has_kms_drm
834   if _xa == 'enabled'
835     error('XA state tracker can only be built on unix-like OSes.')
836   else
837     _xa = 'disabled'
838   endif
839 elif not (with_gallium_nouveau or with_gallium_freedreno or with_gallium_i915
840           or with_gallium_svga)
841   if _xa == 'enabled'
842     error('XA state tracker requires at least one of the following gallium drivers: nouveau, freedreno, i915, svga.')
843   else
844     _xa = 'disabled'
845   endif
846 endif
847 with_gallium_xa = _xa != 'disabled'
848
849 d3d_drivers_path = get_option('d3d-drivers-path')
850 if d3d_drivers_path == ''
851   d3d_drivers_path = join_paths(get_option('prefix'), get_option('libdir'), 'd3d')
852 endif
853
854 with_gallium_st_nine =  get_option('gallium-nine')
855 if with_gallium_st_nine
856   if not with_gallium_softpipe
857     error('The nine state tracker requires gallium softpipe/llvmpipe.')
858   elif not (with_gallium_radeonsi or with_gallium_nouveau or with_gallium_r600
859             or with_gallium_r300 or with_gallium_svga or with_gallium_i915
860             or with_gallium_iris or with_gallium_crocus or with_gallium_zink)
861     error('The nine state tracker requires at least one non-swrast gallium driver.')
862   endif
863   if not with_dri3
864     error('Using nine with wine requires dri3')
865   endif
866 endif
867 with_gallium_st_d3d10umd =  get_option('gallium-d3d10umd')
868 if with_gallium_st_d3d10umd
869   if not with_gallium_softpipe
870     error('The d3d10umd state tracker requires gallium softpipe/llvmpipe.')
871   endif
872 endif
873 _power8 = get_option('power8')
874 if _power8 == 'true'
875   _power8 = 'enabled'
876   warning('power8 option "true" deprecated, please use "enabled" instead.')
877 elif _power8 == 'false'
878   _power8 = 'disabled'
879   warning('power8 option "false" deprecated, please use "disabled" instead.')
880 endif
881 if _power8 != 'disabled'
882   if host_machine.cpu_family() == 'ppc64' and host_machine.endian() == 'little'
883     if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.8')
884       error('Altivec is not supported with gcc version < 4.8.')
885     endif
886     if cc.compiles('''
887         #include <altivec.h>
888         int main() {
889           vector unsigned char r;
890           vector unsigned int v = vec_splat_u32 (1);
891           r = __builtin_vec_vgbbd ((vector unsigned char) v);
892           return 0;
893         }''',
894         args : '-mpower8-vector',
895         name : 'POWER8 intrinsics')
896       pre_args += ['-D_ARCH_PWR8', '-mpower8-vector']
897     elif get_option('power8') == 'enabled'
898       error('POWER8 intrinsic support required but not found.')
899     endif
900   endif
901 endif
902
903 if get_option('vmware-mks-stats')
904   if not with_gallium_svga
905     error('vmware-mks-stats requires gallium VMware/svga driver.')
906   endif
907   pre_args += '-DVMX86_STATS=1'
908 endif
909
910 _opencl = get_option('gallium-opencl')
911 _rtti = get_option('cpp_rtti')
912 if _opencl != 'disabled'
913   if not with_gallium
914     error('OpenCL Clover implementation requires at least one gallium driver.')
915   endif
916   if not _rtti
917     error('The Clover OpenCL state tracker requires rtti')
918   endif
919
920   with_libclc = true
921   with_gallium_opencl = true
922   with_opencl_icd = _opencl == 'icd'
923 else
924   with_gallium_opencl = false
925   with_opencl_icd = false
926 endif
927
928 with_gallium_rusticl = get_option('gallium-rusticl')
929 if with_gallium_rusticl
930   if not with_gallium
931     error('rusticl requires at least one gallium driver.')
932   endif
933
934   if meson.version().version_compare('< 0.61.4')
935     error('rusticl requires meson 0.61.4 or newer')
936   endif
937
938   add_languages('rust', required: true)
939
940   with_clc = true
941   with_libclc = true
942 endif
943
944 dep_clc = null_dep
945 if with_libclc
946   dep_clc = dependency('libclc')
947 endif
948
949 gl_pkgconfig_c_flags = []
950 if with_platform_x11
951   if with_glx == 'xlib'
952     pre_args += '-DUSE_XSHM'
953   else
954     pre_args += '-DGLX_INDIRECT_RENDERING'
955     if with_glx_direct
956       pre_args += '-DGLX_DIRECT_RENDERING'
957     endif
958     if with_dri_platform == 'drm'
959       pre_args += '-DGLX_USE_DRM'
960     elif with_dri_platform == 'apple'
961       pre_args += '-DGLX_USE_APPLEGL'
962     elif with_dri_platform == 'windows'
963       pre_args += '-DGLX_USE_WINDOWSGL'
964     endif
965   endif
966 endif
967
968 with_android_stub = get_option('android-stub')
969 if with_android_stub and not with_platform_android
970   error('`-D android-stub=true` makes no sense without `-D platforms=android`')
971 endif
972
973 if with_platform_android
974   dep_android_mapper4 = null_dep
975   if not with_android_stub
976     dep_android = [
977       dependency('cutils'),
978       dependency('hardware'),
979       dependency('sync'),
980       dependency('backtrace')
981     ]
982     if get_option('platform-sdk-version') >= 26
983       dep_android += dependency('nativewindow')
984     endif
985     if get_option('platform-sdk-version') >= 30
986       dep_android_mapper4 = dependency('android.hardware.graphics.mapper', version : '>= 4.0', required : false)
987     endif
988   endif
989   pre_args += [
990     '-DANDROID',
991     '-DANDROID_API_LEVEL=' + get_option('platform-sdk-version').to_string()
992   ]
993 endif
994
995 prog_python = import('python').find_installation('python3')
996 has_mako = run_command(
997   prog_python, '-c',
998   '''
999 from distutils.version import StrictVersion
1000 import mako
1001 assert StrictVersion(mako.__version__) > StrictVersion("0.8.0")
1002   ''', check: false)
1003 if has_mako.returncode() != 0
1004   error('Python (3.x) mako module >= 0.8.0 required to build mesa.')
1005 endif
1006
1007 if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
1008   error('When using GCC, version 4.4.6 or later is required.')
1009 endif
1010
1011 # Support systems without ETIME (e.g. FreeBSD)
1012 if cc.get_define('ETIME', prefix : '#include <errno.h>') == ''
1013   pre_args += '-DETIME=ETIMEDOUT'
1014 endif
1015
1016 # Define DEBUG for debug builds only (debugoptimized is not included on this one)
1017 if get_option('buildtype') == 'debug'
1018   pre_args += '-DDEBUG'
1019 endif
1020
1021 with_shader_cache = false
1022 _shader_cache = get_option('shader-cache')
1023 if _shader_cache == 'true'
1024   _shader_cache = 'enabled'
1025   warning('shader_cache option "true" deprecated, please use "enabled" instead.')
1026 elif _shader_cache == 'false'
1027   _shader_cache = 'disabled'
1028   warning('shader_cache option "false" deprecated, please use "disabled" instead.')
1029 endif
1030 if _shader_cache != 'disabled'
1031   if host_machine.system() == 'windows'
1032     if _shader_cache == 'enabled'
1033       error('Shader Cache does not currently work on Windows')
1034     endif
1035   else
1036     pre_args += '-DENABLE_SHADER_CACHE'
1037     if not get_option('shader-cache-default')
1038       pre_args += '-DSHADER_CACHE_DISABLE_BY_DEFAULT'
1039     endif
1040     with_shader_cache = true
1041   endif
1042 endif
1043
1044 if with_shader_cache
1045   shader_cache_max_size = get_option('shader-cache-max-size')
1046   if shader_cache_max_size != ''
1047     pre_args += '-DMESA_SHADER_CACHE_MAX_SIZE="@0@"'.format(shader_cache_max_size)
1048   endif
1049 endif
1050
1051 # Check for GCC style builtins
1052 foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
1053              'ffsll', 'popcount', 'popcountll', 'unreachable', 'types_compatible_p']
1054   if cc.has_function(b)
1055     pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
1056   endif
1057 endforeach
1058
1059 # check for GCC __attribute__
1060 _attributes = [
1061   'const', 'flatten', 'malloc', 'pure', 'unused', 'warn_unused_result',
1062   'weak', 'format', 'packed', 'returns_nonnull', 'alias', 'noreturn',
1063 ]
1064 foreach a : cc.get_supported_function_attributes(_attributes)
1065   pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
1066 endforeach
1067 if cc.has_function_attribute('visibility:hidden')
1068   pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISIBILITY'
1069 endif
1070 if cc.compiles('__uint128_t foo(void) { return 0; }',
1071                name : '__uint128_t')
1072   pre_args += '-DHAVE_UINT128'
1073 endif
1074
1075 if cc.has_function('reallocarray')
1076    pre_args += '-DHAVE_REALLOCARRAY'
1077 endif
1078
1079 # TODO: this is very incomplete
1080 if ['linux', 'cygwin', 'gnu', 'freebsd', 'gnu/kfreebsd', 'haiku', 'android'].contains(host_machine.system())
1081   pre_args += '-D_GNU_SOURCE'
1082 elif host_machine.system() == 'sunos'
1083   pre_args += '-D__EXTENSIONS__'
1084 elif host_machine.system() == 'windows'
1085   pre_args += [
1086     '-D_WINDOWS', '-D_WIN32_WINNT=0x0A00', '-DWINVER=0x0A00',
1087     '-DPIPE_SUBSYSTEM_WINDOWS_USER',
1088     '-D_USE_MATH_DEFINES',  # XXX: scons didn't use this for mingw
1089   ]
1090   if cc.get_argument_syntax() == 'msvc'
1091     pre_args += [
1092       '-DVC_EXTRALEAN',
1093       '-D_CRT_SECURE_NO_WARNINGS',
1094       '-D_CRT_SECURE_NO_DEPRECATE',
1095       '-D_SCL_SECURE_NO_WARNINGS',
1096       '-D_SCL_SECURE_NO_DEPRECATE',
1097       '-D_ALLOW_KEYWORD_MACROS',
1098       '-D_HAS_EXCEPTIONS=0', # Tell C++ STL to not use exceptions
1099       '-DNOMINMAX',
1100     ]
1101   else
1102     # When the target is not mingw/ucrt
1103     # NOTE: clang's stddef.h are conflict with mingw/ucrt's stddef.h
1104     # So do not include headers that defined in clang for detecting
1105     # _UCRT
1106     if cc.compiles('''
1107       #include <string.h>
1108       #if defined(__MINGW32__) && defined(_UCRT)
1109       #error
1110       #endif
1111       int main(void) { return 0; }''')
1112       pre_args += ['-D__MSVCRT_VERSION__=0x0700']
1113     endif
1114   endif
1115 elif host_machine.system() == 'openbsd'
1116   pre_args += '-D_ISOC11_SOURCE'
1117 endif
1118
1119 # Check for generic C arguments
1120 c_msvc_compat_args = []
1121 no_override_init_args = []
1122 cpp_msvc_compat_args = []
1123 ld_args_gc_sections = []
1124 if cc.get_argument_syntax() == 'msvc'
1125   _trial = [
1126     '/wd4018',  # signed/unsigned mismatch
1127     '/wd4056',  # overflow in floating-point constant arithmetic
1128     '/wd4244',  # conversion from 'type1' to 'type2', possible loss of data
1129     '/wd4267',  # 'var' : conversion from 'size_t' to 'type', possible loss of data
1130     '/wd4305',  # trancation from 'type1' to 'type2'
1131     '/wd4351',  # new behavior: elements of array 'array' will be default initialized
1132     '/wd4756',  # overflow in constant arithmetic
1133     '/wd4800',  # forcing value to bool 'true' or 'false' (performance warning)
1134     '/wd4996',  # disabled deprecated POSIX name warnings
1135     '/wd4291',  # no matching operator delete found
1136     '/wd4146',  # unary minus operator applied to unsigned type, result still unsigned
1137     '/wd4200',  # nonstandard extension used: zero-sized array in struct/union
1138     '/wd4624',  # destructor was implicitly defined as deleted [from LLVM]
1139     '/wd4309',  # 'initializing': truncation of constant value
1140     '/wd4838',  # conversion from 'int' to 'const char' requires a narrowing conversion
1141     '/wd5105',  # macro expansion producing 'defined' has undefined behavior (winbase.h, need Windows SDK upgrade)
1142     '/we4020',  # Error when passing the wrong number of parameters
1143     '/we4024',  # Error when passing different type of parameter
1144     '/Zc:__cplusplus', #Set __cplusplus macro to match the /std:c++<version> on the command line
1145   ]
1146   c_args += cc.get_supported_arguments(_trial)
1147   cpp_args += cpp.get_supported_arguments(_trial)
1148 else
1149   _trial_c = [
1150     '-Werror=implicit-function-declaration',
1151     '-Werror=missing-prototypes',
1152     '-Werror=return-type',
1153     '-Werror=empty-body',
1154     '-Werror=incompatible-pointer-types',
1155     '-Werror=int-conversion',
1156     '-Wimplicit-fallthrough',
1157     '-Wno-missing-field-initializers',
1158     '-Wno-format-truncation',
1159     '-fno-math-errno',
1160     '-fno-trapping-math',
1161     '-Qunused-arguments',
1162     '-fno-common',
1163     # Clang
1164     '-Wno-microsoft-enum-value',
1165     '-Wno-unused-function',
1166   ]
1167   _trial_cpp = [
1168     '-Werror=return-type',
1169     '-Werror=empty-body',
1170     '-Wno-non-virtual-dtor',
1171     '-Wno-missing-field-initializers',
1172     '-Wno-format-truncation',
1173     '-fno-math-errno',
1174     '-fno-trapping-math',
1175     '-Qunused-arguments',
1176     # Some classes use custom new operator which zeroes memory, however
1177     # gcc does aggressive dead-store elimination which threats all writes
1178     # to the memory before the constructor as "dead stores".
1179     # For now we disable this optimization.
1180     '-flifetime-dse=1',
1181     # Clang
1182     '-Wno-microsoft-enum-value',
1183   ]
1184
1185   # MinGW chokes on format specifiers and I can't get it all working
1186   if not (cc.get_argument_syntax() == 'gcc' and host_machine.system() == 'windows')
1187     _trial_c += ['-Werror=format', '-Wformat-security']
1188     _trial_cpp += ['-Werror=format', '-Wformat-security']
1189   endif
1190
1191   # FreeBSD annotated <pthread.h> but Mesa isn't ready
1192   if not (cc.get_id() == 'clang' and host_machine.system() == 'freebsd')
1193     _trial_c += ['-Werror=thread-safety']
1194   endif
1195
1196   # If the compiler supports it, put function and data symbols in their
1197   # own sections and GC the sections after linking.  This lets drivers
1198   # drop shared code unused by that specific driver (particularly
1199   # relevant for Vulkan drivers).
1200   if cc.links('static char unused() { return 5; } int main() { return 0; }',
1201               args : '-Wl,--gc-sections', name : 'gc-sections')
1202     ld_args_gc_sections += '-Wl,--gc-sections'
1203     _trial_c += ['-ffunction-sections', '-fdata-sections']
1204     _trial_cpp += ['-ffunction-sections', '-fdata-sections']
1205   endif
1206
1207   # Variables that are only used for assertions are considered unused when assertions
1208   # are disabled. Don't treat this as an error, since we build with -Werror even if
1209   # assertions are disabled.
1210   if get_option('b_ndebug') == 'true' or (get_option('buildtype') == 'release' and get_option('b_ndebug') == 'if-release')
1211     _trial_c += ['-Wno-unused-variable', '-Wno-unused-but-set-variable', '/wd4189']
1212     _trial_cpp += ['-Wno-unused-variable', '-Wno-unused-but-set-variable', '/wd4189']
1213   endif
1214
1215   c_args += cc.get_supported_arguments(_trial_c)
1216   cpp_args += cpp.get_supported_arguments(_trial_cpp)
1217
1218   no_override_init_args += cc.get_supported_arguments(
1219     ['-Wno-override-init', '-Wno-initializer-overrides']
1220   )
1221
1222   # Check for C and C++ arguments for MSVC compatibility. These are only used
1223   # in parts of the mesa code base that need to compile with MSVC, mainly
1224   # common code
1225   _trial_msvc = ['-Werror=pointer-arith', '-Werror=vla', '-Werror=gnu-empty-initializer']
1226   c_msvc_compat_args += cc.get_supported_arguments(_trial_msvc)
1227   cpp_msvc_compat_args += cpp.get_supported_arguments(_trial_msvc)
1228 endif
1229
1230 # set linker arguments
1231 if host_machine.system() == 'windows'
1232   if cc.get_argument_syntax() == 'msvc'
1233     add_project_link_arguments(
1234       '/fixed:no',
1235       '/dynamicbase',
1236       '/nxcompat',
1237       language : ['c', 'cpp'],
1238     )
1239     if get_option('buildtype') != 'debug'
1240       add_project_link_arguments(
1241         '/incremental:no',
1242         language : ['c', 'cpp'],
1243       )
1244     endif
1245   else
1246     add_project_link_arguments(
1247       cc.get_supported_link_arguments(
1248         '-Wl,--nxcompat',
1249         '-Wl,--dynamicbase',
1250         '-static-libgcc',
1251         '-static-libstdc++',
1252       ),
1253       language : ['c'],
1254     )
1255     add_project_link_arguments(
1256       cpp.get_supported_link_arguments(
1257         '-Wl,--nxcompat',
1258         '-Wl,--dynamicbase',
1259         '-static-libgcc',
1260         '-static-libstdc++',
1261       ),
1262       language : ['cpp'],
1263     )
1264   endif
1265 endif
1266
1267 if host_machine.cpu_family().startswith('x86') and cc.get_argument_syntax() != 'msvc'
1268   pre_args += '-DUSE_SSE41'
1269   with_sse41 = true
1270   sse41_args = ['-msse4.1']
1271
1272   if host_machine.cpu_family() == 'x86'
1273     if get_option('sse2')
1274       # These settings make generated GCC code match MSVC and follow
1275       # GCC advice on https://gcc.gnu.org/wiki/FloatingPointMath#x86note
1276       #
1277       # NOTE: We need to ensure stack is realigned given that we
1278       # produce shared objects, and have no control over the stack
1279       # alignment policy of the application. Therefore we need
1280       # -mstackrealign or -mincoming-stack-boundary=2.
1281       #
1282       # XXX: We could have SSE without -mstackrealign if we always used
1283       # __attribute__((force_align_arg_pointer)), but that's not
1284       # always the case.
1285       c_args += ['-msse2', '-mfpmath=sse', '-mstackrealign']
1286     else
1287       # GCC on x86 (not x86_64) with -msse* assumes a 16 byte aligned stack, but
1288       # that's not guaranteed
1289       sse41_args += '-mstackrealign'
1290     endif
1291   endif
1292 else
1293   with_sse41 = false
1294   sse41_args = []
1295 endif
1296
1297 # Check for GCC style atomics
1298 dep_atomic = null_dep
1299
1300 if cc.compiles('''#include <stdint.h>
1301                   int main() {
1302                     struct {
1303                       uint64_t *v;
1304                     } x;
1305                     return (int)__atomic_load_n(x.v, __ATOMIC_ACQUIRE) &
1306                            (int)__atomic_add_fetch(x.v, (uint64_t)1, __ATOMIC_ACQ_REL);
1307
1308                   }''',
1309                name : 'GCC atomic builtins')
1310   pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
1311
1312   # Not all atomic calls can be turned into lock-free instructions, in which
1313   # GCC will make calls into the libatomic library. Check whether we need to
1314   # link with -latomic.
1315   #
1316   # This can happen for 64-bit atomic operations on 32-bit architectures such
1317   # as ARM.
1318   if not cc.links('''#include <stdint.h>
1319                      int main() {
1320                        struct {
1321                          uint64_t *v;
1322                        } x;
1323                        return (int)__atomic_load_n(x.v, __ATOMIC_ACQUIRE) &
1324                               (int)__atomic_add_fetch(x.v, (uint64_t)1, __ATOMIC_ACQ_REL);
1325                      }''',
1326                   name : 'GCC atomic builtins required -latomic')
1327     dep_atomic = cc.find_library('atomic')
1328   endif
1329 endif
1330 if not cc.links('''#include <stdint.h>
1331                    uint64_t v;
1332                    int main() {
1333                      return __sync_add_and_fetch(&v, (uint64_t)1);
1334                    }''',
1335                 dependencies : dep_atomic,
1336                 name : 'GCC 64bit atomics')
1337   pre_args += '-DMISSING_64BIT_ATOMICS'
1338 endif
1339
1340 dep_ws2_32 = cc.find_library('ws2_32', required : with_platform_windows)
1341
1342 # TODO: shared/static? Is this even worth doing?
1343
1344 with_asm_arch = ''
1345 if host_machine.cpu_family() == 'x86'
1346   if system_has_kms_drm or host_machine.system() == 'gnu'
1347     with_asm_arch = 'x86'
1348     pre_args += ['-DUSE_X86_ASM', '-DUSE_MMX_ASM', '-DUSE_3DNOW_ASM',
1349                  '-DUSE_SSE_ASM']
1350
1351     if with_glx_read_only_text
1352       pre_args += ['-DGLX_X86_READONLY_TEXT']
1353     endif
1354   endif
1355 elif host_machine.cpu_family() == 'x86_64'
1356   if system_has_kms_drm
1357     with_asm_arch = 'x86_64'
1358     pre_args += ['-DUSE_X86_64_ASM']
1359   endif
1360 elif host_machine.cpu_family() == 'arm'
1361   if system_has_kms_drm
1362     with_asm_arch = 'arm'
1363     pre_args += ['-DUSE_ARM_ASM']
1364   endif
1365 elif host_machine.cpu_family() == 'aarch64'
1366   if system_has_kms_drm
1367     with_asm_arch = 'aarch64'
1368     pre_args += ['-DUSE_AARCH64_ASM']
1369   endif
1370 elif host_machine.cpu_family() == 'sparc64'
1371   if system_has_kms_drm
1372     with_asm_arch = 'sparc'
1373     pre_args += ['-DUSE_SPARC_ASM']
1374   endif
1375 elif host_machine.cpu_family() == 'ppc64' and host_machine.endian() == 'little'
1376   if system_has_kms_drm
1377     with_asm_arch = 'ppc64le'
1378     pre_args += ['-DUSE_PPC64LE_ASM']
1379   endif
1380 elif host_machine.cpu_family() == 'mips64' and host_machine.endian() == 'little'
1381   if system_has_kms_drm
1382     with_asm_arch = 'mips64el'
1383     pre_args += ['-DUSE_MIPS64EL_ASM']
1384   endif
1385 endif
1386
1387 # Check for standard headers and functions
1388 if (cc.has_header_symbol('sys/sysmacros.h', 'major') and
1389   cc.has_header_symbol('sys/sysmacros.h', 'minor') and
1390   cc.has_header_symbol('sys/sysmacros.h', 'makedev'))
1391   pre_args += '-DMAJOR_IN_SYSMACROS'
1392 endif
1393 if (cc.has_header_symbol('sys/mkdev.h', 'major') and
1394   cc.has_header_symbol('sys/mkdev.h', 'minor') and
1395   cc.has_header_symbol('sys/mkdev.h', 'makedev'))
1396   pre_args += '-DMAJOR_IN_MKDEV'
1397 endif
1398
1399 if cc.check_header('sched.h')
1400   pre_args += '-DHAS_SCHED_H'
1401   if cc.has_function('sched_getaffinity')
1402     pre_args += '-DHAS_SCHED_GETAFFINITY'
1403   endif
1404 endif
1405
1406 if not ['linux'].contains(host_machine.system())
1407   # Deprecated on Linux and requires <sys/types.h> on FreeBSD and OpenBSD
1408   if cc.check_header('sys/sysctl.h', prefix : '#include <sys/types.h>')
1409     pre_args += '-DHAVE_SYS_SYSCTL_H'
1410   endif
1411 endif
1412
1413 foreach h : ['xlocale.h', 'linux/futex.h', 'endian.h', 'dlfcn.h', 'sys/shm.h', 'cet.h', 'pthread_np.h']
1414   if cc.check_header(h)
1415     pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
1416   endif
1417 endforeach
1418
1419 functions_to_detect = {
1420   'strtof': '',
1421   'mkostemp': '',
1422   'timespec_get': '#include <time.h>',
1423   'memfd_create': '',
1424   'random_r': '',
1425   'flock': '',
1426   'strtok_r': '',
1427   'getrandom': '',
1428   'qsort_s': '',
1429 }
1430
1431 foreach f, prefix: functions_to_detect
1432   if cc.has_function(f, prefix: prefix)
1433     pre_args += '-DHAVE_@0@'.format(f.to_upper())
1434   endif
1435 endforeach
1436
1437 if cpp.links('''
1438     #define _GNU_SOURCE
1439     #include <stdlib.h>
1440
1441     static int dcomp(const void *l, const void *r, void *t) { return 0; }
1442
1443     int main(int ac, char **av) {
1444       int arr[] = { 1 };
1445       void *t = NULL;
1446       qsort_r((void*)&arr[0], 1, 1, dcomp, t);
1447       return (0);
1448     }''',
1449     args : pre_args,
1450     name : 'GNU qsort_r')
1451   pre_args += '-DHAVE_GNU_QSORT_R'
1452 elif cpp.links('''
1453     #include <stdlib.h>
1454
1455     static int dcomp(void *t, const void *l, const void *r) { return 0; }
1456
1457     int main(int ac, char **av) {
1458       int arr[] = { 1 };
1459       void *t = NULL;
1460       qsort_r((void*)&arr[0], 1, 1, t, dcomp);
1461       return (0);
1462     }''',
1463     args : pre_args,
1464     name : 'BSD qsort_r')
1465   pre_args += '-DHAVE_BSD_QSORT_R'
1466 endif
1467
1468 if cc.has_header_symbol('time.h', 'struct timespec')
1469    pre_args += '-DHAVE_STRUCT_TIMESPEC'
1470 endif
1471
1472 with_c11_threads = false
1473 if cc.has_function('thrd_create', prefix: '#include <threads.h>')
1474   if with_platform_android
1475     # Current only Android's c11 <threads.h> are verified
1476     pre_args += '-DHAVE_THRD_CREATE'
1477     with_c11_threads = true
1478   endif
1479 endif
1480
1481 if cc.has_header_symbol('errno.h', 'program_invocation_name',
1482                         args : '-D_GNU_SOURCE')
1483    pre_args += '-DHAVE_PROGRAM_INVOCATION_NAME'
1484 elif with_tools.contains('intel')
1485   error('Intel tools require the program_invocation_name variable')
1486 endif
1487
1488 if cc.has_header_symbol('math.h', 'issignaling',
1489                         args : '-D_GNU_SOURCE')
1490    pre_args += '-DHAVE_ISSIGNALING'
1491 endif
1492
1493 # MinGW provides a __builtin_posix_memalign function, but not a posix_memalign.
1494 # This means that this check will succeed, but then compilation will later
1495 # fail. MSVC doesn't have this function at all, so only check for it on
1496 # non-windows platforms.
1497 if host_machine.system() != 'windows'
1498   if cc.has_function('posix_memalign')
1499     pre_args += '-DHAVE_POSIX_MEMALIGN'
1500   endif
1501 endif
1502
1503 if cc.has_member('struct dirent', 'd_type', prefix: '''#include <sys/types.h>
1504    #include <dirent.h>''')
1505    pre_args += '-DHAVE_DIRENT_D_TYPE'
1506 endif
1507
1508 # strtod locale support
1509 if cc.links('''
1510     #define _GNU_SOURCE
1511     #include <stdlib.h>
1512     #include <locale.h>
1513     #ifdef HAVE_XLOCALE_H
1514     #include <xlocale.h>
1515     #endif
1516     int main() {
1517       locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
1518       const char *s = "1.0";
1519       char *end;
1520       double d = strtod_l(s, end, loc);
1521       float f = strtof_l(s, end, loc);
1522       freelocale(loc);
1523       return 0;
1524     }''',
1525     args : pre_args,
1526     name : 'strtod has locale support')
1527   pre_args += '-DHAVE_STRTOD_L'
1528 endif
1529
1530 # Check for some linker flags
1531 ld_args_bsymbolic = []
1532 if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic', name : 'Bsymbolic')
1533   ld_args_bsymbolic += '-Wl,-Bsymbolic'
1534 endif
1535 with_ld_version_script = false
1536 if cc.links('int main() { return 0; }',
1537             args : '-Wl,--version-script=@0@'.format(
1538               join_paths(meson.current_source_dir(), 'build-support/conftest.map')),
1539             name : 'version-script')
1540   with_ld_version_script = true
1541 endif
1542 with_ld_dynamic_list = false
1543 if cc.links('int main() { return 0; }',
1544             args : '-Wl,--dynamic-list=@0@'.format(
1545               join_paths(meson.current_source_dir(), 'build-support/conftest.dyn')),
1546             name : 'dynamic-list')
1547   with_ld_dynamic_list = true
1548 endif
1549
1550 ld_args_build_id = cc.get_supported_link_arguments('-Wl,--build-id=sha1')
1551
1552 # check for dl support
1553 dep_dl = null_dep
1554 if host_machine.system() != 'windows'
1555   if not cc.has_function('dlopen')
1556     dep_dl = cc.find_library('dl', required : true)
1557   endif
1558   if cc.has_function('dladdr', dependencies : dep_dl)
1559     # This is really only required for util/disk_cache.h
1560     pre_args += '-DHAVE_DLADDR'
1561   endif
1562 endif
1563
1564 if cc.has_function('dl_iterate_phdr')
1565   pre_args += '-DHAVE_DL_ITERATE_PHDR'
1566 elif with_intel_vk or with_intel_hasvk
1567   error('Intel "Anvil" Vulkan driver requires the dl_iterate_phdr function')
1568 endif
1569
1570 # Determine whether or not the rt library is needed for time functions
1571 if host_machine.system() == 'windows' or cc.has_function('clock_gettime')
1572   dep_clock = null_dep
1573 else
1574   dep_clock = cc.find_library('rt')
1575 endif
1576
1577 dep_zlib = dependency('zlib', version : '>= 1.2.3',
1578                       fallback : ['zlib', 'zlib_dep'],
1579                       required : get_option('zlib'))
1580 if dep_zlib.found()
1581   pre_args += '-DHAVE_ZLIB'
1582 endif
1583
1584 _zstd = get_option('zstd')
1585 if _zstd == 'true'
1586   _zstd = 'enabled'
1587   warning('zstd option "true" deprecated, please use "enabled" instead.')
1588 elif _zstd == 'false'
1589   _zstd = 'disabled'
1590   warning('zstd option "false" deprecated, please use "disabled" instead.')
1591 endif
1592 if _zstd != 'disabled'
1593   dep_zstd = dependency('libzstd', required : _zstd == 'enabled')
1594   if dep_zstd.found()
1595     pre_args += '-DHAVE_ZSTD'
1596   endif
1597 else
1598   dep_zstd = null_dep
1599 endif
1600
1601 with_compression = dep_zlib.found() or dep_zstd.found()
1602 if with_compression
1603   pre_args += '-DHAVE_COMPRESSION'
1604 elif with_shader_cache
1605   error('Shader Cache requires compression')
1606 endif
1607
1608 if host_machine.system() == 'windows'
1609   # For MSVC and MinGW we aren't using pthreads, and dependency('threads') will add linkage
1610   # to pthread for MinGW, so leave the dependency null_dep for Windows. For Windows linking to
1611   # kernel32 is enough for c11/threads.h and it's already linked by meson by default
1612   dep_thread = null_dep
1613 else
1614   dep_thread = dependency('threads')
1615 endif
1616 if dep_thread.found()
1617   pre_args += '-DHAVE_PTHREAD'
1618   if host_machine.system() != 'netbsd' and cc.has_function(
1619       'pthread_setaffinity_np',
1620       dependencies : dep_thread,
1621       prefix : '#include <pthread.h>',
1622       args : '-D_GNU_SOURCE')
1623     pre_args += '-DHAVE_PTHREAD_SETAFFINITY'
1624   endif
1625 endif
1626 if host_machine.system() == 'darwin'
1627   dep_expat = meson.get_compiler('c').find_library('expat')
1628 elif host_machine.system() != 'windows'
1629   dep_expat = dependency('expat', fallback : ['expat', 'expat_dep'],
1630                          required: not with_platform_android)
1631 else
1632   dep_expat = null_dep
1633 endif
1634 # Predefined macros for windows
1635 if host_machine.system() == 'windows'
1636   pre_args += '-DWIN32_LEAN_AND_MEAN' # http://msdn2.microsoft.com/en-us/library/6dwk3a1z.aspx
1637 endif
1638 # this only exists on linux so either this is linux and it will be found, or
1639 # it's not linux and wont
1640 dep_m = cc.find_library('m', required : false)
1641
1642 if host_machine.system() == 'windows'
1643   dep_regex = meson.get_compiler('c').find_library('regex', required : false)
1644   if not dep_regex.found()
1645     dep_regex = declare_dependency(compile_args : ['-DNO_REGEX'])
1646   endif
1647 else
1648   dep_regex = null_dep
1649 endif
1650
1651 if with_platform_haiku
1652   dep_network = cc.find_library('network')
1653 endif
1654
1655 dep_futex = null_dep
1656 if host_machine.system() == 'windows'
1657   if (get_option('min-windows-version') < 8)
1658     pre_args += '-DWINDOWS_NO_FUTEX'
1659   else
1660     dep_futex = cc.find_library('synchronization', required : true)
1661   endif
1662 endif
1663
1664 # Check for libdrm. Various drivers have different libdrm version requirements,
1665 # but we always want to use the same version for all libdrm modules. That means
1666 # even if driver foo requires 2.4.0 and driver bar requires 2.4.3, if foo and
1667 # bar are both on use 2.4.3 for both of them
1668 dep_libdrm_amdgpu = null_dep
1669 dep_libdrm_radeon = null_dep
1670 dep_libdrm_nouveau = null_dep
1671 dep_libdrm_intel = null_dep
1672
1673 _drm_amdgpu_ver = '2.4.110'
1674 _drm_radeon_ver = '2.4.71'
1675 _drm_nouveau_ver = '2.4.102'
1676 _drm_intel_ver = '2.4.75'
1677 _drm_ver = '2.4.109'
1678
1679 _libdrm_checks = [
1680   ['intel', with_gallium_i915],
1681   ['amdgpu', (with_amd_vk and not with_platform_windows) or with_gallium_radeonsi],
1682   ['radeon', (with_gallium_radeonsi or with_gallium_r300 or with_gallium_r600)],
1683   ['nouveau', with_gallium_nouveau],
1684 ]
1685
1686 # Loop over the enables versions and get the highest libdrm requirement for all
1687 # active drivers.
1688 _drm_blame = ''
1689 foreach d : _libdrm_checks
1690   ver = get_variable('_drm_@0@_ver'.format(d[0]))
1691   if d[1] and ver.version_compare('>' + _drm_ver)
1692     _drm_ver = ver
1693     _drm_blame = d[0]
1694   endif
1695 endforeach
1696 if _drm_blame != ''
1697   message('libdrm @0@ needed because @1@ has the highest requirement'.format(_drm_ver, _drm_blame))
1698 endif
1699
1700 # Then get each libdrm module
1701 foreach d : _libdrm_checks
1702   if d[1]
1703     set_variable(
1704       'dep_libdrm_' + d[0],
1705       dependency('libdrm_' + d[0], version : '>=' + _drm_ver)
1706     )
1707   endif
1708 endforeach
1709
1710 with_gallium_drisw_kms = false
1711 dep_libdrm = dependency(
1712   'libdrm', version : '>=' + _drm_ver,
1713   # GNU/Hurd includes egl_dri2, without drm.
1714   required : (with_dri2 and host_machine.system() != 'gnu') or with_dri3
1715 )
1716 if dep_libdrm.found()
1717   pre_args += '-DHAVE_LIBDRM'
1718   if with_dri_platform == 'drm' and with_dri
1719     with_gallium_drisw_kms = true
1720   endif
1721 endif
1722
1723 dep_libudev = dependency('libudev', required : false)
1724 if dep_libudev.found()
1725   pre_args += '-DHAVE_LIBUDEV'
1726 endif
1727
1728 llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit', 'core', 'executionengine', 'scalaropts', 'transformutils', 'instcombine']
1729 llvm_optional_modules = ['coroutines']
1730 if with_amd_vk or with_gallium_radeonsi or with_gallium_r600
1731   llvm_modules += ['amdgpu', 'bitreader', 'ipo']
1732   if with_gallium_r600
1733     llvm_modules += 'asmparser'
1734   endif
1735 endif
1736 if with_gallium_opencl
1737   llvm_modules += [
1738     'linker', 'coverage', 'instrumentation', 'ipo', 'irreader',
1739     'lto', 'option', 'objcarcopts', 'profiledata'
1740   ]
1741   # all-targets is needed to support static linking LLVM build with multiple targets
1742   # windowsdriver is needded with LLVM>=15, but we don't know what LLVM verrsion we are using yet
1743   llvm_optional_modules += ['all-targets', 'frontendopenmp', 'windowsdriver']
1744 endif
1745 if with_clc
1746   llvm_modules += ['coverage', 'target', 'linker', 'irreader', 'option', 'libdriver', 'lto']
1747   # all-targets is needed to support static linking LLVM build with multiple targets
1748   # windowsdriver is needded with LLVM>=15, but we don't know what LLVM verrsion we are using yet
1749   llvm_optional_modules += ['all-targets', 'windowsdriver']
1750 endif
1751 draw_with_llvm = get_option('draw-use-llvm')
1752 if draw_with_llvm
1753   llvm_modules += 'native'
1754   # lto is needded with LLVM>=15, but we don't know what LLVM verrsion we are using yet
1755   llvm_optional_modules += ['lto']
1756 endif
1757
1758 if with_intel_clc
1759   _llvm_version = '>= 13.0.0'
1760 elif with_amd_vk or with_gallium_radeonsi or with_gallium_opencl
1761   _llvm_version = '>= 11.0.0'
1762 elif with_clc
1763   _llvm_version = '>= 10.0.0'
1764 else
1765   _llvm_version = '>= 5.0.0'
1766 endif
1767
1768 _shared_llvm = get_option('shared-llvm')
1769 if _shared_llvm == 'true'
1770   _shared_llvm = 'enabled'
1771   warning('shared_llvm option "true" deprecated, please use "enabled" instead.')
1772 elif _shared_llvm == 'false'
1773   _shared_llvm = 'disabled'
1774   warning('shared_llvm option "false" deprecated, please use "disabled" instead.')
1775 endif
1776 if _shared_llvm == 'auto'
1777   _shared_llvm = (host_machine.system() != 'windows')
1778 else
1779   _shared_llvm = (_shared_llvm == 'enabled')
1780 endif
1781 _llvm = get_option('llvm')
1782 if _llvm == 'true'
1783   _llvm = 'enabled'
1784   warning('llvm option "true" deprecated, please use "enabled" instead.')
1785 elif _llvm == 'false'
1786   _llvm = 'disabled'
1787   warning('llvm option "false" deprecated, please use "disabled" instead.')
1788 endif
1789
1790 # the cmake method can only link statically, so don't attempt to use it if we
1791 # want to link dynamically. Before 0.54.0 meson will try cmake even when shared
1792 # linking is requested, so we need to force the config-tool method to be used
1793 # in that case, but in 0.54.0 meson won't try the cmake method if shared
1794 # linking is requested.
1795 _llvm_method = 'auto'
1796 if meson.version().version_compare('< 0.54.0') and _shared_llvm
1797   _llvm_method = 'config-tool'
1798 endif
1799
1800 dep_llvm = null_dep
1801 with_llvm = false
1802 if _llvm != 'disabled'
1803   dep_llvm = dependency(
1804     'llvm',
1805     version : _llvm_version,
1806     modules : llvm_modules,
1807     optional_modules : llvm_optional_modules,
1808     required : (
1809       with_amd_vk or with_gallium_radeonsi or with_gallium_opencl or with_clc
1810       or _llvm == 'enabled'
1811     ),
1812     static : not _shared_llvm,
1813     method : _llvm_method,
1814     fallback : ['llvm', 'dep_llvm'],
1815     include_type : 'system',
1816   )
1817   with_llvm = dep_llvm.found()
1818 endif
1819 if with_llvm
1820   pre_args += '-DLLVM_AVAILABLE'
1821   pre_args += '-DMESA_LLVM_VERSION_STRING="@0@"'.format(dep_llvm.version())
1822   pre_args += '-DLLVM_IS_SHARED=@0@'.format(_shared_llvm.to_int())
1823
1824   if draw_with_llvm
1825     pre_args += '-DDRAW_LLVM_AVAILABLE'
1826   elif with_swrast_vk
1827     error('Lavapipe requires LLVM draw support.')
1828   endif
1829
1830   if host_machine.system() != 'windows'
1831     # LLVM can be built without rtti, turning off rtti changes the ABI of C++
1832     # programs, so we need to build all C++ code in mesa without rtti as well to
1833     # ensure that linking works. Note that Win32 compilers does handle mismatching RTTI
1834     # without issues, so only apply this for other compilers.
1835     if dep_llvm.type_name() == 'internal'
1836       _llvm_rtti = subproject('llvm').get_variable('has_rtti', true)
1837     else
1838       # The CMake finder will return 'ON', the llvm-config will return 'YES'
1839       _llvm_rtti = ['ON', 'YES'].contains(dep_llvm.get_variable(cmake : 'LLVM_ENABLE_RTTI', configtool: 'has-rtti'))
1840     endif
1841     if _rtti != _llvm_rtti
1842       if _llvm_rtti
1843         error('LLVM was built with RTTI, cannot build Mesa with RTTI disabled. Remove cpp_rtti disable switch or use LLVM built without LLVM_ENABLE_RTTI.')
1844       else
1845         error('LLVM was built without RTTI, so Mesa must also disable RTTI. Use an LLVM built with LLVM_ENABLE_RTTI or add cpp_rtti=false.')
1846       endif
1847     endif
1848   endif
1849
1850   if cc.get_argument_syntax() == 'msvc'
1851     # Suppress "/DELAYLOAD:ole32.dll/shell32.dll ignored" warnings that LLVM adds
1852     add_project_link_arguments(
1853       '/ignore:4199',
1854       language : ['c', 'cpp'],
1855     )
1856   endif
1857 elif with_amd_vk and with_aco_tests
1858   error('ACO tests require LLVM, but LLVM is disabled.')
1859 elif with_gallium_radeonsi or with_swrast_vk
1860   error('The following drivers require LLVM: RadeonSI, SWR, Lavapipe. One of these is enabled, but LLVM is disabled.')
1861 elif with_gallium_opencl
1862   error('The OpenCL "Clover" state tracker requires LLVM, but LLVM is disabled.')
1863 elif with_clc
1864   error('The CLC compiler requires LLVM, but LLVM is disabled.')
1865 else
1866   draw_with_llvm = false
1867 endif
1868
1869 with_opencl_spirv = (_opencl != 'disabled' and get_option('opencl-spirv')) or with_clc
1870 if with_opencl_spirv
1871   chosen_llvm_version_array = dep_llvm.version().split('.')
1872   chosen_llvm_version_major = chosen_llvm_version_array[0].to_int()
1873   chosen_llvm_version_minor = chosen_llvm_version_array[1].to_int()
1874
1875   # Require an SPIRV-LLVM-Translator version compatible with the chosen LLVM
1876   # one.
1877
1878   # This first version check is still needed as maybe LLVM 8.0 was picked but
1879   # we do not want to accept SPIRV-LLVM-Translator 8.0.0.1 as that version
1880   # does not have the required API and those are only available starting from
1881   # 8.0.1.3.
1882   _llvmspirvlib_min_version = '>= 8.0.1.3'
1883   if with_intel_clc
1884     _llvmspirvlib_min_version = '>= 13.0.0.0'
1885   endif
1886
1887   _llvmspirvlib_version = [
1888     _llvmspirvlib_min_version,
1889     '>= @0@.@1@'.format(chosen_llvm_version_major, chosen_llvm_version_minor),
1890     '< @0@.@1@'.format(chosen_llvm_version_major, chosen_llvm_version_minor + 1) ]
1891
1892   dep_spirv_tools = dependency('SPIRV-Tools', required : true, version : '>= 2018.0')
1893   # LLVMSPIRVLib is available at https://github.com/KhronosGroup/SPIRV-LLVM-Translator
1894   dep_llvmspirvlib = dependency('LLVMSPIRVLib', required : true, version : _llvmspirvlib_version)
1895 else
1896   dep_spirv_tools = null_dep
1897   dep_llvmspirvlib = null_dep
1898 endif
1899
1900 dep_clang = null_dep
1901 if with_clc
1902   llvm_libdir = dep_llvm.get_variable(cmake : 'LLVM_LIBRARY_DIR', configtool: 'libdir')
1903
1904   dep_clang = cpp.find_library('clang-cpp', dirs : llvm_libdir, required : false)
1905
1906   if not dep_clang.found() or not _shared_llvm
1907     clang_modules = [
1908       'clangBasic', 'clangAST', 'clangCodeGen', 'clangLex',
1909       'clangDriver', 'clangFrontend', 'clangFrontendTool',
1910       'clangHandleCXX', 'clangHandleLLVM', 'clangSerialization',
1911       'clangSema', 'clangParse', 'clangEdit', 'clangAnalysis'
1912     ]
1913     if dep_llvm.version().version_compare('>= 15.0')
1914       clang_modules += 'clangSupport'
1915     endif
1916
1917     dep_clang = []
1918     foreach m : clang_modules
1919       dep_clang += cpp.find_library(m, dirs : llvm_libdir, required : true)
1920     endforeach
1921   endif
1922 endif
1923
1924 # Be explicit about only using this lib on Windows, to avoid picking
1925 # up random libs with the generic name 'libversion'
1926 dep_version = null_dep
1927 if host_machine.system() == 'windows'
1928   dep_version = cpp.find_library('version')
1929 endif
1930
1931 dep_elf = dependency('libelf', required : false)
1932 if not with_platform_windows and not dep_elf.found()
1933   dep_elf = cc.find_library('elf', required : false)
1934 endif
1935 if dep_elf.found()
1936   pre_args += '-DUSE_LIBELF'
1937 endif
1938
1939 dep_glvnd = null_dep
1940 if with_glvnd
1941   dep_glvnd = dependency('libglvnd', version : '>= 1.3.2')
1942   pre_args += '-DUSE_LIBGLVND=1'
1943 endif
1944
1945 _valgrind = get_option('valgrind')
1946 if _valgrind == 'true'
1947   _valgrind = 'enabled'
1948   warning('valgrind option "true" deprecated, please use "enabled" instead.')
1949 elif _valgrind == 'false'
1950   _valgrind = 'disabled'
1951   warning('valgrind option "false" deprecated, please use "disabled" instead.')
1952 endif
1953 if _valgrind != 'disabled'
1954   dep_valgrind = dependency('valgrind', required : _valgrind == 'enabled')
1955   if dep_valgrind.found()
1956     pre_args += '-DHAVE_VALGRIND'
1957   endif
1958 else
1959   dep_valgrind = null_dep
1960 endif
1961
1962 # AddressSanitizer's leak reports need all the symbols to be present at exit to
1963 # decode well, which runs afoul of our dlopen()/dlclose()ing of the DRI drivers.
1964 # Set a flag so we can skip the dlclose for asan builds.
1965 if ['address', 'address,undefined'].contains(get_option('b_sanitize'))
1966   asan_c_args = ['-DBUILT_WITH_ASAN=1']
1967 else
1968   asan_c_args = ['-DBUILT_WITH_ASAN=0']
1969 endif
1970
1971 yacc_is_bison = true
1972
1973 if build_machine.system() == 'windows'
1974   # Prefer the winflexbison versions, they're much easier to install and have
1975   # better windows support.
1976
1977   prog_flex = find_program('win_flex', required : false)
1978   if prog_flex.found()
1979     # windows compatibility (uses <io.h> instead of <unistd.h> and _isatty,
1980     # _fileno functions)
1981     prog_flex = [prog_flex, '--wincompat']
1982   else
1983     prog_flex = [find_program('flex', 'lex', required : with_any_opengl, disabler : true)]
1984   endif
1985   # Force flex to use const keyword in prototypes, as relies on __cplusplus or
1986   # __STDC__ macro to determine whether it's safe to use const keyword
1987   prog_flex += '-DYY_USE_CONST='
1988
1989   prog_flex_cpp = prog_flex
1990   # Convince win_flex to use <inttypes.h> for C++ files
1991   # Note that we are using a C99 version here rather than C11,
1992   # because using a C11 version can cause the MSVC CRT headers to define
1993   # static_assert to _Static_assert, which breaks other parts of the CRT
1994   prog_flex_cpp += '-D__STDC_VERSION__=199901'
1995
1996   prog_bison = find_program('win_bison', required : false)
1997   if not prog_bison.found()
1998     prog_bison = find_program('bison', 'yacc', required : with_any_opengl, disabler : true)
1999   endif
2000 else
2001   prog_bison = find_program('bison', required : false)
2002
2003   if not prog_bison.found()
2004     prog_bison = find_program('byacc', required : with_any_opengl, disabler : true)
2005     yacc_is_bison = false
2006   endif
2007
2008   # Disable deprecated keyword warnings, since we have to use them for
2009   # old-bison compat.  See discussion in
2010   # https://gitlab.freedesktop.org/mesa/mesa/merge_requests/2161
2011   if find_program('bison', required : false, version : '> 2.3').found()
2012     prog_bison = [prog_bison, '-Wno-deprecated']
2013   endif
2014
2015   prog_flex = find_program('flex', required : with_any_opengl, disabler : true)
2016   prog_flex_cpp = prog_flex
2017 endif
2018
2019 dep_selinux = null_dep
2020 if get_option('selinux')
2021   if get_option('execmem') != true
2022     warning('execmem option is disabled, selinux will not be able to use execmem.')
2023   endif
2024   dep_selinux = dependency('libselinux')
2025   pre_args += '-DMESA_SELINUX'
2026 endif
2027
2028 if get_option('execmem')
2029   pre_args += '-DMESA_EXECMEM'
2030 endif
2031
2032 _libunwind = get_option('libunwind')
2033 if _libunwind == 'true'
2034   _libunwind = 'enabled'
2035   warning('libunwind option "true" deprecated, please use "enabled" instead.')
2036 elif _libunwind == 'false'
2037   _libunwind = 'disabled'
2038   warning('libunwind option "false" deprecated, please use "disabled" instead.')
2039 endif
2040 if _libunwind != 'disabled' and not with_platform_android
2041   if host_machine.system() == 'darwin'
2042     dep_unwind = meson.get_compiler('c').find_library('System')
2043   else
2044     dep_unwind = dependency('libunwind', required : _libunwind == 'enabled')
2045   endif
2046   if dep_unwind.found()
2047     pre_args += '-DHAVE_LIBUNWIND'
2048   endif
2049 else
2050   dep_unwind = null_dep
2051 endif
2052
2053 if with_osmesa
2054   if not with_gallium_softpipe
2055     error('OSMesa gallium requires gallium softpipe or llvmpipe.')
2056   endif
2057   if host_machine.system() == 'windows'
2058     osmesa_lib_name = 'osmesa'
2059   else
2060     osmesa_lib_name = 'OSMesa'
2061   endif
2062   osmesa_bits = get_option('osmesa-bits')
2063   if osmesa_bits != 'unspecified'
2064     warning('osmesa-bits option is deprecated and have no effect, please remove it.')
2065   endif
2066 endif
2067
2068 # TODO: symbol mangling
2069
2070 if with_platform_wayland
2071   dep_wl_scanner = dependency('wayland-scanner', native: true)
2072   prog_wl_scanner = find_program(dep_wl_scanner.get_variable(pkgconfig : 'wayland_scanner'))
2073   if dep_wl_scanner.version().version_compare('>= 1.15')
2074     wl_scanner_arg = 'private-code'
2075   else
2076     wl_scanner_arg = 'code'
2077   endif
2078   dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.24')
2079   dep_wayland_client = dependency('wayland-client', version : '>=1.18')
2080   dep_wayland_server = dependency('wayland-server', version : '>=1.18')
2081   if with_egl
2082     dep_wayland_egl = dependency('wayland-egl-backend', version : '>= 3')
2083     dep_wayland_egl_headers = dep_wayland_egl.partial_dependency(compile_args : true)
2084   endif
2085   wayland_dmabuf_xml = join_paths(
2086     dep_wl_protocols.get_variable(pkgconfig : 'pkgdatadir'), 'unstable',
2087     'linux-dmabuf', 'linux-dmabuf-unstable-v1.xml'
2088   )
2089   pre_args += '-DWL_HIDE_DEPRECATED'
2090 endif
2091
2092 if with_platform_tizen
2093   dep_tpl_egl = dependency('tpl-egl')
2094   dep_libtbm = dependency('libtbm')
2095   dep_libtdm = dependency('libtdm')
2096   dep_wayland_client = dependency('wayland-client')
2097   dep_dlog = dependency('dlog')
2098   dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8')
2099   dep_wayland_client = dependency('wayland-client', version : '>=1.11')
2100   dep_wayland_server = dependency('wayland-server', version : '>=1.11')
2101   pre_args += ['-DHAVE_TIZEN_PLATFORM']
2102 endif
2103
2104 dep_x11 = null_dep
2105 dep_xext = null_dep
2106 dep_xfixes = null_dep
2107 dep_x11_xcb = null_dep
2108 dep_xcb = null_dep
2109 dep_xcb_glx = null_dep
2110 dep_xcb_dri2 = null_dep
2111 dep_xcb_dri3 = null_dep
2112 dep_dri2proto = null_dep
2113 dep_glproto = null_dep
2114 dep_xxf86vm = null_dep
2115 dep_xcb_dri3 = null_dep
2116 dep_xcb_present = null_dep
2117 dep_xcb_sync = null_dep
2118 dep_xcb_xfixes = null_dep
2119 dep_xshmfence = null_dep
2120 dep_xcb_xrandr = null_dep
2121 dep_xcb_shm = null_dep
2122 dep_xlib_xrandr = null_dep
2123 dep_openmp = null_dep
2124
2125 # Even if we find OpenMP, Gitlab CI fails to link with gcc/i386 and clang/anyarch.
2126 if host_machine.cpu_family() == 'x86_64' and cc.get_id() == 'gcc'
2127   dep_openmp = dependency('openmp', required : false)
2128   if dep_openmp.found()
2129     pre_args += ['-DHAVE_OPENMP']
2130   endif
2131 endif
2132
2133 with_dri3_modifiers = false
2134 if with_platform_x11
2135   if with_glx == 'xlib'
2136     dep_x11 = dependency('x11')
2137     dep_xext = dependency('xext')
2138     dep_xcb = dependency('xcb')
2139     dep_xcb_xrandr = dependency('xcb-randr')
2140   elif with_glx == 'dri'
2141     dep_x11 = dependency('x11')
2142     dep_xext = dependency('xext')
2143     dep_xfixes = dependency('xfixes', version : '>= 2.0')
2144     dep_xcb_glx = dependency('xcb-glx', version : '>= 1.8.1')
2145     dep_xcb_shm = dependency('xcb-shm')
2146   endif
2147   if (with_any_vk or with_glx == 'dri' or with_egl or
2148        (with_gallium_vdpau or with_gallium_va or
2149         with_gallium_omx != 'disabled'))
2150     dep_xcb = dependency('xcb')
2151     dep_x11_xcb = dependency('x11-xcb')
2152     if with_dri_platform == 'drm' and not dep_libdrm.found()
2153       error('libdrm required for gallium video statetrackers when using x11')
2154     endif
2155   endif
2156   if with_any_vk or with_egl or (with_glx == 'dri' and with_dri_platform == 'drm')
2157     dep_xcb_dri2 = dependency('xcb-dri2', version : '>= 1.8')
2158
2159     if with_dri3
2160       dep_xcb_dri3 = dependency('xcb-dri3')
2161       dep_xcb_present = dependency('xcb-present')
2162       # until xcb-dri3 has been around long enough to make a hard-dependency:
2163       if (dep_xcb_dri3.version().version_compare('>= 1.13') and
2164           dep_xcb_present.version().version_compare('>= 1.13'))
2165         with_dri3_modifiers = true
2166       endif
2167       dep_xcb_shm = dependency('xcb-shm')
2168       dep_xcb_sync = dependency('xcb-sync')
2169       dep_xshmfence = dependency('xshmfence', version : '>= 1.1')
2170     endif
2171   endif
2172   if with_glx == 'dri' or with_glx == 'xlib'
2173     dep_glproto = dependency('glproto', version : '>= 1.4.14')
2174   endif
2175   if with_glx == 'dri'
2176     if with_dri_platform == 'drm'
2177       dep_dri2proto = dependency('dri2proto', version : '>= 2.8')
2178       if with_glx_direct
2179         dep_xxf86vm = dependency('xxf86vm')
2180       endif
2181     endif
2182   endif
2183   if (with_egl or
2184       with_dri3 or (
2185       with_gallium_vdpau or with_gallium_xa or
2186       with_gallium_omx != 'disabled'))
2187     dep_xcb_xfixes = dependency('xcb-xfixes')
2188   endif
2189   if with_xlib_lease or with_any_vk
2190     dep_xcb_xrandr = dependency('xcb-randr')
2191   endif
2192   if with_xlib_lease
2193     dep_xlib_xrandr = dependency('xrandr', version : '>= 1.3')
2194   endif
2195 endif
2196
2197 if with_dri
2198   pre_args += '-DHAVE_DRI'
2199 endif
2200 if with_dri2
2201   pre_args += '-DHAVE_DRI2'
2202 endif
2203 if with_dri3
2204   pre_args += '-DHAVE_DRI3'
2205 endif
2206 if with_dri3_modifiers
2207   pre_args += '-DHAVE_DRI3_MODIFIERS'
2208 endif
2209 if with_gallium_drisw_kms
2210   pre_args += '-DHAVE_DRISW_KMS'
2211 endif
2212
2213 if get_option('gallium-extra-hud')
2214   pre_args += '-DHAVE_GALLIUM_EXTRA_HUD=1'
2215 endif
2216
2217 _sensors = get_option('lmsensors')
2218 if _sensors == 'true'
2219   _sensors = 'enabled'
2220   warning('lmsensors option "true" deprecated, please use "enabled" instead.')
2221 elif _sensors == 'false'
2222   _sensors = 'disabled'
2223   warning('lmsensors option "false" deprecated, please use "disabled" instead.')
2224 endif
2225 if _sensors != 'disabled'
2226   dep_lmsensors = cc.find_library('sensors', required : _sensors == 'enabled')
2227   if dep_lmsensors.found()
2228     pre_args += '-DHAVE_LIBSENSORS=1'
2229   endif
2230 else
2231   dep_lmsensors = null_dep
2232 endif
2233
2234 _shader_replacement = get_option('custom-shader-replacement')
2235 if _shader_replacement == ''
2236 else
2237   pre_args += '-DCUSTOM_SHADER_REPLACEMENT'
2238 endif
2239
2240 with_perfetto = get_option('perfetto')
2241 with_datasources = get_option('datasources')
2242 with_any_datasource = with_datasources.length() != 0
2243 if with_perfetto
2244   dep_perfetto = dependency('perfetto', fallback: ['perfetto', 'dep_perfetto'])
2245   pre_args += '-DHAVE_PERFETTO'
2246 endif
2247
2248 add_project_arguments(pre_args, language : ['c', 'cpp'])
2249 add_project_arguments(c_args,   language : ['c'])
2250 add_project_arguments(cpp_args, language : ['cpp'])
2251
2252 gl_priv_reqs = []
2253
2254 if with_glx == 'xlib'
2255   gl_priv_reqs += ['x11', 'xext', 'xcb']
2256 elif with_glx == 'dri'
2257   gl_priv_reqs += [
2258     'x11', 'xext', 'xfixes', 'x11-xcb', 'xcb',
2259     'xcb-glx >= 1.8.1']
2260   if with_dri_platform == 'drm'
2261     gl_priv_reqs += 'xcb-dri2 >= 1.8'
2262     if with_glx_direct
2263       gl_priv_reqs += 'xxf86vm'
2264     endif
2265   endif
2266 endif
2267 if dep_libdrm.found()
2268   gl_priv_reqs += 'libdrm >= 2.4.75'
2269 endif
2270
2271 gl_priv_libs = []
2272 if dep_thread.found()
2273   gl_priv_libs += ['-lpthread', '-pthread']
2274 endif
2275 if dep_m.found()
2276   gl_priv_libs += '-lm'
2277 endif
2278 if dep_dl.found()
2279   gl_priv_libs += '-ldl'
2280 endif
2281
2282 # FIXME: autotools lists this as incomplete
2283 gbm_priv_libs = []
2284 if dep_dl.found()
2285   gbm_priv_libs += '-ldl'
2286 endif
2287
2288 pkg = import('pkgconfig')
2289
2290 if host_machine.system() == 'windows'
2291   prog_dumpbin = find_program('dumpbin', required : false)
2292   with_symbols_check = prog_dumpbin.found() and with_tests
2293   if with_symbols_check
2294     symbols_check_args = ['--dumpbin', prog_dumpbin.path()]
2295   endif
2296 else
2297   prog_nm = find_program('nm')
2298   with_symbols_check = with_tests
2299   symbols_check_args = ['--nm', prog_nm.path()]
2300 endif
2301
2302 # This quirk needs to be applied to sources with functions defined in assembly
2303 # as GCC LTO drops them. See: https://bugs.freedesktop.org/show_bug.cgi?id=109391
2304 gcc_lto_quirk = (cc.get_id() == 'gcc') ? ['-fno-lto'] : []
2305
2306 devenv = environment()
2307
2308 dir_compiler_nir = join_paths(meson.current_source_dir(), 'src/compiler/nir/')
2309
2310 subdir('include')
2311 subdir('bin')
2312 subdir('src')
2313
2314 if meson.version().version_compare('>= 0.58')
2315   meson.add_devenv(devenv)
2316 endif
2317
2318 lines = ['',
2319   'prefix:          ' + get_option('prefix'),
2320   'libdir:          ' + get_option('libdir'),
2321   'includedir:      ' + get_option('includedir'),
2322   '',
2323   'OpenGL:          @0@ (ES1: @1@ ES2: @2@)'.format(with_opengl ? 'yes' : 'no',
2324                                                     with_gles1 ? 'yes' : 'no',
2325                                                     with_gles2 ? 'yes' : 'no'),
2326 ]
2327
2328 if with_osmesa
2329   lines += ''
2330   lines += 'OSMesa:          lib' + osmesa_lib_name
2331 else
2332   lines += 'OSMesa:          no'
2333 endif
2334
2335 if with_dri
2336   lines += ''
2337   lines += 'DRI platform:    ' + with_dri_platform
2338   lines += 'DRI driver dir:  ' + dri_drivers_path
2339 endif
2340
2341 if with_glx != 'disabled'
2342   lines += ''
2343   if with_glx == 'dri'
2344     lines += 'GLX:             DRI-based'
2345   elif with_glx == 'xlib'
2346     lines += 'GLX:             Xlib-based'
2347   else
2348     lines += 'GLX:             ' + with_glx
2349   endif
2350 endif
2351
2352 lines += ''
2353 lines += 'EGL:             ' + (with_egl ? 'yes' : 'no')
2354 if with_egl
2355   egl_drivers = []
2356   if with_dri
2357     egl_drivers += 'builtin:egl_dri2'
2358   endif
2359   if with_dri3
2360     egl_drivers += 'builtin:egl_dri3'
2361   endif
2362   if with_platform_windows
2363     egl_drivers += 'builtin:wgl'
2364   endif
2365   lines += 'EGL drivers:     ' + ' '.join(egl_drivers)
2366 endif
2367 if with_egl or with_any_vk
2368   lines += 'EGL/Vulkan/VL platforms:   ' + ' '.join(_platforms)
2369 endif
2370 lines += 'GBM:             ' + (with_gbm ? 'yes' : 'no')
2371 if with_gbm
2372   lines += 'GBM backends path: ' + gbm_backends_path
2373 endif
2374
2375 lines += ''
2376 lines += 'Video Codecs: ' + ' '.join(_codecs)
2377 lines += ''
2378
2379 if with_any_vk
2380   lines += 'Vulkan drivers:  ' + ' '.join(_vulkan_drivers)
2381   lines += 'Vulkan ICD dir:  ' + with_vulkan_icd_dir
2382   if with_any_vulkan_layers
2383     lines += 'Vulkan layers:   ' + ' '.join(get_option('vulkan-layers'))
2384   endif
2385   lines += 'Vulkan Intel Ray Tracing:  ' + (with_intel_vk_rt ? 'yes' : 'no')
2386 else
2387   lines += 'Vulkan drivers:  no'
2388 endif
2389
2390 lines += ''
2391 if with_llvm
2392   lines += 'llvm:            yes'
2393   lines += 'llvm-version:    ' + dep_llvm.version()
2394 else
2395   lines += 'llvm:            no'
2396 endif
2397
2398 lines += ''
2399 if with_gallium
2400   lines += 'Gallium drivers: ' + ' '.join(gallium_drivers)
2401   gallium_st = ['mesa']
2402   if with_gallium_xa
2403     gallium_st += 'xa'
2404   endif
2405   if with_gallium_vdpau
2406     gallium_st += 'vdpau'
2407   endif
2408   if with_gallium_omx != 'disabled'
2409     gallium_st += 'omx' + with_gallium_omx
2410   endif
2411   if with_gallium_va
2412     gallium_st += 'va'
2413   endif
2414   if with_gallium_st_nine
2415     gallium_st += 'nine'
2416   endif
2417   if with_gallium_opencl
2418     gallium_st += 'clover'
2419   endif
2420   lines += 'Gallium st:      ' + ' '.join(gallium_st)
2421 else
2422   lines += 'Gallium:         no'
2423 endif
2424
2425 lines += 'HUD lmsensors:   ' + (dep_lmsensors.found() ? 'yes' : 'no')
2426
2427 lines += ''
2428 lines += 'Shared-glapi:    ' + (with_shared_glapi ? 'yes' : 'no')
2429
2430 lines += ''
2431 lines += 'Perfetto:        ' + (with_perfetto ? 'yes' : 'no')
2432 if with_any_datasource
2433   lines += 'Perfetto ds:     ' + ' '.join(with_datasources)
2434 endif
2435
2436
2437 indent = '        '
2438 summary = indent + ('\n' + indent).join(lines)
2439 message('Configuration summary:\n@0@\n'.format(summary))