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