1 # Copyright © 2017-2019 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 : run_command(
25 [find_program('python', 'python3'), 'bin/meson_get_version.py']
28 meson_version : '>= 0.46',
29 default_options : ['buildtype=debugoptimized', 'b_ndebug=if-release', 'c_std=c99', 'cpp_std=c++14']
32 cc = meson.get_compiler('c')
33 cpp = meson.get_compiler('cpp')
35 null_dep = dependency('', required : false)
37 # Arguments for the preprocessor, put these in a separate array from the C and
38 # C++ (cpp in meson terminology) arguments since they need to be added to the
39 # default arguments for both C and C++.
41 '-D__STDC_CONSTANT_MACROS',
42 '-D__STDC_FORMAT_MACROS',
43 '-D__STDC_LIMIT_MACROS',
44 '-DPACKAGE_VERSION="@0@"'.format(meson.project_version()),
45 '-DPACKAGE_BUGREPORT="https://gitlab.freedesktop.org/mesa/mesa/issues"',
48 with_vulkan_icd_dir = get_option('vulkan-icd-dir')
49 with_tests = get_option('build-tests')
50 with_valgrind = get_option('valgrind')
51 with_libunwind = get_option('libunwind')
52 with_glx_read_only_text = get_option('glx-read-only-text')
53 with_glx_direct = get_option('glx-direct')
54 with_osmesa = get_option('osmesa')
55 with_swr_arches = get_option('swr-arches')
56 with_vulkan_overlay_layer = get_option('vulkan-overlay-layer')
57 with_tools = get_option('tools')
58 if with_tools.contains('all')
73 with_intel_tools = with_tools.contains('intel') or with_tools.contains('intel-ui')
74 with_imgui = with_intel_tools or with_vulkan_overlay_layer
76 dri_drivers_path = get_option('dri-drivers-path')
77 if dri_drivers_path == ''
78 dri_drivers_path = join_paths(get_option('prefix'), get_option('libdir'), 'dri')
80 dri_search_path = get_option('dri-search-path')
81 if dri_search_path == ''
82 dri_search_path = dri_drivers_path
85 with_gles1 = get_option('gles1')
86 with_gles2 = get_option('gles2')
87 if host_machine.system() == 'windows'
88 if with_gles1 == 'auto'
91 if with_gles2 == 'auto'
95 with_opengl = get_option('opengl')
97 # Default shared glapi off for windows, on elsewhere.
98 _sg = get_option('shared-glapi')
100 with_shared_glapi = host_machine.system() != 'windows'
102 with_shared_glapi = _sg == 'true'
105 # shared-glapi is required if at least two OpenGL APIs are being built
106 if not with_shared_glapi
107 if ((with_gles1 == 'true' and with_gles2 == 'true') or
108 (with_gles1 == 'true' and with_opengl) or
109 (with_gles2 == 'true' and with_opengl))
110 error('shared-glapi required for building two or more of OpenGL, OpenGL ES 1.x, OpenGL ES 2.x')
116 # We require OpenGL for OpenGL ES
118 if (with_gles1 == 'true' or with_gles2 == 'true') and not with_opengl
119 error('building OpenGL ES without OpenGL is not supported.')
125 with_gles1 = with_gles1 != 'false'
126 with_gles2 = with_gles2 != 'false'
127 with_any_opengl = with_opengl or with_gles1 or with_gles2
128 # Only build shared_glapi if at least one OpenGL API is enabled
129 with_shared_glapi = with_shared_glapi and with_any_opengl
131 system_has_kms_drm = ['openbsd', 'netbsd', 'freebsd', 'gnu/kfreebsd', 'dragonfly', 'linux', 'sunos'].contains(host_machine.system())
133 dri_drivers = get_option('dri-drivers')
134 if dri_drivers.contains('auto')
135 if system_has_kms_drm
137 if ['x86', 'x86_64'].contains(host_machine.cpu_family())
138 dri_drivers = ['i915', 'i965', 'r100', 'r200', 'nouveau']
139 elif ['arm', 'aarch64'].contains(host_machine.cpu_family())
142 error('Unknown architecture @0@. Please pass -Ddri-drivers to set driver options. Patches gladly accepted to fix this.'.format(
143 host_machine.cpu_family()))
145 elif ['darwin', 'windows', 'cygwin', 'haiku'].contains(host_machine.system())
146 # only swrast would make sense here, but gallium swrast is a much better default
149 error('Unknown OS @0@. Please pass -Ddri-drivers to set driver options. Patches gladly accepted to fix this.'.format(
150 host_machine.system()))
154 with_dri_i915 = dri_drivers.contains('i915')
155 with_dri_i965 = dri_drivers.contains('i965')
156 with_dri_r100 = dri_drivers.contains('r100')
157 with_dri_r200 = dri_drivers.contains('r200')
158 with_dri_nouveau = dri_drivers.contains('nouveau')
159 with_dri_swrast = dri_drivers.contains('swrast')
161 with_dri = dri_drivers.length() != 0 and dri_drivers != ['']
163 gallium_drivers = get_option('gallium-drivers')
164 if gallium_drivers.contains('auto')
165 if system_has_kms_drm
167 if ['x86', 'x86_64'].contains(host_machine.cpu_family())
169 'r300', 'r600', 'radeonsi', 'nouveau', 'virgl', 'svga', 'swrast',
172 elif ['arm', 'aarch64'].contains(host_machine.cpu_family())
174 'kmsro', 'v3d', 'vc4', 'freedreno', 'etnaviv', 'nouveau',
175 'tegra', 'virgl', 'lima', 'panfrost', 'swrast'
178 error('Unknown architecture @0@. Please pass -Dgallium-drivers to set driver options. Patches gladly accepted to fix this.'.format(
179 host_machine.cpu_family()))
181 elif ['darwin', 'windows', 'cygwin', 'haiku'].contains(host_machine.system())
182 gallium_drivers = ['swrast']
184 error('Unknown OS @0@. Please pass -Dgallium-drivers to set driver options. Patches gladly accepted to fix this.'.format(
185 host_machine.system()))
188 with_gallium_kmsro = gallium_drivers.contains('kmsro')
189 with_gallium_radeonsi = gallium_drivers.contains('radeonsi')
190 with_gallium_r300 = gallium_drivers.contains('r300')
191 with_gallium_r600 = gallium_drivers.contains('r600')
192 with_gallium_nouveau = gallium_drivers.contains('nouveau')
193 with_gallium_freedreno = gallium_drivers.contains('freedreno')
194 with_gallium_softpipe = gallium_drivers.contains('swrast')
195 with_gallium_vc4 = gallium_drivers.contains('vc4')
196 with_gallium_v3d = gallium_drivers.contains('v3d')
197 with_gallium_panfrost = gallium_drivers.contains('panfrost')
198 with_gallium_etnaviv = gallium_drivers.contains('etnaviv')
199 with_gallium_tegra = gallium_drivers.contains('tegra')
200 with_gallium_iris = gallium_drivers.contains('iris')
201 with_gallium_i915 = gallium_drivers.contains('i915')
202 with_gallium_svga = gallium_drivers.contains('svga')
203 with_gallium_virgl = gallium_drivers.contains('virgl')
204 with_gallium_swr = gallium_drivers.contains('swr')
205 with_gallium_lima = gallium_drivers.contains('lima')
206 with_gallium_zink = gallium_drivers.contains('zink')
208 if cc.get_id().startswith('intel') and meson.version().version_compare('< 0.49.1')
209 error('Meson does not have sufficient support of ICC before 0.49.1 to compile mesa')
212 with_gallium = gallium_drivers.length() != 0 and gallium_drivers != ['']
214 if with_gallium and system_has_kms_drm
215 _glx = get_option('glx')
216 _egl = get_option('egl')
217 if _glx == 'dri' or _egl == 'true' or (_glx == 'disabled' and _egl != 'false')
222 _vulkan_drivers = get_option('vulkan-drivers')
223 if _vulkan_drivers.contains('auto')
224 if system_has_kms_drm
225 if host_machine.cpu_family().startswith('x86')
226 _vulkan_drivers = ['amd', 'intel']
227 elif ['arm', 'aarch64'].contains(host_machine.cpu_family())
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()))
242 with_intel_vk = _vulkan_drivers.contains('intel')
243 with_amd_vk = _vulkan_drivers.contains('amd')
244 with_freedreno_vk = _vulkan_drivers.contains('freedreno')
245 with_any_vk = _vulkan_drivers.length() != 0 and _vulkan_drivers != ['']
247 if with_dri_swrast and (with_gallium_softpipe or with_gallium_swr)
248 error('Only one swrast provider can be built')
250 if with_dri_i915 and with_gallium_i915
251 error('Only one i915 provider can be built')
253 if with_gallium_kmsro and not (with_gallium_v3d or with_gallium_vc4 or with_gallium_etnaviv or with_gallium_freedreno or with_gallium_panfrost or with_gallium_lima)
254 error('kmsro driver requires one or more renderonly drivers (vc4, etnaviv, freedreno, panfrost, lima)')
256 if with_gallium_tegra and not with_gallium_nouveau
257 error('tegra driver requires nouveau driver')
260 if host_machine.system() == 'darwin'
261 with_dri_platform = 'apple'
262 pre_args += '-DBUILDING_MESA'
263 elif ['windows', 'cygwin'].contains(host_machine.system())
264 with_dri_platform = 'windows'
265 elif system_has_kms_drm
266 with_dri_platform = 'drm'
268 # FIXME: haiku doesn't use dri, and xlib doesn't use dri, probably should
269 # assert here that one of those cases has been met.
270 # FIXME: illumos ends up here as well
271 with_dri_platform = 'none'
274 _platforms = get_option('platforms')
275 if _platforms.contains('auto')
276 if system_has_kms_drm
277 _platforms = ['x11', 'wayland', 'drm', 'surfaceless']
278 elif ['darwin', 'cygwin'].contains(host_machine.system())
279 _platforms = ['x11', 'surfaceless']
280 elif ['haiku'].contains(host_machine.system())
281 _platforms = ['haiku']
282 elif host_machine.system() == 'windows'
283 _platforms = ['windows']
285 error('Unknown OS @0@. Please pass -Dplatforms to set platforms. Patches gladly accepted to fix this.'.format(
286 host_machine.system()))
290 with_platform_android = _platforms.contains('android')
291 with_platform_x11 = _platforms.contains('x11')
292 with_platform_wayland = _platforms.contains('wayland')
293 with_platform_drm = _platforms.contains('drm')
294 with_platform_haiku = _platforms.contains('haiku')
295 with_platform_surfaceless = _platforms.contains('surfaceless')
296 with_platform_windows = _platforms.contains('windows')
298 with_platforms = false
299 if _platforms.length() != 0 and _platforms != ['']
300 # sanity check that list contains no empty strings
301 if _platforms.contains('')
302 error('Invalid argument list given to -Dplatforms, please fix.')
304 with_platforms = true
305 egl_native_platform = _platforms[0]
308 _xlib_lease = get_option('xlib-lease')
309 if _xlib_lease == 'auto'
310 with_xlib_lease = with_platform_x11 and with_platform_drm
312 with_xlib_lease = _xlib_lease == 'true'
315 with_glx = get_option('glx')
316 if with_glx == 'auto'
319 elif with_platform_haiku
320 with_glx = 'disabled'
321 elif host_machine.system() == 'windows'
322 with_glx = 'disabled'
324 # Even when building just gallium drivers the user probably wants dri
326 elif with_platform_x11 and with_any_opengl and not with_any_vk
327 # The automatic behavior should not be to turn on xlib based glx when
328 # building only vulkan drivers
331 with_glx = 'disabled'
340 if not (with_dri or with_gallium or with_glx != 'disabled')
344 with_any_opengl = false
345 with_shared_glapi = false
348 _gbm = get_option('gbm')
350 with_gbm = system_has_kms_drm and with_dri
352 with_gbm = _gbm == 'true'
354 if with_gbm and not system_has_kms_drm
355 error('GBM only supports DRM/KMS platforms')
358 _egl = get_option('egl')
361 not ['darwin', 'windows'].contains(host_machine.system()) and
362 with_dri and with_shared_glapi and with_platforms
366 error('EGL requires dri')
367 elif not with_shared_glapi
368 error('EGL requires shared-glapi')
369 elif not with_platforms
370 error('No platforms specified, consider -Dplatforms=drm,x11,surfaceless at least')
371 elif not ['disabled', 'dri'].contains(with_glx)
372 error('EGL requires dri, but a GLX is being built without dri')
373 elif ['darwin', 'windows'].contains(host_machine.system())
374 error('EGL is not available on Windows or MacOS')
381 if with_egl and not (with_platform_drm or with_platform_surfaceless or with_platform_android)
382 if with_gallium_radeonsi
383 error('RadeonSI requires the drm, surfaceless or android platform when using EGL')
385 if with_gallium_virgl
386 error('Virgl requires the drm, surfaceless or android platform when using EGL')
390 # Android uses emutls for versions <= P/28. For USE_ELF_TLS we need ELF TLS.
391 if host_machine.system() != 'windows' and (not with_platform_android or get_option('platform-sdk-version') >= 29)
392 pre_args += '-DUSE_ELF_TLS'
395 if with_glx != 'disabled'
396 if not (with_platform_x11 and with_any_opengl)
397 error('Cannot build GLX support without X11 platform support and at least one OpenGL API')
398 elif with_glx == 'gallium-xlib'
400 error('Gallium-xlib based GLX requires at least one gallium driver')
401 elif not with_gallium_softpipe
402 error('Gallium-xlib based GLX requires softpipe or llvmpipe.')
404 error('gallium-xlib conflicts with any dri driver')
406 elif with_glx == 'xlib'
408 error('xlib conflicts with any dri driver')
410 elif with_glx == 'dri'
411 if not with_shared_glapi
412 error('dri based GLX requires shared-glapi')
417 with_glvnd = get_option('glvnd')
419 if with_platform_windows
420 error('glvnd cannot be used on Windows')
421 elif with_glx == 'xlib' or with_glx == 'gallium-xlib'
422 error('Cannot build glvnd support for GLX that is not DRI based.')
423 elif with_glx == 'disabled' and not with_egl
424 error('glvnd requires DRI based GLX and/or EGL')
426 if get_option('egl-lib-suffix') != ''
427 error('''EGL lib suffix can't be used with libglvnd''')
431 if with_vulkan_icd_dir == ''
432 with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
435 # GNU/Hurd includes egl_dri2, without drm.
436 with_dri2 = (with_dri or with_any_vk) and (with_dri_platform == 'drm' or
437 host_machine.system() == 'gnu')
438 _dri3 = get_option('dri3')
440 with_dri3 = system_has_kms_drm and with_dri2
442 with_dri3 = _dri3 == 'true'
445 if with_any_vk and (with_platform_x11 and not with_dri3)
446 error('Vulkan drivers require dri3 for X11 support')
449 if with_glx == 'disabled' and not with_egl and not with_gbm and with_osmesa != 'classic'
450 error('building dri drivers require at least one windowing system or classic osmesa')
454 prog_pkgconfig = find_program('pkg-config')
456 _vdpau = get_option('gallium-vdpau')
457 if not system_has_kms_drm
459 error('VDPAU state tracker can only be build on unix-like OSes.')
463 elif not with_platform_x11
465 error('VDPAU state tracker requires X11 support.')
469 elif not (with_gallium_r300 or with_gallium_r600 or with_gallium_radeonsi or
470 with_gallium_nouveau)
472 error('VDPAU state tracker requires at least one of the following gallium drivers: r300, r600, radeonsi, nouveau.')
478 with_gallium_vdpau = false
480 dep_vdpau = dependency('vdpau', version : '>= 1.1', required : _vdpau == 'true')
482 dep_vdpau = declare_dependency(
483 compile_args : run_command(prog_pkgconfig, ['vdpau', '--cflags']).stdout().split()
485 with_gallium_vdpau = true
489 if with_gallium_vdpau
490 pre_args += '-DHAVE_ST_VDPAU'
492 vdpau_drivers_path = get_option('vdpau-libs-path')
493 if vdpau_drivers_path == ''
494 vdpau_drivers_path = join_paths(get_option('libdir'), 'vdpau')
498 dep_vulkan = dependency('vulkan')
501 _xvmc = get_option('gallium-xvmc')
502 if not system_has_kms_drm
504 error('XVMC state tracker can only be build on unix-like OSes.')
508 elif not with_platform_x11
510 error('XVMC state tracker requires X11 support.')
514 elif not (with_gallium_r600 or with_gallium_nouveau)
516 error('XVMC state tracker requires at least one of the following gallium drivers: r600, nouveau.')
523 with_gallium_xvmc = false
525 dep_xvmc = dependency('xvmc', version : '>= 1.0.6', required : _xvmc == 'true')
526 dep_xv = dependency('xv', required : _xvmc == 'true')
527 with_gallium_xvmc = dep_xvmc.found() and dep_xv.found()
530 xvmc_drivers_path = get_option('xvmc-libs-path')
531 if xvmc_drivers_path == ''
532 xvmc_drivers_path = get_option('libdir')
535 _omx = get_option('gallium-omx')
536 if not system_has_kms_drm
537 if ['auto', 'disabled'].contains(_omx)
540 error('OMX state tracker can only be built on unix-like OSes.')
542 elif not (with_gallium_r600 or with_gallium_radeonsi or with_gallium_nouveau)
543 if ['auto', 'disabled'].contains(_omx)
546 error('OMX state tracker requires at least one of the following gallium drivers: r600, radeonsi, nouveau.')
549 with_gallium_omx = _omx
552 if ['auto', 'bellagio'].contains(_omx)
553 dep_omx = dependency(
554 'libomxil-bellagio', required : _omx == 'bellagio'
557 with_gallium_omx = 'bellagio'
560 if ['auto', 'tizonia'].contains(_omx)
561 if with_dri and with_egl
562 dep_omx = dependency(
563 'libtizonia', version : '>= 0.10.0',
564 required : _omx == 'tizonia',
567 dependency('libtizplatform', required : _omx == 'tizonia'),
568 dependency('tizilheaders', required : _omx == 'tizonia'),
570 if dep_omx.found() and dep_omx_other[0].found() and dep_omx_other[1].found()
571 with_gallium_omx = 'tizonia'
573 elif _omx == 'tizonia'
574 error('OMX-Tizonia state tracker requires dri and egl')
578 with_gallium_omx = 'disabled'
580 with_gallium_omx = _omx
584 '-DENABLE_ST_OMX_BELLAGIO=' + (with_gallium_omx == 'bellagio' ? '1' : '0'),
585 '-DENABLE_ST_OMX_TIZONIA=' + (with_gallium_omx == 'tizonia' ? '1' : '0'),
589 omx_drivers_path = get_option('omx-libs-path')
591 if with_gallium_omx != 'disabled'
592 # Figure out where to put the omx driver.
593 # FIXME: this could all be vastly simplified by adding a 'defined_variable'
594 # argument to meson's get_pkgconfig_variable method.
595 if omx_drivers_path == ''
596 _omx_libdir = dep_omx.get_pkgconfig_variable('libdir')
597 _omx_drivers_dir = dep_omx.get_pkgconfig_variable('pluginsdir')
598 if _omx_libdir == get_option('libdir')
599 omx_drivers_path = _omx_drivers_dir
602 # This will fail on windows. Does OMX run on windows?
603 _omx_libdir = _omx_libdir.split('/')
604 _omx_drivers_dir = _omx_drivers_dir.split('/')
605 foreach o : _omx_drivers_dir
606 if not _omx_libdir.contains(o)
610 omx_drivers_path = join_paths(get_option('libdir'), _omx_base_dir)
615 _va = get_option('gallium-va')
616 if not system_has_kms_drm
618 error('VA state tracker can only be built on unix-like OSes.')
622 elif not (with_gallium_r600 or with_gallium_radeonsi or with_gallium_nouveau)
624 error('VA state tracker requires at least one of the following gallium drivers: r600, radeonsi, nouveau.')
629 with_gallium_va = false
632 dep_va = dependency('libva', version : '>= 0.38.0', required : _va == 'true')
634 dep_va_headers = declare_dependency(
635 compile_args : run_command(prog_pkgconfig, ['libva', '--cflags']).stdout().split()
637 with_gallium_va = true
641 va_drivers_path = get_option('va-libs-path')
642 if va_drivers_path == ''
643 va_drivers_path = join_paths(get_option('libdir'), 'dri')
646 _xa = get_option('gallium-xa')
647 if not system_has_kms_drm
649 error('XA state tracker can only be built on unix-like OSes.')
653 elif not (with_gallium_nouveau or with_gallium_freedreno or with_gallium_i915
654 or with_gallium_svga)
656 error('XA state tracker requires at least one of the following gallium drivers: nouveau, freedreno, i915, svga.')
661 with_gallium_xa = _xa != 'false'
663 d3d_drivers_path = get_option('d3d-drivers-path')
664 if d3d_drivers_path == ''
665 d3d_drivers_path = join_paths(get_option('prefix'), get_option('libdir'), 'd3d')
668 with_gallium_st_nine = get_option('gallium-nine')
669 if with_gallium_st_nine
670 if not with_gallium_softpipe
671 error('The nine state tracker requires gallium softpipe/llvmpipe.')
672 elif not (with_gallium_radeonsi or with_gallium_nouveau or with_gallium_r600
673 or with_gallium_r300 or with_gallium_svga or with_gallium_i915
674 or with_gallium_iris)
675 error('The nine state tracker requires at least one non-swrast gallium driver.')
678 error('Using nine with wine requires dri3')
682 if get_option('power8') != 'false'
683 # on old versions of meson the cpu family would return as ppc64le on little
684 # endian power8, this was changed in 0.48 such that the family would always
685 # be ppc64 regardless of endianness, and then the machine.endian() value
686 # should be checked. Since we support versions < 0.48 we need to use
688 if host_machine.cpu_family().startswith('ppc64') and host_machine.endian() == 'little'
689 if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.8')
690 error('Altivec is not supported with gcc version < 4.8.')
695 vector unsigned char r;
696 vector unsigned int v = vec_splat_u32 (1);
697 r = __builtin_vec_vgbbd ((vector unsigned char) v);
700 args : '-mpower8-vector',
701 name : 'POWER8 intrinsics')
702 pre_args += ['-D_ARCH_PWR8', '-mpower8-vector']
703 elif get_option('power8') == 'true'
704 error('POWER8 intrinsic support required but not found.')
709 _opencl = get_option('gallium-opencl')
711 if _opencl != 'disabled'
713 error('OpenCL Clover implementation requires at least one gallium driver.')
716 dep_clc = dependency('libclc')
717 with_gallium_opencl = true
718 with_opencl_icd = _opencl == 'icd'
720 with_opencl_spirv = get_option('opencl-spirv')
722 dep_spirv_tools = dependency('SPIRV-Tools', required : true, version : '>= 2018.0')
723 # LLVMSPIRVLib is available at https://github.com/KhronosGroup/SPIRV-LLVM-Translator
724 dep_llvmspirvlib = dependency('LLVMSPIRVLib', required : true, version : '>= 0.2.1')
726 dep_spirv_tools = null_dep
727 dep_llvmspirvlib = null_dep
730 if host_machine.cpu_family().startswith('ppc') and cpp.compiles('''
731 #if !defined(__VEC__) || !defined(__ALTIVEC__)
732 #error "AltiVec not enabled"
735 clover_cpp_std += ['cpp_std=gnu++11']
739 dep_spirv_tools = null_dep
740 dep_llvmspirvlib = null_dep
741 with_gallium_opencl = false
742 with_opencl_icd = false
743 with_opencl_spirv = false
746 gl_pkgconfig_c_flags = []
748 if with_any_vk or with_egl or (with_glx == 'dri' and with_dri_platform == 'drm')
749 pre_args += '-DHAVE_X11_PLATFORM'
751 if with_glx == 'xlib' or with_glx == 'gallium-xlib'
752 pre_args += '-DUSE_XSHM'
754 pre_args += '-DGLX_INDIRECT_RENDERING'
756 pre_args += '-DGLX_DIRECT_RENDERING'
758 if with_dri_platform == 'drm'
759 pre_args += '-DGLX_USE_DRM'
760 elif with_dri_platform == 'apple'
761 pre_args += '-DGLX_USE_APPLEGL'
762 elif with_dri_platform == 'windows'
763 pre_args += '-DGLX_USE_WINDOWSGL'
767 pre_args += '-DEGL_NO_X11'
768 gl_pkgconfig_c_flags += '-DEGL_NO_X11'
771 if with_egl and not with_gbm
772 error('EGL drm platform requires gbm')
774 pre_args += '-DHAVE_DRM_PLATFORM'
776 if with_platform_surfaceless
777 pre_args += '-DHAVE_SURFACELESS_PLATFORM'
779 if with_platform_android
781 dependency('cutils'),
782 dependency('hardware'),
785 if get_option('platform-sdk-version') >= 26
786 dep_android += dependency('nativewindow')
788 pre_args += '-DHAVE_ANDROID_PLATFORM'
790 if with_platform_haiku
791 pre_args += '-DHAVE_HAIKU_PLATFORM'
794 if meson.version().version_compare('>=0.50')
795 prog_python = import('python').find_installation('python3')
797 prog_python = import('python3').find_python()
799 has_mako = run_command(
802 from distutils.version import StrictVersion
804 assert StrictVersion(mako.__version__) > StrictVersion("0.8.0")
806 if has_mako.returncode() != 0
807 error('Python (3.x) mako module >= 0.8.0 required to build mesa.')
810 if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
811 error('When using GCC, version 4.4.6 or later is required.')
814 # Support systems without ETIME (e.g. FreeBSD)
815 if cc.get_define('ETIME', prefix : '#include <errno.h>') == ''
816 pre_args += '-DETIME=ETIMEDOUT'
819 # Define DEBUG for debug builds only (debugoptimized is not included on this one)
820 if get_option('buildtype') == 'debug'
821 pre_args += '-DDEBUG'
824 with_shader_cache = false
825 _shader_cache = get_option('shader-cache')
826 if _shader_cache != 'false'
827 if host_machine.system() == 'windows'
828 if _shader_cache == 'true'
829 error('Shader Cache does not currently work on Windows')
832 pre_args += '-DENABLE_SHADER_CACHE'
833 with_shader_cache = true
836 if with_amd_vk and not with_shader_cache
837 error('Radv requires shader cache support')
840 # Check for GCC style builtins
841 foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
842 'ffsll', 'popcount', 'popcountll', 'unreachable']
843 if cc.has_function(b)
844 pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
848 # check for GCC __attribute__
849 foreach a : ['const', 'flatten', 'malloc', 'pure', 'unused',
850 'warn_unused_result', 'weak',]
851 if cc.compiles('int foo(void) __attribute__((@0@));'.format(a),
852 name : '__attribute__((@0@))'.format(a))
853 pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
856 if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
857 name : '__attribute__((format(...)))')
858 pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
860 if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
861 name : '__attribute__((packed))')
862 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
864 if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
865 name : '__attribute__((returns_nonnull))')
866 pre_args += '-DHAVE_FUNC_ATTRIBUTE_RETURNS_NONNULL'
868 if cc.compiles('''int foo_def(void) __attribute__((visibility("default")));
869 int foo_hid(void) __attribute__((visibility("hidden")));
870 int foo_int(void) __attribute__((visibility("internal")));
871 int foo_pro(void) __attribute__((visibility("protected")));''',
872 name : '__attribute__((visibility(...)))')
873 pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISIBILITY'
875 if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
876 name : '__attribute__((alias(...)))')
877 pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
879 if cc.compiles('int foo(void) __attribute__((__noreturn__));',
880 name : '__attribute__((__noreturn__))')
881 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NORETURN'
883 if cc.compiles('__uint128_t foo(void) { return 0; }',
884 name : '__uint128_t')
885 pre_args += '-DHAVE_UINT128'
888 # TODO: this is very incomplete
889 if ['linux', 'cygwin', 'gnu', 'freebsd', 'gnu/kfreebsd'].contains(host_machine.system())
890 pre_args += '-D_GNU_SOURCE'
891 elif host_machine.system() == 'sunos'
892 pre_args += '-D__EXTENSIONS__'
893 elif host_machine.system() == 'windows'
895 '-D_WINDOWS', '-D_WIN32_WINNT=0x0601', '-D_WINVER=0x0601',
896 '-DPIPE_SUBSYSTEM_WINDOWS_USER',
897 '-D_USE_MATH_DEFINES', # XXX: scons doesn't use this for mingw
899 if cc.get_id() == 'msvc'
902 '-D_CRT_SECURE_NO_WARNINGS',
903 '-D_CRT_SECURE_NO_DEPRECATE',
904 '-D_SCL_SECURE_NO_WARNINGS',
905 '-D_SCL_SECURE_NO_DEPRECATE',
906 '-D_ALLOW_KEYWORD_MACROS',
907 '-D_HAS_EXCEPTIONS=0', # Tell C++ STL to not use exceptions
910 pre_args += ['-D__MSVCRT_VERSION__=0x0700']
914 # Check for generic C arguments
917 c_msvc_compat_args = []
918 no_override_init_args = []
921 cpp_msvc_compat_args = []
922 if cc.get_id() == 'msvc'
923 foreach a : ['/wd4018', # signed/unsigned mismatch
924 '/wd4056', # overflow in floating-point constant arithmetic
925 '/wd4244', # conversion from 'type1' to 'type2', possible loss of data
926 '/wd4267', # 'var' : conversion from 'size_t' to 'type', possible loss of data
927 '/wd4305', # trancation from 'type1' to 'type2'
928 '/wd4351', # new behavior: elements of array 'array' will be default initialized
929 '/wd4756', # overflow in constant arithmetic
930 '/wd4800', # forcing value to bool 'true' or 'false' (performance warning)
931 '/wd4996', # disabled deprecated POSIX name warnings
932 '/wd4291'] # no matching operator delete found
933 if cc.has_argument(a)
936 if cpp.has_argument(a)
940 if cc.has_argument('-Wmicrosoft-enum-value') # Clang
941 c_args += '-Wno-microsoft-enum-value'
942 cpp_args += '-Wno-microsoft-enum-value'
946 '-Werror=implicit-function-declaration',
947 '-Werror=missing-prototypes',
948 '-Werror=return-type',
949 '-Werror=empty-body',
950 '-Werror=incompatible-pointer-types',
951 '-Werror=int-conversion',
952 '-Wno-missing-field-initializers',
953 '-Wno-format-truncation',
955 '-fno-trapping-math',
956 '-Qunused-arguments',
958 # MinGW chokes on format specifiers and I can't get it all working
959 if not (cc.get_id() == 'gcc' and host_machine.system() == 'windows')
960 _trial += ['-Werror=format', '-Wformat-security']
963 if cc.has_argument(a)
969 '-Werror=return-type',
970 '-Werror=empty-body',
971 '-Wno-non-virtual-dtor',
972 '-Wno-missing-field-initializers',
973 '-Wno-format-truncation',
975 '-fno-trapping-math',
976 '-Qunused-arguments',
978 # MinGW chokes on format specifiers and I can't get it all working
979 if not (cc.get_id() == 'gcc' and host_machine.system() == 'windows')
980 _trial += ['-Werror=format', '-Wformat-security']
983 if cpp.has_argument(a)
988 foreach a : ['-Wno-override-init', '-Wno-initializer-overrides']
989 if cc.has_argument(a)
990 no_override_init_args += a
994 if cc.has_argument('-fvisibility=hidden')
995 c_vis_args += '-fvisibility=hidden'
998 # Check for C and C++ arguments for MSVC compatibility. These are only used
999 # in parts of the mesa code base that need to compile with MSVC, mainly
1001 foreach a : ['-Werror=pointer-arith', '-Werror=vla', '-Werror=gnu-empty-initializer']
1002 if cc.has_argument(a)
1003 c_msvc_compat_args += a
1005 if cpp.has_argument(a)
1006 cpp_msvc_compat_args += a
1010 if cpp.has_argument('-fvisibility=hidden')
1011 cpp_vis_args += '-fvisibility=hidden'
1016 # set linker arguments
1017 if host_machine.system() == 'windows'
1018 if cc.get_id() == 'msvc'
1019 add_project_link_arguments(
1024 language : ['c', 'cpp'],
1027 add_project_link_arguments(
1029 '-Wl,--dynamicbase',
1031 '-static-libstdc++',
1032 language : ['c', 'cpp'],
1037 if host_machine.cpu_family().startswith('x86') and cc.get_id() != 'msvc'
1038 pre_args += '-DUSE_SSE41'
1040 sse41_args = ['-msse4.1']
1042 # GCC on x86 (not x86_64) with -msse* assumes a 16 byte aligned stack, but
1043 # that's not guaranteed
1044 if host_machine.cpu_family() == 'x86'
1045 sse41_args += '-mstackrealign'
1052 # Check for GCC style atomics
1053 dep_atomic = null_dep
1055 if cc.compiles('''#include <stdint.h>
1060 return (int)__atomic_load_n(x.v, __ATOMIC_ACQUIRE) &
1061 (int)__atomic_add_fetch(x.v, (uint64_t)1, __ATOMIC_ACQ_REL);
1064 name : 'GCC atomic builtins')
1065 pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
1067 # Not all atomic calls can be turned into lock-free instructions, in which
1068 # GCC will make calls into the libatomic library. Check whether we need to
1069 # link with -latomic.
1071 # This can happen for 64-bit atomic operations on 32-bit architectures such
1073 if not cc.links('''#include <stdint.h>
1078 return (int)__atomic_load_n(x.v, __ATOMIC_ACQUIRE) &
1079 (int)__atomic_add_fetch(x.v, (uint64_t)1, __ATOMIC_ACQ_REL);
1081 name : 'GCC atomic builtins required -latomic')
1082 dep_atomic = cc.find_library('atomic')
1085 if not cc.links('''#include <stdint.h>
1088 return __sync_add_and_fetch(&v, (uint64_t)1);
1090 dependencies : dep_atomic,
1091 name : 'GCC 64bit atomics')
1092 pre_args += '-DMISSING_64BIT_ATOMICS'
1095 dep_ws2_32 = cc.find_library('ws2_32', required : with_platform_windows)
1097 # TODO: shared/static? Is this even worth doing?
1100 if host_machine.cpu_family() == 'x86'
1101 if system_has_kms_drm or host_machine.system() == 'gnu'
1102 with_asm_arch = 'x86'
1103 pre_args += ['-DUSE_X86_ASM', '-DUSE_MMX_ASM', '-DUSE_3DNOW_ASM',
1106 if with_glx_read_only_text
1107 pre_args += ['-DGLX_X86_READONLY_TEXT']
1110 elif host_machine.cpu_family() == 'x86_64'
1111 if system_has_kms_drm
1112 with_asm_arch = 'x86_64'
1113 pre_args += ['-DUSE_X86_64_ASM']
1115 elif host_machine.cpu_family() == 'arm'
1116 if system_has_kms_drm
1117 with_asm_arch = 'arm'
1118 pre_args += ['-DUSE_ARM_ASM']
1120 elif host_machine.cpu_family() == 'aarch64'
1121 if system_has_kms_drm
1122 with_asm_arch = 'aarch64'
1123 pre_args += ['-DUSE_AARCH64_ASM']
1125 elif host_machine.cpu_family() == 'sparc64'
1126 if system_has_kms_drm
1127 with_asm_arch = 'sparc'
1128 pre_args += ['-DUSE_SPARC_ASM']
1130 elif host_machine.cpu_family().startswith('ppc64') and host_machine.endian() == 'little'
1131 if system_has_kms_drm
1132 with_asm_arch = 'ppc64le'
1133 pre_args += ['-DUSE_PPC64LE_ASM']
1137 # Check for standard headers and functions
1138 if (cc.has_header_symbol('sys/sysmacros.h', 'major') and
1139 cc.has_header_symbol('sys/sysmacros.h', 'minor') and
1140 cc.has_header_symbol('sys/sysmacros.h', 'makedev'))
1141 pre_args += '-DMAJOR_IN_SYSMACROS'
1143 if (cc.has_header_symbol('sys/mkdev.h', 'major') and
1144 cc.has_header_symbol('sys/mkdev.h', 'minor') and
1145 cc.has_header_symbol('sys/mkdev.h', 'makedev'))
1146 pre_args += '-DMAJOR_IN_MKDEV'
1149 foreach h : ['xlocale.h', 'sys/sysctl.h', 'linux/futex.h', 'endian.h', 'dlfcn.h', 'execinfo.h', 'sys/shm.h', 'cet.h']
1150 if cc.compiles('#include <@0@>'.format(h), name : '@0@'.format(h))
1151 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
1155 foreach f : ['strtof', 'mkostemp', 'timespec_get', 'memfd_create', 'random_r', 'flock', 'strtok_r']
1156 if cc.has_function(f)
1157 pre_args += '-DHAVE_@0@'.format(f.to_upper())
1161 if cc.has_header_symbol('errno.h', 'program_invocation_name',
1162 args : '-D_GNU_SOURCE')
1163 pre_args += '-DHAVE_PROGRAM_INVOCATION_NAME'
1164 elif with_tools.contains('intel')
1165 error('Intel tools require the program_invocation_name variable')
1168 # MinGW provides a __builtin_posix_memalign function, but not a posix_memalign.
1169 # This means that this check will succeed, but then compilation will later
1170 # fail. MSVC doesn't have this function at all, so only check for it on
1171 # non-windows platforms.
1172 if host_machine.system() != 'windows'
1173 if cc.has_function('posix_memalign')
1174 pre_args += '-DHAVE_POSIX_MEMALIGN'
1178 if cc.has_member('struct dirent', 'd_type', prefix: '''#include <sys/types.h>
1179 #include <dirent.h>''')
1180 pre_args += '-DHAVE_DIRENT_D_TYPE'
1183 # strtod locale support
1188 #ifdef HAVE_XLOCALE_H
1189 #include <xlocale.h>
1192 locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
1193 const char *s = "1.0";
1195 double d = strtod_l(s, end, loc);
1196 float f = strtof_l(s, end, loc);
1201 name : 'strtod has locale support')
1202 pre_args += '-DHAVE_STRTOD_L'
1205 # Check for some linker flags
1206 ld_args_bsymbolic = []
1207 if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic', name : 'Bsymbolic')
1208 ld_args_bsymbolic += '-Wl,-Bsymbolic'
1210 ld_args_gc_sections = []
1211 if cc.links('static char unused() { return 5; } int main() { return 0; }',
1212 args : '-Wl,--gc-sections', name : 'gc-sections')
1213 ld_args_gc_sections += '-Wl,--gc-sections'
1215 with_ld_version_script = false
1216 if cc.links('int main() { return 0; }',
1217 args : '-Wl,--version-script=@0@'.format(
1218 join_paths(meson.source_root(), 'build-support/conftest.map')),
1219 name : 'version-script')
1220 with_ld_version_script = true
1222 with_ld_dynamic_list = false
1223 if cc.links('int main() { return 0; }',
1224 args : '-Wl,--dynamic-list=@0@'.format(
1225 join_paths(meson.source_root(), 'build-support/conftest.dyn')),
1226 name : 'dynamic-list')
1227 with_ld_dynamic_list = true
1230 ld_args_build_id = cc.get_supported_link_arguments('-Wl,--build-id=sha1')
1232 # check for dl support
1234 if not cc.has_function('dlopen')
1235 dep_dl = cc.find_library('dl', required : host_machine.system() != 'windows')
1237 if cc.has_function('dladdr', dependencies : dep_dl)
1238 # This is really only required for megadrivers
1239 pre_args += '-DHAVE_DLADDR'
1242 if cc.has_function('dl_iterate_phdr')
1243 pre_args += '-DHAVE_DL_ITERATE_PHDR'
1245 error('Intel "Anvil" Vulkan driver requires the dl_iterate_phdr function')
1246 elif with_dri_i965 and with_shader_cache
1247 error('Intel i965 GL driver requires dl_iterate_phdr when built with shader caching.')
1250 # Determine whether or not the rt library is needed for time functions
1251 if host_machine.system() == 'windows' or cc.has_function('clock_gettime')
1252 dep_clock = null_dep
1254 dep_clock = cc.find_library('rt')
1257 # TODO: some of these may be conditional
1258 dep_zlib = dependency('zlib', version : '>= 1.2.3', fallback : ['zlib', 'zlib_dep'])
1259 pre_args += '-DHAVE_ZLIB'
1261 _zstd = get_option('zstd')
1263 dep_zstd = dependency('libzstd', required : _zstd == 'true')
1265 pre_args += '-DHAVE_ZSTD'
1271 dep_thread = dependency('threads')
1272 if dep_thread.found() and host_machine.system() != 'windows'
1273 pre_args += '-DHAVE_PTHREAD'
1275 'pthread_setaffinity_np',
1276 dependencies : dep_thread,
1277 prefix : '#include <pthread.h>',
1278 args : '-D_GNU_SOURCE')
1279 pre_args += '-DHAVE_PTHREAD_SETAFFINITY'
1282 'pthread_setaffinity_np',
1283 dependencies : dep_thread,
1284 prefix : '#include <pthread_np.h>')
1285 pre_args += '-DPTHREAD_SETAFFINITY_IN_NP_HEADER'
1288 if host_machine.system() != 'windows'
1289 dep_expat = dependency('expat', fallback : ['expat', 'expat_dep'])
1291 dep_expat = null_dep
1293 # this only exists on linux so either this is linux and it will be found, or
1294 # it's not linux and wont
1295 dep_m = cc.find_library('m', required : false)
1297 # Check for libdrm. Various drivers have different libdrm version requirements,
1298 # but we always want to use the same version for all libdrm modules. That means
1299 # even if driver foo requires 2.4.0 and driver bar requires 2.4.3, if foo and
1300 # bar are both on use 2.4.3 for both of them
1301 dep_libdrm_amdgpu = null_dep
1302 dep_libdrm_radeon = null_dep
1303 dep_libdrm_nouveau = null_dep
1304 dep_libdrm_intel = null_dep
1306 _drm_amdgpu_ver = '2.4.100'
1307 _drm_radeon_ver = '2.4.71'
1308 _drm_nouveau_ver = '2.4.66'
1309 _drm_intel_ver = '2.4.75'
1313 ['intel', with_dri_i915 or with_gallium_i915],
1314 ['amdgpu', with_amd_vk or with_gallium_radeonsi],
1315 ['radeon', (with_gallium_radeonsi or with_dri_r100 or with_dri_r200 or
1316 with_gallium_r300 or with_gallium_r600)],
1317 ['nouveau', (with_gallium_nouveau or with_dri_nouveau)],
1320 # VC4 only needs core libdrm support of this version, not a libdrm_vc4
1326 # etnaviv only needs core libdrm
1327 if with_gallium_etnaviv
1331 # Loop over the enables versions and get the highest libdrm requirement for all
1334 foreach d : _libdrm_checks
1335 ver = get_variable('_drm_@0@_ver'.format(d[0]))
1336 if d[1] and ver.version_compare('>' + _drm_ver)
1342 message('libdrm @0@ needed because @1@ has the highest requirement'.format(_drm_ver, _drm_blame))
1345 # Then get each libdrm module
1346 foreach d : _libdrm_checks
1349 'dep_libdrm_' + d[0],
1350 dependency('libdrm_' + d[0], version : '>=' + _drm_ver)
1355 with_gallium_drisw_kms = false
1356 dep_libdrm = dependency(
1357 'libdrm', version : '>=' + _drm_ver,
1358 # GNU/Hurd includes egl_dri2, without drm.
1359 required : (with_dri2 and host_machine.system() != 'gnu') or with_dri3
1361 if dep_libdrm.found()
1362 pre_args += '-DHAVE_LIBDRM'
1363 if with_dri_platform == 'drm' and with_dri
1364 with_gallium_drisw_kms = true
1368 llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit', 'core', 'executionengine', 'scalaropts', 'transformutils', 'instcombine']
1369 llvm_optional_modules = ['coroutines']
1370 if with_amd_vk or with_gallium_radeonsi or with_gallium_r600
1371 llvm_modules += ['amdgpu', 'native', 'bitreader', 'ipo']
1372 if with_gallium_r600
1373 llvm_modules += 'asmparser'
1376 if with_gallium_opencl
1378 'all-targets', 'linker', 'coverage', 'instrumentation', 'ipo', 'irreader',
1379 'lto', 'option', 'objcarcopts', 'profiledata',
1383 if with_amd_vk or with_gallium_radeonsi
1384 _llvm_version = '>= 8.0.0'
1385 elif with_gallium_swr
1386 _llvm_version = '>= 6.0.0'
1388 _llvm_version = '>= 3.9.0'
1391 _shared_llvm = get_option('shared-llvm')
1392 _llvm = get_option('llvm')
1394 # The cmake method will never find libllvm.so|dylib; this is fine for windows
1395 # because llvm doesn't support libllvm.dll
1396 _llvm_method = 'config-tool'
1397 if (meson.version().version_compare('>= 0.51.0') and
1398 host_machine.system() == 'windows')
1399 _llvm_method = 'cmake'
1405 dep_llvm = dependency(
1407 version : _llvm_version,
1408 modules : llvm_modules,
1409 optional_modules : llvm_optional_modules,
1411 with_amd_vk or with_gallium_radeonsi or with_gallium_swr or
1412 with_gallium_opencl or _llvm == 'true'
1414 static : not _shared_llvm,
1415 method : _llvm_method,
1416 fallback : ['llvm', 'dep_llvm'],
1418 with_llvm = dep_llvm.found()
1421 pre_args += '-DLLVM_AVAILABLE'
1422 pre_args += '-DMESA_LLVM_VERSION_STRING="@0@"'.format(dep_llvm.version())
1424 # LLVM can be built without rtti, turning off rtti changes the ABI of C++
1425 # programs, so we need to build all C++ code in mesa without rtti as well to
1426 # ensure that linking works.
1428 # In meson 0.51.0 we can use cmake to find LLVM in addittion to meson's
1429 # builtin llvm-config based finder. A new generic variable getter method
1430 # has also been added, so we'll use that if we can, to cover the cmake case.
1431 if dep_llvm.type_name() == 'internal'
1432 _rtti = subproject('llvm').get_variable('has_rtti', true)
1433 elif meson.version().version_compare('>=0.51')
1434 # The CMake finder will return 'ON', the llvm-config will return 'YES'
1435 _rtti = ['ON', 'YES'].contains(dep_llvm.get_variable(cmake : 'LLVM_ENABLE_RTTI', configtool: 'has-rtti'))
1437 _rtti = dep_llvm.get_configtool_variable('has-rtti') == 'YES'
1440 if with_gallium_nouveau
1441 error('The Nouveau driver requires rtti. You either need to turn off nouveau or use an LLVM built with LLVM_ENABLE_RTTI.')
1442 elif with_gallium_opencl
1443 error('The Clover OpenCL state tracker requires rtti, you need to turn off clover or use an LLVM built with LLVM_ENABLE_RTTI.')
1445 if cc.get_id() == 'msvc'
1448 cpp_args += '-fno-rtti'
1451 elif with_amd_vk or with_gallium_radeonsi or with_gallium_swr
1452 error('The following drivers require LLVM: Radv, RadeonSI, SWR. One of these is enabled, but LLVM is disabled.')
1453 elif with_gallium_opencl
1454 error('The OpenCL "Clover" state tracker requires LLVM, but LLVM is disabled.')
1457 if (with_amd_vk or with_gallium_radeonsi or with_gallium_opencl or
1458 (with_gallium_r600 and with_llvm))
1459 dep_elf = dependency('libelf', required : false)
1460 if not dep_elf.found()
1461 dep_elf = cc.find_library('elf')
1467 dep_glvnd = null_dep
1469 dep_glvnd = dependency('libglvnd', version : '>= 1.2.0')
1470 pre_args += '-DUSE_LIBGLVND=1'
1473 if with_valgrind != 'false'
1474 dep_valgrind = dependency('valgrind', required : with_valgrind == 'true')
1475 if dep_valgrind.found()
1476 pre_args += '-DHAVE_VALGRIND'
1479 dep_valgrind = null_dep
1482 # pthread stubs. Lets not and say we didn't
1484 if host_machine.system() == 'windows'
1485 # Prefer the winflexbison versions, they're much easier to install and have
1486 # better windows support.
1488 prog_flex = find_program('win_flex', required : false)
1489 if prog_flex.found()
1490 # windows compatibility (uses <io.h> instead of <unistd.h> and _isatty,
1491 # _fileno functions)
1492 prog_flex = [prog_flex, '--wincompat']
1494 prog_flex = [find_program('lex', 'flex', required : with_any_opengl)]
1496 # Force flex to use const keyword in prototypes, as relies on __cplusplus or
1497 # __STDC__ macro to determine whether it's safe to use const keyword, but
1498 # MSVC never defines __STDC__ unless we disable all MSVC extensions.
1499 prog_flex += '-DYY_USE_CONST='
1501 prog_bison = find_program('win_bison', required : false)
1502 if not prog_bison.found()
1503 prog_bison = find_program('yacc', 'bison', required : with_any_opengl)
1506 prog_bison = find_program('bison', required : with_any_opengl)
1507 prog_flex = find_program('flex', required : with_any_opengl)
1510 dep_selinux = null_dep
1511 if get_option('selinux')
1512 dep_selinux = dependency('libselinux')
1513 pre_args += '-DMESA_SELINUX'
1516 if with_libunwind != 'false'
1517 dep_unwind = dependency('libunwind', required : with_libunwind == 'true')
1518 if dep_unwind.found()
1519 pre_args += '-DHAVE_LIBUNWIND'
1522 dep_unwind = null_dep
1525 if with_osmesa != 'none'
1526 if with_osmesa == 'gallium' and not with_gallium_softpipe
1527 error('OSMesa gallium requires gallium softpipe or llvmpipe.')
1529 if host_machine.system() == 'windows'
1530 osmesa_lib_name = 'osmesa'
1532 osmesa_lib_name = 'OSMesa'
1534 osmesa_bits = get_option('osmesa-bits')
1535 if osmesa_bits != '8'
1536 if with_dri or with_glx != 'disabled'
1537 error('OSMesa bits must be 8 if building glx or dir based drivers')
1539 osmesa_lib_name = osmesa_lib_name + osmesa_bits
1541 '-DCHAN_BITS=@0@'.format(osmesa_bits), '-DDEFAULT_SOFTWARE_DEPTH_BITS=31'
1546 # TODO: symbol mangling
1548 if with_platform_wayland
1549 dep_wl_scanner = dependency('wayland-scanner', native: true)
1550 prog_wl_scanner = find_program(dep_wl_scanner.get_pkgconfig_variable('wayland_scanner'))
1551 if dep_wl_scanner.version().version_compare('>= 1.15')
1552 wl_scanner_arg = 'private-code'
1554 wl_scanner_arg = 'code'
1556 dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8')
1557 dep_wayland_client = dependency('wayland-client', version : '>=1.11')
1558 dep_wayland_server = dependency('wayland-server', version : '>=1.11')
1560 dep_wayland_egl = dependency('wayland-egl-backend', version : '>= 3')
1561 dep_wayland_egl_headers = declare_dependency(
1562 compile_args : run_command(prog_pkgconfig, ['wayland-egl-backend', '--cflags']).stdout().split())
1564 wayland_dmabuf_xml = join_paths(
1565 dep_wl_protocols.get_pkgconfig_variable('pkgdatadir'), 'unstable',
1566 'linux-dmabuf', 'linux-dmabuf-unstable-v1.xml'
1568 pre_args += ['-DHAVE_WAYLAND_PLATFORM', '-DWL_HIDE_DEPRECATED']
1573 dep_xdamage = null_dep
1574 dep_xfixes = null_dep
1575 dep_x11_xcb = null_dep
1577 dep_xcb_glx = null_dep
1578 dep_xcb_dri2 = null_dep
1579 dep_xcb_dri3 = null_dep
1580 dep_dri2proto = null_dep
1581 dep_glproto = null_dep
1582 dep_xxf86vm = null_dep
1583 dep_xcb_dri3 = null_dep
1584 dep_xcb_present = null_dep
1585 dep_xcb_sync = null_dep
1586 dep_xcb_xfixes = null_dep
1587 dep_xshmfence = null_dep
1588 dep_xcb_xrandr = null_dep
1589 dep_xlib_xrandr = null_dep
1590 if with_platform_x11
1591 if with_glx == 'xlib' or with_glx == 'gallium-xlib'
1592 dep_x11 = dependency('x11')
1593 dep_xext = dependency('xext')
1594 dep_xcb = dependency('xcb')
1595 elif with_glx == 'dri'
1596 dep_x11 = dependency('x11')
1597 dep_xext = dependency('xext')
1598 dep_xdamage = dependency('xdamage', version : '>= 1.1')
1599 dep_xfixes = dependency('xfixes')
1600 dep_xcb_glx = dependency('xcb-glx', version : '>= 1.8.1')
1602 if (with_any_vk or with_glx == 'dri' or with_egl or
1603 (with_gallium_vdpau or with_gallium_xvmc or with_gallium_va or
1604 with_gallium_omx != 'disabled'))
1605 dep_xcb = dependency('xcb')
1606 dep_x11_xcb = dependency('x11-xcb')
1607 if with_dri_platform == 'drm' and not dep_libdrm.found()
1608 error('libdrm required for gallium video statetrackers when using x11')
1611 if with_any_vk or with_egl or (with_glx == 'dri' and with_dri_platform == 'drm')
1612 dep_xcb_dri2 = dependency('xcb-dri2', version : '>= 1.8')
1615 pre_args += '-DHAVE_DRI3'
1616 dep_xcb_dri3 = dependency('xcb-dri3')
1617 dep_xcb_present = dependency('xcb-present')
1618 # until xcb-dri3 has been around long enough to make a hard-dependency:
1619 if (dep_xcb_dri3.version().version_compare('>= 1.13') and
1620 dep_xcb_present.version().version_compare('>= 1.13'))
1621 pre_args += '-DHAVE_DRI3_MODIFIERS'
1623 dep_xcb_sync = dependency('xcb-sync')
1624 dep_xshmfence = dependency('xshmfence', version : '>= 1.1')
1627 if with_glx == 'dri' or with_glx == 'gallium-xlib'
1628 dep_glproto = dependency('glproto', version : '>= 1.4.14')
1630 if with_glx == 'dri'
1631 if with_dri_platform == 'drm'
1632 dep_dri2proto = dependency('dri2proto', version : '>= 2.8')
1633 dep_xxf86vm = dependency('xxf86vm')
1637 with_gallium_vdpau or with_gallium_xvmc or with_gallium_xa or
1638 with_gallium_omx != 'disabled'))
1639 dep_xcb_xfixes = dependency('xcb-xfixes')
1642 dep_xcb_xrandr = dependency('xcb-randr')
1643 dep_xlib_xrandr = dependency('xrandr', version : '>= 1.3')
1647 if get_option('gallium-extra-hud')
1648 pre_args += '-DHAVE_GALLIUM_EXTRA_HUD=1'
1651 _sensors = get_option('lmsensors')
1652 if _sensors != 'false'
1653 dep_lmsensors = cc.find_library('sensors', required : _sensors == 'true')
1654 if dep_lmsensors.found()
1655 pre_args += '-DHAVE_LIBSENSORS=1'
1658 dep_lmsensors = null_dep
1661 foreach a : pre_args
1662 add_project_arguments(a, language : ['c', 'cpp'])
1665 add_project_arguments(a, language : ['c'])
1667 foreach a : cpp_args
1668 add_project_arguments(a, language : ['cpp'])
1673 if with_glx == 'xlib' or with_glx == 'gallium-xlib'
1674 gl_priv_reqs += ['x11', 'xext', 'xcb']
1675 elif with_glx == 'dri'
1677 'x11', 'xext', 'xdamage >= 1.1', 'xfixes', 'x11-xcb', 'xcb',
1679 if with_dri_platform == 'drm'
1680 gl_priv_reqs += 'xcb-dri2 >= 1.8'
1681 gl_priv_reqs += 'xxf86vm'
1684 if dep_libdrm.found()
1685 gl_priv_reqs += 'libdrm >= 2.4.75'
1689 if dep_thread.found()
1690 gl_priv_libs += ['-lpthread', '-pthread']
1693 gl_priv_libs += '-lm'
1696 gl_priv_libs += '-ldl'
1699 pkg = import('pkgconfig')
1701 if host_machine.system() == 'windows'
1702 prog_dumpbin = find_program('dumpbin', required : false)
1703 with_symbols_check = prog_dumpbin.found() and with_tests
1704 symbols_check_args = ['--dumpbin', prog_dumpbin.path()]
1706 prog_nm = find_program('nm')
1707 with_symbols_check = with_tests
1708 symbols_check_args = ['--nm', prog_nm.path()]
1711 # This quirk needs to be applied to sources with functions defined in assembly
1712 # as GCC LTO drops them. See: https://bugs.freedesktop.org/show_bug.cgi?id=109391
1713 gcc_lto_quirk = (cc.get_id() == 'gcc') ? ['-fno-lto'] : []
1719 # Meson 0.49 and earlier seems to have a bug that fails to evaluate the string-
1720 # formatting below unless the first argument is passed as a variable. This has
1721 # been fixed in Meson 0.50 and beyond, but we need to keep it like this for now
1722 # for backwards compatibility.
1723 _with_opengl_string = with_opengl ? 'yes' : 'no'
1726 'prefix: ' + get_option('prefix'),
1727 'libdir: ' + get_option('libdir'),
1728 'includedir: ' + get_option('includedir'),
1730 'OpenGL: @0@ (ES1: @1@ ES2: @2@)'.format(_with_opengl_string,
1731 with_gles1 ? 'yes' : 'no',
1732 with_gles2 ? 'yes' : 'no'),
1735 if with_osmesa != 'none'
1738 if with_osmesa == 'gallium'
1739 suffix = '(Gallium)'
1741 lines += 'OSMesa: lib' + osmesa_lib_name + suffix
1743 lines += 'OSMesa: no'
1748 lines += 'DRI platform: ' + with_dri_platform
1749 if dri_drivers.length() != 0 and dri_drivers != ['']
1750 lines += 'DRI drivers: ' + ' '.join(dri_drivers)
1752 lines += 'DRI drivers: no'
1754 lines += 'DRI driver dir: ' + dri_drivers_path
1757 if with_glx != 'disabled'
1759 if with_glx == 'dri'
1760 lines += 'GLX: DRI-based'
1761 elif with_glx == 'xlib'
1762 lines += 'GLX: Xlib-based'
1763 elif with_glx == 'gallium-xlib'
1764 lines += 'GLX: Xlib-based (Gallium)'
1766 lines += 'GLX: ' + with_glx
1771 lines += 'EGL: ' + (with_egl ? 'yes' : 'no')
1775 egl_drivers += 'builtin:egl_dri2'
1778 egl_drivers += 'builtin:egl_dri3'
1780 lines += 'EGL drivers: ' + ' '.join(egl_drivers)
1782 lines += 'GBM: ' + (with_gbm ? 'yes' : 'no')
1784 lines += 'EGL/Vulkan/VL platforms: ' + ' '.join(_platforms)
1789 lines += 'Vulkan drivers: ' + ' '.join(_vulkan_drivers)
1790 lines += 'Vulkan ICD dir: ' + with_vulkan_icd_dir
1792 lines += 'Vulkan drivers: no'
1797 lines += 'llvm: yes'
1798 lines += 'llvm-version: ' + dep_llvm.version()
1805 lines += 'Gallium drivers: ' + ' '.join(gallium_drivers)
1806 gallium_st = ['mesa']
1810 if with_gallium_xvmc
1811 gallium_st += 'xvmc'
1813 if with_gallium_xvmc
1814 gallium_st += 'xvmc'
1816 if with_gallium_vdpau
1817 gallium_st += 'vdpau'
1819 if with_gallium_omx != 'disabled'
1820 gallium_st += 'omx' + with_gallium_omx
1825 if with_gallium_st_nine
1826 gallium_st += 'nine'
1828 if with_gallium_opencl
1829 gallium_st += 'clover'
1831 lines += 'Gallium st: ' + ' '.join(gallium_st)
1833 lines += 'Gallium: no'
1836 lines += 'HUD lmsensors: ' + (dep_lmsensors.found() ? 'yes' : 'no')
1839 lines += 'Shared-glapi: ' + (with_shared_glapi ? 'yes' : 'no')
1843 summary = indent + ('\n' + indent).join(lines)
1844 message('Configuration summary:\n@0@\n'.format(summary))