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