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
24 version : files('VERSION'),
26 meson_version : '>= 0.60',
27 default_options : ['buildtype=debugoptimized', 'b_ndebug=if-release', 'c_std=c11', 'cpp_std=c++17', 'rust_std=2021']
30 cc = meson.get_compiler('c')
31 cpp = meson.get_compiler('cpp')
33 null_dep = dependency('', required : false)
35 if get_option('layout') != 'mirror'
36 error('`mirror` is the only build directory layout supported')
39 # Arguments for the preprocessor, put these in a separate array from the C and
40 # C++ (cpp in meson terminology) arguments since they need to be added to the
41 # default arguments for both C and C++.
43 '-D__STDC_CONSTANT_MACROS',
44 '-D__STDC_FORMAT_MACROS',
45 '-D__STDC_LIMIT_MACROS',
46 '-DPACKAGE_VERSION="@0@"'.format(meson.project_version()),
47 '-DPACKAGE_BUGREPORT="https://gitlab.freedesktop.org/mesa/mesa/-/issues"',
49 # Arguments for c or cpp compiler, can be compiler options
55 with_moltenvk_dir = get_option('moltenvk-dir')
56 with_vulkan_icd_dir = get_option('vulkan-icd-dir')
57 with_tests = get_option('build-tests')
58 with_glcpp_tests = get_option('enable-glcpp-tests')
59 with_aco_tests = get_option('build-aco-tests')
60 with_glx_read_only_text = get_option('glx-read-only-text')
61 with_glx_direct = get_option('glx-direct')
62 with_osmesa = get_option('osmesa')
63 with_vulkan_overlay_layer = get_option('vulkan-layers').contains('overlay')
64 with_vulkan_device_select_layer = get_option('vulkan-layers').contains('device-select')
65 with_tools = get_option('tools')
66 if with_tools.contains('all')
83 with_any_vulkan_layers = get_option('vulkan-layers').length() != 0
84 with_intel_tools = with_tools.contains('intel') or with_tools.contains('intel-ui')
85 with_imgui = with_intel_tools or with_vulkan_overlay_layer
87 dri_drivers_path = get_option('dri-drivers-path')
88 if dri_drivers_path == ''
89 dri_drivers_path = join_paths(get_option('prefix'), get_option('libdir'), 'dri')
91 dri_search_path = get_option('dri-search-path')
92 if dri_search_path == ''
93 dri_search_path = dri_drivers_path
96 gbm_backends_path = get_option('gbm-backends-path')
97 if gbm_backends_path == ''
98 gbm_backends_path = join_paths(get_option('prefix'), get_option('libdir'), 'gbm')
101 # Default shared glapi disabled for windows, enabled elsewhere.
102 with_shared_glapi = get_option('shared-glapi') \
103 .disable_auto_if(host_machine.system() == 'windows') \
106 with_opengl = get_option('opengl')
108 with_gles1 = get_option('gles1') \
109 .require(with_shared_glapi, error_message : 'OpengGL ES 1.x requires shared-glapi') \
112 with_gles2 = get_option('gles2') \
113 .require(with_shared_glapi, error_message : 'OpengGL ES 2.x requires shared-glapi') \
116 pre_args += '-DHAVE_OPENGL=@0@'.format(with_opengl ? '1' : '0')
117 pre_args += '-DHAVE_OPENGL_ES_1=@0@'.format(with_gles1 ? '1' : '0')
118 pre_args += '-DHAVE_OPENGL_ES_2=@0@'.format(with_gles2 ? '1' : '0')
120 with_any_opengl = with_opengl or with_gles1 or with_gles2
121 # Only build shared_glapi if at least one OpenGL API is enabled
122 with_shared_glapi = with_shared_glapi and with_any_opengl
124 system_has_kms_drm = ['openbsd', 'netbsd', 'freebsd', 'gnu/kfreebsd', 'dragonfly', 'linux', 'sunos', 'android'].contains(host_machine.system())
126 gallium_drivers = get_option('gallium-drivers')
127 if gallium_drivers.contains('auto')
128 if system_has_kms_drm
130 if ['x86', 'x86_64'].contains(host_machine.cpu_family())
132 'r300', 'r600', 'radeonsi', 'nouveau', 'virgl', 'svga', 'swrast',
133 'iris', 'crocus', 'i915'
135 elif ['arm', 'aarch64'].contains(host_machine.cpu_family())
137 'v3d', 'vc4', 'freedreno', 'etnaviv', 'nouveau', 'svga',
138 'tegra', 'virgl', 'lima', 'panfrost', 'swrast', 'iris'
140 elif ['mips', 'mips64', 'riscv32', 'riscv64'].contains(host_machine.cpu_family())
142 'r300', 'r600', 'radeonsi', 'nouveau', 'virgl', 'swrast'
144 elif ['loongarch64'].contains(host_machine.cpu_family())
146 'r300', 'r600', 'radeonsi', 'nouveau', 'virgl', 'etnaviv', 'swrast'
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 ['darwin', 'windows', 'cygwin', 'haiku'].contains(host_machine.system())
153 gallium_drivers = ['swrast']
155 error('Unknown OS @0@. Please pass -Dgallium-drivers to set driver options. Patches gladly accepted to fix this.'.format(
156 host_machine.system()))
159 with_gallium_radeonsi = gallium_drivers.contains('radeonsi')
160 with_gallium_r300 = gallium_drivers.contains('r300')
161 with_gallium_r600 = gallium_drivers.contains('r600')
162 with_gallium_nouveau = gallium_drivers.contains('nouveau')
163 with_gallium_freedreno = gallium_drivers.contains('freedreno')
164 with_gallium_softpipe = gallium_drivers.contains('swrast')
165 with_gallium_vc4 = gallium_drivers.contains('vc4')
166 with_gallium_v3d = gallium_drivers.contains('v3d')
167 with_gallium_panfrost = gallium_drivers.contains('panfrost')
168 with_gallium_etnaviv = gallium_drivers.contains('etnaviv')
169 with_gallium_tegra = gallium_drivers.contains('tegra')
170 with_gallium_crocus = gallium_drivers.contains('crocus')
171 with_gallium_iris = gallium_drivers.contains('iris')
172 with_gallium_i915 = gallium_drivers.contains('i915')
173 with_gallium_svga = gallium_drivers.contains('svga')
174 with_gallium_virgl = gallium_drivers.contains('virgl')
175 with_gallium_lima = gallium_drivers.contains('lima')
176 with_gallium_zink = gallium_drivers.contains('zink')
177 with_gallium_d3d12 = gallium_drivers.contains('d3d12')
178 with_gallium_asahi = gallium_drivers.contains('asahi')
179 foreach gallium_driver : gallium_drivers
180 pre_args += '-DHAVE_@0@'.format(gallium_driver.to_upper())
183 freedreno_kmds = get_option('freedreno-kmds')
184 # If building only vulkan with only kgsl kmd support, there is no libdrm
186 if freedreno_kmds.length() == 1 and freedreno_kmds.contains('kgsl') and not with_gallium_freedreno
187 system_has_kms_drm = false
190 with_gallium = gallium_drivers.length() != 0
191 with_gallium_kmsro = system_has_kms_drm and [
193 with_gallium_etnaviv,
194 with_gallium_freedreno,
196 with_gallium_panfrost,
202 if with_gallium and system_has_kms_drm
203 _glx = get_option('glx')
204 _egl = get_option('egl')
205 if _glx == 'dri' or _egl.enabled() or (_glx == 'disabled' and _egl.allowed())
210 _vulkan_drivers = get_option('vulkan-drivers')
211 if _vulkan_drivers.contains('auto')
212 if system_has_kms_drm
213 if host_machine.cpu_family().startswith('x86')
214 _vulkan_drivers = ['amd', 'intel', 'intel_hasvk', 'swrast']
215 elif ['arm', 'aarch64'].contains(host_machine.cpu_family())
216 _vulkan_drivers = ['swrast', 'intel']
217 elif ['mips', 'mips64', 'riscv32', 'riscv64'].contains(host_machine.cpu_family())
218 _vulkan_drivers = ['amd', 'swrast']
219 elif ['loongarch64'].contains(host_machine.cpu_family())
220 _vulkan_drivers = ['amd', 'swrast']
222 error('Unknown architecture @0@. Please pass -Dvulkan-drivers to set driver options. Patches gladly accepted to fix this.'.format(
223 host_machine.cpu_family()))
225 elif ['darwin', 'windows', 'cygwin', 'haiku'].contains(host_machine.system())
226 # No vulkan driver supports windows or macOS currently
229 error('Unknown OS @0@. Please pass -Dvulkan-drivers to set driver options. Patches gladly accepted to fix this.'.format(
230 host_machine.system()))
234 with_intel_vk = _vulkan_drivers.contains('intel')
235 with_intel_hasvk = _vulkan_drivers.contains('intel_hasvk')
236 with_amd_vk = _vulkan_drivers.contains('amd')
237 with_freedreno_vk = _vulkan_drivers.contains('freedreno')
238 with_panfrost_vk = _vulkan_drivers.contains('panfrost')
239 with_swrast_vk = _vulkan_drivers.contains('swrast')
240 with_virtio_vk = _vulkan_drivers.contains('virtio')
241 with_broadcom_vk = _vulkan_drivers.contains('broadcom')
242 with_imagination_vk = _vulkan_drivers.contains('imagination-experimental')
243 with_imagination_srv = get_option('imagination-srv')
244 with_microsoft_vk = _vulkan_drivers.contains('microsoft-experimental')
245 with_nouveau_vk = _vulkan_drivers.contains('nouveau-experimental')
246 with_any_vk = _vulkan_drivers.length() != 0
248 with_any_broadcom = [
254 if ['x86_64'].contains(host_machine.cpu_family())
255 with_intel_clc = get_option('intel-clc') == 'enabled'
256 with_intel_vk_rt = with_intel_vk and get_option('intel-clc') != 'disabled'
258 with_intel_clc = false
259 with_intel_vk_rt = false
271 with_any_nouveau = with_gallium_nouveau or with_nouveau_vk
273 if with_nouveau_vk and get_option('nvk-legacy-uapi')
274 pre_args += '-DNVK_NEW_UAPI=0'
276 pre_args += '-DNVK_NEW_UAPI=1'
279 if with_swrast_vk and not with_gallium_softpipe
280 error('swrast vulkan requires gallium swrast')
282 if with_gallium_tegra and not with_gallium_nouveau
283 error('tegra driver requires nouveau driver')
285 if with_aco_tests and not with_amd_vk
286 error('ACO tests require Radv')
289 with_microsoft_clc = get_option('microsoft-clc').enabled()
290 with_clc = with_microsoft_clc or with_intel_clc
291 with_spirv_to_dxil = get_option('spirv-to-dxil')
293 if host_machine.system() == 'darwin'
294 with_dri_platform = 'apple'
295 pre_args += '-DBUILDING_MESA'
296 elif ['windows', 'cygwin'].contains(host_machine.system())
297 with_dri_platform = 'windows'
298 elif system_has_kms_drm
299 with_dri_platform = 'drm'
301 # FIXME: haiku doesn't use dri, and xlib doesn't use dri, probably should
302 # assert here that one of those cases has been met.
303 # FIXME: illumos ends up here as well
304 with_dri_platform = 'none'
307 with_vulkan_beta = get_option('vulkan-beta')
308 if host_machine.system() == 'darwin'
309 #macOS seems to need beta extensions to build for now:
310 with_vulkan_beta = true
313 pre_args += '-DVK_ENABLE_BETA_EXTENSIONS'
316 _codecs = get_option('video-codecs')
317 foreach c : ['vc1dec', 'h264dec', 'h264enc', 'h265dec', 'h265enc']
318 pre_args += '-DVIDEO_CODEC_@0@=@1@'.format(c.to_upper(), _codecs.contains(c).to_int())
321 _platforms = get_option('platforms')
322 if _platforms.contains('auto')
323 if system_has_kms_drm
324 _platforms = ['x11', 'wayland']
325 elif ['darwin', 'cygwin'].contains(host_machine.system())
327 elif ['haiku'].contains(host_machine.system())
328 _platforms = ['haiku']
329 elif host_machine.system() == 'windows'
330 _platforms = ['windows']
332 error('Unknown OS @0@. Please pass -Dplatforms to set platforms. Patches gladly accepted to fix this.'.format(
333 host_machine.system()))
337 with_platform_android = _platforms.contains('android')
338 with_platform_x11 = _platforms.contains('x11')
339 with_platform_wayland = _platforms.contains('wayland')
340 with_platform_haiku = _platforms.contains('haiku')
341 with_platform_windows = _platforms.contains('windows')
343 with_glx = get_option('glx')
344 if with_glx == 'auto'
346 with_glx = 'disabled'
347 elif with_platform_android
348 with_glx = 'disabled'
351 elif with_platform_haiku
352 with_glx = 'disabled'
353 elif host_machine.system() == 'windows'
354 with_glx = 'disabled'
356 # Even when building just gallium drivers the user probably wants dri
358 elif with_platform_x11 and with_any_opengl and not with_any_vk
359 # The automatic behavior should not be to turn on xlib based glx when
360 # building only vulkan drivers
363 with_glx = 'disabled'
372 if not with_opengl and with_glx != 'disabled'
373 error('Building GLX without OpenGL is not supported.') \
376 if not (with_dri or with_gallium or with_glx != 'disabled')
380 with_any_opengl = false
381 with_shared_glapi = false
384 with_gbm = get_option('gbm') \
385 .require(system_has_kms_drm, error_message : 'GBM only supports DRM/KMS platforms') \
386 .disable_auto_if(not with_dri) \
389 with_xlib_lease = get_option('xlib-lease') \
390 .require(with_platform_x11 and system_has_kms_drm, error_message : 'xlib-lease requires X11 and KMS/DRM support') \
393 with_egl = get_option('egl') \
394 .require(host_machine.system() != 'darwin', error_message : 'EGL not supported on MacOS') \
395 .require(with_platform_windows or with_platform_haiku or with_dri or with_platform_android, error_message : 'EGL requires DRI, Haiku, Windows or Android') \
396 .require(with_shared_glapi, error_message : 'EGL requires shared-glapi') \
397 .require(with_glx != 'xlib', error_message :'EGL requires DRI, but GLX is being built with xlib support') \
398 .disable_auto_if(with_platform_haiku) \
402 _platforms += 'surfaceless'
403 if with_gbm and not with_platform_android
407 egl_native_platform = get_option('egl-native-platform')
408 if egl_native_platform.contains('auto')
409 egl_native_platform = _platforms[0]
413 if with_egl and not _platforms.contains(egl_native_platform)
414 error('-Degl-native-platform does not specify an enabled platform')
417 if 'x11' in _platforms
421 foreach platform : _platforms
422 pre_args += '-DHAVE_@0@_PLATFORM'.format(platform.to_upper())
425 if with_platform_android and get_option('platform-sdk-version') >= 29
426 # By default the NDK compiler, at least, emits emutls references instead of
427 # ELF TLS, even when building targeting newer API levels. Make it actually do
429 c_cpp_args += '-fno-emulated-tls'
432 # -mtls-dialect=gnu2 speeds up non-initial-exec TLS significantly but requires
433 # full toolchain (including libc) support.
434 have_mtls_dialect = false
435 foreach c_arg : get_option('c_args')
436 if c_arg.startswith('-mtls-dialect=')
437 have_mtls_dialect = true
441 if not have_mtls_dialect
442 # need .run to check libc support. meson aborts when calling .run when
443 # cross-compiling, but because this is just an optimization we can skip it
444 if meson.is_cross_build() and not meson.can_run_host_binaries()
445 warning('cannot auto-detect -mtls-dialect when cross-compiling, using compiler default')
447 # -fpic to force dynamic tls, otherwise TLS relaxation defeats check
448 gnu2_test = cc.run('int __thread x; int main() { return x; }',
449 args: ['-mtls-dialect=gnu2', '-fpic'],
450 name: '-mtls-dialect=gnu2')
451 if gnu2_test.returncode() == 0 and (
452 # check for lld 13 bug: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5665
453 host_machine.cpu_family() != 'x86_64' or
454 # get_linker_id misses LDFLAGS=-fuse-ld=lld: https://github.com/mesonbuild/meson/issues/6377
455 #cc.get_linker_id() != 'ld.lld' or
456 cc.links('''int __thread x; int y; int main() { __asm__(
457 "leaq x@TLSDESC(%rip), %rax\n"
458 "movq y@GOTPCREL(%rip), %rdx\n"
459 "call *x@TLSCALL(%rax)\n"); }''', name: 'split TLSDESC')
461 c_cpp_args += '-mtls-dialect=gnu2'
466 if with_glx != 'disabled'
467 if not (with_platform_x11 and with_any_opengl)
468 error('Cannot build GLX support without X11 platform support and at least one OpenGL API')
469 elif with_glx == 'xlib'
471 error('xlib based GLX requires at least one gallium driver')
472 elif not with_gallium_softpipe
473 error('xlib based GLX requires softpipe or llvmpipe.')
475 error('xlib conflicts with any dri driver')
477 elif with_glx == 'dri'
478 if not with_shared_glapi
479 error('dri based GLX requires shared-glapi')
484 with_glvnd = get_option('glvnd')
485 glvnd_vendor_name = get_option('glvnd-vendor-name')
487 if with_platform_windows
488 error('glvnd cannot be used on Windows')
489 elif with_glx == 'xlib'
490 error('Cannot build glvnd support for GLX that is not DRI based.')
491 elif with_glx == 'disabled' and not with_egl
492 error('glvnd requires DRI based GLX and/or EGL')
494 if get_option('egl-lib-suffix') != ''
495 error('''EGL lib suffix can't be used with libglvnd''')
499 if with_vulkan_icd_dir == ''
500 with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
503 # GNU/Hurd includes egl_dri2, without drm.
504 with_dri2 = (with_dri or with_any_vk) and (with_dri_platform == 'drm' or
505 host_machine.system() == 'gnu')
506 with_dri3 = get_option('dri3').disable_auto_if(not (system_has_kms_drm and with_dri2)).allowed()
508 if with_any_vk and (with_platform_x11 and not with_dri3)
509 error('Vulkan drivers require dri3 for X11 support')
512 if with_glx == 'disabled' and not with_egl and not with_gbm
513 error('building dri drivers require at least one windowing system')
517 if with_gallium_kmsro and (with_platform_x11 and not with_dri3)
518 error('kmsro requires dri3 for X11 support')
521 dep_dxheaders = null_dep
522 if with_gallium_d3d12 or with_microsoft_clc or with_microsoft_vk
523 dep_dxheaders = dependency('directx-headers', required : false)
524 if not dep_dxheaders.found()
525 dep_dxheaders = dependency('DirectX-Headers',
526 version : '>= 1.610.0',
527 fallback : ['DirectX-Headers', 'dep_dxheaders'],
528 required : with_gallium_d3d12 or with_microsoft_vk
533 _with_gallium_d3d12_video = get_option('gallium-d3d12-video')
534 with_gallium_d3d12_video = false
535 if with_gallium_d3d12 and not _with_gallium_d3d12_video.disabled()
536 with_gallium_d3d12_video = true
537 pre_args += '-DHAVE_GALLIUM_D3D12_VIDEO'
541 with_gallium_d3d12_video,
542 with_gallium_nouveau,
544 with_gallium_radeonsi,
548 vdpau = get_option('gallium-vdpau') \
549 .require(system_has_kms_drm, error_message : 'VDPAU state tracker can only be build on unix-like OSes.') \
550 .require(with_platform_x11, error_message : 'VDPAU state tracker requires X11 support.') \
551 .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).')
553 dep_vdpau = dependency('vdpau', version : '>= 1.1', required : vdpau)
555 dep_vdpau = dep_vdpau.partial_dependency(compile_args : true)
556 pre_args += '-DHAVE_ST_VDPAU'
558 with_gallium_vdpau = dep_vdpau.found()
560 vdpau_drivers_path = get_option('vdpau-libs-path')
561 if vdpau_drivers_path == ''
562 vdpau_drivers_path = join_paths(get_option('libdir'), 'vdpau')
565 if with_vulkan_overlay_layer or with_aco_tests or with_amd_vk or with_intel_vk
566 prog_glslang = find_program('glslangValidator', native : true)
567 if run_command(prog_glslang, [ '--quiet', '--version' ], check : false).returncode() == 0
568 glslang_quiet = ['--quiet']
575 _omx = get_option('gallium-omx')
576 if not system_has_kms_drm
577 if ['auto', 'disabled'].contains(_omx)
580 error('OMX state tracker can only be built on unix-like OSes.')
582 elif not (with_gallium_r600 or with_gallium_radeonsi or with_gallium_nouveau)
583 if ['auto', 'disabled'].contains(_omx)
586 error('OMX state tracker requires at least one of the following gallium drivers: r600, radeonsi, nouveau.')
589 with_gallium_omx = _omx
592 if ['auto', 'bellagio'].contains(_omx)
593 dep_omx = dependency(
594 'libomxil-bellagio', required : _omx == 'bellagio'
597 with_gallium_omx = 'bellagio'
600 if ['auto', 'tizonia'].contains(_omx)
601 if with_dri and with_egl
602 dep_omx = dependency(
603 'libtizonia', version : '>= 0.10.0',
604 required : _omx == 'tizonia',
607 dependency('libtizplatform', required : _omx == 'tizonia'),
608 dependency('tizilheaders', required : _omx == 'tizonia'),
610 if dep_omx.found() and dep_omx_other[0].found() and dep_omx_other[1].found()
611 with_gallium_omx = 'tizonia'
613 elif _omx == 'tizonia'
614 error('OMX-Tizonia state tracker requires dri and egl')
618 with_gallium_omx = 'disabled'
620 with_gallium_omx = _omx
624 '-DENABLE_ST_OMX_BELLAGIO=' + (with_gallium_omx == 'bellagio' ? '1' : '0'),
625 '-DENABLE_ST_OMX_TIZONIA=' + (with_gallium_omx == 'tizonia' ? '1' : '0'),
629 omx_drivers_path = get_option('omx-libs-path')
631 if with_gallium_omx != 'disabled'
632 # Figure out where to put the omx driver.
633 # FIXME: this could all be vastly simplified by adding a 'defined_variable'
634 # argument to meson's get_variable method.
635 if omx_drivers_path == ''
636 _omx_libdir = dep_omx.get_variable(pkgconfig : 'libdir')
637 _omx_drivers_dir = dep_omx.get_variable(pkgconfig : 'pluginsdir')
638 if _omx_libdir == get_option('libdir')
639 omx_drivers_path = _omx_drivers_dir
642 # This will fail on windows. Does OMX run on windows?
643 _omx_libdir = _omx_libdir.split('/')
644 _omx_drivers_dir = _omx_drivers_dir.split('/')
645 foreach o : _omx_drivers_dir
646 if not _omx_libdir.contains(o)
650 omx_drivers_path = join_paths(get_option('libdir'), _omx_base_dir)
656 with_gallium_d3d12_video,
657 with_gallium_nouveau,
659 with_gallium_radeonsi,
663 _va = get_option('gallium-va') \
664 .require(_va_drivers.contains(true),
665 error_message : 'VA state tracker requires at least one of the following gallium drivers: r600, radeonsi, nouveau, d3d12 (with option gallium-d3d12-video), virgl.')
666 _dep_va_name = host_machine.system() == 'windows' ? 'libva-win32' : 'libva'
667 dep_va = dependency(_dep_va_name, version : '>= 1.8.0', required : _va)
669 dep_va_headers = dep_va.partial_dependency(compile_args : true)
670 if cc.has_header_symbol('va/va.h', 'VASurfaceAttribDRMFormatModifiers',
671 dependencies: dep_va_headers)
672 pre_args += '-DHAVE_VA_SURFACE_ATTRIB_DRM_FORMAT_MODIFIERS'
675 with_gallium_va = dep_va.found()
677 va_drivers_path = get_option('va-libs-path')
678 if va_drivers_path == ''
679 va_drivers_path = join_paths(get_option('libdir'), 'dri')
682 with_gallium_xa = get_option('gallium-xa') \
683 .require(system_has_kms_drm, error_message : 'XA state tracker can only be built on unix-like OSes.') \
684 .require(with_gallium_nouveau or with_gallium_freedreno or with_gallium_i915 or with_gallium_svga,
685 error_message : 'XA state tracker requires at least one of the following gallium drivers: nouveau, freedreno, i915, svga.') \
688 d3d_drivers_path = get_option('d3d-drivers-path')
689 if d3d_drivers_path == ''
690 d3d_drivers_path = join_paths(get_option('prefix'), get_option('libdir'), 'd3d')
693 with_gallium_st_nine = get_option('gallium-nine')
694 if with_gallium_st_nine
695 if not with_gallium_softpipe
696 error('The nine state tracker requires gallium softpipe/llvmpipe.')
699 with_gallium_freedreno,
702 with_gallium_nouveau,
703 with_gallium_panfrost,
706 with_gallium_radeonsi,
710 error('The nine state tracker requires at least one non-swrast gallium driver.')
713 error('Using nine with wine requires dri3')
716 with_gallium_st_d3d10umd = get_option('gallium-d3d10umd')
717 if with_gallium_st_d3d10umd
718 if not with_gallium_softpipe
719 error('The d3d10umd state tracker requires gallium softpipe/llvmpipe.')
722 _power8 = get_option('power8')
724 if host_machine.cpu_family() == 'ppc64' and host_machine.endian() == 'little'
725 if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.8')
726 error('Altivec is not supported with gcc version < 4.8.')
731 vector unsigned char r;
732 vector unsigned int v = vec_splat_u32 (1);
733 r = __builtin_vec_vgbbd ((vector unsigned char) v);
736 args : '-mpower8-vector',
737 name : 'POWER8 intrinsics')
738 pre_args += ['-D_ARCH_PWR8']
739 c_cpp_args += '-mpower8-vector'
740 elif _power8.enabled()
741 error('POWER8 intrinsic support required but not found.')
746 if get_option('vmware-mks-stats')
747 if not with_gallium_svga
748 error('vmware-mks-stats requires gallium VMware/svga driver.')
750 pre_args += '-DVMX86_STATS=1'
753 _opencl = get_option('gallium-opencl')
754 _rtti = get_option('cpp_rtti')
755 if _opencl != 'disabled'
757 error('OpenCL Clover implementation requires at least one gallium driver.')
760 error('The Clover OpenCL state tracker requires rtti')
764 with_gallium_opencl = true
765 with_opencl_icd = _opencl == 'icd'
767 with_gallium_opencl = false
768 with_opencl_icd = false
771 with_gallium_rusticl = get_option('gallium-rusticl')
772 if with_gallium_rusticl
774 error('rusticl requires at least one gallium driver.')
777 if meson.version().version_compare('< 1.2')
778 error('rusticl requires meson 1.2.0 or newer')
781 add_languages('rust', required: true)
788 dep_clc = dependency('libclc')
791 gl_pkgconfig_c_flags = []
792 with_glx_indirect_rendering = false
794 if with_glx == 'xlib'
795 pre_args += '-DUSE_XSHM'
797 with_glx_indirect_rendering = true
798 pre_args += '-DGLX_INDIRECT_RENDERING'
800 pre_args += '-DGLX_DIRECT_RENDERING'
802 if with_dri_platform == 'drm'
803 pre_args += '-DGLX_USE_DRM'
804 elif with_dri_platform == 'apple'
805 pre_args += '-DGLX_USE_APPLEGL'
806 elif with_dri_platform == 'windows'
807 pre_args += '-DGLX_USE_WINDOWSGL'
812 with_glapi_export_proto_entry_points = false
813 if with_shared_glapi and not with_glx_indirect_rendering
814 # Imply !defined(GLX_INDIRECT_RENDERING)
815 with_glapi_export_proto_entry_points = true
817 pre_args += '-DGLAPI_EXPORT_PROTO_ENTRY_POINTS=@0@'.format(with_glapi_export_proto_entry_points ? '1' : '0')
819 with_android_stub = get_option('android-stub')
820 if with_android_stub and not with_platform_android
821 error('`-D android-stub=true` makes no sense without `-D platforms=android`')
824 with_libbacktrace = get_option('android-libbacktrace') \
825 .require(with_platform_android, error_message : '`-D android-libbacktrace=enabled` makes no sense without `-D platforms=android`') \
826 .disable_auto_if(not with_platform_android) \
830 cpp_args += '-DWITH_LIBBACKTRACE'
833 if with_platform_android
834 dep_android_mapper4 = null_dep
835 if not with_android_stub
837 dependency('cutils'),
838 dependency('hardware'),
842 dep_android += dependency('backtrace')
844 if get_option('platform-sdk-version') >= 26
845 dep_android += dependency('nativewindow')
847 if get_option('platform-sdk-version') >= 30
848 dep_android_mapper4 = dependency('android.hardware.graphics.mapper', version : '>= 4.0', required : false)
853 '-DANDROID_API_LEVEL=' + get_option('platform-sdk-version').to_string()
857 # On Android, seccomp kills the process on kernels without
858 # CONFIG_KCMP/CONFIG_CHECKPOINT_RESTORE if it attemps to use KCMP.
859 # Since we can't detect that, err on the side of caution and disable
860 # KCMP by default on Android.
861 if get_option('allow-kcmp') \
862 .disable_auto_if(with_platform_android) \
864 pre_args += '-DALLOW_KCMP'
867 prog_python = import('python').find_installation('python3')
868 has_mako = run_command(
871 from distutils.version import StrictVersion
873 assert StrictVersion(mako.__version__) >= StrictVersion("0.8.0")
875 if has_mako.returncode() != 0
876 error('Python (3.x) mako module >= 0.8.0 required to build mesa.')
879 if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
880 error('When using GCC, version 4.4.6 or later is required.')
883 # Support systems without ETIME (e.g. FreeBSD)
884 if cc.get_define('ETIME', prefix : '#include <errno.h>') == ''
885 pre_args += '-DETIME=ETIMEDOUT'
888 # Define DEBUG for debug builds only (debugoptimized is not included on this one)
889 if get_option('buildtype') == 'debug'
890 pre_args += '-DDEBUG'
893 with_shader_cache = get_option('shader-cache') \
894 .require(host_machine.system() != 'windows', error_message : 'Shader Cache does not currently work on Windows') \
898 pre_args += '-DENABLE_SHADER_CACHE'
899 if not get_option('shader-cache-default')
900 pre_args += '-DSHADER_CACHE_DISABLE_BY_DEFAULT'
903 shader_cache_max_size = get_option('shader-cache-max-size')
904 if shader_cache_max_size != ''
905 pre_args += '-DMESA_SHADER_CACHE_MAX_SIZE="@0@"'.format(shader_cache_max_size)
909 # Check for GCC style builtins
910 foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
911 'ffsll', 'popcount', 'popcountll', 'unreachable', 'types_compatible_p']
912 if cc.has_function(b)
913 pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
917 # check for GCC __attribute__
919 'const', 'flatten', 'malloc', 'pure', 'unused', 'warn_unused_result',
920 'weak', 'format', 'packed', 'returns_nonnull', 'alias', 'noreturn',
923 foreach a : cc.get_supported_function_attributes(_attributes)
924 pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
926 if cc.has_function_attribute('visibility:hidden')
927 pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISIBILITY'
929 if cc.compiles('__uint128_t foo(void) { return 0; }',
930 name : '__uint128_t')
931 pre_args += '-DHAVE_UINT128'
934 if cc.has_function('reallocarray')
935 pre_args += '-DHAVE_REALLOCARRAY'
937 if cc.has_function('fmemopen')
938 pre_args += '-DHAVE_FMEMOPEN'
941 # TODO: this is very incomplete
942 if ['linux', 'cygwin', 'gnu', 'freebsd', 'gnu/kfreebsd', 'haiku', 'android'].contains(host_machine.system())
943 pre_args += '-D_GNU_SOURCE'
944 elif host_machine.system() == 'sunos'
945 pre_args += '-D__EXTENSIONS__'
946 elif host_machine.system() == 'windows'
948 '-D_WINDOWS', '-D_WIN32_WINNT=0x0A00', '-DWINVER=0x0A00',
949 '-DPIPE_SUBSYSTEM_WINDOWS_USER',
950 '-D_USE_MATH_DEFINES', # XXX: scons didn't use this for mingw
952 if cc.get_argument_syntax() == 'msvc'
955 '-D_CRT_SECURE_NO_WARNINGS',
956 '-D_CRT_SECURE_NO_DEPRECATE',
957 '-D_SCL_SECURE_NO_WARNINGS',
958 '-D_SCL_SECURE_NO_DEPRECATE',
959 '-D_ALLOW_KEYWORD_MACROS',
960 '-D_HAS_EXCEPTIONS=0', # Tell C++ STL to not use exceptions
964 # When the target is not mingw/ucrt
965 # NOTE: clang's stddef.h are conflict with mingw/ucrt's stddef.h
966 # So do not include headers that defined in clang for detecting
970 #if defined(__MINGW32__) && defined(_UCRT)
973 int main(void) { return 0; }''')
974 pre_args += ['-D__MSVCRT_VERSION__=0x0700']
977 elif host_machine.system() == 'openbsd'
978 pre_args += '-D_ISOC11_SOURCE'
981 # Check for generic C arguments
982 c_msvc_compat_args = []
983 no_override_init_args = []
984 cpp_msvc_compat_args = []
985 ld_args_gc_sections = []
986 if cc.get_argument_syntax() == 'msvc'
988 '/wd4018', # signed/unsigned mismatch
989 '/wd4056', # overflow in floating-point constant arithmetic
990 '/wd4244', # conversion from 'type1' to 'type2', possible loss of data
991 '/wd4267', # 'var' : conversion from 'size_t' to 'type', possible loss of data
992 '/wd4305', # truncation from 'type1' to 'type2'
993 '/wd4351', # new behavior: elements of array 'array' will be default initialized
994 '/wd4756', # overflow in constant arithmetic
995 '/wd4800', # forcing value to bool 'true' or 'false' (performance warning)
996 '/wd4996', # disabled deprecated POSIX name warnings
997 '/wd4291', # no matching operator delete found
998 '/wd4146', # unary minus operator applied to unsigned type, result still unsigned
999 '/wd4200', # nonstandard extension used: zero-sized array in struct/union
1000 '/wd4624', # destructor was implicitly defined as deleted [from LLVM]
1001 '/wd4309', # 'initializing': truncation of constant value
1002 '/wd4838', # conversion from 'int' to 'const char' requires a narrowing conversion
1003 '/wd5105', # macro expansion producing 'defined' has undefined behavior (winbase.h, need Windows SDK upgrade)
1004 '/we4020', # Error when passing the wrong number of parameters
1005 '/we4024', # Error when passing different type of parameter
1006 '/we4189', # 'identifier' : local variable is initialized but not referenced
1007 '/Zc:__cplusplus', #Set __cplusplus macro to match the /std:c++<version> on the command line
1009 c_args += cc.get_supported_arguments(_trial)
1010 cpp_args += cpp.get_supported_arguments(_trial)
1013 '-Werror=implicit-function-declaration',
1014 '-Werror=missing-prototypes',
1015 '-Werror=return-type',
1016 '-Werror=empty-body',
1017 '-Werror=incompatible-pointer-types',
1018 '-Werror=int-conversion',
1019 '-Wimplicit-fallthrough',
1020 '-Wmisleading-indentation',
1021 '-Wno-missing-field-initializers',
1022 '-Wno-format-truncation',
1023 '-Wno-nonnull-compare',
1025 '-fno-trapping-math',
1026 '-Qunused-arguments',
1029 '-Wno-microsoft-enum-value',
1030 '-Wno-unused-function',
1033 '-Werror=return-type',
1034 '-Werror=empty-body',
1035 '-Wmisleading-indentation',
1036 '-Wno-non-virtual-dtor',
1037 '-Wno-missing-field-initializers',
1038 '-Wno-format-truncation',
1040 '-fno-trapping-math',
1041 '-Qunused-arguments',
1042 # Some classes use custom new operator which zeroes memory, however
1043 # gcc does aggressive dead-store elimination which threats all writes
1044 # to the memory before the constructor as "dead stores".
1045 # For now we disable this optimization.
1048 '-Wno-microsoft-enum-value',
1051 # MinGW chokes on format specifiers and I can't get it all working
1052 if not (cc.get_argument_syntax() == 'gcc' and host_machine.system() == 'windows')
1053 _trial_c += ['-Werror=format', '-Wformat-security']
1054 _trial_cpp += ['-Werror=format', '-Wformat-security']
1057 # FreeBSD annotated <pthread.h> but Mesa isn't ready
1058 if not (cc.get_id() == 'clang' and host_machine.system() == 'freebsd')
1059 _trial_c += ['-Werror=thread-safety']
1062 # If the compiler supports it, put function and data symbols in their
1063 # own sections and GC the sections after linking. This lets drivers
1064 # drop shared code unused by that specific driver (particularly
1065 # relevant for Vulkan drivers).
1066 if cc.links('static char unused() { return 5; } int main() { return 0; }',
1067 args : '-Wl,--gc-sections', name : 'gc-sections')
1068 ld_args_gc_sections += '-Wl,--gc-sections'
1069 _trial_c += ['-ffunction-sections', '-fdata-sections']
1070 _trial_cpp += ['-ffunction-sections', '-fdata-sections']
1073 # Variables that are only used for assertions are considered unused when assertions
1074 # are disabled. Don't treat this as an error, since we build with -Werror even if
1075 # assertions are disabled.
1076 if get_option('b_ndebug') == 'true' or (get_option('buildtype') == 'release' and get_option('b_ndebug') == 'if-release')
1077 _trial_c += ['-Wno-unused-variable', '-Wno-unused-but-set-variable', '/wd4189']
1078 _trial_cpp += ['-Wno-unused-variable', '-Wno-unused-but-set-variable', '/wd4189']
1081 c_args += cc.get_supported_arguments(_trial_c)
1082 cpp_args += cpp.get_supported_arguments(_trial_cpp)
1084 no_override_init_args += cc.get_supported_arguments(
1085 ['-Wno-override-init', '-Wno-initializer-overrides']
1088 # Check for C and C++ arguments for MSVC compatibility. These are only used
1089 # in parts of the mesa code base that need to compile with MSVC, mainly
1091 _trial_msvc = ['-Werror=pointer-arith', '-Werror=vla', '-Werror=gnu-empty-initializer']
1092 c_msvc_compat_args += cc.get_supported_arguments(_trial_msvc)
1093 cpp_msvc_compat_args += cpp.get_supported_arguments(_trial_msvc)
1096 # set linker arguments
1097 if host_machine.system() == 'windows'
1098 if cc.get_argument_syntax() == 'msvc'
1099 add_project_link_arguments(
1103 language : ['c', 'cpp'],
1105 if get_option('buildtype') != 'debug'
1106 add_project_link_arguments(
1108 language : ['c', 'cpp'],
1112 add_project_link_arguments(
1113 cc.get_supported_link_arguments(
1115 '-Wl,--dynamicbase',
1117 '-static-libstdc++',
1121 add_project_link_arguments(
1122 cpp.get_supported_link_arguments(
1124 '-Wl,--dynamicbase',
1126 '-static-libstdc++',
1137 if host_machine.cpu_family().startswith('x86')
1138 pre_args += '-DUSE_SSE41'
1141 if cc.get_id() != 'msvc'
1142 sse41_args = ['-msse4.1']
1144 if host_machine.cpu_family() == 'x86'
1145 # x86_64 have sse2 by default, so sse2 args only for x86
1146 sse2_arg = ['-msse2', '-mfpmath=sse']
1147 sse2_args = [sse2_arg, '-mstackrealign']
1148 if get_option('sse2')
1149 # These settings make generated GCC code match MSVC and follow
1150 # GCC advice on https://gcc.gnu.org/wiki/FloatingPointMath#x86note
1152 # NOTE: We need to ensure stack is realigned given that we
1153 # produce shared objects, and have no control over the stack
1154 # alignment policy of the application. Therefore we need
1155 # -mstackrealign or -mincoming-stack-boundary=2.
1157 # XXX: We could have SSE without -mstackrealign if we always used
1158 # __attribute__((force_align_arg_pointer)), but that's not
1160 c_cpp_args += sse2_args
1161 # sse2_args are adopted into c_cpp_args to avoid duplicated sse2 command line args
1165 # GCC on x86 (not x86_64) with -msse* assumes a 16 byte aligned stack, but
1166 # that's not guaranteed
1167 sse41_args += '-mstackrealign'
1173 # Check for GCC style atomics
1174 dep_atomic = null_dep
1176 if cc.compiles('''#include <stdint.h>
1181 return (int)__atomic_load_n(x.v, __ATOMIC_ACQUIRE) &
1182 (int)__atomic_add_fetch(x.v, (uint64_t)1, __ATOMIC_ACQ_REL);
1185 name : 'GCC atomic builtins')
1186 pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
1188 # Not all atomic calls can be turned into lock-free instructions, in which
1189 # GCC will make calls into the libatomic library. Check whether we need to
1190 # link with -latomic.
1192 # This can happen for 64-bit atomic operations on 32-bit architectures such
1194 if not cc.links('''#include <stdint.h>
1199 return (int)__atomic_load_n(x.v, __ATOMIC_ACQUIRE) &
1200 (int)__atomic_add_fetch(x.v, (uint64_t)1, __ATOMIC_ACQ_REL);
1202 name : 'GCC atomic builtins required -latomic')
1203 dep_atomic = cc.find_library('atomic')
1206 if not cc.links('''#include <stdint.h>
1209 return __sync_add_and_fetch(&v, (uint64_t)1);
1211 dependencies : dep_atomic,
1212 name : 'GCC 64bit atomics')
1213 pre_args += '-DMISSING_64BIT_ATOMICS'
1216 dep_ws2_32 = cc.find_library('ws2_32', required : with_platform_windows)
1218 # TODO: shared/static? Is this even worth doing?
1221 if host_machine.cpu_family() == 'x86'
1222 if system_has_kms_drm or host_machine.system() == 'gnu'
1223 with_asm_arch = 'x86'
1224 pre_args += ['-DUSE_X86_ASM']
1226 if with_glx_read_only_text
1227 pre_args += ['-DGLX_X86_READONLY_TEXT']
1230 elif host_machine.cpu_family() == 'x86_64'
1231 if system_has_kms_drm
1232 with_asm_arch = 'x86_64'
1233 pre_args += ['-DUSE_X86_64_ASM']
1235 elif host_machine.cpu_family() == 'arm'
1236 if system_has_kms_drm
1237 with_asm_arch = 'arm'
1238 pre_args += ['-DUSE_ARM_ASM']
1240 elif host_machine.cpu_family() == 'aarch64'
1241 if system_has_kms_drm
1242 with_asm_arch = 'aarch64'
1243 pre_args += ['-DUSE_AARCH64_ASM']
1245 elif host_machine.cpu_family() == 'sparc64'
1246 if system_has_kms_drm
1247 with_asm_arch = 'sparc'
1248 pre_args += ['-DUSE_SPARC_ASM']
1250 elif host_machine.cpu_family() == 'ppc64' and host_machine.endian() == 'little'
1251 if system_has_kms_drm
1252 with_asm_arch = 'ppc64le'
1253 pre_args += ['-DUSE_PPC64LE_ASM']
1255 elif host_machine.cpu_family() == 'mips64' and host_machine.endian() == 'little'
1256 if system_has_kms_drm
1257 with_asm_arch = 'mips64el'
1258 pre_args += ['-DUSE_MIPS64EL_ASM']
1260 elif host_machine.cpu_family() == 'loongarch64'
1261 if system_has_kms_drm
1262 with_asm_arch = 'loongarch64'
1263 pre_args += ['-DUSE_LOONGARCH64_ASM']
1267 # Check for standard headers and functions
1268 if (cc.has_header_symbol('sys/sysmacros.h', 'major') and
1269 cc.has_header_symbol('sys/sysmacros.h', 'minor') and
1270 cc.has_header_symbol('sys/sysmacros.h', 'makedev'))
1271 pre_args += '-DMAJOR_IN_SYSMACROS'
1273 if (cc.has_header_symbol('sys/mkdev.h', 'major') and
1274 cc.has_header_symbol('sys/mkdev.h', 'minor') and
1275 cc.has_header_symbol('sys/mkdev.h', 'makedev'))
1276 pre_args += '-DMAJOR_IN_MKDEV'
1279 if cc.check_header('sched.h')
1280 pre_args += '-DHAS_SCHED_H'
1281 if cc.has_function('sched_getaffinity')
1282 pre_args += '-DHAS_SCHED_GETAFFINITY'
1286 if not ['linux'].contains(host_machine.system())
1287 # Deprecated on Linux and requires <sys/types.h> on FreeBSD and OpenBSD
1288 if cc.check_header('sys/sysctl.h', prefix : '#include <sys/types.h>')
1289 pre_args += '-DHAVE_SYS_SYSCTL_H'
1293 foreach h : ['xlocale.h', 'linux/futex.h', 'endian.h', 'dlfcn.h', 'sys/shm.h',
1294 'cet.h', 'pthread_np.h', 'renderdoc_app.h', 'sys/inotify.h']
1295 if cc.check_header(h)
1296 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
1300 functions_to_detect = {
1309 'posix_fallocate': '',
1312 foreach f, prefix: functions_to_detect
1313 if cc.has_function(f, prefix: prefix)
1314 pre_args += '-DHAVE_@0@'.format(f.to_upper())
1322 static int dcomp(const void *l, const void *r, void *t) { return 0; }
1324 int main(int ac, char **av) {
1327 qsort_r((void*)&arr[0], 1, 1, dcomp, t);
1331 name : 'GNU qsort_r')
1332 pre_args += '-DHAVE_GNU_QSORT_R'
1336 static int dcomp(void *t, const void *l, const void *r) { return 0; }
1338 int main(int ac, char **av) {
1341 qsort_r((void*)&arr[0], 1, 1, t, dcomp);
1345 name : 'BSD qsort_r')
1346 pre_args += '-DHAVE_BSD_QSORT_R'
1349 if cc.has_header_symbol('time.h', 'struct timespec')
1350 pre_args += '-DHAVE_STRUCT_TIMESPEC'
1353 with_c11_threads = false
1354 if cc.has_function('thrd_create', prefix: '#include <threads.h>')
1355 if with_platform_android
1356 # Current only Android's c11 <threads.h> are verified
1357 pre_args += '-DHAVE_THRD_CREATE'
1358 with_c11_threads = true
1362 if cc.has_header_symbol('errno.h', 'program_invocation_name',
1363 args : '-D_GNU_SOURCE')
1364 pre_args += '-DHAVE_PROGRAM_INVOCATION_NAME'
1365 elif with_tools.contains('intel')
1366 error('Intel tools require the program_invocation_name variable')
1369 if cc.has_header_symbol('math.h', 'issignaling',
1370 args : '-D_GNU_SOURCE')
1371 pre_args += '-DHAVE_ISSIGNALING'
1374 # MinGW provides a __builtin_posix_memalign function, but not a posix_memalign.
1375 # This means that this check will succeed, but then compilation will later
1376 # fail. MSVC doesn't have this function at all, so only check for it on
1377 # non-windows platforms.
1378 if host_machine.system() != 'windows'
1379 if cc.has_function('posix_memalign')
1380 pre_args += '-DHAVE_POSIX_MEMALIGN'
1384 if cc.has_member('struct dirent', 'd_type', prefix: '''#include <sys/types.h>
1385 #include <dirent.h>''')
1386 pre_args += '-DHAVE_DIRENT_D_TYPE'
1389 # strtod locale support
1394 #ifdef HAVE_XLOCALE_H
1395 #include <xlocale.h>
1398 locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
1399 const char *s = "1.0";
1401 double d = strtod_l(s, end, loc);
1402 float f = strtof_l(s, end, loc);
1407 name : 'strtod has locale support')
1408 pre_args += '-DHAVE_STRTOD_L'
1411 # Check for some linker flags
1412 ld_args_bsymbolic = []
1413 if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic', name : 'Bsymbolic')
1414 ld_args_bsymbolic += '-Wl,-Bsymbolic'
1416 with_ld_version_script = false
1417 if cc.links('int main() { return 0; }',
1418 args : '-Wl,--version-script=@0@'.format(
1419 join_paths(meson.current_source_dir(), 'build-support/conftest.map')),
1420 name : 'version-script')
1421 with_ld_version_script = true
1423 with_ld_dynamic_list = false
1424 if cc.links('int main() { return 0; }',
1425 args : '-Wl,--dynamic-list=@0@'.format(
1426 join_paths(meson.current_source_dir(), 'build-support/conftest.dyn')),
1427 name : 'dynamic-list')
1428 with_ld_dynamic_list = true
1431 ld_args_build_id = cc.get_supported_link_arguments('-Wl,--build-id=sha1')
1433 # check for dl support
1435 if host_machine.system() != 'windows'
1436 if not cc.has_function('dlopen')
1437 dep_dl = cc.find_library('dl', required : true)
1439 if cc.has_function('dladdr', dependencies : dep_dl)
1440 # This is really only required for util/disk_cache.h
1441 pre_args += '-DHAVE_DLADDR'
1445 if cc.has_function('dl_iterate_phdr')
1446 pre_args += '-DHAVE_DL_ITERATE_PHDR'
1447 elif with_intel_vk or with_intel_hasvk
1448 error('Intel "Anvil" Vulkan driver requires the dl_iterate_phdr function')
1451 # only used in Iris and ANV
1452 if with_any_intel and ['x86', 'x86_64'].contains(host_machine.cpu_family())
1453 pre_args += '-DSUPPORT_INTEL_INTEGRATED_GPUS'
1456 if get_option('intel-xe-kmd').enabled()
1457 pre_args += '-DINTEL_XE_KMD_SUPPORTED'
1460 if with_intel_hasvk and host_machine.cpu_family().startswith('x86') == false
1461 error('Intel "hasvk" Vulkan driver requires x86 or x86_64 CPU family')
1464 if with_gallium_crocus and host_machine.cpu_family().startswith('x86') == false
1465 error('Intel "crocus" Gallium driver requires x86 or x86_64 CPU family')
1468 if with_gallium_i915 and host_machine.cpu_family().startswith('x86') == false
1469 error('Intel "i915" Gallium driver requires x86 or x86_64 CPU family')
1472 # Determine whether or not the rt library is needed for time functions
1473 if host_machine.system() == 'windows' or cc.has_function('clock_gettime')
1474 dep_clock = null_dep
1476 dep_clock = cc.find_library('rt')
1479 dep_zlib = dependency('zlib', version : '>= 1.2.3',
1480 fallback : ['zlib', 'zlib_dep'],
1481 required : get_option('zlib'))
1483 pre_args += '-DHAVE_ZLIB'
1486 dep_zstd = dependency('libzstd', required : get_option('zstd'))
1488 pre_args += '-DHAVE_ZSTD'
1491 with_compression = dep_zlib.found() or dep_zstd.found()
1493 pre_args += '-DHAVE_COMPRESSION'
1494 elif with_shader_cache
1495 error('Shader Cache requires compression')
1498 if host_machine.system() == 'windows'
1499 # For MSVC and MinGW we aren't using pthreads, and dependency('threads') will add linkage
1500 # to pthread for MinGW, so leave the dependency null_dep for Windows. For Windows linking to
1501 # kernel32 is enough for c11/threads.h and it's already linked by meson by default
1502 dep_thread = null_dep
1504 dep_thread = dependency('threads')
1506 if dep_thread.found()
1507 pre_args += '-DHAVE_PTHREAD'
1508 if host_machine.system() != 'netbsd' and cc.has_function(
1509 'pthread_setaffinity_np',
1510 dependencies : dep_thread,
1511 prefix : '#include <pthread.h>',
1512 args : '-D_GNU_SOURCE')
1513 pre_args += '-DHAVE_PTHREAD_SETAFFINITY'
1517 with_expat = get_option('expat') \
1518 .disable_auto_if(with_platform_android or with_platform_windows)
1520 if host_machine.system() == 'darwin'
1521 dep_expat = meson.get_compiler('c').find_library('expat', required : with_expat)
1523 dep_expat = dependency('expat', fallback : ['expat', 'expat_dep'],
1524 required : with_expat)
1527 # TODO: with Meson 1.1.0 this can be replaced with with_expat.enable_if(with_intel_tools)
1528 if with_intel_tools and not dep_expat.found()
1529 error('Intel tools require expat')
1532 # We don't require expat on Android or Windows
1533 use_xmlconfig = get_option('xmlconfig') \
1534 .require(not (with_platform_android or with_platform_windows),
1535 error_message : 'xmlconfig not available on Android or Windows') \
1536 .require(dep_expat.found(),
1537 error_message : 'requires expat') \
1540 # Predefined macros for windows
1541 if host_machine.system() == 'windows'
1542 pre_args += '-DWIN32_LEAN_AND_MEAN' # http://msdn2.microsoft.com/en-us/library/6dwk3a1z.aspx
1544 # this only exists on linux so either this is linux and it will be found, or
1545 # it's not linux and wont
1546 dep_m = cc.find_library('m', required : false)
1548 if host_machine.system() == 'windows'
1549 dep_regex = meson.get_compiler('c').find_library('regex', required : false)
1550 if not dep_regex.found()
1551 dep_regex = declare_dependency(compile_args : ['-DNO_REGEX'])
1554 dep_regex = null_dep
1557 if with_platform_haiku
1558 dep_network = cc.find_library('network')
1561 dep_futex = null_dep
1562 if host_machine.system() == 'windows'
1563 if (get_option('min-windows-version') < 8)
1564 pre_args += '-DWINDOWS_NO_FUTEX'
1566 dep_futex = cc.find_library('synchronization', required : true)
1570 # Check for libdrm. Various drivers have different libdrm version requirements,
1571 # but we always want to use the same version for all libdrm modules. That means
1572 # even if driver foo requires 2.4.0 and driver bar requires 2.4.3, if foo and
1573 # bar are both on use 2.4.3 for both of them
1574 dep_libdrm_amdgpu = null_dep
1575 dep_libdrm_radeon = null_dep
1576 dep_libdrm_nouveau = null_dep
1577 dep_libdrm_intel = null_dep
1579 _drm_amdgpu_ver = '2.4.110'
1580 _drm_radeon_ver = '2.4.71'
1581 _drm_nouveau_ver = '2.4.102'
1582 _drm_intel_ver = '2.4.75'
1583 _drm_ver = '2.4.109'
1586 ['intel', with_gallium_i915],
1587 ['amdgpu', (with_amd_vk and not with_platform_windows) or with_gallium_radeonsi],
1588 ['radeon', (with_gallium_radeonsi or with_gallium_r300 or with_gallium_r600)],
1589 ['nouveau', with_any_nouveau],
1592 # Loop over the enables versions and get the highest libdrm requirement for all
1595 foreach d : _libdrm_checks
1596 ver = get_variable('_drm_@0@_ver'.format(d[0]))
1597 if d[1] and ver.version_compare('>' + _drm_ver)
1603 message('libdrm @0@ needed because @1@ has the highest requirement'.format(_drm_ver, _drm_blame))
1606 # Then get each libdrm module
1607 foreach d : _libdrm_checks
1610 'dep_libdrm_' + d[0],
1611 dependency('libdrm_' + d[0], version : '>=' + _drm_ver)
1616 with_gallium_drisw_kms = false
1617 if system_has_kms_drm
1618 dep_libdrm = dependency(
1619 'libdrm', version : '>=' + _drm_ver,
1620 # GNU/Hurd includes egl_dri2, without drm.
1621 required : (with_dri2 and host_machine.system() != 'gnu') or with_dri3
1624 # We should prevent libdrm from being available when the target doesn't have it to avoid transitive
1625 # dependencies (such as vk-runtime) linking to it
1626 dep_libdrm = null_dep
1628 if dep_libdrm.found()
1629 pre_args += '-DHAVE_LIBDRM'
1630 if with_dri_platform == 'drm' and with_dri
1631 with_gallium_drisw_kms = true
1635 dep_libudev = dependency('libudev', required : false)
1636 if dep_libudev.found()
1637 pre_args += '-DHAVE_LIBUDEV'
1640 llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit', 'core', 'executionengine', 'scalaropts', 'transformutils', 'instcombine']
1641 llvm_optional_modules = ['coroutines']
1642 if with_amd_vk or with_gallium_radeonsi or with_gallium_r600
1643 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
1644 if with_gallium_r600
1645 llvm_modules += 'asmparser'
1648 if with_gallium_opencl
1650 'linker', 'coverage', 'instrumentation', 'ipo', 'irreader',
1651 'lto', 'option', 'objcarcopts', 'profiledata'
1653 # all-targets is needed to support static linking LLVM build with multiple targets
1654 # windowsdriver is needded with LLVM>=15, but we don't know what LLVM verrsion we are using yet
1655 llvm_optional_modules += ['all-targets', 'frontendopenmp', 'windowsdriver']
1658 llvm_modules += ['coverage', 'target', 'linker', 'irreader', 'option', 'libdriver', 'lto']
1659 # all-targets is needed to support static linking LLVM build with multiple targets.
1660 # windowsdriver is needded with LLVM>=15 and frontendhlsl is needed with LLVM>=16,
1661 # but we don't know what LLVM version we are using yet
1662 llvm_optional_modules += ['all-targets', 'windowsdriver', 'frontendhlsl']
1664 draw_with_llvm = get_option('draw-use-llvm')
1666 llvm_modules += 'native'
1667 # lto is needded with LLVM>=15, but we don't know what LLVM verrsion we are using yet
1668 llvm_optional_modules += ['lto']
1671 if with_amd_vk or with_gallium_radeonsi
1672 _llvm_version = '>= 15.0.0'
1674 _llvm_version = '>= 13.0.0'
1675 elif with_gallium_opencl
1676 _llvm_version = '>= 11.0.0'
1678 _llvm_version = '>= 10.0.0'
1680 _llvm_version = '>= 5.0.0'
1683 _shared_llvm = get_option('shared-llvm') \
1684 .disable_auto_if(host_machine.system() == 'windows') \
1687 _llvm = get_option('llvm')
1691 dep_llvm = dependency(
1693 version : _llvm_version,
1694 modules : llvm_modules,
1695 optional_modules : llvm_optional_modules,
1697 with_amd_vk or with_gallium_radeonsi or with_gallium_opencl or with_clc
1700 static : not _shared_llvm,
1701 fallback : ['llvm', 'dep_llvm'],
1702 include_type : 'system',
1704 with_llvm = dep_llvm.found()
1707 pre_args += '-DLLVM_AVAILABLE'
1708 pre_args += '-DMESA_LLVM_VERSION_STRING="@0@"'.format(dep_llvm.version())
1709 pre_args += '-DLLVM_IS_SHARED=@0@'.format(_shared_llvm.to_int())
1712 pre_args += '-DDRAW_LLVM_AVAILABLE'
1714 error('Lavapipe requires LLVM draw support.')
1717 if host_machine.system() != 'windows'
1718 # LLVM can be built without rtti, turning off rtti changes the ABI of C++
1719 # programs, so we need to build all C++ code in mesa without rtti as well to
1720 # ensure that linking works. Note that Win32 compilers does handle mismatching RTTI
1721 # without issues, so only apply this for other compilers.
1722 if dep_llvm.type_name() == 'internal'
1723 _llvm_rtti = subproject('llvm').get_variable('has_rtti', true)
1725 # The CMake finder will return 'ON', the llvm-config will return 'YES'
1726 _llvm_rtti = ['ON', 'YES'].contains(dep_llvm.get_variable(cmake : 'LLVM_ENABLE_RTTI', configtool: 'has-rtti'))
1728 if _rtti != _llvm_rtti
1730 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.')
1732 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.')
1737 if cc.get_argument_syntax() == 'msvc'
1738 # Suppress "/DELAYLOAD:ole32.dll/shell32.dll ignored" warnings that LLVM adds
1739 add_project_link_arguments(
1741 language : ['c', 'cpp'],
1744 elif with_amd_vk and with_aco_tests
1745 error('ACO tests require LLVM, but LLVM is disabled.')
1746 elif with_gallium_radeonsi or with_swrast_vk
1747 error('The following drivers require LLVM: RadeonSI, Lavapipe. One of these is enabled, but LLVM is disabled.')
1748 elif with_gallium_opencl
1749 error('The OpenCL "Clover" state tracker requires LLVM, but LLVM is disabled.')
1751 error('The CLC compiler requires LLVM, but LLVM is disabled.')
1753 draw_with_llvm = false
1756 with_opencl_spirv = (_opencl != 'disabled' and get_option('opencl-spirv')) or with_intel_clc or with_microsoft_clc or with_gallium_rusticl
1757 if with_opencl_spirv
1758 chosen_llvm_version_array = dep_llvm.version().split('.')
1759 chosen_llvm_version_major = chosen_llvm_version_array[0].to_int()
1760 chosen_llvm_version_minor = chosen_llvm_version_array[1].to_int()
1762 # Require an SPIRV-LLVM-Translator version compatible with the chosen LLVM
1765 # This first version check is still needed as maybe LLVM 8.0 was picked but
1766 # we do not want to accept SPIRV-LLVM-Translator 8.0.0.1 as that version
1767 # does not have the required API and those are only available starting from
1769 _llvmspirvlib_min_version = '>= 8.0.1.3'
1771 _llvmspirvlib_min_version = '>= 13.0.0.0'
1774 _llvmspirvlib_version = [
1775 _llvmspirvlib_min_version,
1776 '>= @0@.@1@'.format(chosen_llvm_version_major, chosen_llvm_version_minor),
1777 '< @0@.@1@'.format(chosen_llvm_version_major, chosen_llvm_version_minor + 1) ]
1779 dep_spirv_tools = dependency('SPIRV-Tools', required : true, version : '>= 2018.0')
1780 # LLVMSPIRVLib is available at https://github.com/KhronosGroup/SPIRV-LLVM-Translator
1781 dep_llvmspirvlib = dependency('LLVMSPIRVLib', required : true, version : _llvmspirvlib_version)
1783 dep_spirv_tools = null_dep
1784 dep_llvmspirvlib = null_dep
1787 dep_clang = null_dep
1789 llvm_libdir = dep_llvm.get_variable(cmake : 'LLVM_LIBRARY_DIR', configtool: 'libdir')
1791 dep_clang = cpp.find_library('clang-cpp', dirs : llvm_libdir, required : false)
1793 if not dep_clang.found() or not _shared_llvm
1795 'clangBasic', 'clangAST', 'clangCodeGen', 'clangLex',
1796 'clangDriver', 'clangFrontend', 'clangFrontendTool',
1797 'clangHandleCXX', 'clangHandleLLVM', 'clangSerialization',
1798 'clangSema', 'clangParse', 'clangEdit', 'clangAnalysis'
1800 if dep_llvm.version().version_compare('>= 15.0')
1801 clang_modules += 'clangSupport'
1803 if dep_llvm.version().version_compare('>= 16.0')
1804 clang_modules += 'clangASTMatchers'
1808 foreach m : clang_modules
1809 dep_clang += cpp.find_library(m, dirs : llvm_libdir, required : true)
1814 # Be explicit about only using this lib on Windows, to avoid picking
1815 # up random libs with the generic name 'libversion'
1816 dep_version = null_dep
1817 if host_machine.system() == 'windows'
1818 dep_version = cpp.find_library('version')
1821 dep_elf = dependency('libelf', required : false)
1822 if not with_platform_windows and not dep_elf.found()
1823 dep_elf = cc.find_library('elf', required : false)
1826 pre_args += '-DUSE_LIBELF'
1829 dep_glvnd = null_dep
1831 dep_glvnd = dependency('libglvnd', version : '>= 1.3.2')
1832 pre_args += '-DUSE_LIBGLVND=1'
1835 dep_valgrind = dependency('valgrind', required : get_option('valgrind'))
1836 if dep_valgrind.found()
1837 pre_args += '-DHAVE_VALGRIND'
1840 # AddressSanitizer's leak reports need all the symbols to be present at exit to
1841 # decode well, which runs afoul of our dlopen()/dlclose()ing of the DRI drivers.
1842 # Set a flag so we can skip the dlclose for asan builds.
1843 if ['address', 'address,undefined'].contains(get_option('b_sanitize'))
1844 asan_c_args = ['-DBUILT_WITH_ASAN=1']
1846 asan_c_args = ['-DBUILT_WITH_ASAN=0']
1849 yacc_is_bison = true
1850 needs_flex_bison = with_any_opengl or with_freedreno_vk or with_intel_tools or with_gallium
1852 if build_machine.system() == 'windows'
1853 # Prefer the winflexbison versions, they're much easier to install and have
1854 # better windows support.
1856 prog_flex = find_program('win_flex', required : false)
1857 if prog_flex.found()
1858 # windows compatibility (uses <io.h> instead of <unistd.h> and _isatty,
1859 # _fileno functions)
1860 prog_flex = [prog_flex, '--wincompat']
1862 prog_flex = [find_program('flex', 'lex', required : needs_flex_bison, disabler : true)]
1864 # Force flex to use const keyword in prototypes, as relies on __cplusplus or
1865 # __STDC__ macro to determine whether it's safe to use const keyword
1866 prog_flex += '-DYY_USE_CONST='
1868 prog_flex_cpp = prog_flex
1869 # Convince win_flex to use <inttypes.h> for C++ files
1870 # Note that we are using a C99 version here rather than C11,
1871 # because using a C11 version can cause the MSVC CRT headers to define
1872 # static_assert to _Static_assert, which breaks other parts of the CRT
1873 prog_flex_cpp += '-D__STDC_VERSION__=199901'
1875 prog_bison = find_program('win_bison', required : false)
1876 if not prog_bison.found()
1877 prog_bison = find_program('bison', 'yacc', required : needs_flex_bison, disabler : true)
1880 prog_bison = find_program('bison', required : false)
1882 if not prog_bison.found()
1883 prog_bison = find_program('byacc', required : needs_flex_bison, disabler : true)
1884 yacc_is_bison = false
1887 # Disable deprecated keyword warnings, since we have to use them for
1888 # old-bison compat. See discussion in
1889 # https://gitlab.freedesktop.org/mesa/mesa/merge_requests/2161
1890 if find_program('bison', required : false, version : '> 2.3').found()
1891 prog_bison = [prog_bison, '-Wno-deprecated']
1894 prog_flex = find_program('flex', required : needs_flex_bison, disabler : true)
1895 prog_flex_cpp = prog_flex
1898 dep_selinux = null_dep
1899 if get_option('selinux')
1900 dep_selinux = dependency('libselinux')
1901 pre_args += '-DMESA_SELINUX'
1904 _libunwind = get_option('libunwind') \
1905 .require(not with_platform_android, error_message : 'Android requires the use of the backtrace library, not libunwind')
1906 if host_machine.system() == 'darwin'
1907 dep_unwind = meson.get_compiler('c').find_library('System', required : _libunwind)
1909 dep_unwind = dependency('libunwind', required : _libunwind)
1911 if dep_unwind.found()
1912 pre_args += '-DHAVE_LIBUNWIND'
1916 if not with_gallium_softpipe
1917 error('OSMesa gallium requires gallium softpipe or llvmpipe.')
1919 if host_machine.system() == 'windows'
1920 osmesa_lib_name = 'osmesa'
1922 osmesa_lib_name = 'OSMesa'
1926 # TODO: symbol mangling
1928 if with_platform_wayland
1929 dep_wl_scanner = dependency('wayland-scanner', native: true)
1930 prog_wl_scanner = find_program(dep_wl_scanner.get_variable(pkgconfig : 'wayland_scanner'))
1931 if dep_wl_scanner.version().version_compare('>= 1.15')
1932 wl_scanner_arg = 'private-code'
1934 wl_scanner_arg = 'code'
1936 dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.30')
1937 dep_wayland_client = dependency('wayland-client', version : '>=1.18')
1938 dep_wayland_server = dependency('wayland-server', version : '>=1.18')
1940 dep_wayland_egl = dependency('wayland-egl-backend', version : '>= 3')
1941 dep_wayland_egl_headers = dep_wayland_egl.partial_dependency(compile_args : true)
1943 pre_args += '-DWL_HIDE_DEPRECATED'
1948 dep_xfixes = null_dep
1949 dep_x11_xcb = null_dep
1951 dep_xcb_keysyms = null_dep
1952 dep_xcb_glx = null_dep
1953 dep_xcb_dri2 = null_dep
1954 dep_xcb_dri3 = null_dep
1955 dep_dri2proto = null_dep
1956 dep_glproto = null_dep
1957 dep_xxf86vm = null_dep
1958 dep_xcb_dri3 = null_dep
1959 dep_xcb_present = null_dep
1960 dep_xcb_sync = null_dep
1961 dep_xcb_xfixes = null_dep
1962 dep_xshmfence = null_dep
1963 dep_xcb_xrandr = null_dep
1964 dep_xcb_shm = null_dep
1965 dep_xlib_xrandr = null_dep
1966 dep_openmp = null_dep
1968 # Even if we find OpenMP, Gitlab CI fails to link with gcc/i386 and clang/anyarch.
1969 if host_machine.cpu_family() == 'x86_64' and cc.get_id() == 'gcc'
1970 dep_openmp = dependency('openmp', required : false)
1971 if dep_openmp.found()
1972 pre_args += ['-DHAVE_OPENMP']
1976 with_dri3_modifiers = false
1977 with_xcb_keysyms = false
1978 if with_platform_x11
1979 if with_glx == 'xlib'
1980 dep_x11 = dependency('x11')
1981 dep_xext = dependency('xext')
1982 dep_xcb = dependency('xcb')
1983 dep_xcb_xrandr = dependency('xcb-randr')
1984 elif with_glx == 'dri'
1985 dep_x11 = dependency('x11')
1986 dep_xext = dependency('xext')
1987 dep_xfixes = dependency('xfixes', version : '>= 2.0')
1988 dep_xcb_glx = dependency('xcb-glx', version : '>= 1.8.1')
1989 dep_xcb_shm = dependency('xcb-shm')
1991 if (with_any_vk or with_glx == 'dri' or with_egl or
1992 (with_gallium_vdpau or with_gallium_va or
1993 with_gallium_omx != 'disabled'))
1994 dep_xcb = dependency('xcb')
1995 dep_xcb_keysyms = dependency('xcb-keysyms', required : false)
1996 with_xcb_keysyms = dep_xcb_keysyms.found()
1998 pre_args += '-DXCB_KEYSYMS_AVAILABLE'
2000 dep_x11_xcb = dependency('x11-xcb')
2001 if with_dri_platform == 'drm' and not dep_libdrm.found()
2002 error('libdrm required for gallium video statetrackers when using x11')
2005 if with_any_vk or with_egl or (with_glx == 'dri' and with_dri_platform == 'drm')
2006 dep_xcb_dri2 = dependency('xcb-dri2', version : '>= 1.8')
2009 dep_xcb_dri3 = dependency('xcb-dri3')
2010 dep_xcb_present = dependency('xcb-present')
2011 # until xcb-dri3 has been around long enough to make a hard-dependency:
2012 if (dep_xcb_dri3.version().version_compare('>= 1.13') and
2013 dep_xcb_present.version().version_compare('>= 1.13'))
2014 with_dri3_modifiers = true
2016 dep_xcb_shm = dependency('xcb-shm')
2017 dep_xcb_sync = dependency('xcb-sync')
2018 dep_xshmfence = dependency('xshmfence', version : '>= 1.1')
2021 if with_glx == 'dri' or with_glx == 'xlib'
2022 dep_glproto = dependency('glproto', version : '>= 1.4.14')
2024 if with_glx == 'dri'
2025 if with_dri_platform == 'drm'
2026 dep_dri2proto = dependency('dri2proto', version : '>= 2.8')
2028 dep_xxf86vm = dependency('xxf86vm')
2034 with_gallium_vdpau or with_gallium_xa or
2035 with_gallium_omx != 'disabled'))
2036 dep_xcb_xfixes = dependency('xcb-xfixes')
2038 if with_xlib_lease or with_any_vk
2039 dep_xcb_xrandr = dependency('xcb-randr')
2042 dep_xlib_xrandr = dependency('xrandr', version : '>= 1.3')
2047 pre_args += '-DHAVE_DRI'
2050 pre_args += '-DHAVE_DRI2'
2053 pre_args += '-DHAVE_DRI3'
2055 if with_dri3_modifiers
2056 pre_args += '-DHAVE_DRI3_MODIFIERS'
2058 if with_gallium_drisw_kms
2059 pre_args += '-DHAVE_DRISW_KMS'
2062 if get_option('gallium-extra-hud')
2063 pre_args += '-DHAVE_GALLIUM_EXTRA_HUD=1'
2066 dep_lmsensors = cc.find_library('sensors', required : get_option('lmsensors'))
2067 if dep_lmsensors.found()
2068 pre_args += '-DHAVE_LIBSENSORS=1'
2071 _shader_replacement = get_option('custom-shader-replacement')
2072 if _shader_replacement == ''
2074 pre_args += '-DCUSTOM_SHADER_REPLACEMENT'
2077 with_perfetto = get_option('perfetto')
2078 with_datasources = get_option('datasources')
2079 with_any_datasource = with_datasources.length() != 0
2081 dep_perfetto = dependency('perfetto', fallback: ['perfetto', 'dep_perfetto'])
2082 pre_args += '-DHAVE_PERFETTO'
2085 with_gpuvis = get_option('gpuvis')
2087 pre_args += '-DHAVE_GPUVIS'
2090 add_project_arguments(pre_args, language : ['c', 'cpp'])
2091 add_project_arguments(c_cpp_args, language : ['c', 'cpp'])
2093 add_project_arguments(c_args, language : ['c'])
2094 add_project_arguments(cpp_args, language : ['cpp'])
2098 if with_glx == 'xlib'
2099 gl_priv_reqs += ['x11', 'xext', 'xcb']
2100 elif with_glx == 'dri'
2102 'x11', 'xext', 'xfixes', 'x11-xcb', 'xcb',
2104 if with_dri_platform == 'drm'
2105 gl_priv_reqs += 'xcb-dri2 >= 1.8'
2107 gl_priv_reqs += 'xxf86vm'
2111 if dep_libdrm.found()
2112 gl_priv_reqs += 'libdrm >= 2.4.75'
2116 if dep_thread.found()
2117 gl_priv_libs += ['-lpthread', '-pthread']
2120 gl_priv_libs += '-lm'
2123 gl_priv_libs += '-ldl'
2126 # FIXME: autotools lists this as incomplete
2129 gbm_priv_libs += '-ldl'
2132 pkg = import('pkgconfig')
2134 if host_machine.system() == 'windows'
2135 prog_dumpbin = find_program('dumpbin', required : false)
2136 with_symbols_check = prog_dumpbin.found() and with_tests
2137 if with_symbols_check
2138 symbols_check_args = ['--dumpbin', prog_dumpbin.full_path()]
2141 prog_nm = find_program('nm')
2142 with_symbols_check = with_tests
2143 symbols_check_args = ['--nm', prog_nm.full_path()]
2146 # This quirk needs to be applied to sources with functions defined in assembly
2147 # as GCC LTO drops them. See: https://bugs.freedesktop.org/show_bug.cgi?id=109391
2148 gcc_lto_quirk = (cc.get_id() == 'gcc') ? ['-fno-lto'] : []
2150 devenv = environment()
2152 dir_compiler_nir = join_paths(meson.current_source_dir(), 'src/compiler/nir/')
2153 dir_source_root = meson.project_source_root()
2160 meson.add_devenv(devenv)
2164 'prefix': get_option('prefix'),
2165 'libdir': get_option('libdir'),
2166 'includedir': get_option('includedir'),
2168 section: 'Directories'
2173 'c_cpp_args': c_cpp_args,
2175 section: 'Common C and C++ arguments'
2180 'OpenGL': with_opengl,
2183 'Shared glapi': with_shared_glapi,
2184 'GLVND': with_glvnd,
2186 section: 'OpenGL', bool_yn: true
2191 'Platform': with_dri_platform,
2192 'Driver dir': dri_drivers_path,
2194 section: 'DRI', bool_yn: true, list_sep: ' '
2199 'Enabled': with_glx != 'disabled',
2200 'Provider': with_glx == 'disabled' ? 'None' : with_glx
2202 section: 'GLX', bool_yn: true, list_sep: ' '
2205 egl_summary = {'Enabled': with_egl}
2209 egl_drivers += 'builtin:egl_dri2'
2212 egl_drivers += 'builtin:egl_dri3'
2214 if with_platform_windows
2215 egl_drivers += 'builtin:wgl'
2217 egl_summary += {'Drivers': egl_drivers}
2218 egl_summary += {'Platforms': _platforms}
2220 summary(egl_summary, section: 'EGL', bool_yn: true, list_sep: ' ')
2222 gbm_summary = {'Enabled': with_gbm}
2224 gbm_summary += {'Backends path': gbm_backends_path}
2226 summary(gbm_summary, section: 'GBM', bool_yn: true, list_sep: ' ')
2228 vulkan_summary = {'Drivers': _vulkan_drivers.length() != 0 ? _vulkan_drivers : false }
2230 vulkan_summary += {'Platforms': _platforms}
2231 vulkan_summary += {'ICD dir': with_vulkan_icd_dir}
2232 if with_any_vulkan_layers
2233 vulkan_summary += {'Layers': get_option('vulkan-layers')}
2235 vulkan_summary += {'Intel Ray tracing': with_intel_vk_rt}
2237 summary(vulkan_summary, section: 'Vulkan', bool_yn: true, list_sep: ' ')
2239 video_summary = {'Codecs': _codecs.length() != 0 ? _codecs : false}
2241 if with_gallium_vdpau
2242 video_apis += 'vdpau'
2248 video_apis += 'vulkan'
2253 if with_gallium_omx != 'disabled'
2256 video_summary += {'APIs': video_apis.length() != 0 ? video_apis : false}
2257 summary(video_summary, section: 'Video', bool_yn: true, list_sep: ' ')
2259 llvm_summary = {'Enabled': with_llvm}
2261 llvm_summary += {'Version': dep_llvm.version()}
2263 summary(llvm_summary, section: 'LLVM', bool_yn: true, list_sep: ' ')
2265 gallium_summary = {'Enabled': with_gallium}
2267 gallium_summary += {'Drivers': gallium_drivers}
2268 gallium_summary += {'Platforms': _platforms}
2270 gallium_frontends = ['mesa']
2272 gallium_frontends += 'xa'
2274 if with_gallium_vdpau
2275 gallium_frontends += 'vdpau'
2277 if with_gallium_omx != 'disabled'
2278 gallium_frontends += 'omx' + with_gallium_omx
2281 gallium_frontends += 'va'
2283 if with_gallium_st_nine
2284 gallium_frontends += 'nine'
2286 if with_gallium_opencl
2287 gallium_frontends += 'clover'
2289 if with_gallium_rusticl
2290 gallium_frontends += 'rusticl'
2292 gallium_summary += {'Frontends': gallium_frontends}
2293 gallium_summary += {'Off-screen rendering (OSMesa)': with_osmesa ? 'lib' + osmesa_lib_name : false}
2294 gallium_summary += {'HUD lm-sensors': dep_lmsensors.found()}
2296 summary(gallium_summary, section: 'Gallium', bool_yn: true, list_sep: ' ')
2298 perfetto_summary = {'Enabled': with_perfetto}
2299 if with_perfetto and with_any_datasource
2300 perfetto_summary += {'Data source': with_datasources}
2302 summary(perfetto_summary, section: 'Perfetto', bool_yn: true, list_sep: ' ')