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_dri3 = true # XXX: need a switch for this
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')
44 with_windowsdri = false
46 with_gles1 = get_option('gles1')
47 with_gles2 = get_option('gles2')
48 with_opengl = get_option('opengl')
49 with_any_opengl = with_opengl or with_gles1 or with_gles2
50 with_shared_glapi = get_option('shared-glapi')
52 # TODO: these will need options, but at the moment they just control header
57 # shared-glapi is required if at least two OpenGL APIs are being built
58 if not with_shared_glapi
59 if ((with_gles1 and with_gles2) or (with_gles1 and with_opengl)
60 or (with_gles2 and with_opengl))
61 error('shared-glapi required for building two or more of OpenGL, OpenGL ES 1.x, OpenGL ES 2.x')
65 # We require OpenGL for OpenGL ES
66 if (with_gles1 or with_gles2) and not with_opengl
67 error('building OpenGL ES without OpenGL is not supported.')
72 _drivers = get_option('dri-drivers')
74 _split = _drivers.split(',')
75 with_dri_i965 = _split.contains('i965')
83 with_any_opengl = false
84 with_shared_glapi = false
87 # TODO: there are more platforms required for non-vulkan drivers
88 with_platform_wayland = false
89 with_platform_x11 = false
90 _platforms = get_option('platforms')
92 _split = _platforms.split(',')
93 with_platform_x11 = _split.contains('x11')
94 with_platform_wayland = _split.contains('wayland')
97 if with_vulkan_icd_dir == ''
98 with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
101 with_intel_vk = false
103 _vulkan_drivers = get_option('vulkan-drivers')
104 if _vulkan_drivers != ''
105 _split = _vulkan_drivers.split(',')
106 with_intel_vk = _split.contains('intel')
107 with_amd_vk = _split.contains('amd')
108 if not (with_platform_x11 or with_platform_wayland)
109 error('Vulkan requires at least one platform (x11, wayland)')
113 prog_python2 = find_program('python2')
114 has_mako = run_command(prog_python2, '-c', 'import mako')
115 if has_mako.returncode() != 0
116 error('Python (2.x) mako module required to build mesa.')
119 cc = meson.get_compiler('c')
120 if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
121 error('When using GCC, version 4.4.6 or later is required.')
124 # Define DEBUG for debug and debugoptimized builds
125 if get_option('buildtype').startswith('debug')
126 pre_args += '-DDEBUG'
129 if get_option('shader-cache')
130 pre_args += '-DENABLE_SHADER_CACHE'
132 error('Radv requires shader cache support')
135 # Check for GCC style builtins
136 foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
137 'ffsll', 'popcount', 'popcountll', 'unreachable']
138 if cc.has_function(b)
139 pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
143 # check for GCC __attribute__
144 foreach a : ['const', 'flatten', 'malloc', 'pure', 'unused',
145 'warn_unused_result', 'weak',]
146 if cc.compiles('int foo(void) __attribute__((@0@));'.format(a),
147 name : '__attribute__((@0@))'.format(a))
148 pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
151 if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
152 name : '__attribute__((format(...)))')
153 pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
155 if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
156 name : '__attribute__((packed))')
157 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
159 if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
160 name : '__attribute__((returns_nonnull))')
161 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NONNULL'
163 if cc.compiles('''int foo_def(void) __attribute__((visibility("default")));
164 int foo_hid(void) __attribute__((visibility("hidden")));
165 int foo_int(void) __attribute__((visibility("internal")));
166 int foo_pro(void) __attribute__((visibility("protected")));''',
167 name : '__attribute__((visibility(...)))')
168 pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISBILITY'
170 if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
171 name : '__attribute__((alias(...)))')
172 pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
175 # TODO: this is very incomplete
176 if host_machine.system() == 'linux'
177 pre_args += '-D_GNU_SOURCE'
180 # Check for generic C arguments
182 foreach a : ['-Wall', '-Werror=implicit-function-declaration',
183 '-Werror=missing-prototypes', '-fno-math-errno',
184 '-fno-trapping-math', '-Qunused-arguments']
185 if cc.has_argument(a)
190 if cc.has_argument('-fvisibility=hidden')
191 c_vis_args += '-fvisibility=hidden'
194 # Check for generic C++ arguments
195 cpp = meson.get_compiler('cpp')
197 foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math',
198 '-Qunused-arguments', '-Wno-non-virtual-dtor']
199 if cpp.has_argument(a)
204 if cpp.has_argument('-fvisibility=hidden')
205 cpp_vis_args += '-fvisibility=hidden'
208 # Check for C and C++ arguments for MSVC2013 compatibility. These are only used
209 # in parts of the mesa code base that need to compile with old versions of
210 # MSVC, mainly common code
211 c_msvc_compat_args = []
212 cpp_msvc_compat_args = []
213 foreach a : ['-Werror=pointer-arith', '-Werror=vla']
214 if cc.has_argument(a)
215 c_msvc_compat_args += a
217 if cpp.has_argument(a)
218 cpp_msvc_compat_args += a
222 no_override_init_args = []
223 foreach a : ['-Wno-override-init', '-Wno-initializer-overrides']
224 if cc.has_argument(a)
225 no_override_init_args += a
229 # TODO: SSE41 (which is only required for core mesa)
231 # Check for GCC style atomics
232 if cc.compiles('int main() { int n; return __atomic_load_n(&n, __ATOMIC_ACQUIRE); }',
233 name : 'GCC atomic builtins')
234 pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
236 if not cc.links('''#include <stdint.h>
239 return __sync_add_and_fetch(&v, (uint64_t)1);
241 name : 'GCC 64bit atomics')
242 pre_args += '-DMISSING_64_BIT_ATOMICS'
247 # TODO: shared/static? Is this even worth doing?
249 # I don't think that I need to set any of the debug stuff, I think meson
250 # handles that for us
254 # TODO: texture-float (gallium/mesa only)
256 # TODO: cross-compiling. I don't think this is relavent to meson
258 # FIXME: enable asm when cross compiler
259 # This is doable (autotools does it), but it's not of immediate concern
260 if meson.is_cross_build()
261 message('Cross compiling, disabling asm')
267 # TODO: SPARC and PPC
268 if host_machine.cpu_family() == 'x86'
269 if ['linux', 'bsd'].contains(host_machine.system()) # FIXME: hurd?
270 with_asm_arch = 'x86'
271 pre_args += ['-DUSE_X86_ASM', '-DUSE_MMX_ASM', '-DUSE_3DNOW_ASM',
274 elif host_machine.cpu_family() == 'x86_64'
275 if host_machine.system() == 'linux'
276 with_asm_arch = 'x86_64'
277 pre_args += ['-DUSE_X86_64_ASM']
279 elif host_machine.cpu_family() == 'arm'
280 if host_machine.system() == 'linux'
281 with_asm_arch = 'arm'
282 pre_args += ['-DUSE_ARM_ASM']
284 elif host_machine.cpu_family() == 'aarch64'
285 if host_machine.system() == 'linux'
286 with_asm_arch = 'aarch64'
287 pre_args += ['-DUSE_AARCH64_ASM']
292 # Check for standard headers and functions
293 if cc.has_header_symbol('sys/sysmacros.h', 'major')
294 pre_args += '-DMAJOR_IN_SYSMACROS'
295 elif cc.has_header_symbol('sys/mkdev.h', 'major')
296 pre_args += '-DMAJOR_IN_MKDEV'
299 foreach h : ['xlocale.h', 'sys/sysctl.h']
301 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
305 foreach f : ['strtof', 'mkostemp', 'posix_memalign']
306 if cc.has_function(f)
307 pre_args += '-DHAVE_@0@'.format(f.to_upper())
311 # strtod locale support
316 #ifdef HAVE_XLOCALE_H
320 locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
321 const char *s = "1.0";
323 double d = strtod_l(s, end, loc);
324 float f = strtod_l(s, end, loc);
328 extra_args : pre_args,
329 name : 'strtod has locale support')
330 pre_args += '-DHAVE_STRTOD_L'
333 # Check for some linker flags
334 ld_args_bsymbolic = []
335 if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic')
336 ld_args_bsymbolic += '-Wl,-Bsymbolic'
338 ld_args_gc_sections = []
339 if cc.links('static char unused() { return 5; } int main() { return 0; }',
340 args : '-Wl,--gc-sections')
341 ld_args_gc_sections += '-Wl,--gc-sections'
344 # check for dl support
345 if cc.has_function('dlopen')
348 dep_dl = cc.find_library('dl')
350 if cc.has_function('dladdr', dependencies : dep_dl)
351 # This is really only required for megadrivers
352 pre_args += '-DHAVE_DLADDR'
355 if cc.has_function('dl_iterate_phdr')
356 pre_args += '-DHAVE_DL_ITERATE_PHDR'
358 # TODO: this is required for vulkan
361 # Determine whether or not the rt library is needed for time functions
362 if cc.has_function('clock_gettime')
365 dep_clock = cc.find_library('rt')
368 # TODO: some of these may be conditional
369 dep_zlib = dependency('zlib', version : '>= 1.2.3')
370 dep_thread = dependency('threads')
371 pre_args += '-DHAVE_PTHREAD'
372 dep_elf = dependency('libelf', required : false)
373 if not dep_elf.found()
374 dep_elf = cc.find_library('elf', required : with_amd_vk) # TODO: clover, r600, radeonsi
376 dep_expat = dependency('expat')
377 # this only exists on linux so either this is linux and it will be found, or
378 # its not linux and and wont
379 dep_m = cc.find_library('m', required : false)
381 # TODO: conditionalize libdrm requirement
382 dep_libdrm = dependency('libdrm', version : '>= 2.4.75')
383 pre_args += '-DHAVE_LIBDRM'
384 dep_libdrm_amdgpu = []
386 dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.82')
389 llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
391 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
393 dep_llvm = dependency(
394 'llvm', version : '>= 3.9.0', required : false, modules : llvm_modules,
396 if not dep_llvm.found()
398 error('Radv requires llvm.')
401 _llvm_version = dep_llvm.version().split('.')
402 # Development versions of LLVM have an 'svn' suffix, we don't want that for
403 # our version checks.
404 _llvm_patch = _llvm_version[2]
405 if _llvm_patch.endswith('svn')
406 _llvm_patch = _llvm_patch.split('s')[0]
409 '-DHAVE_LLVM=0x0@0@@1@@2@'.format(_llvm_version[0], _llvm_version[1], _llvm_patch),
410 '-DMESA_LLVM_VERSION_PATCH=@0@'.format(_llvm_patch),
414 # TODO: make this conditional
415 dep_valgrind = dependency('valgrind', required : false)
416 if dep_valgrind.found() and with_valgrind
417 pre_args += '-DHAVE_VALGRIND'
420 # pthread stubs. Lets not and say we didn't
422 prog_bison = find_program('bison', required : with_any_opengl)
423 prog_flex = find_program('flex', required : with_any_opengl)
428 # TODO: llvm-prefix and llvm-shared-libs
430 # TODO: unwind (llvm [radeon, gallivm] and gallium)
432 # TODO: flags for opengl, gles, dri
438 # TODO: osmesa provider
440 # TODO: flags for xa, egl, gbm, nin, xvmc, vdpau, omx, va, opencl,
443 # TODO: gallium drivers
447 # TODO: symbol mangling
453 # TODO: libgl requirements
455 # TODO: GLX configuration
457 # TODO: egl configuration
459 if with_platform_wayland
460 prog_wl_scanner = find_program('wayland-scanner')
461 dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8')
462 dep_wayland_client = dependency('wayland-client', version : '>=1.11')
463 dep_wayland_server = dependency('wayland-server', version : '>=1.11')
466 dep_wl_protocols = []
467 dep_wayland_client = []
468 dep_wayland_server = []
475 dependency('x11-xcb'),
477 dependency('xcb-dri2', version : '>= 1.8'),
478 dependency('xcb-xfixes'),
480 pre_args += '-DHAVE_X11_PLATFORM'
484 dependency('xcb-dri3'),
485 dependency('xcb-present'),
486 dependency('xcb-sync'),
487 dependency('xshmfence', version : '>= 1.1'),
490 # TODO: dri3 is required for vulkan
494 # TODO: platforms for !vulkan
506 # TODO: vallium G3DVL
516 # TODO: gallium tests
518 # TODO: various libdirs
522 # TODO: gallium driver dirs
524 # FIXME: this is a workaround for #2326
525 prog_touch = find_program('touch')
526 dummy_cpp = custom_target(
528 output : 'dummy.cpp',
529 command : [prog_touch, '@OUTPUT@'],
533 add_project_arguments(a, language : ['c', 'cpp'])
536 add_project_arguments(a, language : ['c'])
539 add_project_arguments(a, language : ['cpp'])
542 inc_include = include_directories('include')
544 pkg = import('pkgconfig')