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