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