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