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