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