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