1 # Copyright © 2017-2020 Intel Corporation
2 # SPDX-License-Identifier: MIT
7 version : files('VERSION'),
9 meson_version : '>= 1.1.0',
11 'buildtype=debugoptimized',
12 'b_ndebug=if-release',
16 'build.rust_std=2021',
20 if host_machine.system() == 'darwin'
21 add_languages('objc', native : false)
22 add_project_arguments('-fobjc-arc', language : 'objc')
25 cc = meson.get_compiler('c')
26 cpp = meson.get_compiler('cpp')
28 sizeof_pointer = cc.sizeof('void*').to_string()
30 null_dep = dependency('', required : false)
32 if get_option('layout') != 'mirror'
33 error('`mirror` is the only build directory layout supported')
36 with_mesa_debug = get_option('buildtype') == 'debug'
38 # This means the final value of b_ndebug==true
39 with_mesa_ndebug = get_option('b_ndebug') == 'true' or (get_option('buildtype') == 'release' and get_option('b_ndebug') == 'if-release')
41 # Arguments for the preprocessor, put these in a separate array from the C and
42 # C++ (cpp in meson terminology) arguments since they need to be added to the
43 # default arguments for both C and C++.
45 '-D__STDC_CONSTANT_MACROS',
46 '-D__STDC_FORMAT_MACROS',
47 '-D__STDC_LIMIT_MACROS',
48 '-DPACKAGE_VERSION="@0@"'.format(meson.project_version()),
49 '-DPACKAGE_BUGREPORT="https://gitlab.freedesktop.org/mesa/mesa/-/issues"',
51 # Arguments for c or cpp compiler, can be compiler options
57 with_moltenvk_dir = get_option('moltenvk-dir')
58 with_vulkan_icd_dir = get_option('vulkan-icd-dir')
59 with_tests = get_option('build-tests')
60 with_glcpp_tests = get_option('enable-glcpp-tests')
61 with_aco_tests = get_option('build-aco-tests')
62 with_glx_read_only_text = get_option('glx-read-only-text')
63 with_glx_direct = get_option('glx-direct')
64 with_osmesa = get_option('osmesa')
65 with_vulkan_overlay_layer = get_option('vulkan-layers').contains('overlay')
66 with_vulkan_device_select_layer = get_option('vulkan-layers').contains('device-select')
67 with_vulkan_screenshot_layer = get_option('vulkan-layers').contains('screenshot')
68 with_tools = get_option('tools')
69 if with_tools.contains('all')
86 with_any_vulkan_layers = get_option('vulkan-layers').length() != 0
87 with_intel_tools = with_tools.contains('intel') or with_tools.contains('intel-ui')
88 with_imgui = with_intel_tools or with_vulkan_overlay_layer
90 dri_drivers_path = get_option('dri-drivers-path')
91 if dri_drivers_path == ''
92 dri_drivers_path = join_paths(get_option('prefix'), get_option('libdir'), 'dri')
95 gbm_backends_path = get_option('gbm-backends-path')
96 if gbm_backends_path == ''
97 gbm_backends_path = join_paths(get_option('prefix'), get_option('libdir'), 'gbm')
100 # Default shared glapi disabled for windows, enabled elsewhere.
101 with_shared_glapi = get_option('shared-glapi') \
102 .disable_auto_if(host_machine.system() == 'windows') \
105 with_opengl = get_option('opengl')
107 with_gles1 = get_option('gles1') \
108 .require(with_shared_glapi, error_message : 'OpengGL ES 1.x requires shared-glapi') \
111 with_gles2 = get_option('gles2') \
112 .require(with_shared_glapi, error_message : 'OpengGL ES 2.x requires shared-glapi') \
115 pre_args += '-DHAVE_OPENGL=@0@'.format(with_opengl.to_int())
116 pre_args += '-DHAVE_OPENGL_ES_1=@0@'.format(with_gles1.to_int())
117 pre_args += '-DHAVE_OPENGL_ES_2=@0@'.format(with_gles2.to_int())
119 with_any_opengl = with_opengl or with_gles1 or with_gles2
120 # Only build shared_glapi if at least one OpenGL API is enabled
121 with_shared_glapi = with_shared_glapi and with_any_opengl
123 system_has_kms_drm = ['openbsd', 'netbsd', 'freebsd', 'gnu/kfreebsd', 'dragonfly', 'linux', 'sunos', 'android', 'managarm'].contains(host_machine.system())
125 gallium_drivers = get_option('gallium-drivers')
126 if gallium_drivers.contains('auto')
127 if system_has_kms_drm
129 if ['x86', 'x86_64'].contains(host_machine.cpu_family())
131 'r300', 'r600', 'radeonsi', 'nouveau', 'virgl', 'svga', 'llvmpipe', 'softpipe',
132 'iris', 'crocus', 'i915', 'zink'
134 elif ['arm', 'aarch64'].contains(host_machine.cpu_family())
136 'v3d', 'vc4', 'freedreno', 'etnaviv', 'nouveau', 'svga',
137 'tegra', 'virgl', 'lima', 'panfrost', 'llvmpipe', 'softpipe', 'iris',
140 elif ['mips', 'mips64', 'ppc', 'ppc64', 'riscv32', 'riscv64'].contains(host_machine.cpu_family())
142 'r300', 'r600', 'radeonsi', 'nouveau', 'virgl', 'llvmpipe', 'softpipe', 'zink'
144 elif ['loongarch64'].contains(host_machine.cpu_family())
146 'r300', 'r600', 'radeonsi', 'nouveau', 'virgl', 'etnaviv', 'llvmpipe', 'softpipe', 'zink'
149 error('Unknown architecture @0@. Please pass -Dgallium-drivers to set driver options. Patches gladly accepted to fix this.'.format(
150 host_machine.cpu_family()))
152 elif ['windows'].contains(host_machine.system())
153 gallium_drivers = ['llvmpipe', 'softpipe', 'zink', 'd3d12']
154 elif ['darwin', 'cygwin', 'haiku'].contains(host_machine.system())
155 gallium_drivers = ['llvmpipe', 'softpipe']
157 error('Unknown OS @0@. Please pass -Dgallium-drivers to set driver options. Patches gladly accepted to fix this.'.format(
158 host_machine.system()))
160 elif gallium_drivers.contains('all')
161 # Build-test everything except for i915, which depends on libdrm-intel which
162 # is not available on non-Intel distros.
164 'r300', 'r600', 'radeonsi', 'crocus', 'v3d', 'vc4', 'freedreno', 'etnaviv',
165 'nouveau', 'svga', 'tegra', 'virgl', 'lima', 'panfrost', 'llvmpipe', 'softpipe', 'iris',
166 'zink', 'd3d12', 'asahi'
170 # compatibility for meson configurations asking for 'swrast'
171 with_swrast = gallium_drivers.contains('swrast')
173 warning('`gallium-drivers=swrast` is a deprecated alias for `gallium-drivers=softpipe,llvmpipe` and will be removed in version 25.0')
176 with_gallium_radeonsi = gallium_drivers.contains('radeonsi')
177 with_gallium_r300 = gallium_drivers.contains('r300')
178 with_gallium_r600 = gallium_drivers.contains('r600')
179 with_gallium_nouveau = gallium_drivers.contains('nouveau')
180 with_gallium_freedreno = gallium_drivers.contains('freedreno')
181 with_gallium_softpipe = with_swrast or gallium_drivers.contains('softpipe')
182 with_gallium_llvmpipe = with_swrast or gallium_drivers.contains('llvmpipe')
183 with_gallium_vc4 = gallium_drivers.contains('vc4')
184 with_gallium_v3d = gallium_drivers.contains('v3d')
185 with_gallium_panfrost = gallium_drivers.contains('panfrost')
186 with_gallium_etnaviv = gallium_drivers.contains('etnaviv')
187 with_gallium_tegra = gallium_drivers.contains('tegra')
188 with_gallium_crocus = gallium_drivers.contains('crocus')
189 with_gallium_iris = gallium_drivers.contains('iris')
190 with_gallium_i915 = gallium_drivers.contains('i915')
191 with_gallium_svga = gallium_drivers.contains('svga')
192 with_gallium_virgl = gallium_drivers.contains('virgl')
193 with_gallium_lima = gallium_drivers.contains('lima')
194 with_gallium_zink = gallium_drivers.contains('zink')
195 with_gallium_d3d12 = gallium_drivers.contains('d3d12')
196 with_gallium_asahi = gallium_drivers.contains('asahi')
197 foreach gallium_driver : gallium_drivers
198 pre_args += '-DHAVE_@0@'.format(gallium_driver.to_upper())
201 # compatibility for "swrast" as an internal-ish driver name
202 with_gallium_swrast = with_gallium_softpipe or with_gallium_llvmpipe
203 if with_gallium_swrast
204 pre_args += '-DHAVE_SWRAST'
207 with_gallium = gallium_drivers.length() != 0
208 with_gallium_kmsro = system_has_kms_drm and [
210 with_gallium_etnaviv,
211 with_gallium_freedreno,
213 with_gallium_panfrost,
218 _vulkan_drivers = get_option('vulkan-drivers')
219 if _vulkan_drivers.contains('auto')
220 if system_has_kms_drm
221 if host_machine.cpu_family().startswith('x86')
222 _vulkan_drivers = ['amd', 'intel', 'intel_hasvk', 'nouveau', 'swrast']
223 elif ['arm', 'aarch64'].contains(host_machine.cpu_family())
224 _vulkan_drivers = ['swrast', 'intel']
225 elif ['mips', 'mips64', 'ppc', 'ppc64', 'riscv32', 'riscv64'].contains(host_machine.cpu_family())
226 _vulkan_drivers = ['amd', 'swrast']
227 elif ['loongarch64'].contains(host_machine.cpu_family())
228 _vulkan_drivers = ['amd', 'swrast']
230 error('Unknown architecture @0@. Please pass -Dvulkan-drivers to set driver options. Patches gladly accepted to fix this.'.format(
231 host_machine.cpu_family()))
233 elif ['darwin', 'windows', 'cygwin', 'haiku'].contains(host_machine.system())
234 # No vulkan driver supports windows or macOS currently
237 error('Unknown OS @0@. Please pass -Dvulkan-drivers to set driver options. Patches gladly accepted to fix this.'.format(
238 host_machine.system()))
240 elif _vulkan_drivers.contains('all')
241 # Build every vulkan driver regardless of architecture.
242 _vulkan_drivers = ['amd', 'intel', 'intel_hasvk', 'swrast',
243 'freedreno', 'panfrost', 'virtio', 'broadcom',
244 'imagination-experimental', 'microsoft-experimental',
245 'nouveau', 'asahi', 'gfxstream']
248 with_intel_vk = _vulkan_drivers.contains('intel')
249 with_intel_hasvk = _vulkan_drivers.contains('intel_hasvk')
250 with_amd_vk = _vulkan_drivers.contains('amd')
251 with_freedreno_vk = _vulkan_drivers.contains('freedreno')
252 with_panfrost_vk = _vulkan_drivers.contains('panfrost')
253 with_swrast_vk = _vulkan_drivers.contains('swrast')
254 with_virtio_vk = _vulkan_drivers.contains('virtio')
255 with_broadcom_vk = _vulkan_drivers.contains('broadcom')
256 with_imagination_vk = _vulkan_drivers.contains('imagination-experimental')
257 with_imagination_srv = get_option('imagination-srv')
258 with_microsoft_vk = _vulkan_drivers.contains('microsoft-experimental')
259 with_nouveau_vk = _vulkan_drivers.contains('nouveau')
260 with_asahi_vk = _vulkan_drivers.contains('asahi')
261 with_gfxstream_vk = _vulkan_drivers.contains('gfxstream')
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')
268 with_any_llvmpipe = with_gallium_llvmpipe or with_swrast_vk
269 with_gallium_or_lvp = with_gallium or with_swrast_vk
271 freedreno_kmds = get_option('freedreno-kmds')
272 if freedreno_kmds.length() != 0 and freedreno_kmds != [ 'msm' ] and with_freedreno_vk
273 if freedreno_kmds.contains('msm')
274 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.')
275 elif with_gallium_kmsro
276 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.')
277 elif _vulkan_drivers != [ 'freedreno' ]
278 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.')
280 # If DRM support isn't needed, we can get rid of it since linking
281 # to libdrm can be a potential compatibility hazard.
282 system_has_kms_drm = false
287 if with_gallium and system_has_kms_drm
288 _glx = get_option('glx')
289 _egl = get_option('egl')
290 if _glx == 'dri' or _egl.enabled() or (_glx == 'disabled' and _egl.allowed())
295 with_any_broadcom = [
301 if get_option('intel-clc') != 'system'
302 # Require intel-clc with Anv & Iris (for internal shaders)
303 with_intel_clc = get_option('intel-clc') == 'enabled' or \
304 with_intel_vk or with_gallium_iris
306 with_intel_clc = false
309 with_intel_vk_rt = get_option('intel-rt') \
310 .disable_auto_if(not with_intel_vk) \
311 .disable_if(host_machine.cpu_family() != 'x86_64', error_message : 'Intel Ray Tracing is only supported on x86_64') \
323 with_any_nouveau = with_gallium_nouveau or with_nouveau_vk
325 # needed in the loader
327 pre_args += '-DHAVE_NVK'
330 if with_gallium_tegra and not with_gallium_nouveau
331 error('tegra driver requires nouveau driver')
333 if with_aco_tests and not with_amd_vk
334 error('ACO tests require Radv')
337 with_microsoft_clc = get_option('microsoft-clc').enabled()
338 with_spirv_to_dxil = get_option('spirv-to-dxil')
340 if host_machine.system() == 'darwin'
341 with_dri_platform = 'apple'
342 pre_args += '-DBUILDING_MESA'
343 elif ['windows', 'cygwin'].contains(host_machine.system())
344 with_dri_platform = 'windows'
345 elif system_has_kms_drm
346 with_dri_platform = 'drm'
348 # FIXME: haiku doesn't use dri, and xlib doesn't use dri, probably should
349 # assert here that one of those cases has been met.
350 # FIXME: illumos ends up here as well
351 with_dri_platform = 'none'
354 with_vulkan_beta = get_option('vulkan-beta')
355 if host_machine.system() == 'darwin'
356 #macOS seems to need beta extensions to build for now:
357 with_vulkan_beta = true
360 pre_args += '-DVK_ENABLE_BETA_EXTENSIONS'
363 _codecs = get_option('video-codecs')
364 patent_codecs = ['vc1dec', 'h264dec', 'h264enc', 'h265dec', 'h265enc']
365 free_codecs = ['av1dec', 'av1enc', 'vp9dec']
366 all_codecs = patent_codecs + free_codecs
368 if _codecs.contains('all')
370 elif _codecs.contains('all_free')
371 selected_codecs = _codecs
372 _codecs = free_codecs
373 foreach c : patent_codecs
374 if selected_codecs.contains(c)
379 foreach c : all_codecs
380 pre_args += '-DVIDEO_CODEC_@0@=@1@'.format(c.to_upper(), _codecs.contains(c).to_int())
383 _platforms = get_option('platforms')
384 if _platforms.contains('auto')
385 if system_has_kms_drm
386 _platforms = ['x11', 'wayland']
387 elif host_machine.system() == 'cygwin'
389 elif host_machine.system() == 'haiku'
390 _platforms = ['haiku']
391 elif host_machine.system() == 'windows'
392 _platforms = ['windows']
393 elif host_machine.system() == 'darwin'
394 _platforms = ['x11', 'macos']
396 error('Unknown OS @0@. Please pass -Dplatforms to set platforms. Patches gladly accepted to fix this.'.format(
397 host_machine.system()))
401 with_platform_android = _platforms.contains('android')
402 with_platform_x11 = _platforms.contains('x11')
403 with_platform_xcb = _platforms.contains('xcb')
404 with_platform_wayland = _platforms.contains('wayland')
405 with_platform_haiku = _platforms.contains('haiku')
406 with_platform_windows = _platforms.contains('windows')
407 with_platform_macos = _platforms.contains('macos')
409 with_glx = get_option('glx')
410 if with_glx == 'auto'
412 with_glx = 'disabled'
413 elif with_platform_android
414 with_glx = 'disabled'
417 elif with_platform_haiku
418 with_glx = 'disabled'
419 elif host_machine.system() == 'windows'
420 with_glx = 'disabled'
422 # Even when building just gallium drivers the user probably wants dri
424 elif with_platform_x11 and with_any_opengl and not with_any_vk
425 # The automatic behavior should not be to turn on xlib based glx when
426 # building only vulkan drivers
429 with_glx = 'disabled'
438 if not with_opengl and with_glx != 'disabled'
439 error('Building GLX without OpenGL is not supported.')
442 if not (with_dri or with_gallium or with_glx != 'disabled')
446 with_any_opengl = false
447 with_shared_glapi = false
450 with_gbm = get_option('gbm') \
451 .require(system_has_kms_drm, error_message : 'GBM only supports DRM/KMS platforms') \
452 .disable_auto_if(not with_dri) \
455 with_xlib_lease = get_option('xlib-lease') \
456 .require(with_platform_x11 and (system_has_kms_drm or with_dri_platform == 'apple'), error_message : 'xlib-lease requires X11 and KMS/DRM support') \
459 with_egl = get_option('egl') \
460 .require(with_platform_windows or with_platform_haiku or with_dri or with_platform_android, error_message : 'EGL requires DRI, Haiku, Windows or Android') \
461 .require(with_shared_glapi, error_message : 'EGL requires shared-glapi') \
462 .require(with_glx != 'xlib', error_message :'EGL requires DRI, but GLX is being built with xlib support') \
463 .disable_auto_if(with_platform_haiku) \
467 _platforms += 'surfaceless'
468 if with_gbm and not with_platform_android
472 egl_native_platform = get_option('egl-native-platform')
473 if egl_native_platform.contains('auto')
474 egl_native_platform = _platforms[0]
478 if with_egl and not _platforms.contains(egl_native_platform)
479 error('-Degl-native-platform does not specify an enabled platform')
482 if 'x11' in _platforms
486 foreach platform : _platforms
487 pre_args += '-DHAVE_@0@_PLATFORM'.format(platform.to_upper())
490 if with_platform_android and get_option('platform-sdk-version') >= 29
491 # By default the NDK compiler, at least, emits emutls references instead of
492 # ELF TLS, even when building targeting newer API levels. Make it actually do
494 c_cpp_args += '-fno-emulated-tls'
495 add_project_link_arguments('-Wl,-plugin-opt=-emulated-tls=0', language: ['c', 'cpp'])
498 # -mtls-dialect=gnu2 speeds up non-initial-exec TLS significantly but requires
499 # full toolchain (including libc) support.
500 have_mtls_dialect = false
501 foreach c_arg : get_option('c_args')
502 if c_arg.startswith('-mtls-dialect=')
503 have_mtls_dialect = true
507 if not have_mtls_dialect
508 # need .run to check libc support. meson aborts when calling .run when
509 # cross-compiling, but because this is just an optimization we can skip it
510 if meson.is_cross_build() and not meson.can_run_host_binaries()
511 warning('cannot auto-detect -mtls-dialect when cross-compiling, using compiler default')
513 # The way to specify the TLSDESC dialect is architecture-specific.
514 # We probe both because there is not a fallback guaranteed to work for all
515 # future architectures.
516 foreach tlsdesc_arg : ['-mtls-dialect=gnu2', '-mtls-dialect=desc']
517 # -fpic to force dynamic tls, otherwise TLS relaxation defeats check
518 tlsdesc_test = cc.run('int __thread x; int main() { return x; }',
519 args: [tlsdesc_arg, '-fpic'],
521 if tlsdesc_test.returncode() == 0 and (
522 # check for lld 13 bug: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5665
523 host_machine.cpu_family() != 'x86_64' or
524 # get_linker_id misses LDFLAGS=-fuse-ld=lld: https://github.com/mesonbuild/meson/issues/6377
525 #cc.get_linker_id() != 'ld.lld' or
526 cc.links('''int __thread x; int y; int main() { __asm__(
527 "leaq x@TLSDESC(%rip), %rax\n"
528 "movq y@GOTPCREL(%rip), %rdx\n"
529 "call *x@TLSCALL(%rax)\n"); }''', name: 'split TLSDESC')
531 c_cpp_args += tlsdesc_arg
538 if with_glx != 'disabled'
539 if not (with_platform_x11 and with_any_opengl)
540 error('Cannot build GLX support without X11 platform support and at least one OpenGL API')
541 elif with_glx == 'xlib'
543 error('xlib based GLX requires at least one gallium driver')
544 elif not with_gallium_swrast
545 error('xlib based GLX requires softpipe or llvmpipe.')
547 error('xlib conflicts with any dri driver')
549 elif with_glx == 'dri'
550 if not with_shared_glapi
551 error('dri based GLX requires shared-glapi')
556 _glvnd = get_option('glvnd') \
557 .require(not with_platform_windows,
558 error_message: 'glvnd cannot be used on Windows') \
559 .require(with_glx != 'xlib',
560 error_message: 'Cannot build glvnd support for GLX that is not DRI based.') \
561 .require(with_glx != 'disabled' or with_egl,
562 error_message: 'glvnd requires DRI based GLX and/or EGL') \
563 .require(get_option('egl-lib-suffix') == '',
564 error_message: '''EGL lib suffix can't be used with libglvnd''')
565 dep_glvnd = dependency('libglvnd', version : '>= 1.3.2', required : _glvnd)
566 with_glvnd = dep_glvnd.found()
567 pre_args += '-DUSE_LIBGLVND=@0@'.format(with_glvnd.to_int())
568 glvnd_vendor_name = get_option('glvnd-vendor-name')
570 if with_vulkan_icd_dir == ''
571 with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
574 with_dri2 = (with_dri or with_any_vk) and (with_dri_platform == 'drm' or with_dri_platform == 'apple')
576 with_x11_dri2 = with_dri2 and get_option('legacy-x11').contains('dri2')
579 if with_glx == 'disabled' and not with_egl and not with_gbm
580 error('building dri drivers require at least one windowing system')
584 dep_dxheaders = null_dep
585 if with_gallium_d3d12 or with_microsoft_clc or with_microsoft_vk
586 dep_dxheaders = dependency('directx-headers', required : false)
587 if not dep_dxheaders.found()
588 dep_dxheaders = dependency('DirectX-Headers',
589 version : '>= 1.614.1',
590 fallback : ['DirectX-Headers', 'dep_dxheaders'],
591 required : with_gallium_d3d12 or with_microsoft_vk
596 _with_gallium_d3d12_video = get_option('gallium-d3d12-video')
597 with_gallium_d3d12_video = false
598 if with_gallium_d3d12 and not _with_gallium_d3d12_video.disabled()
599 with_gallium_d3d12_video = true
600 pre_args += '-DHAVE_GALLIUM_D3D12_VIDEO'
604 with_gallium_d3d12_video,
605 with_gallium_nouveau,
607 with_gallium_radeonsi,
611 vdpau = get_option('gallium-vdpau') \
612 .require(system_has_kms_drm, error_message : 'VDPAU state tracker can only be build on unix-like OSes.') \
613 .require(with_platform_x11, error_message : 'VDPAU state tracker requires X11 support.') \
614 .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).')
616 dep_vdpau = dependency('vdpau', version : '>= 1.5', required : vdpau)
618 dep_vdpau = dep_vdpau.partial_dependency(compile_args : true)
619 pre_args += '-DHAVE_ST_VDPAU'
621 with_gallium_vdpau = dep_vdpau.found()
623 vdpau_drivers_path = get_option('vdpau-libs-path')
624 if vdpau_drivers_path == ''
625 vdpau_drivers_path = join_paths(get_option('libdir'), 'vdpau')
628 # GLSL has interesting version output and Meson doesn't parse it correctly as of
630 prog_glslang = find_program('glslangValidator', native : true,
631 required : with_vulkan_overlay_layer or with_aco_tests or with_amd_vk or with_intel_vk)
632 if prog_glslang.found()
633 # Check if glslang has depfile support. Support was added in 11.3.0, but
634 # Windows path support was broken until 11.9.0.
636 # It is intentional to check the build machine, since we need to ensure that
637 # glslang will output valid paths on the build platform
638 _glslang_check = build_machine.system() == 'windows' ? '>= 11.9.0' : '>= 11.3.0'
639 if run_command(prog_glslang, ['--version'], check : false).stdout().split(':')[2].version_compare(_glslang_check)
640 glslang_depfile = ['--depfile', '@DEPFILE@']
644 if run_command(prog_glslang, [ '--quiet', '--version' ], check : false).returncode() == 0
645 glslang_quiet = ['--quiet']
652 with_gallium_d3d12_video,
653 with_gallium_nouveau,
655 with_gallium_radeonsi,
659 _va = get_option('gallium-va') \
660 .require(_va_drivers.contains(true),
661 error_message : 'VA state tracker requires at least one of the following gallium drivers: r600, radeonsi, nouveau, d3d12 (with option gallium-d3d12-video), virgl.')
662 _dep_va_name = host_machine.system() == 'windows' ? 'libva-win32' : 'libva'
663 dep_va = dependency(_dep_va_name, version : '>= 1.8.0', required : _va)
665 dep_va_headers = dep_va.partial_dependency(compile_args : true)
666 if cc.has_header_symbol('va/va.h', 'VASurfaceAttribDRMFormatModifiers',
667 dependencies: dep_va_headers)
668 pre_args += '-DHAVE_VA_SURFACE_ATTRIB_DRM_FORMAT_MODIFIERS'
671 with_gallium_va = dep_va.found()
673 va_drivers_path = get_option('va-libs-path')
674 if va_drivers_path == ''
675 va_drivers_path = join_paths(get_option('libdir'), 'dri')
678 with_gallium_xa = get_option('gallium-xa') \
679 .require(system_has_kms_drm, error_message : 'XA state tracker can only be built on unix-like OSes.') \
680 .require(with_gallium_nouveau or with_gallium_freedreno or with_gallium_i915 or with_gallium_svga,
681 error_message : 'XA state tracker requires at least one of the following gallium drivers: nouveau, freedreno, i915, svga.') \
684 d3d_drivers_path = get_option('d3d-drivers-path')
685 if d3d_drivers_path == ''
686 d3d_drivers_path = join_paths(get_option('prefix'), get_option('libdir'), 'd3d')
689 with_gallium_st_nine = get_option('gallium-nine')
690 if with_gallium_st_nine
691 if not with_gallium_swrast
692 error('The nine state tracker requires gallium softpipe/llvmpipe.')
695 with_gallium_freedreno,
698 with_gallium_nouveau,
699 with_gallium_panfrost,
702 with_gallium_radeonsi,
706 error('The nine state tracker requires at least one non-swrast gallium driver.')
709 with_gallium_st_d3d10umd = get_option('gallium-d3d10umd')
710 if with_gallium_st_d3d10umd
711 if not with_gallium_swrast
712 error('The d3d10umd state tracker requires gallium softpipe/llvmpipe.')
715 _power8 = get_option('power8')
717 if host_machine.cpu_family() == 'ppc64' and host_machine.endian() == 'little'
718 if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.8')
719 error('Altivec is not supported with gcc version < 4.8.')
724 vector unsigned char r;
725 vector unsigned int v = vec_splat_u32 (1);
726 r = __builtin_vec_vgbbd ((vector unsigned char) v);
729 args : '-mpower8-vector',
730 name : 'POWER8 intrinsics')
731 pre_args += ['-D_ARCH_PWR8']
732 c_cpp_args += '-mpower8-vector'
733 elif _power8.enabled()
734 error('POWER8 intrinsic support required but not found.')
739 if get_option('vmware-mks-stats')
740 if not with_gallium_svga
741 error('vmware-mks-stats requires gallium VMware/svga driver.')
743 pre_args += '-DVMX86_STATS=1'
746 _opencl = get_option('gallium-opencl')
747 _rtti = get_option('cpp_rtti')
748 if _opencl != 'disabled'
750 error('OpenCL Clover implementation requires at least one gallium driver.')
753 error('The Clover OpenCL state tracker requires rtti')
756 with_gallium_clover = true
757 with_opencl_icd = _opencl == 'icd'
759 with_gallium_clover = false
760 with_opencl_icd = false
763 with_gallium_rusticl = get_option('gallium-rusticl')
764 if with_gallium_rusticl
766 error('rusticl requires at least one gallium driver.')
770 if with_gallium_rusticl or with_nouveau_vk or with_tools.contains('etnaviv')
771 if with_gallium_rusticl
772 # uses rust.bindgen.output_inline_wrapper needing 1.4.0
773 if meson.version().version_compare('< 1.4.0')
774 error('Rusticl requires meson 1.4.0 or newer')
777 # see https://github.com/mesonbuild/meson/issues/12758 (backported to 1.3.2)
778 if meson.version().version_compare('< 1.3.2')
779 error('Mesa Rust support requires meson 1.3.2 or newer')
783 add_languages('rust', required: true)
784 rustc = meson.get_compiler('rust')
785 rust = import('rust')
787 if rustc.version().version_compare('< 1.78')
788 error('Mesa requires Rust 1.78.0 or newer')
791 bindgen_version = find_program('bindgen').version()
792 if bindgen_version == 'unknown'
793 error('Failed to detect bindgen version. If you are using bindgen 0.69.0, ' +
794 'please either update to 0.69.1 or downgrade to 0.68.1. ' +
795 'You can install the latest version for your user with `cargo install bindgen-cli`.')
798 if bindgen_version.version_compare('< 0.65')
799 error('Mesa requires bindgen 0.65 or newer. ' +
800 'If your distribution does not ship a recent enough version, ' +
801 'you can install the latest version for your user with `cargo install bindgen-cli`.')
805 with_clc = with_microsoft_clc or with_intel_clc or with_gallium_asahi or with_asahi_vk or with_gallium_rusticl
808 if with_gallium_clover or with_clc
809 dep_clc = dependency('libclc')
812 gl_pkgconfig_c_flags = []
813 with_glx_indirect_rendering = false
815 if with_glx == 'xlib'
816 pre_args += '-DUSE_XSHM'
818 with_glx_indirect_rendering = true
819 pre_args += '-DGLX_INDIRECT_RENDERING'
821 pre_args += '-DGLX_DIRECT_RENDERING'
823 if with_dri_platform == 'drm'
824 pre_args += '-DGLX_USE_DRM'
825 elif with_dri_platform == 'apple'
826 pre_args += '-DGLX_USE_APPLEGL'
827 # Check to see if more than just the default 'swrast' is required
828 if (not with_gallium_softpipe) or 1 < gallium_drivers.length()
829 # Switch the MacOS code from "forwarding to the OpenGL.framework" mode
830 # and into actual Gallium Driver mode
831 pre_args += '-DGLX_USE_APPLE'
833 elif with_dri_platform == 'windows'
834 pre_args += '-DGLX_USE_WINDOWSGL'
839 with_glapi_export_proto_entry_points = false
840 if with_shared_glapi and not with_glx_indirect_rendering
841 # Imply !defined(GLX_INDIRECT_RENDERING)
842 with_glapi_export_proto_entry_points = true
844 pre_args += '-DGLAPI_EXPORT_PROTO_ENTRY_POINTS=@0@'.format(with_glapi_export_proto_entry_points.to_int())
846 with_android_stub = get_option('android-stub')
847 if with_android_stub and not with_platform_android
848 error('`-D android-stub=true` makes no sense without `-D platforms=android`')
851 with_libbacktrace = get_option('android-libbacktrace') \
852 .require(with_platform_android, error_message : '`-D android-libbacktrace=enabled` makes no sense without `-D platforms=android`') \
853 .disable_auto_if(not with_platform_android) \
857 cpp_args += '-DWITH_LIBBACKTRACE'
860 if with_platform_android
861 dep_android_ui = null_dep
862 dep_android_mapper4 = null_dep
863 if not with_android_stub
865 dependency('cutils'),
866 dependency('hardware'),
871 dep_android += dependency('backtrace')
873 if get_option('platform-sdk-version') >= 26
874 dep_android += dependency('nativewindow')
876 if get_option('platform-sdk-version') >= 30
877 dep_android_mapper4 = dependency('android.hardware.graphics.mapper', version : '>= 4.0', required : false)
879 if get_option('platform-sdk-version') >= 35
880 dep_android_ui = dependency('ui', required : false)
883 pre_args += '-DANDROID_API_LEVEL=' + get_option('platform-sdk-version').to_string()
884 if get_option('android-strict')
885 pre_args += '-DANDROID_STRICT'
889 # On Android, seccomp kills the process on kernels without
890 # CONFIG_KCMP/CONFIG_CHECKPOINT_RESTORE if it attemps to use KCMP.
891 # Since we can't detect that, err on the side of caution and disable
892 # KCMP by default on Android.
893 if get_option('allow-kcmp') \
894 .disable_auto_if(with_platform_android) \
896 pre_args += '-DALLOW_KCMP'
899 prog_python = import('python').find_installation('python3')
900 has_mako = run_command(
904 from packaging.version import Version
906 from distutils.version import StrictVersion as Version
908 assert Version(mako.__version__) >= Version("0.8.0")
910 if has_mako.returncode() != 0
911 error('Python (3.x) mako module >= 0.8.0 required to build mesa.')
914 has_yaml = run_command(
919 if has_yaml.returncode() != 0
920 error('Python (3.x) yaml module (PyYAML) required to build mesa.')
923 if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
924 error('When using GCC, version 4.4.6 or later is required.')
927 # Support systems without ETIME (e.g. FreeBSD)
928 if cc.get_define('ETIME', prefix : '#include <errno.h>') == ''
929 pre_args += '-DETIME=ETIMEDOUT'
932 # Define MESA_DEBUG to 1 for debug builds only (debugoptimized is not included on this one);
933 # otherwise define MESA_DEBUG to 0
934 pre_args += '-DMESA_DEBUG=@0@'.format(with_mesa_debug.to_int())
936 with_split_debug = get_option('split-debug') \
937 .disable_if(not cc.has_argument('-gsplit-dwarf'),
938 error_message : 'split-debug requires compiler -gsplit-dwarf support') \
939 .disable_if(not cc.has_link_argument('-Wl,--gdb-index'),
940 error_message : 'split-debug requires the linker argument -Wl,--gdb-index')
942 if with_split_debug.allowed() and get_option('debug')
943 add_project_arguments('-gsplit-dwarf', language : ['c', 'cpp'])
944 add_project_link_arguments('-Wl,--gdb-index', language : ['c', 'cpp'])
947 with_shader_cache = get_option('shader-cache') \
948 .require(host_machine.system() != 'windows', error_message : 'Shader Cache does not currently work on Windows') \
952 pre_args += '-DENABLE_SHADER_CACHE'
953 if not get_option('shader-cache-default')
954 pre_args += '-DSHADER_CACHE_DISABLE_BY_DEFAULT'
957 shader_cache_max_size = get_option('shader-cache-max-size')
958 if shader_cache_max_size != ''
959 pre_args += '-DMESA_SHADER_CACHE_MAX_SIZE="@0@"'.format(shader_cache_max_size)
963 # Check for GCC style builtins
964 foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
965 'ffsll', 'popcount', 'popcountll', 'unreachable', 'types_compatible_p']
966 if cc.has_function(b)
967 pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
971 # check for GCC __attribute__
973 'const', 'flatten', 'malloc', 'pure', 'unused', 'warn_unused_result',
974 'weak', 'format', 'packed', 'returns_nonnull', 'alias', 'noreturn',
977 foreach a : cc.get_supported_function_attributes(_attributes)
978 pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
980 if cc.has_function_attribute('visibility:hidden')
981 pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISIBILITY'
983 if cc.compiles('__uint128_t foo(void) { return 0; }',
984 name : '__uint128_t')
985 pre_args += '-DHAVE_UINT128'
988 if cc.has_function('reallocarray')
989 pre_args += '-DHAVE_REALLOCARRAY'
991 if cc.has_function('fmemopen')
992 pre_args += '-DHAVE_FMEMOPEN'
995 # TODO: this is very incomplete
996 if ['linux', 'cygwin', 'gnu', 'freebsd', 'gnu/kfreebsd', 'haiku', 'android', 'managarm'].contains(host_machine.system())
997 pre_args += '-D_GNU_SOURCE'
998 elif host_machine.system() == 'sunos'
999 pre_args += '-D__EXTENSIONS__'
1000 elif host_machine.system() == 'windows'
1002 '-D_WINDOWS', '-D_WIN32_WINNT=0x0A00', '-DWINVER=0x0A00',
1003 '-DPIPE_SUBSYSTEM_WINDOWS_USER',
1004 '-D_USE_MATH_DEFINES', # XXX: scons didn't use this for mingw
1006 if cc.get_argument_syntax() == 'msvc'
1009 '-D_CRT_SECURE_NO_WARNINGS',
1010 '-D_CRT_SECURE_NO_DEPRECATE',
1011 '-D_SCL_SECURE_NO_WARNINGS',
1012 '-D_SCL_SECURE_NO_DEPRECATE',
1013 '-D_ALLOW_KEYWORD_MACROS',
1014 '-D_HAS_EXCEPTIONS=0', # Tell C++ STL to not use exceptions
1018 # When the target is not mingw/ucrt
1019 # NOTE: clang's stddef.h are conflict with mingw/ucrt's stddef.h
1020 # So do not include headers that defined in clang for detecting
1024 #if defined(__MINGW32__) && defined(_UCRT)
1027 int main(void) { return 0; }''')
1028 pre_args += ['-D__MSVCRT_VERSION__=0x0700']
1031 elif host_machine.system() == 'openbsd'
1032 pre_args += '-D_ISOC11_SOURCE'
1035 # Check for generic C arguments
1036 c_msvc_compat_args = []
1037 no_override_init_args = []
1038 cpp_msvc_compat_args = []
1039 ld_args_gc_sections = []
1040 if cc.get_argument_syntax() == 'msvc'
1042 '/wd4018', # signed/unsigned mismatch
1043 '/wd4056', # overflow in floating-point constant arithmetic
1044 '/wd4244', # conversion from 'type1' to 'type2', possible loss of data
1045 '/wd4267', # 'var' : conversion from 'size_t' to 'type', possible loss of data
1046 '/wd4305', # truncation from 'type1' to 'type2'
1047 '/wd4351', # new behavior: elements of array 'array' will be default initialized
1048 '/wd4756', # overflow in constant arithmetic
1049 '/wd4800', # forcing value to bool 'true' or 'false' (performance warning)
1050 '/wd4996', # disabled deprecated POSIX name warnings
1051 '/wd4291', # no matching operator delete found
1052 '/wd4146', # unary minus operator applied to unsigned type, result still unsigned
1053 '/wd4200', # nonstandard extension used: zero-sized array in struct/union
1054 '/wd4624', # destructor was implicitly defined as deleted [from LLVM]
1055 '/wd4309', # 'initializing': truncation of constant value
1056 '/wd4838', # conversion from 'int' to 'const char' requires a narrowing conversion
1057 '/wd5105', # macro expansion producing 'defined' has undefined behavior (winbase.h, need Windows SDK upgrade)
1058 '/we4020', # Error when passing the wrong number of parameters
1059 '/we4024', # Error when passing different type of parameter
1060 '/we4189', # 'identifier' : local variable is initialized but not referenced
1061 '/Zc:__cplusplus', #Set __cplusplus macro to match the /std:c++<version> on the command line
1063 c_args += cc.get_supported_arguments(_trial)
1064 cpp_args += cpp.get_supported_arguments(_trial)
1067 '-Werror=implicit-function-declaration',
1068 '-Werror=missing-prototypes',
1069 '-Werror=return-type',
1070 '-Werror=empty-body',
1071 '-Werror=incompatible-pointer-types',
1072 '-Werror=int-conversion',
1073 '-Wimplicit-fallthrough',
1074 '-Wmisleading-indentation',
1075 '-Wno-missing-field-initializers',
1076 '-Wno-format-truncation',
1077 '-Wno-nonnull-compare',
1079 '-fno-trapping-math',
1080 '-Qunused-arguments',
1082 '-Wno-unknown-pragmas',
1084 '-Wno-microsoft-enum-value',
1085 '-Wno-unused-function',
1088 '-Werror=return-type',
1089 '-Werror=empty-body',
1090 '-Wmisleading-indentation',
1091 '-Wno-non-virtual-dtor',
1092 '-Wno-missing-field-initializers',
1093 '-Wno-format-truncation',
1095 '-fno-trapping-math',
1096 '-Qunused-arguments',
1097 # Some classes use custom new operator which zeroes memory, however
1098 # gcc does aggressive dead-store elimination which threats all writes
1099 # to the memory before the constructor as "dead stores".
1100 # For now we disable this optimization.
1102 '-Wno-unknown-pragmas',
1104 '-Wno-microsoft-enum-value',
1107 # MinGW chokes on format specifiers and I can't get it all working
1108 if not (cc.get_argument_syntax() == 'gcc' and host_machine.system() == 'windows')
1109 _trial_c += ['-Werror=format', '-Wformat-security']
1110 _trial_cpp += ['-Werror=format', '-Wformat-security']
1113 # FreeBSD annotated <pthread.h> but Mesa isn't ready
1114 if not (cc.get_id() == 'clang' and host_machine.system() == 'freebsd')
1115 _trial_c += ['-Werror=thread-safety']
1118 # If the compiler supports it, put function and data symbols in their
1119 # own sections and GC the sections after linking. This lets drivers
1120 # drop shared code unused by that specific driver (particularly
1121 # relevant for Vulkan drivers).
1122 if cc.links('static char unused() { return 5; } int main() { return 0; }',
1123 args : '-Wl,--gc-sections', name : 'gc-sections')
1124 ld_args_gc_sections += '-Wl,--gc-sections'
1125 _trial_c += ['-ffunction-sections', '-fdata-sections']
1126 _trial_cpp += ['-ffunction-sections', '-fdata-sections']
1129 # Variables that are only used for assertions are considered unused when assertions
1130 # are disabled. Don't treat this as an error, since we build with -Werror even if
1131 # assertions are disabled.
1133 _trial_c += ['-Wno-unused-variable', '-Wno-unused-but-set-variable', '/wd4189']
1134 _trial_cpp += ['-Wno-unused-variable', '-Wno-unused-but-set-variable', '/wd4189']
1137 c_args += cc.get_supported_arguments(_trial_c)
1138 cpp_args += cpp.get_supported_arguments(_trial_cpp)
1140 no_override_init_args += cc.get_supported_arguments(
1141 ['-Wno-override-init', '-Wno-initializer-overrides']
1144 # Check for C and C++ arguments for MSVC compatibility. These are only used
1145 # in parts of the mesa code base that need to compile with MSVC, mainly
1147 _trial_msvc = ['-Werror=pointer-arith', '-Werror=vla', '-Werror=gnu-empty-initializer']
1148 c_msvc_compat_args += cc.get_supported_arguments(_trial_msvc)
1149 cpp_msvc_compat_args += cpp.get_supported_arguments(_trial_msvc)
1152 # set linker arguments
1153 if host_machine.system() == 'windows'
1154 if cc.get_argument_syntax() == 'msvc'
1155 add_project_link_arguments(
1159 language : ['c', 'cpp'],
1161 if get_option('buildtype') != 'debug'
1162 add_project_link_arguments(
1164 language : ['c', 'cpp'],
1168 add_project_link_arguments(
1169 cc.get_supported_link_arguments(
1171 '-Wl,--dynamicbase',
1173 '-static-libstdc++',
1177 add_project_link_arguments(
1178 cpp.get_supported_link_arguments(
1180 '-Wl,--dynamicbase',
1182 '-static-libstdc++',
1193 if host_machine.cpu_family().startswith('x86')
1194 pre_args += '-DUSE_SSE41'
1197 if cc.get_id() != 'msvc'
1198 sse41_args = ['-msse4.1']
1200 if host_machine.cpu_family() == 'x86'
1201 # x86_64 have sse2 by default, so sse2 args only for x86
1202 sse2_arg = ['-msse2', '-mfpmath=sse']
1203 sse2_args = [sse2_arg, '-mstackrealign']
1204 if get_option('sse2')
1205 # These settings make generated GCC code match MSVC and follow
1206 # GCC advice on https://gcc.gnu.org/wiki/FloatingPointMath#x86note
1208 # NOTE: We need to ensure stack is realigned given that we
1209 # produce shared objects, and have no control over the stack
1210 # alignment policy of the application. Therefore we need
1211 # -mstackrealign or -mincoming-stack-boundary=2.
1213 # XXX: We could have SSE without -mstackrealign if we always used
1214 # __attribute__((force_align_arg_pointer)), but that's not
1216 c_cpp_args += sse2_args
1217 # sse2_args are adopted into c_cpp_args to avoid duplicated sse2 command line args
1221 # GCC on x86 (not x86_64) with -msse* assumes a 16 byte aligned stack, but
1222 # that's not guaranteed
1223 sse41_args += '-mstackrealign'
1229 # Detect __builtin_ia32_clflushopt support
1230 if cc.has_function('__builtin_ia32_clflushopt', args : '-mclflushopt')
1231 pre_args += '-DHAVE___BUILTIN_IA32_CLFLUSHOPT'
1232 clflushopt_args = ['-mclflushopt']
1233 with_clflushopt = true
1235 clflushopt_args = []
1236 with_clflushopt = false
1239 # Check for GCC style atomics
1240 dep_atomic = null_dep
1242 if cc.compiles('''#include <stdint.h>
1247 return (int)__atomic_load_n(x.v, __ATOMIC_ACQUIRE) &
1248 (int)__atomic_add_fetch(x.v, (uint64_t)1, __ATOMIC_ACQ_REL);
1251 name : 'GCC atomic builtins')
1252 pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
1254 # Not all atomic calls can be turned into lock-free instructions, in which
1255 # GCC will make calls into the libatomic library. Check whether we need to
1256 # link with -latomic.
1258 # This can happen for 64-bit atomic operations on 32-bit architectures such
1260 if not cc.links('''#include <stdint.h>
1265 return (int)__atomic_load_n(x.v, __ATOMIC_ACQUIRE) &
1266 (int)__atomic_add_fetch(x.v, (uint64_t)1, __ATOMIC_ACQ_REL);
1268 name : 'GCC atomic builtins required -latomic')
1269 dep_atomic = cc.find_library('atomic')
1272 if not cc.links('''#include <stdint.h>
1275 return __sync_add_and_fetch(&v, (uint64_t)1);
1277 dependencies : dep_atomic,
1278 name : 'GCC 64bit atomics')
1279 pre_args += '-DMISSING_64BIT_ATOMICS'
1282 dep_ws2_32 = cc.find_library('ws2_32', required : with_platform_windows)
1284 # TODO: shared/static? Is this even worth doing?
1287 if host_machine.cpu_family() == 'x86'
1288 if system_has_kms_drm or host_machine.system() == 'gnu'
1289 with_asm_arch = 'x86'
1290 pre_args += ['-DUSE_X86_ASM']
1292 if with_glx_read_only_text
1293 pre_args += ['-DGLX_X86_READONLY_TEXT']
1296 elif host_machine.cpu_family() == 'x86_64'
1297 if system_has_kms_drm
1298 with_asm_arch = 'x86_64'
1299 pre_args += ['-DUSE_X86_64_ASM']
1301 elif host_machine.cpu_family() == 'arm'
1302 if system_has_kms_drm
1303 with_asm_arch = 'arm'
1304 pre_args += ['-DUSE_ARM_ASM']
1306 elif host_machine.cpu_family() == 'aarch64'
1307 if system_has_kms_drm
1308 with_asm_arch = 'aarch64'
1309 pre_args += ['-DUSE_AARCH64_ASM']
1311 elif host_machine.cpu_family() == 'sparc64'
1312 if system_has_kms_drm
1313 with_asm_arch = 'sparc'
1314 pre_args += ['-DUSE_SPARC_ASM']
1316 elif host_machine.cpu_family() == 'ppc64' and host_machine.endian() == 'little'
1317 if system_has_kms_drm
1318 with_asm_arch = 'ppc64le'
1319 pre_args += ['-DUSE_PPC64LE_ASM']
1321 elif host_machine.cpu_family() == 'mips64' and host_machine.endian() == 'little'
1322 if system_has_kms_drm
1323 with_asm_arch = 'mips64el'
1324 pre_args += ['-DUSE_MIPS64EL_ASM']
1326 elif host_machine.cpu_family() == 'loongarch64'
1327 if system_has_kms_drm
1328 with_asm_arch = 'loongarch64'
1329 pre_args += ['-DUSE_LOONGARCH64_ASM']
1333 # Check for standard headers and functions
1334 if (cc.has_header_symbol('sys/sysmacros.h', 'major') and
1335 cc.has_header_symbol('sys/sysmacros.h', 'minor') and
1336 cc.has_header_symbol('sys/sysmacros.h', 'makedev'))
1337 pre_args += '-DMAJOR_IN_SYSMACROS'
1339 if (cc.has_header_symbol('sys/mkdev.h', 'major') and
1340 cc.has_header_symbol('sys/mkdev.h', 'minor') and
1341 cc.has_header_symbol('sys/mkdev.h', 'makedev'))
1342 pre_args += '-DMAJOR_IN_MKDEV'
1345 if cc.check_header('sched.h')
1346 pre_args += '-DHAS_SCHED_H'
1347 if cc.has_function('sched_getaffinity')
1348 pre_args += '-DHAS_SCHED_GETAFFINITY'
1352 if not ['linux'].contains(host_machine.system())
1353 # Deprecated on Linux and requires <sys/types.h> on FreeBSD and OpenBSD
1354 if cc.check_header('sys/sysctl.h', prefix : '#include <sys/types.h>')
1355 pre_args += '-DHAVE_SYS_SYSCTL_H'
1359 foreach h : ['xlocale.h', 'linux/futex.h', 'endian.h', 'dlfcn.h', 'sys/shm.h',
1360 'cet.h', 'pthread_np.h', 'sys/inotify.h', 'linux/udmabuf.h']
1361 if cc.check_header(h)
1362 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
1366 functions_to_detect = {
1375 'posix_fallocate': '',
1376 'secure_getenv': '',
1379 foreach f, prefix: functions_to_detect
1380 if cc.has_function(f, prefix: prefix)
1381 pre_args += '-DHAVE_@0@'.format(f.to_upper())
1389 static int dcomp(const void *l, const void *r, void *t) { return 0; }
1391 int main(int ac, char **av) {
1394 qsort_r((void*)&arr[0], 1, 1, dcomp, t);
1398 name : 'GNU qsort_r')
1399 pre_args += '-DHAVE_GNU_QSORT_R'
1403 static int dcomp(void *t, const void *l, const void *r) { return 0; }
1405 int main(int ac, char **av) {
1408 qsort_r((void*)&arr[0], 1, 1, t, dcomp);
1412 name : 'BSD qsort_r')
1413 pre_args += '-DHAVE_BSD_QSORT_R'
1416 if cc.has_header_symbol('time.h', 'struct timespec')
1417 pre_args += '-DHAVE_STRUCT_TIMESPEC'
1420 with_c11_threads = false
1421 if cc.has_function('thrd_create', prefix: '#include <threads.h>')
1422 if with_platform_android
1423 # Current only Android's c11 <threads.h> are verified
1424 pre_args += '-DHAVE_THRD_CREATE'
1425 with_c11_threads = true
1429 if cc.has_header_symbol('errno.h', 'program_invocation_name',
1430 args : '-D_GNU_SOURCE')
1431 pre_args += '-DHAVE_PROGRAM_INVOCATION_NAME'
1432 elif with_tools.contains('intel')
1433 error('Intel tools require the program_invocation_name variable')
1436 if cc.has_header_symbol('math.h', 'issignaling',
1437 args : '-D_GNU_SOURCE')
1438 pre_args += '-DHAVE_ISSIGNALING'
1441 # MinGW provides a __builtin_posix_memalign function, but not a posix_memalign.
1442 # This means that this check will succeed, but then compilation will later
1443 # fail. MSVC doesn't have this function at all, so only check for it on
1444 # non-windows platforms.
1445 if host_machine.system() != 'windows'
1446 if cc.has_function('posix_memalign')
1447 pre_args += '-DHAVE_POSIX_MEMALIGN'
1451 if cc.has_member('struct dirent', 'd_type', prefix: '''#include <sys/types.h>
1452 #include <dirent.h>''')
1453 pre_args += '-DHAVE_DIRENT_D_TYPE'
1456 # strtod locale support
1461 #ifdef HAVE_XLOCALE_H
1462 #include <xlocale.h>
1465 locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
1466 const char *s = "1.0";
1468 double d = strtod_l(s, &end, loc);
1469 float f = strtof_l(s, &end, loc);
1474 name : 'strtod has locale support')
1475 pre_args += '-DHAVE_STRTOD_L'
1478 # Check for some linker flags
1479 ld_args_bsymbolic = []
1480 if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic', name : 'Bsymbolic')
1481 ld_args_bsymbolic += '-Wl,-Bsymbolic'
1483 with_ld_version_script = false
1484 if cc.links('int main() { return 0; }',
1485 args : '-Wl,--version-script=@0@'.format(
1486 join_paths(meson.current_source_dir(), 'build-support/conftest.map')),
1487 name : 'version-script')
1488 with_ld_version_script = true
1490 with_ld_dynamic_list = false
1491 if cc.links('int main() { return 0; }',
1492 args : '-Wl,--dynamic-list=@0@'.format(
1493 join_paths(meson.current_source_dir(), 'build-support/conftest.dyn')),
1494 name : 'dynamic-list')
1495 with_ld_dynamic_list = true
1498 ld_args_build_id = cc.get_supported_link_arguments('-Wl,--build-id=sha1')
1500 # check for dl support
1502 if host_machine.system() != 'windows'
1503 if not cc.has_function('dlopen')
1504 dep_dl = cc.find_library('dl', required : true)
1506 if cc.has_function('dladdr', dependencies : dep_dl)
1507 # This is really only required for util/disk_cache.h
1508 pre_args += '-DHAVE_DLADDR'
1512 if cc.has_function('dl_iterate_phdr')
1513 pre_args += '-DHAVE_DL_ITERATE_PHDR'
1514 elif with_intel_vk or with_intel_hasvk
1515 error('Intel "Anvil" Vulkan driver requires the dl_iterate_phdr function')
1518 if with_any_intel and ['x86', 'x86_64'].contains(host_machine.cpu_family())
1519 pre_args += '-DSUPPORT_INTEL_INTEGRATED_GPUS'
1522 if with_gallium_i915 and host_machine.cpu_family().startswith('x86') == false
1523 error('Intel "i915" Gallium driver requires x86 or x86_64 CPU family')
1526 # Determine whether or not the rt library is needed for time functions
1527 if host_machine.system() == 'windows' or cc.has_function('clock_gettime')
1528 dep_clock = null_dep
1530 dep_clock = cc.find_library('rt')
1533 # IMPORTANT: We can't upgrade Zlib beyond 1.2.5 because it would break Viewperf.
1534 dep_zlib = dependency('zlib', version : '>= 1.2.3',
1535 allow_fallback: true,
1536 required : get_option('zlib'))
1538 pre_args += '-DHAVE_ZLIB'
1541 dep_zstd = dependency('libzstd', required : get_option('zstd'))
1543 pre_args += '-DHAVE_ZSTD'
1546 with_compression = dep_zlib.found() or dep_zstd.found()
1548 pre_args += '-DHAVE_COMPRESSION'
1549 elif with_shader_cache
1550 error('Shader Cache requires compression')
1553 if host_machine.system() == 'windows'
1554 # For MSVC and MinGW we aren't using pthreads, and dependency('threads') will add linkage
1555 # to pthread for MinGW, so leave the dependency null_dep for Windows. For Windows linking to
1556 # kernel32 is enough for c11/threads.h and it's already linked by meson by default
1557 dep_thread = null_dep
1559 dep_thread = dependency('threads')
1561 if dep_thread.found()
1562 pre_args += '-DHAVE_PTHREAD'
1563 if host_machine.system() != 'netbsd' and cc.has_function(
1564 'pthread_setaffinity_np',
1565 dependencies : dep_thread,
1566 prefix : '#include <pthread.h>',
1567 args : '-D_GNU_SOURCE')
1568 pre_args += '-DHAVE_PTHREAD_SETAFFINITY'
1572 with_expat = get_option('expat') \
1573 .disable_auto_if(with_platform_android or with_platform_windows)
1575 if host_machine.system() == 'darwin'
1576 dep_expat = meson.get_compiler('c').find_library('expat', required : with_expat)
1578 dep_expat = dependency('expat', allow_fallback: true,
1579 required : with_expat)
1582 # TODO: with Meson 1.1.0 this can be replaced with with_expat.enable_if(with_intel_tools)
1583 if with_intel_tools and not dep_expat.found()
1584 error('Intel tools require expat')
1587 # We don't require expat on Android or Windows
1588 use_xmlconfig = get_option('xmlconfig') \
1589 .require(not (with_platform_android or with_platform_windows),
1590 error_message : 'xmlconfig not available on Android or Windows') \
1591 .require(dep_expat.found(),
1592 error_message : 'requires expat') \
1595 # Predefined macros for windows
1596 if host_machine.system() == 'windows'
1597 pre_args += '-DWIN32_LEAN_AND_MEAN' # http://msdn2.microsoft.com/en-us/library/6dwk3a1z.aspx
1599 # this only exists on linux so either this is linux and it will be found, or
1600 # it's not linux and wont
1601 dep_m = cc.find_library('m', required : false)
1603 if host_machine.system() == 'windows'
1604 dep_regex = meson.get_compiler('c').find_library('regex', required : false)
1605 if not dep_regex.found()
1606 dep_regex = declare_dependency(compile_args : ['-DNO_REGEX'])
1609 dep_regex = null_dep
1612 if with_platform_haiku
1613 dep_network = cc.find_library('network')
1616 dep_futex = null_dep
1617 if host_machine.system() == 'windows'
1618 if (get_option('min-windows-version') < 8)
1619 pre_args += '-DWINDOWS_NO_FUTEX'
1621 dep_futex = cc.find_library('synchronization', required : true)
1625 # Check for libdrm. Various drivers have different libdrm version requirements,
1626 # but we always want to use the same version for all libdrm modules. That means
1627 # even if driver foo requires 2.4.0 and driver bar requires 2.4.3, if foo and
1628 # bar are both on use 2.4.3 for both of them
1629 dep_libdrm_amdgpu = null_dep
1630 dep_libdrm_intel = null_dep
1632 _drm_amdgpu_ver = '2.4.121'
1633 _drm_intel_ver = '2.4.75'
1634 _drm_ver = '2.4.109'
1637 ['intel', with_gallium_i915],
1638 ['amdgpu', (with_amd_vk and not with_platform_windows) or with_gallium_radeonsi],
1641 # Loop over the enables versions and get the highest libdrm requirement for all
1644 foreach d : _libdrm_checks
1645 ver = get_variable('_drm_@0@_ver'.format(d[0]))
1646 if d[1] and ver.version_compare('>' + _drm_ver)
1652 message('libdrm @0@ needed because @1@ has the highest requirement'.format(_drm_ver, _drm_blame))
1655 # Then get each libdrm module
1656 foreach d : _libdrm_checks
1659 'dep_libdrm_' + d[0],
1660 dependency('libdrm_' + d[0], version : '>=' + _drm_ver)
1665 with_gallium_drisw_kms = false
1666 if system_has_kms_drm
1667 dep_libdrm = dependency(
1668 'libdrm', version : '>=' + _drm_ver,
1669 required : with_dri2 or with_dri or with_gbm
1672 # We should prevent libdrm from being available when the target doesn't have it to avoid transitive
1673 # dependencies (such as vk-runtime) linking to it
1674 dep_libdrm = null_dep
1676 if dep_libdrm.found()
1677 pre_args += '-DHAVE_LIBDRM'
1678 if with_dri_platform == 'drm' and with_dri
1679 with_gallium_drisw_kms = true
1683 dep_libudev = dependency('libudev', required : false)
1684 if dep_libudev.found()
1685 pre_args += '-DHAVE_LIBUDEV'
1688 llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit', 'core', 'executionengine', 'scalaropts', 'transformutils', 'instcombine']
1689 llvm_optional_modules = ['coroutines']
1690 if with_amd_vk or with_gallium_radeonsi or with_gallium_r600
1691 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
1692 if with_gallium_r600
1693 llvm_modules += 'asmparser'
1696 if with_gallium_clover
1698 'linker', 'coverage', 'instrumentation', 'ipo', 'irreader',
1699 'lto', 'option', 'objcarcopts', 'profiledata'
1701 # all-targets is needed to support static linking LLVM build with multiple targets
1702 # windowsdriver is needded with LLVM>=15, but we don't know what LLVM verrsion we are using yet
1703 llvm_optional_modules += ['all-targets', 'frontendopenmp', 'windowsdriver']
1706 llvm_modules += ['coverage', 'target', 'linker', 'irreader', 'option', 'libdriver', 'lto']
1707 # all-targets is needed to support static linking LLVM build with multiple targets.
1708 # windowsdriver is needded with LLVM>=15 and frontendhlsl is needed with LLVM>=16,
1709 # but we don't know what LLVM version we are using yet
1710 llvm_optional_modules += ['all-targets', 'windowsdriver', 'frontendhlsl', 'frontenddriver']
1712 draw_with_llvm = get_option('draw-use-llvm')
1714 llvm_modules += 'native'
1715 # lto is needded with LLVM>=15, but we don't know what LLVM verrsion we are using yet
1716 llvm_optional_modules += ['lto']
1718 amd_with_llvm = get_option('amd-use-llvm')
1720 # MCJIT is deprecated in LLVM and will not accept new architecture ports,
1721 # so any architecture not in the exhaustive list will have to rely on LLVM
1722 # ORCJIT for llvmpipe functionality.
1723 llvm_has_mcjit = host_machine.cpu_family() in ['aarch64', 'arm', 'ppc', 'ppc64', 's390x', 'x86', 'x86_64']
1724 llvm_with_orcjit = get_option('llvm-orcjit') or not llvm_has_mcjit
1726 if with_amd_vk or with_gallium_radeonsi or with_clc or llvm_with_orcjit
1727 _llvm_version = '>= 15.0.0'
1728 elif with_gallium_clover
1729 _llvm_version = '>= 11.0.0'
1731 _llvm_version = '>= 5.0.0'
1734 _shared_llvm = get_option('shared-llvm') \
1735 .disable_auto_if(host_machine.system() == 'windows') \
1738 _llvm = get_option('llvm')
1742 dep_llvm = dependency(
1744 method : host_machine.system() == 'windows' ? 'auto' : 'config-tool',
1745 version : _llvm_version,
1746 modules : llvm_modules,
1747 optional_modules : llvm_optional_modules,
1749 with_amd_vk or with_gallium_radeonsi or with_gallium_clover or with_clc
1752 static : not _shared_llvm,
1753 fallback : ['llvm', 'dep_llvm'],
1754 include_type : 'system',
1756 with_llvm = dep_llvm.found()
1759 pre_args += '-DMESA_LLVM_VERSION_STRING="@0@"'.format(dep_llvm.version())
1760 pre_args += '-DLLVM_IS_SHARED=@0@'.format(_shared_llvm.to_int())
1762 if (with_swrast_vk or with_gallium_llvmpipe) and not draw_with_llvm
1763 error('Lavapipe and llvmpipe require LLVM draw support.')
1766 if with_gallium_r600 and not amd_with_llvm
1767 error('R600 requires LLVM AMD support.')
1770 if host_machine.system() != 'windows'
1771 # LLVM can be built without rtti, turning off rtti changes the ABI of C++
1772 # programs, so we need to build all C++ code in mesa without rtti as well to
1773 # ensure that linking works. Note that Win32 compilers does handle mismatching RTTI
1774 # without issues, so only apply this for other compilers.
1775 if dep_llvm.type_name() == 'internal'
1776 _llvm_rtti = subproject('llvm').get_variable('has_rtti', true)
1778 # The CMake finder will return 'ON', the llvm-config will return 'YES'
1779 _llvm_rtti = ['ON', 'YES'].contains(dep_llvm.get_variable(cmake : 'LLVM_ENABLE_RTTI', configtool: 'has-rtti'))
1781 if _rtti != _llvm_rtti
1783 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.')
1785 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.')
1790 if cc.get_argument_syntax() == 'msvc'
1791 # Suppress "/DELAYLOAD:ole32.dll/shell32.dll ignored" warnings that LLVM adds
1792 add_project_link_arguments(
1794 language : ['c', 'cpp'],
1797 elif with_amd_vk and with_aco_tests
1798 error('ACO tests require LLVM, but LLVM is disabled.')
1800 error('lavapipe requires LLVM and is enabled, but LLVM is disabled.')
1801 elif with_any_llvmpipe
1802 error('llvmpipe requires LLVM and is enabled, but LLVM is disabled.')
1803 elif with_gallium_clover
1804 error('The OpenCL "Clover" state tracker requires LLVM, but LLVM is disabled.')
1806 error('The CLC compiler requires LLVM, but LLVM is disabled.')
1808 draw_with_llvm = false
1810 amd_with_llvm = amd_with_llvm and with_llvm
1811 pre_args += '-DLLVM_AVAILABLE=@0@'.format(with_llvm.to_int())
1812 pre_args += '-DDRAW_LLVM_AVAILABLE=@0@'.format((with_llvm and draw_with_llvm).to_int())
1813 pre_args += '-DAMD_LLVM_AVAILABLE=@0@'.format(amd_with_llvm.to_int())
1814 pre_args += '-DGALLIVM_USE_ORCJIT=@0@'.format((with_llvm and llvm_with_orcjit).to_int())
1817 chosen_llvm_version_array = dep_llvm.version().split('.')
1818 chosen_llvm_version_major = chosen_llvm_version_array[0].to_int()
1819 chosen_llvm_version_minor = chosen_llvm_version_array[1].to_int()
1821 # Require an SPIRV-LLVM-Translator version compatible with the chosen LLVM
1824 # This first version check is still needed as maybe LLVM 8.0 was picked but
1825 # we do not want to accept SPIRV-LLVM-Translator 8.0.0.1 as that version
1826 # does not have the required API and those are only available starting from
1828 _llvmspirvlib_min_version = '>= 8.0.1.3'
1830 _llvmspirvlib_min_version = '>= 15.0.0.0'
1833 _llvmspirvlib_version = [
1834 _llvmspirvlib_min_version,
1835 '>= @0@.@1@'.format(chosen_llvm_version_major, chosen_llvm_version_minor),
1836 '< @0@.@1@'.format(chosen_llvm_version_major, chosen_llvm_version_minor + 1) ]
1838 # LLVMSPIRVLib is available at https://github.com/KhronosGroup/SPIRV-LLVM-Translator
1839 dep_llvmspirvlib = dependency('LLVMSPIRVLib', required : true, version : _llvmspirvlib_version)
1841 dep_llvmspirvlib = null_dep
1844 dep_spirv_tools = dependency(
1846 required : with_clc,
1847 version : '>= 2022.1'
1849 if dep_spirv_tools.found()
1850 pre_args += '-DHAVE_SPIRV_TOOLS'
1853 dep_clang = null_dep
1854 if with_clc or with_gallium_clover
1855 llvm_libdir = dep_llvm.get_variable(cmake : 'LLVM_LIBRARY_DIR', configtool: 'libdir')
1857 dep_clang = cpp.find_library('clang-cpp', dirs : llvm_libdir, required : false)
1859 if not dep_clang.found() or not _shared_llvm
1861 'clangBasic', 'clangAST', 'clangCodeGen', 'clangLex',
1862 'clangDriver', 'clangFrontend', 'clangFrontendTool',
1863 'clangHandleCXX', 'clangHandleLLVM', 'clangSerialization',
1864 'clangSema', 'clangParse', 'clangEdit', 'clangAnalysis'
1866 if dep_llvm.version().version_compare('>= 15.0')
1867 clang_modules += 'clangSupport'
1869 if dep_llvm.version().version_compare('>= 16.0') or with_gallium_clover
1870 clang_modules += 'clangASTMatchers'
1872 if dep_llvm.version().version_compare('>= 18.0')
1873 clang_modules += 'clangAPINotes'
1877 foreach m : clang_modules
1878 dep_clang += cpp.find_library(m, dirs : llvm_libdir, required : true)
1883 dep_lua = dependency('lua54', 'lua5.4', 'lua-5.4',
1884 'lua53', 'lua5.3', 'lua-5.3',
1885 'lua', required: false,
1886 allow_fallback: with_tools.contains('freedreno'),
1889 # Be explicit about only using this lib on Windows, to avoid picking
1890 # up random libs with the generic name 'libversion'
1891 dep_version = null_dep
1892 if host_machine.system() == 'windows'
1893 dep_version = cpp.find_library('version')
1896 dep_elf = dependency('libelf', required : false)
1897 if not with_platform_windows and not dep_elf.found()
1898 dep_elf = cc.find_library('elf', required : false)
1901 pre_args += '-DUSE_LIBELF'
1902 elif with_gallium_radeonsi
1903 error('Gallium driver radeonsi requires libelf')
1906 dep_valgrind = dependency('valgrind', required : get_option('valgrind'))
1907 if dep_valgrind.found()
1908 pre_args += '-DHAVE_VALGRIND'
1911 # AddressSanitizer's leak reports need all the symbols to be present at exit to
1912 # decode well, which runs afoul of our dlopen()/dlclose()ing of the DRI drivers.
1913 # Set a flag so we can skip the dlclose for asan builds.
1914 if ['address', 'address,undefined'].contains(get_option('b_sanitize'))
1915 asan_c_args = ['-DBUILT_WITH_ASAN=1']
1917 asan_c_args = ['-DBUILT_WITH_ASAN=0']
1920 # ThreadSanitizer can't deal with futexes, and reports races for cases we don't care about
1921 # so add a define to work silence these issues.
1922 if get_option('b_sanitize') == 'thread'
1923 pre_args += '-DTHREAD_SANITIZER=1'
1924 # meson versions prior to 1.4 will warn "Consider using the built-in option for sanitizers ..."
1925 # later on because it only checks whether the option starts with "-fsanitize",
1926 # but there is no built-in option for adding a blacklist
1927 tsan_blacklist = '-fsanitize-blacklist=@0@'.format(join_paths(meson.project_source_root(), 'build-support', 'tsan-blacklist.txt'))
1928 if cc.has_argument(tsan_blacklist)
1929 pre_args += tsan_blacklist
1931 warning('Compiler does not support "-fsanitize-blacklist", expected race conditions will not be surpressed')
1934 pre_args += '-DTHREAD_SANITIZER=0'
1937 yacc_is_bison = true
1938 needs_flex_bison = with_any_opengl or with_freedreno_vk or with_intel_tools or with_gallium
1940 if build_machine.system() == 'windows'
1941 # Prefer the winflexbison versions, they're much easier to install and have
1942 # better windows support.
1944 prog_flex = find_program('win_flex', required : false)
1945 if prog_flex.found()
1946 # windows compatibility (uses <io.h> instead of <unistd.h> and _isatty,
1947 # _fileno functions)
1948 prog_flex = [prog_flex, '--wincompat']
1950 prog_flex = [find_program('flex', 'lex', required : needs_flex_bison, disabler : true)]
1952 # Force flex to use const keyword in prototypes, as relies on __cplusplus or
1953 # __STDC__ macro to determine whether it's safe to use const keyword
1954 prog_flex += '-DYY_USE_CONST='
1956 prog_flex_cpp = prog_flex
1957 # Convince win_flex to use <inttypes.h> for C++ files
1958 # Note that we are using a C99 version here rather than C11,
1959 # because using a C11 version can cause the MSVC CRT headers to define
1960 # static_assert to _Static_assert, which breaks other parts of the CRT
1961 prog_flex_cpp += '-D__STDC_VERSION__=199901'
1963 prog_bison = find_program('win_bison', required : false)
1964 if not prog_bison.found()
1965 prog_bison = find_program('bison', 'yacc', required : needs_flex_bison, disabler : true)
1968 prog_bison = find_program('bison', required : false)
1970 if not prog_bison.found()
1971 prog_bison = find_program('byacc', required : needs_flex_bison, disabler : true)
1972 yacc_is_bison = false
1975 # Disable deprecated keyword warnings, since we have to use them for
1976 # old-bison compat. See discussion in
1977 # https://gitlab.freedesktop.org/mesa/mesa/merge_requests/2161
1978 if find_program('bison', required : false, version : '> 2.3').found()
1979 prog_bison = [prog_bison, '-Wno-deprecated']
1982 prog_flex = find_program('flex', required : needs_flex_bison, disabler : true)
1983 prog_flex_cpp = prog_flex
1986 _libunwind = get_option('libunwind') \
1987 .require(not with_platform_android, error_message : 'Android requires the use of the backtrace library, not libunwind')
1988 if host_machine.system() == 'darwin'
1989 dep_unwind = meson.get_compiler('c').find_library('System', required : _libunwind)
1991 dep_unwind = dependency('libunwind', required : _libunwind)
1993 if dep_unwind.found()
1994 pre_args += '-DHAVE_LIBUNWIND'
1998 if not with_gallium_swrast
1999 error('OSMesa gallium requires gallium softpipe or llvmpipe.')
2001 if host_machine.system() == 'windows'
2002 osmesa_lib_name = 'osmesa'
2004 osmesa_lib_name = 'OSMesa'
2008 # TODO: symbol mangling
2010 if with_platform_wayland
2011 dep_wl_scanner = dependency('wayland-scanner', native: true)
2012 prog_wl_scanner = find_program(dep_wl_scanner.get_variable(pkgconfig : 'wayland_scanner'))
2013 if dep_wl_scanner.version().version_compare('>= 1.15')
2014 wl_scanner_arg = 'private-code'
2016 wl_scanner_arg = 'code'
2018 dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.38', default_options: [ 'tests=false' ])
2019 dep_wayland_client = dependency('wayland-client', version : '>=1.18')
2020 dep_wayland_server = dependency('wayland-server', version : '>=1.18')
2022 dep_wayland_egl = dependency('wayland-egl-backend', version : '>= 3')
2023 dep_wayland_egl_headers = dep_wayland_egl.partial_dependency(compile_args : true)
2025 pre_args += '-DWL_HIDE_DEPRECATED'
2027 'wl_display_dispatch_queue_timeout',
2028 prefix : '#include <wayland-client.h>',
2029 dependencies: dep_wayland_client)
2030 pre_args += ['-DHAVE_WL_DISPATCH_QUEUE_TIMEOUT']
2033 'wl_display_create_queue_with_name',
2034 prefix : '#include <wayland-client.h>',
2035 dependencies: dep_wayland_client)
2036 pre_args += ['-DHAVE_WL_CREATE_QUEUE_WITH_NAME']
2040 # Even if we find OpenMP, Gitlab CI fails to link with gcc/i386 and clang/anyarch.
2041 dep_openmp = null_dep
2042 if host_machine.cpu_family() == 'x86_64' and cc.get_id() == 'gcc'
2043 dep_openmp = dependency('openmp', required : false)
2044 if dep_openmp.found()
2045 pre_args += ['-DHAVE_OPENMP']
2051 dep_xfixes = null_dep
2052 dep_x11_xcb = null_dep
2054 dep_xcb_keysyms = null_dep
2055 dep_xcb_glx = null_dep
2056 dep_xcb_dri2 = null_dep
2057 dep_xcb_dri3 = null_dep
2058 dep_dri2proto = null_dep
2059 dep_glproto = null_dep
2060 dep_xxf86vm = null_dep
2061 dep_xcb_present = null_dep
2062 dep_xcb_sync = null_dep
2063 dep_xcb_xfixes = null_dep
2064 dep_xshmfence = null_dep
2065 dep_xcb_xrandr = null_dep
2066 dep_xcb_shm = null_dep
2067 dep_xlib_xrandr = null_dep
2069 dep_dri2proto_version = '>= 2.8'
2070 dep_glproto_version = '>= 1.4.14'
2071 dep_xcb_dri2_version = '>= 1.8'
2072 dep_xcb_dri3_version = '>= 1.13'
2073 dep_xcb_glx_version = '>= 1.8.1'
2074 dep_xcb_present_version = '>= 1.13'
2075 dep_xfixes_version = '>= 2.0'
2076 dep_xlib_xrandr_version = '>= 1.3'
2077 dep_xshmfence_version = '>= 1.1'
2079 with_dri3_explicit_sync = false
2080 with_xcb_keysyms = false
2081 if with_platform_x11
2082 dep_xcb = dependency('xcb')
2083 dep_xcb_xrandr = dependency('xcb-randr')
2084 if with_glx == 'xlib'
2085 dep_x11 = dependency('x11')
2086 dep_xext = dependency('xext')
2087 elif with_glx == 'dri'
2088 dep_x11 = dependency('x11')
2089 dep_xext = dependency('xext')
2090 dep_xfixes = dependency('xfixes', version : dep_xfixes_version)
2091 dep_xcb_glx = dependency('xcb-glx', version : dep_xcb_glx_version)
2092 dep_xcb_shm = dependency('xcb-shm')
2093 elif with_gallium_rusticl
2094 # needed for GL sharing extension
2095 dep_x11 = dependency('x11')
2097 if (with_any_vk or with_glx == 'dri' or with_egl or
2098 (with_gallium_vdpau or with_gallium_va))
2099 dep_xcb = dependency('xcb')
2100 dep_xcb_keysyms = dependency('xcb-keysyms', required : false)
2101 with_xcb_keysyms = dep_xcb_keysyms.found()
2103 pre_args += '-DXCB_KEYSYMS_AVAILABLE'
2105 dep_x11_xcb = dependency('x11-xcb')
2106 dep_xcb_dri2 = dependency('xcb-dri2', version : dep_xcb_dri2_version, required : with_x11_dri2)
2107 if with_dri_platform == 'drm' and not dep_libdrm.found()
2108 error('libdrm required for gallium video statetrackers when using x11')
2111 if with_dri_platform == 'drm'
2112 dep_xcb_dri2 = dependency('xcb-dri2', version : dep_xcb_dri2_version, required : with_x11_dri2)
2114 dep_xcb_dri3 = dependency('xcb-dri3', version : dep_xcb_dri3_version)
2115 dep_xcb_present = dependency('xcb-present', version : dep_xcb_present_version)
2116 if (dep_xcb_dri3.version().version_compare('>= 1.17') and
2117 dep_xcb_present.version().version_compare('>= 1.17'))
2118 with_dri3_explicit_sync = true
2120 dep_xcb_shm = dependency('xcb-shm')
2121 dep_xcb_sync = dependency('xcb-sync')
2122 dep_xshmfence = dependency('xshmfence', version : dep_xshmfence_version)
2123 pre_args += '-DHAVE_X11_DRM'
2125 if with_glx == 'dri' or with_glx == 'xlib'
2126 dep_glproto = dependency('glproto', version : dep_glproto_version)
2128 if with_glx == 'dri'
2129 if with_dri_platform == 'drm'
2130 dep_dri2proto = dependency('dri2proto', version : dep_dri2proto_version)
2132 dep_xxf86vm = dependency('xxf86vm')
2139 with_gallium_vdpau or with_gallium_xa)
2140 dep_xcb_xfixes = dependency('xcb-xfixes')
2143 dep_xcb_dri3 = dependency('xcb-dri3', version : dep_xcb_dri3_version)
2144 dep_xcb_present = dependency('xcb-present', version : dep_xcb_present_version)
2145 dep_xcb_shm = dependency('xcb-shm')
2146 dep_xshmfence = dependency('xshmfence', version : dep_xshmfence_version)
2148 if with_xlib_lease or with_any_vk
2149 dep_xcb_xrandr = dependency('xcb-randr')
2152 dep_xlib_xrandr = dependency('xrandr', version : dep_xlib_xrandr_version)
2157 pre_args += '-DHAVE_DRI'
2160 pre_args += '-DHAVE_DRI2'
2163 pre_args += '-DHAVE_X11_DRI2'
2165 if with_dri3_explicit_sync
2166 pre_args += '-DHAVE_DRI3_EXPLICIT_SYNC'
2168 if with_gallium_drisw_kms
2169 pre_args += '-DHAVE_DRISW_KMS'
2172 if get_option('gallium-extra-hud')
2173 pre_args += '-DHAVE_GALLIUM_EXTRA_HUD=1'
2176 dep_lmsensors = cc.find_library('sensors', required : get_option('lmsensors'))
2177 if dep_lmsensors.found()
2178 pre_args += '-DHAVE_LIBSENSORS=1'
2181 _shader_replacement = get_option('custom-shader-replacement')
2182 if _shader_replacement == ''
2184 pre_args += '-DCUSTOM_SHADER_REPLACEMENT'
2187 with_perfetto = get_option('perfetto')
2188 with_datasources = get_option('datasources')
2189 with_any_datasource = with_datasources.length() != 0
2191 dep_perfetto = dependency('perfetto', fallback: ['perfetto', 'dep_perfetto'])
2192 pre_args += '-DHAVE_PERFETTO'
2195 with_teflon = get_option('teflon')
2196 if with_teflon and with_tests
2197 dep_xtensor = dependency('xtensor')
2198 dep_flatbuffers = dependency('flatbuffers')
2199 prog_flatc = find_program('flatc')
2202 with_gpuvis = get_option('gpuvis')
2204 pre_args += '-DHAVE_GPUVIS'
2207 add_project_arguments(pre_args, language : ['c', 'cpp'])
2208 add_project_arguments(c_cpp_args, language : ['c', 'cpp'])
2210 add_project_arguments(c_args, language : ['c'])
2211 add_project_arguments(cpp_args, language : ['cpp'])
2215 if with_glx == 'xlib'
2216 gl_priv_reqs += ['x11', 'xext', 'xcb']
2217 elif with_glx == 'dri'
2219 'x11', 'xext', 'xfixes', 'x11-xcb', 'xcb',
2221 if with_dri_platform == 'drm'
2222 gl_priv_reqs += 'xcb-dri2 >= 1.8'
2224 gl_priv_reqs += 'xxf86vm'
2228 if dep_libdrm.found()
2229 gl_priv_reqs += 'libdrm >= 2.4.75'
2233 if dep_thread.found()
2234 gl_priv_libs += ['-lpthread', '-pthread']
2237 gl_priv_libs += '-lm'
2240 gl_priv_libs += '-ldl'
2243 # FIXME: autotools lists this as incomplete
2246 gbm_priv_libs += '-ldl'
2249 pkg = import('pkgconfig')
2251 if host_machine.system() == 'windows'
2252 prog_dumpbin = find_program('dumpbin', required : false)
2253 with_symbols_check = prog_dumpbin.found() and with_tests
2254 if with_symbols_check
2255 symbols_check_args = ['--dumpbin', prog_dumpbin.full_path()]
2258 prog_nm = find_program('nm')
2259 with_symbols_check = with_tests
2260 symbols_check_args = ['--nm', prog_nm.full_path()]
2263 # This quirk needs to be applied to sources with functions defined in assembly
2264 # as GCC LTO drops them. See: https://bugs.freedesktop.org/show_bug.cgi?id=109391
2265 gcc_lto_quirk = (cc.get_id() == 'gcc') ? ['-fno-lto'] : []
2267 devenv = environment()
2269 dir_compiler_nir = join_paths(meson.current_source_dir(), 'src/compiler/nir/')
2270 dir_source_root = meson.project_source_root()
2277 meson.add_devenv(devenv)
2279 sphinx = find_program('sphinx-build', version : '>= 4.3',
2280 required: get_option('html-docs'))
2287 'prefix': get_option('prefix'),
2288 'libdir': get_option('libdir'),
2289 'includedir': get_option('includedir'),
2291 section: 'Directories'
2296 'c_cpp_args': c_cpp_args,
2298 section: 'Common C and C++ arguments'
2303 'OpenGL': with_opengl,
2306 'Shared glapi': with_shared_glapi,
2307 'GLVND': with_glvnd,
2309 section: 'OpenGL', bool_yn: true
2314 'Platform': with_dri_platform,
2315 'Driver dir': dri_drivers_path,
2317 section: 'DRI', bool_yn: true, list_sep: ' '
2322 'Enabled': with_glx != 'disabled',
2323 'Provider': with_glx == 'disabled' ? 'None' : with_glx
2325 section: 'GLX', bool_yn: true, list_sep: ' '
2328 egl_summary = {'Enabled': with_egl}
2332 egl_drivers += 'builtin:egl_dri2'
2334 if with_dri_platform == 'drm'
2335 egl_drivers += 'builtin:egl_dri3'
2337 if with_platform_windows
2338 egl_drivers += 'builtin:wgl'
2340 egl_summary += {'Drivers': egl_drivers}
2341 egl_summary += {'Platforms': _platforms}
2343 summary(egl_summary, section: 'EGL', bool_yn: true, list_sep: ' ')
2345 gbm_summary = {'Enabled': with_gbm}
2347 gbm_summary += {'Backends path': gbm_backends_path}
2349 summary(gbm_summary, section: 'GBM', bool_yn: true, list_sep: ' ')
2351 vulkan_summary = {'Drivers': _vulkan_drivers.length() != 0 ? _vulkan_drivers : false }
2353 vulkan_summary += {'Platforms': _platforms}
2354 vulkan_summary += {'ICD dir': with_vulkan_icd_dir}
2355 if with_any_vulkan_layers
2356 vulkan_summary += {'Layers': get_option('vulkan-layers')}
2358 vulkan_summary += {'Intel Ray tracing': with_intel_vk_rt}
2360 summary(vulkan_summary, section: 'Vulkan', bool_yn: true, list_sep: ' ')
2362 video_summary = {'Codecs': _codecs.length() != 0 ? _codecs : false}
2364 if with_gallium_vdpau
2365 video_apis += 'vdpau'
2371 video_apis += 'vulkan'
2376 video_summary += {'APIs': video_apis.length() != 0 ? video_apis : false}
2377 summary(video_summary, section: 'Video', bool_yn: true, list_sep: ' ')
2379 llvm_summary = {'Enabled': with_llvm}
2381 llvm_summary += {'Version': dep_llvm.version()}
2383 summary(llvm_summary, section: 'LLVM', bool_yn: true, list_sep: ' ')
2385 gallium_summary = {'Enabled': with_gallium}
2387 gallium_summary += {'Drivers': gallium_drivers}
2388 gallium_summary += {'Platforms': _platforms}
2390 gallium_frontends = ['mesa']
2392 gallium_frontends += 'xa'
2394 if with_gallium_vdpau
2395 gallium_frontends += 'vdpau'
2398 gallium_frontends += 'va'
2400 if with_gallium_st_nine
2401 gallium_frontends += 'nine'
2403 if with_gallium_clover
2404 gallium_frontends += 'clover'
2406 if with_gallium_rusticl
2407 gallium_frontends += 'rusticl'
2409 gallium_summary += {'Frontends': gallium_frontends}
2410 gallium_summary += {'Off-screen rendering (OSMesa)': with_osmesa ? 'lib' + osmesa_lib_name : false}
2411 gallium_summary += {'HUD lm-sensors': dep_lmsensors.found()}
2413 summary(gallium_summary, section: 'Gallium', bool_yn: true, list_sep: ' ')
2415 perfetto_summary = {'Enabled': with_perfetto}
2416 if with_perfetto and with_any_datasource
2417 perfetto_summary += {'Data source': with_datasources}
2419 summary(perfetto_summary, section: 'Perfetto', bool_yn: true, list_sep: ' ')
2421 teflon_summary = {'Enabled': with_teflon}
2422 summary(teflon_summary, section: 'Teflon (TensorFlow Lite delegate)', bool_yn: true, list_sep: ' ')