1 # Copyright © 2017 Intel Corporation
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:
10 # The above copyright notice and this permission notice shall be included in
11 # all copies or substantial portions of the Software.
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
21 project('mesa', ['c', 'cpp'], version : '17.3.0-devel', license : 'MIT',
22 default_options : ['c_std=c99', 'cpp_std=c++11'])
24 # Arguments for the preprocessor, put these in a separate array from the C and
25 # C++ (cpp in meson terminology) arguments since they need to be added to the
26 # default arguments for both C and C++.
28 '-D__STDC_CONSTANT_MACROS',
29 '-D__STDC_FORMAT_MACROS',
30 '-D__STDC_LIMIT_MACROS',
31 '-DVERSION="@0@"'.format(meson.project_version()),
32 '-DPACKAGE_VERSION=VERSION',
33 '-DPACKAGE_BUGREPORT="https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa"',
36 with_vulkan_icd_dir = get_option('vulkan-icd-dir')
37 with_tests = get_option('build-tests')
38 with_valgrind = get_option('valgrind')
39 with_asm = get_option('asm')
40 if get_option('texture-float')
41 pre_args += '-DTEXTURE_FLOAT_ENABLED'
42 message('WARNING: Floating-point texture enabled. Please consult docs/patents.txt and your lawyer before building mesa.')
47 with_windowsdri = false
49 dri_drivers_path = get_option('dri-drivers-path')
50 if dri_drivers_path == ''
51 dri_drivers_path = join_paths(get_option('libdir'), 'dri')
54 with_gles1 = get_option('gles1')
55 with_gles2 = get_option('gles2')
56 with_opengl = get_option('opengl')
57 with_any_opengl = with_opengl or with_gles1 or with_gles2
58 # Only build shared_glapi if at least one OpenGL API is enabled
59 with_shared_glapi = get_option('shared-glapi') and with_any_opengl
61 # TODO: these will need options, but at the moment they just control header
65 # shared-glapi is required if at least two OpenGL APIs are being built
66 if not with_shared_glapi
67 if ((with_gles1 and with_gles2) or (with_gles1 and with_opengl)
68 or (with_gles2 and with_opengl))
69 error('shared-glapi required for building two or more of OpenGL, OpenGL ES 1.x, OpenGL ES 2.x')
73 # We require OpenGL for OpenGL ES
74 if (with_gles1 or with_gles2) and not with_opengl
75 error('building OpenGL ES without OpenGL is not supported.')
81 with_dri_swrast = false
82 _drivers = get_option('dri-drivers')
84 _split = _drivers.split(',')
85 with_dri_i915 = _split.contains('i915')
86 with_dri_i965 = _split.contains('i965')
87 with_dri_swrast = _split.contains('swrast')
93 dep_libdrm_intel = dependency('libdrm_intel', version : '>= 2.4.75')
100 with_any_opengl = false
101 with_shared_glapi = false
105 with_dri_platform = 'drm'
108 # TODO: gallium drivers
110 # TODO: conditionalize libdrm requirement
111 dep_libdrm = dependency('libdrm', version : '>= 2.4.75')
112 pre_args += '-DHAVE_LIBDRM'
114 with_dri2 = with_dri_platform == 'drm' and dep_libdrm.found()
115 with_dri3 = get_option('dri3')
116 if with_dri3 == 'auto'
117 if host_machine.system() == 'linux' and with_dri2
122 elif with_dri3 == 'yes'
124 error('dri3 support requires libdrm')
131 # TODO: there are more platforms required for non-vulkan drivers
132 with_platform_wayland = false
133 with_platform_x11 = false
134 _platforms = get_option('platforms')
136 _split = _platforms.split(',')
137 with_platform_x11 = _split.contains('x11')
138 with_platform_wayland = _split.contains('wayland')
141 with_gbm = get_option('gbm')
142 if with_gbm == 'auto' and with_dri # TODO: or gallium
143 with_gbm = host_machine.system() == 'linux'
144 elif with_gbm == 'yes'
145 if not ['linux', 'bsd'].contains(host_machine.system())
146 error('GBM only supports unix-like platforms')
153 with_glx = get_option('glx')
154 if with_glx != 'disabled'
155 pre_args += '-DGLX_USE_TLS'
156 if not (with_platform_x11 and with_any_opengl) and with_glx != 'auto'
157 error('Cannot build GLX support without X11 platform support and at least one OpenGL API')
158 elif with_glx == 'gallium-xlib'
160 error('Gallium-xlib based GLX requires at least one gallium driver')
162 error('gallium-xlib conflicts with any dri driver')
164 elif with_glx == 'dri' and not with_dri
165 error('dri based GLX requires at least one DRI driver')
166 elif with_glx == 'auto'
170 with_glx = 'gallium-xlib'
171 elif with_platform_x11 and with_any_opengl
174 with_glx = 'disabled'
179 with_glvnd = get_option('glvnd')
180 if with_glvnd and with_glx != 'dri'
181 message('glvnd requires dri based glx')
184 # TODO: toggle for this
185 with_glx_direct = true
187 if with_vulkan_icd_dir == ''
188 with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
191 with_intel_vk = false
194 _vulkan_drivers = get_option('vulkan-drivers')
195 if _vulkan_drivers != ''
196 _split = _vulkan_drivers.split(',')
197 with_intel_vk = _split.contains('intel')
198 with_amd_vk = _split.contains('amd')
199 with_any_vk = with_amd_vk or with_intel_vk
200 if not (with_platform_x11 or with_platform_wayland)
201 error('Vulkan requires at least one platform (x11, wayland)')
203 if with_platform_x11 and not with_dri3
204 error('Vulkan drivers require dri3 for X11 support')
208 if with_dri # TODO: or gallium
209 if with_glx == 'disabled' # TODO: or egl
210 error('building dri or gallium drivers require at least one window system')
214 prog_python2 = find_program('python2')
215 has_mako = run_command(prog_python2, '-c', 'import mako')
216 if has_mako.returncode() != 0
217 error('Python (2.x) mako module required to build mesa.')
220 cc = meson.get_compiler('c')
221 if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
222 error('When using GCC, version 4.4.6 or later is required.')
225 # Define DEBUG for debug and debugoptimized builds
226 if get_option('buildtype').startswith('debug')
227 pre_args += '-DDEBUG'
230 if get_option('shader-cache')
231 pre_args += '-DENABLE_SHADER_CACHE'
233 error('Radv requires shader cache support')
236 # Check for GCC style builtins
237 foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
238 'ffsll', 'popcount', 'popcountll', 'unreachable']
239 if cc.has_function(b)
240 pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
244 # check for GCC __attribute__
245 foreach a : ['const', 'flatten', 'malloc', 'pure', 'unused',
246 'warn_unused_result', 'weak',]
247 if cc.compiles('int foo(void) __attribute__((@0@));'.format(a),
248 name : '__attribute__((@0@))'.format(a))
249 pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
252 if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
253 name : '__attribute__((format(...)))')
254 pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
256 if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
257 name : '__attribute__((packed))')
258 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
260 if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
261 name : '__attribute__((returns_nonnull))')
262 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NONNULL'
264 if cc.compiles('''int foo_def(void) __attribute__((visibility("default")));
265 int foo_hid(void) __attribute__((visibility("hidden")));
266 int foo_int(void) __attribute__((visibility("internal")));
267 int foo_pro(void) __attribute__((visibility("protected")));''',
268 name : '__attribute__((visibility(...)))')
269 pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISBILITY'
271 if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
272 name : '__attribute__((alias(...)))')
273 pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
276 # TODO: this is very incomplete
277 if host_machine.system() == 'linux'
278 pre_args += '-D_GNU_SOURCE'
281 # Check for generic C arguments
283 foreach a : ['-Wall', '-Werror=implicit-function-declaration',
284 '-Werror=missing-prototypes', '-fno-math-errno',
285 '-fno-trapping-math', '-Qunused-arguments']
286 if cc.has_argument(a)
291 if cc.has_argument('-fvisibility=hidden')
292 c_vis_args += '-fvisibility=hidden'
295 # Check for generic C++ arguments
296 cpp = meson.get_compiler('cpp')
298 foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math',
299 '-Qunused-arguments', '-Wno-non-virtual-dtor']
300 if cpp.has_argument(a)
305 if cpp.has_argument('-fvisibility=hidden')
306 cpp_vis_args += '-fvisibility=hidden'
309 # Check for C and C++ arguments for MSVC2013 compatibility. These are only used
310 # in parts of the mesa code base that need to compile with old versions of
311 # MSVC, mainly common code
312 c_msvc_compat_args = []
313 cpp_msvc_compat_args = []
314 foreach a : ['-Werror=pointer-arith', '-Werror=vla']
315 if cc.has_argument(a)
316 c_msvc_compat_args += a
318 if cpp.has_argument(a)
319 cpp_msvc_compat_args += a
323 no_override_init_args = []
324 foreach a : ['-Wno-override-init', '-Wno-initializer-overrides']
325 if cc.has_argument(a)
326 no_override_init_args += a
330 # TODO: SSE41 (which is only required for core mesa)
332 # Check for GCC style atomics
333 if cc.compiles('int main() { int n; return __atomic_load_n(&n, __ATOMIC_ACQUIRE); }',
334 name : 'GCC atomic builtins')
335 pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
337 if not cc.links('''#include <stdint.h>
340 return __sync_add_and_fetch(&v, (uint64_t)1);
342 name : 'GCC 64bit atomics')
343 pre_args += '-DMISSING_64_BIT_ATOMICS'
348 # TODO: shared/static? Is this even worth doing?
350 # I don't think that I need to set any of the debug stuff, I think meson
351 # handles that for us
355 # TODO: texture-float (gallium/mesa only)
357 # TODO: cross-compiling. I don't think this is relavent to meson
359 # FIXME: enable asm when cross compiler
360 # This is doable (autotools does it), but it's not of immediate concern
361 if meson.is_cross_build()
362 message('Cross compiling, disabling asm')
368 # TODO: SPARC and PPC
369 if host_machine.cpu_family() == 'x86'
370 if ['linux', 'bsd'].contains(host_machine.system()) # FIXME: hurd?
371 with_asm_arch = 'x86'
372 pre_args += ['-DUSE_X86_ASM', '-DUSE_MMX_ASM', '-DUSE_3DNOW_ASM',
375 elif host_machine.cpu_family() == 'x86_64'
376 if host_machine.system() == 'linux'
377 with_asm_arch = 'x86_64'
378 pre_args += ['-DUSE_X86_64_ASM']
380 elif host_machine.cpu_family() == 'arm'
381 if host_machine.system() == 'linux'
382 with_asm_arch = 'arm'
383 pre_args += ['-DUSE_ARM_ASM']
385 elif host_machine.cpu_family() == 'aarch64'
386 if host_machine.system() == 'linux'
387 with_asm_arch = 'aarch64'
388 pre_args += ['-DUSE_AARCH64_ASM']
393 # Check for standard headers and functions
394 if cc.has_header_symbol('sys/sysmacros.h', 'major')
395 pre_args += '-DMAJOR_IN_SYSMACROS'
396 elif cc.has_header_symbol('sys/mkdev.h', 'major')
397 pre_args += '-DMAJOR_IN_MKDEV'
400 foreach h : ['xlocale.h', 'sys/sysctl.h']
402 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
406 foreach f : ['strtof', 'mkostemp', 'posix_memalign']
407 if cc.has_function(f)
408 pre_args += '-DHAVE_@0@'.format(f.to_upper())
412 # strtod locale support
417 #ifdef HAVE_XLOCALE_H
421 locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
422 const char *s = "1.0";
424 double d = strtod_l(s, end, loc);
425 float f = strtod_l(s, end, loc);
429 extra_args : pre_args,
430 name : 'strtod has locale support')
431 pre_args += '-DHAVE_STRTOD_L'
434 # Check for some linker flags
435 ld_args_bsymbolic = []
436 if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic')
437 ld_args_bsymbolic += '-Wl,-Bsymbolic'
439 ld_args_gc_sections = []
440 if cc.links('static char unused() { return 5; } int main() { return 0; }',
441 args : '-Wl,--gc-sections')
442 ld_args_gc_sections += '-Wl,--gc-sections'
445 # check for dl support
446 if cc.has_function('dlopen')
449 dep_dl = cc.find_library('dl')
451 if cc.has_function('dladdr', dependencies : dep_dl)
452 # This is really only required for megadrivers
453 pre_args += '-DHAVE_DLADDR'
456 if cc.has_function('dl_iterate_phdr')
457 pre_args += '-DHAVE_DL_ITERATE_PHDR'
459 # TODO: this is required for vulkan
462 # Determine whether or not the rt library is needed for time functions
463 if cc.has_function('clock_gettime')
466 dep_clock = cc.find_library('rt')
469 # TODO: some of these may be conditional
470 dep_zlib = dependency('zlib', version : '>= 1.2.3')
471 dep_thread = dependency('threads')
472 pre_args += '-DHAVE_PTHREAD'
473 dep_elf = dependency('libelf', required : false)
474 if not dep_elf.found()
475 dep_elf = cc.find_library('elf', required : with_amd_vk) # TODO: clover, r600, radeonsi
477 dep_expat = dependency('expat')
478 # this only exists on linux so either this is linux and it will be found, or
479 # its not linux and and wont
480 dep_m = cc.find_library('m', required : false)
482 dep_libdrm_amdgpu = []
484 dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.82')
487 llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
489 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
491 dep_llvm = dependency(
492 'llvm', version : '>= 3.9.0', required : false, modules : llvm_modules,
494 if not dep_llvm.found()
496 error('Radv requires llvm.')
499 _llvm_version = dep_llvm.version().split('.')
500 # Development versions of LLVM have an 'svn' suffix, we don't want that for
501 # our version checks.
502 _llvm_patch = _llvm_version[2]
503 if _llvm_patch.endswith('svn')
504 _llvm_patch = _llvm_patch.split('s')[0]
507 '-DHAVE_LLVM=0x0@0@@1@@2@'.format(_llvm_version[0], _llvm_version[1], _llvm_patch),
508 '-DMESA_LLVM_VERSION_PATCH=@0@'.format(_llvm_patch),
514 dep_glvnd = dependency('libglvnd', version : '>= 0.2.0')
515 pre_args += '-DUSE_LIBGLVND=1'
518 # TODO: make this conditional
519 dep_valgrind = dependency('valgrind', required : false)
520 if dep_valgrind.found() and with_valgrind
521 pre_args += '-DHAVE_VALGRIND'
524 # pthread stubs. Lets not and say we didn't
526 prog_bison = find_program('bison', required : with_any_opengl)
527 prog_flex = find_program('flex', required : with_any_opengl)
532 # TODO: llvm-prefix and llvm-shared-libs
534 # TODO: unwind (llvm [radeon, gallivm] and gallium)
536 # TODO: flags for opengl, gles, dri
542 # TODO: osmesa provider
544 # TODO: flags for xa, egl, gbm, nin, xvmc, vdpau, omx, va, opencl,
547 # TODO: gallium drivers
549 # TODO: symbol mangling
551 # TODO: egl configuration
553 if with_platform_wayland
554 prog_wl_scanner = find_program('wayland-scanner')
555 dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8')
556 dep_wayland_client = dependency('wayland-client', version : '>=1.11')
557 dep_wayland_server = dependency('wayland-server', version : '>=1.11')
560 dep_wl_protocols = []
561 dep_wayland_client = []
562 dep_wayland_server = []
572 if with_glx == 'xlib'
575 elif with_glx == 'gallium-xlib'
579 pre_args += '-DGLX_INDIRECT_RENDERING'
581 pre_args += '-DGLX_DIRECT_RENDERING'
583 if with_dri_platform == 'drm'
584 pre_args += '-DGLX_USE_DRM'
585 dep_dri2proto = dependency('dri2proto', version : '>= 2.8')
589 dependency('xdamage', version : '>= 1.1'),
590 dependency('xfixes'),
591 dependency('x11-xcb'),
593 dependency('xcb-glx', version : '>= 1.8.1'),
596 dep_xf86vm = dependency('xxf86vm', required : false)
600 if with_glx != 'disabled'
601 dep_glproto = dependency('glproto', version : '>= 1.4.14')
603 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
605 dependency('x11-xcb'),
607 dependency('xcb-dri2', version : '>= 1.8'),
608 dependency('xcb-xfixes'),
610 pre_args += '-DHAVE_X11_PLATFORM'
612 pre_args += '-DHAVE_DRI3'
615 dependency('xcb-dri3'),
616 dependency('xcb-present'),
617 dependency('xcb-sync'),
618 dependency('xshmfence', version : '>= 1.1'),
624 # TODO: platforms for !vulkan
632 # TODO: vallium G3DVL
642 # TODO: gallium tests
644 # TODO: various libdirs
648 # TODO: gallium driver dirs
650 # FIXME: this is a workaround for #2326
651 prog_touch = find_program('touch')
652 dummy_cpp = custom_target(
654 output : 'dummy.cpp',
655 command : [prog_touch, '@OUTPUT@'],
659 add_project_arguments(a, language : ['c', 'cpp'])
662 add_project_arguments(a, language : ['c'])
665 add_project_arguments(a, language : ['cpp'])
668 inc_include = include_directories('include')
670 pkg = import('pkgconfig')