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