Dylan Baker | d199225 | 2017-09-14 17:57:17 -0700 | [diff] [blame] | 1 | # Copyright © 2017 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 | |
| 21 | project('mesa', ['c', 'cpp'], version : '17.3.0-devel', license : 'MIT', |
| 22 | default_options : ['c_std=c99']) |
| 23 | |
| 24 | with_dri3 = true # XXX: need a switch for this |
Dylan Baker | e915b8d | 2017-09-28 14:02:51 -0700 | [diff] [blame^] | 25 | with_vulkan_icd_dir = get_option('vulkan-icd-dir') |
Dylan Baker | d199225 | 2017-09-14 17:57:17 -0700 | [diff] [blame] | 26 | with_tests = get_option('build-tests') |
| 27 | with_valgrind = get_option('valgrind') |
| 28 | |
| 29 | # TODO: there are more platforms required for non-vulkan drivers |
| 30 | with_platform_wayland = false |
| 31 | with_platform_x11 = false |
| 32 | _platforms = get_option('platforms') |
| 33 | if _platforms != '' |
| 34 | _split = _platforms.split(',') |
| 35 | with_platform_x11 = _split.contains('x11') |
| 36 | with_platform_wayland = _split.contains('wayland') |
| 37 | endif |
| 38 | |
| 39 | if with_vulkan_icd_dir == '' |
| 40 | with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d') |
| 41 | endif |
| 42 | |
| 43 | with_intel_vk = false |
| 44 | with_amd_vk = false |
| 45 | _vulkan_drivers = get_option('vulkan-drivers') |
| 46 | if _vulkan_drivers != '' |
| 47 | _split = _vulkan_drivers.split(',') |
| 48 | with_intel_vk = _split.contains('intel') |
| 49 | with_amd_vk = _split.contains('amd') |
| 50 | if not (with_platform_x11 or with_platform_wayland) |
| 51 | error('Vulkan requires at least one platform (x11, wayland)') |
| 52 | endif |
| 53 | endif |
| 54 | |
| 55 | prog_python2 = find_program('python2') |
Dylan Baker | 9342a7d | 2017-09-28 10:48:30 -0700 | [diff] [blame] | 56 | has_mako = run_command(prog_python2, '-c', 'import mako') |
| 57 | if has_mako.returncode() != 0 |
| 58 | error('Python (2.x) mako module required to build mesa.') |
| 59 | endif |
Dylan Baker | d199225 | 2017-09-14 17:57:17 -0700 | [diff] [blame] | 60 | |
| 61 | cc = meson.get_compiler('c') |
| 62 | if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6') |
Eric Engestrom | 1262e82 | 2017-09-29 15:25:18 +0100 | [diff] [blame] | 63 | error('When using GCC, version 4.4.6 or later is required.') |
Dylan Baker | d199225 | 2017-09-14 17:57:17 -0700 | [diff] [blame] | 64 | endif |
| 65 | |
| 66 | # Arguments for the preprocessor, put these in a separate array from the C and |
| 67 | # C++ (cpp in meson terminology) arguments since they need to be added to the |
| 68 | # default arguments for both C and C++. |
| 69 | pre_args = ['-D__STDC_CONSTANT_MACROS', '-D__STDC_FORMAT_MACROS', |
| 70 | '-D__STDC_LIMIT_MACROS', |
| 71 | '-DVERSION="@0@"'.format(meson.project_version())] |
| 72 | |
| 73 | # Define DEBUG for debug and debugoptimized builds |
| 74 | if get_option('buildtype').startswith('debug') |
| 75 | pre_args += '-DDEBUG' |
| 76 | endif |
| 77 | |
Dylan Baker | 673dda8 | 2017-09-20 11:53:29 -0700 | [diff] [blame] | 78 | if get_option('shader-cache') |
| 79 | pre_args += '-DENABLE_SHADER_CACHE' |
| 80 | elif with_amd_vk |
| 81 | error('Radv requires shader cache support') |
| 82 | endif |
| 83 | |
Dylan Baker | d199225 | 2017-09-14 17:57:17 -0700 | [diff] [blame] | 84 | # Check for GCC style builtins |
| 85 | foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs', |
| 86 | 'ffsll', 'popcount', 'popcountll', 'unreachable'] |
| 87 | if cc.has_function(b) |
| 88 | pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper()) |
| 89 | endif |
| 90 | endforeach |
| 91 | |
Dylan Baker | 673dda8 | 2017-09-20 11:53:29 -0700 | [diff] [blame] | 92 | # check for GCC __attribute__ |
Dylan Baker | d199225 | 2017-09-14 17:57:17 -0700 | [diff] [blame] | 93 | foreach a : ['const', 'flatten', 'malloc', 'pure', 'unused', |
| 94 | 'warn_unused_result', 'weak',] |
| 95 | if cc.compiles('int foo(void) __attribute__((@0@));'.format(a), |
| 96 | name : '__attribute__((@0@))'.format(a)) |
| 97 | pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper()) |
| 98 | endif |
| 99 | endforeach |
| 100 | if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));', |
| 101 | name : '__attribute__((format(...)))') |
| 102 | pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT' |
| 103 | endif |
| 104 | if cc.compiles('struct __attribute__((packed)) foo { int bar; };', |
| 105 | name : '__attribute__((packed))') |
| 106 | pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED' |
| 107 | endif |
| 108 | if cc.compiles('int *foo(void) __attribute__((returns_nonnull));', |
| 109 | name : '__attribute__((returns_nonnull))') |
| 110 | pre_args += '-DHAVE_FUNC_ATTRIBUTE_NONNULL' |
| 111 | endif |
| 112 | if cc.compiles('''int foo_def(void) __attribute__((visibility("default"))); |
| 113 | int foo_hid(void) __attribute__((visibility("hidden"))); |
| 114 | int foo_int(void) __attribute__((visibility("internal"))); |
| 115 | int foo_pro(void) __attribute__((visibility("protected")));''', |
| 116 | name : '__attribute__((visibility(...)))') |
| 117 | pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISBILITY' |
| 118 | endif |
| 119 | if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));', |
| 120 | name : '__attribute__((alias(...)))') |
| 121 | pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS' |
| 122 | endif |
| 123 | |
| 124 | # TODO: this is very incomplete |
| 125 | if host_machine.system() == 'linux' |
| 126 | pre_args += '-D_GNU_SOURCE' |
| 127 | endif |
| 128 | |
| 129 | # Check for generic C arguments |
| 130 | c_args = [] |
| 131 | foreach a : ['-Wall', '-Werror=implicit-function-declaration', |
| 132 | '-Werror=missing-prototypes', '-fno-math-errno', |
| 133 | '-fno-trapping-math', '-Qunused-arguments'] |
| 134 | if cc.has_argument(a) |
| 135 | c_args += a |
| 136 | endif |
| 137 | endforeach |
| 138 | c_vis_args = [] |
| 139 | if cc.has_argument('-fvisibility=hidden') |
| 140 | c_vis_args += '-fvisibility=hidden' |
| 141 | endif |
| 142 | |
| 143 | # Check for generic C++ arguments |
| 144 | cpp = meson.get_compiler('cpp') |
| 145 | cpp_args = [] |
| 146 | foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math', |
| 147 | '-Qunused-arguments', '-Wno-non-virtual-dtor'] |
| 148 | if cpp.has_argument(a) |
| 149 | cpp_args += a |
| 150 | endif |
| 151 | endforeach |
| 152 | cpp_vis_args = [] |
| 153 | if cpp.has_argument('-fvisibility=hidden') |
| 154 | cpp_vis_args += '-fvisibility=hidden' |
| 155 | endif |
| 156 | |
| 157 | # Check for C and C++ arguments for MSVC2013 compatibility. These are only used |
| 158 | # in parts of the mesa code base that need to compile with old versions of |
| 159 | # MSVC, mainly common code |
| 160 | c_msvc_compat_args = [] |
| 161 | cpp_msvc_compat_args = [] |
| 162 | foreach a : ['-Werror=pointer-arith', '-Werror=vla'] |
| 163 | if cc.has_argument(a) |
| 164 | c_msvc_compat_args += a |
| 165 | endif |
| 166 | if cpp.has_argument(a) |
| 167 | cpp_msvc_compat_args += a |
| 168 | endif |
| 169 | endforeach |
| 170 | |
| 171 | no_override_init_args = [] |
| 172 | foreach a : ['-Wno-override-init', '-Wno-initializer-overrides'] |
| 173 | if cc.has_argument(a) |
| 174 | no_override_init_args += a |
| 175 | endif |
| 176 | endforeach |
| 177 | |
| 178 | # TODO: SSE41 (which is only required for core mesa) |
| 179 | |
| 180 | # Check for GCC style atomics |
| 181 | if cc.compiles('int main() { int n; return __atomic_load_n(&n, __ATOMIC_ACQUIRE); }', |
| 182 | name : 'GCC atomic builtins') |
| 183 | pre_args += '-DUSE_GCC_ATOMIC_BUILTINS' |
| 184 | endif |
| 185 | if not cc.links('''#include <stdint.h> |
| 186 | uint64_t v; |
| 187 | int main() { |
| 188 | return __sync_add_and_fetch(&v, (uint64_t)1); |
| 189 | }''', |
| 190 | name : 'GCC 64bit atomics') |
| 191 | pre_args += '-DMISSING_64_BIT_ATOMICS' |
| 192 | endif |
| 193 | |
| 194 | # TODO: endian |
| 195 | # TODO: powr8 |
| 196 | # TODO: shared/static? Is this even worth doing? |
| 197 | |
| 198 | # I don't think that I need to set any of the debug stuff, I think meson |
| 199 | # handles that for us |
| 200 | |
| 201 | # TODO: ldflags |
| 202 | |
| 203 | # TODO: texture-float (gallium/mesa only) |
| 204 | |
| 205 | # TODO: cross-compiling. I don't think this is relavent to meson |
| 206 | |
| 207 | # TODO: assembly support. mesa and vc4 |
| 208 | |
| 209 | # Check for standard headers and functions |
| 210 | if cc.has_header_symbol('sys/sysmacros.h', 'major') |
| 211 | pre_args += '-DMAJOR_IN_SYSMACROS' |
| 212 | elif cc.has_header_symbol('sys/mkdev.h', 'major') |
| 213 | pre_args += '-DMAJOR_IN_MKDEV' |
| 214 | endif |
| 215 | |
| 216 | foreach h : ['xlocale.h', 'sys/sysctl.h'] |
| 217 | if cc.has_header(h) |
| 218 | pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify()) |
| 219 | endif |
| 220 | endforeach |
| 221 | |
| 222 | foreach f : ['strtof', 'mkostemp', 'posix_memalign'] |
| 223 | if cc.has_function(f) |
| 224 | pre_args += '-DHAVE_@0@'.format(f.to_upper()) |
| 225 | endif |
| 226 | endforeach |
| 227 | |
| 228 | # strtod locale support |
| 229 | if cc.links(''' |
| 230 | #define _GNU_SOURCE |
| 231 | #include <stdlib.h> |
| 232 | #include <locale.h> |
| 233 | #ifdef HAVE_XLOCALE_H |
| 234 | #include <xlocale.h> |
| 235 | #endif |
| 236 | int main() { |
| 237 | locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL); |
| 238 | const char *s = "1.0"; |
| 239 | char *end; |
| 240 | double d = strtod_l(s, end, loc); |
| 241 | float f = strtod_l(s, end, loc); |
| 242 | freelocale(loc); |
| 243 | return 0; |
| 244 | }''', |
| 245 | extra_args : pre_args, |
| 246 | name : 'strtod has locale support') |
| 247 | pre_args += '-DHAVE_STRTOD_L' |
| 248 | endif |
| 249 | |
| 250 | # Check for some linker flags |
| 251 | ld_args_bsymbolic = [] |
| 252 | if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic') |
| 253 | ld_args_bsymbolic += '-Wl,-Bsymbolic' |
| 254 | endif |
| 255 | ld_args_gc_sections = [] |
| 256 | if cc.links('static char unused() { return 5; } int main() { return 0; }', |
| 257 | args : '-Wl,--gc-sections') |
| 258 | ld_args_gc_sections += '-Wl,--gc-sections' |
| 259 | endif |
| 260 | |
| 261 | # check for dl support |
| 262 | if cc.has_function('dlopen') |
| 263 | dep_dl = [] |
| 264 | else |
| 265 | dep_dl = cc.find_library('dl') |
| 266 | endif |
| 267 | pre_args += '-DHAVE_DLOPEN' |
| 268 | |
| 269 | if not cc.has_function('dladdr', dependencies : dep_dl) |
| 270 | error('dl library doesn\'t have dladdr') |
| 271 | endif |
| 272 | |
| 273 | if cc.has_function('dl_iterate_phdr') |
| 274 | pre_args += '-DHAVE_DL_ITERATE_PHDR' |
| 275 | else |
| 276 | # TODO: this is required for vulkan |
| 277 | endif |
| 278 | |
| 279 | # Determine whether or not the rt library is needed for time functions |
| 280 | if cc.has_function('clock_gettime') |
| 281 | dep_clock = [] |
| 282 | else |
| 283 | dep_clock = cc.find_library('rt') |
| 284 | endif |
| 285 | |
| 286 | # TODO: some of these may be conditional |
| 287 | dep_zlib = dependency('zlib', version : '>= 1.2.3') |
| 288 | dep_thread = dependency('threads') |
| 289 | pre_args += '-DHAVE_PTHREAD' |
| 290 | dep_elf = dependency('libelf') |
| 291 | dep_expat = dependency('expat') |
| 292 | # this only exists on linux so either this is linux and it will be found, or |
| 293 | # its not linux and and wont |
| 294 | dep_m = cc.find_library('m', required : false) |
| 295 | |
| 296 | # TODO: conditionalize libdrm requirement |
| 297 | dep_libdrm = dependency('libdrm', version : '>= 2.4.75') |
| 298 | pre_args += '-DHAVE_LIBDRM' |
Dylan Baker | 673dda8 | 2017-09-20 11:53:29 -0700 | [diff] [blame] | 299 | dep_libdrm_amdgpu = [] |
| 300 | if with_amd_vk |
| 301 | dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.82') |
| 302 | endif |
| 303 | |
| 304 | llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit'] |
| 305 | if with_amd_vk |
| 306 | llvm_modules += ['amdgpu', 'bitreader', 'ipo'] |
| 307 | endif |
| 308 | dep_llvm = dependency( |
| 309 | 'llvm', version : '>= 3.9.0', required : false, modules : llvm_modules, |
| 310 | ) |
| 311 | if not dep_llvm.found() |
| 312 | if with_amd_vk |
| 313 | error('Radv requires llvm.') |
| 314 | endif |
| 315 | else |
| 316 | _llvm_version = dep_llvm.version().split('.') |
| 317 | # Development versions of LLVM have an 'svn' suffix, we don't want that for |
| 318 | # our version checks. |
| 319 | _llvm_patch = _llvm_version[2] |
| 320 | if _llvm_patch.endswith('svn') |
| 321 | _llvm_patch = _llvm_patch.split('s')[0] |
| 322 | endif |
| 323 | pre_args += [ |
| 324 | '-DHAVE_LLVM=0x0@0@@1@@2@'.format(_llvm_version[0], _llvm_version[1], _llvm_patch), |
| 325 | '-DMESA_LLVM_VERSION_PATCH=@0@'.format(_llvm_patch), |
| 326 | ] |
| 327 | endif |
Dylan Baker | d199225 | 2017-09-14 17:57:17 -0700 | [diff] [blame] | 328 | |
| 329 | # TODO: make this conditional |
| 330 | dep_valgrind = dependency('valgrind', required : false) |
| 331 | if dep_valgrind.found() and with_valgrind |
| 332 | pre_args += '-DHAVE_VALGRIND' |
| 333 | endif |
| 334 | |
| 335 | # pthread stubs. Lets not and say we didn't |
| 336 | |
| 337 | # TODO: selinux |
| 338 | |
| 339 | # TODO: llvm-prefix and llvm-shared-libs |
| 340 | |
Dylan Baker | d199225 | 2017-09-14 17:57:17 -0700 | [diff] [blame] | 341 | # TODO: unwind (llvm [radeon, gallivm] and gallium) |
| 342 | |
| 343 | # TODO: flags for opengl, gles, dri |
| 344 | |
| 345 | # TODO: gallium-hud |
| 346 | |
| 347 | # TODO: glx provider |
| 348 | |
| 349 | # TODO: osmesa provider |
| 350 | |
| 351 | # TODO: flags for xa, egl, gbm, nin, xvmc, vdpau, omx, va, opencl, |
| 352 | # gallium-tests, |
| 353 | |
| 354 | # TODO: gallium drivers |
| 355 | |
| 356 | # TODO: libglvnd |
| 357 | |
| 358 | # TODO: symbol mangling |
| 359 | |
| 360 | # TODO: dri handling |
| 361 | |
| 362 | # TODO: shared-glapi |
| 363 | |
| 364 | # TODO: libgl requirements |
| 365 | |
| 366 | # TODO: GLX configuration |
| 367 | |
| 368 | # TODO: egl configuration |
| 369 | |
| 370 | if with_platform_wayland |
| 371 | prog_wl_scanner = find_program('wayland-scanner') |
| 372 | dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8') |
| 373 | dep_wayland_client = dependency('wayland-client', version : '>=1.11') |
| 374 | dep_wayland_server = dependency('wayland-server', version : '>=1.11') |
| 375 | else |
| 376 | prog_wl_scanner = [] |
| 377 | dep_wl_protocols = [] |
| 378 | dep_wayland_client = [] |
| 379 | dep_wayland_server = [] |
| 380 | endif |
| 381 | |
| 382 | dep_xcb_dri2 = [] |
| 383 | dep_xcb_dri3 = [] |
| 384 | if with_platform_x11 |
| 385 | dep_xcb_dri2 = [ |
| 386 | dependency('x11-xcb'), |
| 387 | dependency('xcb'), |
| 388 | dependency('xcb-dri2', version : '>= 1.8'), |
| 389 | dependency('xcb-xfixes'), |
| 390 | ] |
| 391 | if with_dri3 |
| 392 | dep_xcb_dri3 = [ |
| 393 | dep_xcb_dri2, |
| 394 | dependency('xcb-dri3'), |
| 395 | dependency('xcb-present'), |
| 396 | dependency('xcb-sync'), |
| 397 | dependency('xshmfence', version : '>= 1.1'), |
| 398 | ] |
| 399 | else |
| 400 | # TODO: dri3 is required for vulkan |
| 401 | endif |
| 402 | endif |
| 403 | |
| 404 | # TODO: platforms for !vulkan |
| 405 | |
| 406 | # TODO: dri paths |
| 407 | |
| 408 | # TODO: dri drivers |
| 409 | |
| 410 | # TODO: osmesa |
| 411 | |
| 412 | # TODO: egl |
| 413 | |
| 414 | # TODO: xa |
| 415 | |
| 416 | # TODO: vallium G3DVL |
| 417 | |
| 418 | # TODO: nine |
| 419 | |
| 420 | # TODO: clover |
| 421 | |
| 422 | # TODO: egl sans x11 |
| 423 | |
| 424 | # TODO: xvmc |
| 425 | |
| 426 | # TODO: gallium tests |
| 427 | |
| 428 | # TODO: various libdirs |
| 429 | |
| 430 | # TODO: swr |
| 431 | |
| 432 | # TODO: gallium driver dirs |
| 433 | |
| 434 | # FIXME: this is a workaround for #2326 |
| 435 | prog_touch = find_program('touch') |
| 436 | dummy_cpp = custom_target( |
| 437 | 'dummy_cpp', |
| 438 | output : 'dummy.cpp', |
| 439 | command : [prog_touch, '@OUTPUT@'], |
| 440 | ) |
| 441 | |
| 442 | foreach a : pre_args |
| 443 | add_project_arguments(a, language : ['c', 'cpp']) |
| 444 | endforeach |
| 445 | foreach a : c_args |
| 446 | add_project_arguments(a, language : ['c']) |
| 447 | endforeach |
| 448 | foreach a : cpp_args |
| 449 | add_project_arguments(a, language : ['cpp']) |
| 450 | endforeach |
| 451 | |
| 452 | inc_include = include_directories('include') |
| 453 | |
| 454 | subdir('include') |
| 455 | subdir('src') |