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