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"',
37 with_vulkan_icd_dir = get_option('vulkan-icd-dir')
38 with_tests = get_option('build-tests')
39 with_valgrind = get_option('valgrind')
40 with_asm = get_option('asm')
41 with_llvm = get_option('llvm')
42 if get_option('texture-float')
43 pre_args += '-DTEXTURE_FLOAT_ENABLED'
44 message('WARNING: Floating-point texture enabled. Please consult docs/patents.txt and your lawyer before building mesa.')
49 with_windowsdri = false
51 dri_drivers_path = get_option('dri-drivers-path')
52 if dri_drivers_path == ''
53 dri_drivers_path = join_paths(get_option('libdir'), 'dri')
56 with_gles1 = get_option('gles1')
57 with_gles2 = get_option('gles2')
58 with_opengl = get_option('opengl')
59 with_any_opengl = with_opengl or with_gles1 or with_gles2
60 # Only build shared_glapi if at least one OpenGL API is enabled
61 with_shared_glapi = get_option('shared-glapi') and with_any_opengl
63 # TODO: these will need options, but at the moment they just control header
67 # shared-glapi is required if at least two OpenGL APIs are being built
68 if not with_shared_glapi
69 if ((with_gles1 and with_gles2) or (with_gles1 and with_opengl)
70 or (with_gles2 and with_opengl))
71 error('shared-glapi required for building two or more of OpenGL, OpenGL ES 1.x, OpenGL ES 2.x')
75 # We require OpenGL for OpenGL ES
76 if (with_gles1 or with_gles2) and not with_opengl
77 error('building OpenGL ES without OpenGL is not supported.')
83 with_dri_swrast = false
84 _drivers = get_option('dri-drivers')
86 _split = _drivers.split(',')
87 with_dri_i915 = _split.contains('i915')
88 with_dri_i965 = _split.contains('i965')
89 with_dri_swrast = _split.contains('swrast')
95 dep_libdrm_intel = dependency('libdrm_intel', version : '>= 2.4.75')
102 with_any_opengl = false
103 with_shared_glapi = false
107 with_dri_platform = 'drm'
110 # TODO: gallium drivers
112 # TODO: conditionalize libdrm requirement
113 dep_libdrm = dependency('libdrm', version : '>= 2.4.75')
114 pre_args += '-DHAVE_LIBDRM'
116 with_dri2 = with_dri_platform == 'drm' and dep_libdrm.found()
117 with_dri3 = get_option('dri3')
118 if with_dri3 == 'auto'
119 if host_machine.system() == 'linux' and with_dri2
124 elif with_dri3 == 'yes'
126 error('dri3 support requires libdrm')
133 # TODO: there are more platforms required for non-vulkan drivers
134 with_platform_wayland = false
135 with_platform_x11 = false
136 _platforms = get_option('platforms')
138 _split = _platforms.split(',')
139 with_platform_x11 = _split.contains('x11')
140 with_platform_wayland = _split.contains('wayland')
143 with_gbm = get_option('gbm')
144 if with_gbm == 'auto' and with_dri # TODO: or gallium
145 with_gbm = host_machine.system() == 'linux'
146 elif with_gbm == 'yes'
147 if not ['linux', 'bsd'].contains(host_machine.system())
148 error('GBM only supports unix-like platforms')
155 pre_args += '-DGLX_USE_TLS'
156 with_glx = get_option('glx')
157 if with_glx != 'disabled'
158 if not (with_platform_x11 and with_any_opengl) and with_glx != 'auto'
159 error('Cannot build GLX support without X11 platform support and at least one OpenGL API')
160 elif with_glx == 'gallium-xlib'
162 error('Gallium-xlib based GLX requires at least one gallium driver')
164 error('gallium-xlib conflicts with any dri driver')
166 elif with_glx == 'dri' and not with_dri
167 error('dri based GLX requires at least one DRI driver')
168 elif with_glx == 'auto'
172 with_glx = 'gallium-xlib'
173 elif with_platform_x11 and with_any_opengl
176 with_glx = 'disabled'
181 with_glvnd = get_option('glvnd')
182 if with_glvnd and with_glx != 'dri'
183 message('glvnd requires dri based glx')
186 # TODO: toggle for this
187 with_glx_direct = true
189 if with_vulkan_icd_dir == ''
190 with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
193 with_intel_vk = false
196 _vulkan_drivers = get_option('vulkan-drivers')
197 if _vulkan_drivers != ''
198 _split = _vulkan_drivers.split(',')
199 with_intel_vk = _split.contains('intel')
200 with_amd_vk = _split.contains('amd')
201 with_any_vk = with_amd_vk or with_intel_vk
202 if not (with_platform_x11 or with_platform_wayland)
203 error('Vulkan requires at least one platform (x11, wayland)')
205 if with_platform_x11 and not with_dri3
206 error('Vulkan drivers require dri3 for X11 support')
210 if with_dri # TODO: or gallium
211 if with_glx == 'disabled' # TODO: or egl
212 error('building dri or gallium drivers require at least one window system')
216 prog_python2 = find_program('python2')
217 has_mako = run_command(prog_python2, '-c', 'import mako')
218 if has_mako.returncode() != 0
219 error('Python (2.x) mako module required to build mesa.')
222 cc = meson.get_compiler('c')
223 if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
224 error('When using GCC, version 4.4.6 or later is required.')
227 # Define DEBUG for debug and debugoptimized builds
228 if get_option('buildtype').startswith('debug')
229 pre_args += '-DDEBUG'
232 if get_option('shader-cache')
233 pre_args += '-DENABLE_SHADER_CACHE'
235 error('Radv requires shader cache support')
238 # Check for GCC style builtins
239 foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
240 'ffsll', 'popcount', 'popcountll', 'unreachable']
241 if cc.has_function(b)
242 pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
246 # check for GCC __attribute__
247 foreach a : ['const', 'flatten', 'malloc', 'pure', 'unused',
248 'warn_unused_result', 'weak',]
249 if cc.compiles('int foo(void) __attribute__((@0@));'.format(a),
250 name : '__attribute__((@0@))'.format(a))
251 pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
254 if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
255 name : '__attribute__((format(...)))')
256 pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
258 if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
259 name : '__attribute__((packed))')
260 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
262 if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
263 name : '__attribute__((returns_nonnull))')
264 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NONNULL'
266 if cc.compiles('''int foo_def(void) __attribute__((visibility("default")));
267 int foo_hid(void) __attribute__((visibility("hidden")));
268 int foo_int(void) __attribute__((visibility("internal")));
269 int foo_pro(void) __attribute__((visibility("protected")));''',
270 name : '__attribute__((visibility(...)))')
271 pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISBILITY'
273 if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
274 name : '__attribute__((alias(...)))')
275 pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
278 # TODO: this is very incomplete
279 if host_machine.system() == 'linux'
280 pre_args += '-D_GNU_SOURCE'
283 # Check for generic C arguments
285 foreach a : ['-Wall', '-Werror=implicit-function-declaration',
286 '-Werror=missing-prototypes', '-fno-math-errno',
287 '-fno-trapping-math', '-Qunused-arguments']
288 if cc.has_argument(a)
293 if cc.has_argument('-fvisibility=hidden')
294 c_vis_args += '-fvisibility=hidden'
297 # Check for generic C++ arguments
298 cpp = meson.get_compiler('cpp')
300 foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math',
301 '-Qunused-arguments', '-Wno-non-virtual-dtor']
302 if cpp.has_argument(a)
307 if cpp.has_argument('-fvisibility=hidden')
308 cpp_vis_args += '-fvisibility=hidden'
311 # Check for C and C++ arguments for MSVC2013 compatibility. These are only used
312 # in parts of the mesa code base that need to compile with old versions of
313 # MSVC, mainly common code
314 c_msvc_compat_args = []
315 cpp_msvc_compat_args = []
316 foreach a : ['-Werror=pointer-arith', '-Werror=vla']
317 if cc.has_argument(a)
318 c_msvc_compat_args += a
320 if cpp.has_argument(a)
321 cpp_msvc_compat_args += a
325 no_override_init_args = []
326 foreach a : ['-Wno-override-init', '-Wno-initializer-overrides']
327 if cc.has_argument(a)
328 no_override_init_args += a
332 # TODO: SSE41 (which is only required for core mesa)
334 # Check for GCC style atomics
335 if cc.compiles('int main() { int n; return __atomic_load_n(&n, __ATOMIC_ACQUIRE); }',
336 name : 'GCC atomic builtins')
337 pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
339 if not cc.links('''#include <stdint.h>
342 return __sync_add_and_fetch(&v, (uint64_t)1);
344 name : 'GCC 64bit atomics')
345 pre_args += '-DMISSING_64_BIT_ATOMICS'
350 # TODO: shared/static? Is this even worth doing?
352 # I don't think that I need to set any of the debug stuff, I think meson
353 # handles that for us
357 # TODO: texture-float (gallium/mesa only)
359 # TODO: cross-compiling. I don't think this is relavent to meson
361 # FIXME: enable asm when cross compiler
362 # This is doable (autotools does it), but it's not of immediate concern
363 if meson.is_cross_build()
364 message('Cross compiling, disabling asm')
370 # TODO: SPARC and PPC
371 if host_machine.cpu_family() == 'x86'
372 if ['linux', 'bsd'].contains(host_machine.system()) # FIXME: hurd?
373 with_asm_arch = 'x86'
374 pre_args += ['-DUSE_X86_ASM', '-DUSE_MMX_ASM', '-DUSE_3DNOW_ASM',
377 elif host_machine.cpu_family() == 'x86_64'
378 if host_machine.system() == 'linux'
379 with_asm_arch = 'x86_64'
380 pre_args += ['-DUSE_X86_64_ASM']
382 elif host_machine.cpu_family() == 'arm'
383 if host_machine.system() == 'linux'
384 with_asm_arch = 'arm'
385 pre_args += ['-DUSE_ARM_ASM']
387 elif host_machine.cpu_family() == 'aarch64'
388 if host_machine.system() == 'linux'
389 with_asm_arch = 'aarch64'
390 pre_args += ['-DUSE_AARCH64_ASM']
395 # Check for standard headers and functions
396 if cc.has_header_symbol('sys/sysmacros.h', 'major')
397 pre_args += '-DMAJOR_IN_SYSMACROS'
398 elif cc.has_header_symbol('sys/mkdev.h', 'major')
399 pre_args += '-DMAJOR_IN_MKDEV'
402 foreach h : ['xlocale.h', 'sys/sysctl.h']
404 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
408 foreach f : ['strtof', 'mkostemp', 'posix_memalign']
409 if cc.has_function(f)
410 pre_args += '-DHAVE_@0@'.format(f.to_upper())
414 # strtod locale support
419 #ifdef HAVE_XLOCALE_H
423 locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
424 const char *s = "1.0";
426 double d = strtod_l(s, end, loc);
427 float f = strtod_l(s, end, loc);
431 extra_args : pre_args,
432 name : 'strtod has locale support')
433 pre_args += '-DHAVE_STRTOD_L'
436 # Check for some linker flags
437 ld_args_bsymbolic = []
438 if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic', name : 'Bsymbolic')
439 ld_args_bsymbolic += '-Wl,-Bsymbolic'
441 ld_args_gc_sections = []
442 if cc.links('static char unused() { return 5; } int main() { return 0; }',
443 args : '-Wl,--gc-sections', name : 'gc-sections')
444 ld_args_gc_sections += '-Wl,--gc-sections'
446 with_ld_version_script = false
447 if cc.links('int main() { return 0; }',
448 args : '-Wl,--version-script=@0@'.format(
449 join_paths(meson.source_root(), 'build-support/conftest.map')),
450 name : 'version-script')
451 with_ld_version_script = true
453 with_ld_dynamic_list = false
454 if cc.links('int main() { return 0; }',
455 args : '-Wl,--dynamic-list=@0@'.format(
456 join_paths(meson.source_root(), 'build-support/conftest.dyn')),
457 name : 'dynamic-list')
458 with_ld_dynamic_list = true
461 # check for dl support
462 if cc.has_function('dlopen')
465 dep_dl = cc.find_library('dl')
467 if cc.has_function('dladdr', dependencies : dep_dl)
468 # This is really only required for megadrivers
469 pre_args += '-DHAVE_DLADDR'
472 if cc.has_function('dl_iterate_phdr')
473 pre_args += '-DHAVE_DL_ITERATE_PHDR'
475 # TODO: this is required for vulkan
478 # Determine whether or not the rt library is needed for time functions
479 if cc.has_function('clock_gettime')
482 dep_clock = cc.find_library('rt')
485 # TODO: some of these may be conditional
486 dep_zlib = dependency('zlib', version : '>= 1.2.3')
487 dep_thread = dependency('threads')
488 pre_args += '-DHAVE_PTHREAD'
489 dep_elf = dependency('libelf', required : false)
490 if not dep_elf.found()
491 dep_elf = cc.find_library('elf', required : with_amd_vk) # TODO: clover, r600, radeonsi
493 dep_expat = dependency('expat')
494 # this only exists on linux so either this is linux and it will be found, or
495 # its not linux and and wont
496 dep_m = cc.find_library('m', required : false)
498 dep_libdrm_amdgpu = []
500 dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.82')
503 llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
505 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
507 dep_llvm = dependency(
508 'llvm', version : '>= 3.9.0', required : false, modules : llvm_modules,
512 _llvm_version = dep_llvm.version().split('.')
513 # Development versions of LLVM have an 'svn' suffix, we don't want that for
514 # our version checks.
515 _llvm_patch = _llvm_version[2]
516 if _llvm_patch.endswith('svn')
517 _llvm_patch = _llvm_patch.split('s')[0]
520 '-DHAVE_LLVM=0x0@0@@1@@2@'.format(_llvm_version[0], _llvm_version[1], _llvm_patch),
521 '-DMESA_LLVM_VERSION_PATCH=@0@'.format(_llvm_patch),
525 error('The following drivers requires LLVM: Radv. One of these is enabled, but LLVM was not found.')
529 error('The following drivers requires LLVM: Radv. One of these is enabled, but LLVM is disabled.')
534 dep_glvnd = dependency('libglvnd', version : '>= 0.2.0')
535 pre_args += '-DUSE_LIBGLVND=1'
538 # TODO: make this conditional
539 dep_valgrind = dependency('valgrind', required : false)
540 if dep_valgrind.found() and with_valgrind
541 pre_args += '-DHAVE_VALGRIND'
544 # pthread stubs. Lets not and say we didn't
546 prog_bison = find_program('bison', required : with_any_opengl)
547 prog_flex = find_program('flex', required : with_any_opengl)
552 # TODO: llvm-prefix and llvm-shared-libs
554 # TODO: unwind (llvm [radeon, gallivm] and gallium)
556 # TODO: flags for opengl, gles, dri
562 # TODO: osmesa provider
564 # TODO: flags for xa, egl, gbm, nin, xvmc, vdpau, omx, va, opencl,
567 # TODO: gallium drivers
569 # TODO: symbol mangling
571 # TODO: egl configuration
573 if with_platform_wayland
574 prog_wl_scanner = find_program('wayland-scanner')
575 dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8')
576 dep_wayland_client = dependency('wayland-client', version : '>=1.11')
577 dep_wayland_server = dependency('wayland-server', version : '>=1.11')
580 dep_wl_protocols = []
581 dep_wayland_client = []
582 dep_wayland_server = []
592 if with_glx == 'xlib'
595 elif with_glx == 'gallium-xlib'
599 pre_args += '-DGLX_INDIRECT_RENDERING'
601 pre_args += '-DGLX_DIRECT_RENDERING'
603 if with_dri_platform == 'drm'
604 pre_args += '-DGLX_USE_DRM'
605 dep_dri2proto = dependency('dri2proto', version : '>= 2.8')
609 dependency('xdamage', version : '>= 1.1'),
610 dependency('xfixes'),
611 dependency('x11-xcb'),
613 dependency('xcb-glx', version : '>= 1.8.1'),
616 dep_xf86vm = dependency('xxf86vm', required : false)
620 if with_glx != 'disabled'
621 dep_glproto = dependency('glproto', version : '>= 1.4.14')
623 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
625 dependency('x11-xcb'),
627 dependency('xcb-dri2', version : '>= 1.8'),
628 dependency('xcb-xfixes'),
630 pre_args += '-DHAVE_X11_PLATFORM'
632 pre_args += '-DHAVE_DRI3'
635 dependency('xcb-dri3'),
636 dependency('xcb-present'),
637 dependency('xcb-sync'),
638 dependency('xshmfence', version : '>= 1.1'),
644 # TODO: platforms for !vulkan
652 # TODO: vallium G3DVL
662 # TODO: gallium tests
664 # TODO: various libdirs
668 # TODO: gallium driver dirs
670 # FIXME: this is a workaround for #2326
671 prog_touch = find_program('touch')
672 dummy_cpp = custom_target(
674 output : 'dummy.cpp',
675 command : [prog_touch, '@OUTPUT@'],
679 add_project_arguments(a, language : ['c', 'cpp'])
682 add_project_arguments(a, language : ['c'])
685 add_project_arguments(a, language : ['cpp'])
688 inc_include = include_directories('include')
690 pkg = import('pkgconfig')