blob: 958bd2313f11e6f5c36d8f5ea7b6ddb4070536a8 [file] [log] [blame]
Dylan Bakerd1992252017-09-14 17:57:17 -07001# 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
21project('mesa', ['c', 'cpp'], version : '17.3.0-devel', license : 'MIT',
Dylan Baker052c0d52017-09-30 20:04:09 -070022 default_options : ['c_std=c99', 'cpp_std=c++11'])
Dylan Bakerd1992252017-09-14 17:57:17 -070023
Dylan Baker32180562017-09-20 20:11:32 -070024# 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++.
27pre_args = [
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"',
34]
35
Dylan Bakerd1992252017-09-14 17:57:17 -070036with_dri3 = true # XXX: need a switch for this
Dylan Bakere915b8d2017-09-28 14:02:51 -070037with_vulkan_icd_dir = get_option('vulkan-icd-dir')
Dylan Bakerd1992252017-09-14 17:57:17 -070038with_tests = get_option('build-tests')
39with_valgrind = get_option('valgrind')
Dylan Baker32180562017-09-20 20:11:32 -070040with_asm = get_option('asm')
41
42# XXX: yeah, do these
43with_appledri = false
44with_windowsdri = false
45
46with_gles1 = get_option('gles1')
47with_gles2 = get_option('gles2')
48with_opengl = get_option('opengl')
49with_any_opengl = with_opengl or with_gles1 or with_gles2
50with_shared_glapi = get_option('shared-glapi')
51
52# TODO: these will need options, but at the moment they just control header
53# installs
54with_glx = false
55with_osmesa = false
56
57# shared-glapi is required if at least two OpenGL APIs are being built
58if 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')
62 endif
63endif
64
65# We require OpenGL for OpenGL ES
66if (with_gles1 or with_gles2) and not with_opengl
67 error('building OpenGL ES without OpenGL is not supported.')
68endif
69
70with_dri = false
71with_dri_i965 = false
72_drivers = get_option('dri-drivers')
73if _drivers != ''
74 _split = _drivers.split(',')
75 with_dri_i965 = _split.contains('i965')
76 with_dri = true
77endif
78
79if not with_dri
80 with_gles1 = false
81 with_gles2 = false
82 with_opengl = false
83 with_any_opengl = false
84 with_shared_glapi = false
85endif
Dylan Bakerd1992252017-09-14 17:57:17 -070086
87# TODO: there are more platforms required for non-vulkan drivers
88with_platform_wayland = false
89with_platform_x11 = false
90_platforms = get_option('platforms')
91if _platforms != ''
92 _split = _platforms.split(',')
93 with_platform_x11 = _split.contains('x11')
94 with_platform_wayland = _split.contains('wayland')
95endif
96
97if with_vulkan_icd_dir == ''
98 with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
99endif
100
101with_intel_vk = false
102with_amd_vk = false
103_vulkan_drivers = get_option('vulkan-drivers')
104if _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)')
110 endif
111endif
112
113prog_python2 = find_program('python2')
Dylan Baker9342a7d2017-09-28 10:48:30 -0700114has_mako = run_command(prog_python2, '-c', 'import mako')
115if has_mako.returncode() != 0
116 error('Python (2.x) mako module required to build mesa.')
117endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700118
119cc = meson.get_compiler('c')
120if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
Eric Engestrom1262e822017-09-29 15:25:18 +0100121 error('When using GCC, version 4.4.6 or later is required.')
Dylan Bakerd1992252017-09-14 17:57:17 -0700122endif
123
Dylan Bakerd1992252017-09-14 17:57:17 -0700124# Define DEBUG for debug and debugoptimized builds
125if get_option('buildtype').startswith('debug')
126 pre_args += '-DDEBUG'
127endif
128
Dylan Baker673dda82017-09-20 11:53:29 -0700129if get_option('shader-cache')
130 pre_args += '-DENABLE_SHADER_CACHE'
131elif with_amd_vk
132 error('Radv requires shader cache support')
133endif
134
Dylan Bakerd1992252017-09-14 17:57:17 -0700135# Check for GCC style builtins
136foreach 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())
140 endif
141endforeach
142
Dylan Baker673dda82017-09-20 11:53:29 -0700143# check for GCC __attribute__
Dylan Bakerd1992252017-09-14 17:57:17 -0700144foreach 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())
149 endif
150endforeach
151if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
152 name : '__attribute__((format(...)))')
153 pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
154endif
155if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
156 name : '__attribute__((packed))')
157 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
158endif
159if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
160 name : '__attribute__((returns_nonnull))')
161 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NONNULL'
162endif
163if 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'
169endif
170if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
171 name : '__attribute__((alias(...)))')
172 pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
173endif
174
175# TODO: this is very incomplete
176if host_machine.system() == 'linux'
177 pre_args += '-D_GNU_SOURCE'
178endif
179
180# Check for generic C arguments
181c_args = []
182foreach 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)
186 c_args += a
187 endif
188endforeach
189c_vis_args = []
190if cc.has_argument('-fvisibility=hidden')
191 c_vis_args += '-fvisibility=hidden'
192endif
193
194# Check for generic C++ arguments
195cpp = meson.get_compiler('cpp')
196cpp_args = []
197foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math',
198 '-Qunused-arguments', '-Wno-non-virtual-dtor']
199 if cpp.has_argument(a)
200 cpp_args += a
201 endif
202endforeach
203cpp_vis_args = []
204if cpp.has_argument('-fvisibility=hidden')
205 cpp_vis_args += '-fvisibility=hidden'
206endif
207
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
211c_msvc_compat_args = []
212cpp_msvc_compat_args = []
213foreach a : ['-Werror=pointer-arith', '-Werror=vla']
214 if cc.has_argument(a)
215 c_msvc_compat_args += a
216 endif
217 if cpp.has_argument(a)
218 cpp_msvc_compat_args += a
219 endif
220endforeach
221
222no_override_init_args = []
223foreach a : ['-Wno-override-init', '-Wno-initializer-overrides']
224 if cc.has_argument(a)
225 no_override_init_args += a
226 endif
227endforeach
228
229# TODO: SSE41 (which is only required for core mesa)
230
231# Check for GCC style atomics
232if 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'
235endif
236if not cc.links('''#include <stdint.h>
237 uint64_t v;
238 int main() {
239 return __sync_add_and_fetch(&v, (uint64_t)1);
240 }''',
241 name : 'GCC 64bit atomics')
242 pre_args += '-DMISSING_64_BIT_ATOMICS'
243endif
244
245# TODO: endian
246# TODO: powr8
247# TODO: shared/static? Is this even worth doing?
248
249# I don't think that I need to set any of the debug stuff, I think meson
250# handles that for us
251
252# TODO: ldflags
253
254# TODO: texture-float (gallium/mesa only)
255
256# TODO: cross-compiling. I don't think this is relavent to meson
257
Dylan Baker32180562017-09-20 20:11:32 -0700258# FIXME: enable asm when cross compiler
259# This is doable (autotools does it), but it's not of immediate concern
260if meson.is_cross_build()
261 message('Cross compiling, disabling asm')
262 with_asm = false
263endif
264
265with_asm_arch = ''
266if with_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',
272 '-DUSE_SSE_ASM']
273 endif
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']
278 endif
279 elif host_machine.cpu_family() == 'arm'
280 if host_machine.system() == 'linux'
281 with_asm_arch = 'arm'
282 pre_args += ['-DUSE_ARM_ASM']
283 endif
284 elif host_machine.cpu_family() == 'aarch64'
285 if host_machine.system() == 'linux'
286 with_asm_arch = 'aarch64'
287 pre_args += ['-DUSE_AARCH64_ASM']
288 endif
289 endif
290endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700291
292# Check for standard headers and functions
293if cc.has_header_symbol('sys/sysmacros.h', 'major')
294 pre_args += '-DMAJOR_IN_SYSMACROS'
295elif cc.has_header_symbol('sys/mkdev.h', 'major')
296 pre_args += '-DMAJOR_IN_MKDEV'
297endif
298
299foreach h : ['xlocale.h', 'sys/sysctl.h']
300 if cc.has_header(h)
301 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
302 endif
303endforeach
304
305foreach f : ['strtof', 'mkostemp', 'posix_memalign']
306 if cc.has_function(f)
307 pre_args += '-DHAVE_@0@'.format(f.to_upper())
308 endif
309endforeach
310
311# strtod locale support
312if cc.links('''
313 #define _GNU_SOURCE
314 #include <stdlib.h>
315 #include <locale.h>
316 #ifdef HAVE_XLOCALE_H
317 #include <xlocale.h>
318 #endif
319 int main() {
320 locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
321 const char *s = "1.0";
322 char *end;
323 double d = strtod_l(s, end, loc);
324 float f = strtod_l(s, end, loc);
325 freelocale(loc);
326 return 0;
327 }''',
328 extra_args : pre_args,
329 name : 'strtod has locale support')
330 pre_args += '-DHAVE_STRTOD_L'
331endif
332
333# Check for some linker flags
334ld_args_bsymbolic = []
335if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic')
336 ld_args_bsymbolic += '-Wl,-Bsymbolic'
337endif
338ld_args_gc_sections = []
339if cc.links('static char unused() { return 5; } int main() { return 0; }',
340 args : '-Wl,--gc-sections')
341 ld_args_gc_sections += '-Wl,--gc-sections'
342endif
343
344# check for dl support
345if cc.has_function('dlopen')
346 dep_dl = []
347else
348 dep_dl = cc.find_library('dl')
349endif
Dylan Baker32180562017-09-20 20:11:32 -0700350if cc.has_function('dladdr', dependencies : dep_dl)
351 # This is really only required for megadrivers
352 pre_args += '-DHAVE_DLADDR'
Dylan Bakerd1992252017-09-14 17:57:17 -0700353endif
354
355if cc.has_function('dl_iterate_phdr')
356 pre_args += '-DHAVE_DL_ITERATE_PHDR'
357else
358 # TODO: this is required for vulkan
359endif
360
361# Determine whether or not the rt library is needed for time functions
362if cc.has_function('clock_gettime')
363 dep_clock = []
364else
365 dep_clock = cc.find_library('rt')
366endif
367
368# TODO: some of these may be conditional
369dep_zlib = dependency('zlib', version : '>= 1.2.3')
370dep_thread = dependency('threads')
371pre_args += '-DHAVE_PTHREAD'
Dylan Bakercc4f5872017-09-27 11:30:21 -0700372dep_elf = dependency('libelf', required : false)
373if not dep_elf.found()
Dylan Baker97aea7d2017-10-04 11:36:06 -0700374 dep_elf = cc.find_library('elf', required : with_amd_vk) # TODO: clover, r600, radeonsi
Dylan Bakercc4f5872017-09-27 11:30:21 -0700375endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700376dep_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
379dep_m = cc.find_library('m', required : false)
380
381# TODO: conditionalize libdrm requirement
382dep_libdrm = dependency('libdrm', version : '>= 2.4.75')
383pre_args += '-DHAVE_LIBDRM'
Dylan Baker673dda82017-09-20 11:53:29 -0700384dep_libdrm_amdgpu = []
385if with_amd_vk
386 dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.82')
387endif
388
389llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
390if with_amd_vk
391 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
392endif
393dep_llvm = dependency(
394 'llvm', version : '>= 3.9.0', required : false, modules : llvm_modules,
395)
396if not dep_llvm.found()
397 if with_amd_vk
398 error('Radv requires llvm.')
399 endif
400else
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]
407 endif
408 pre_args += [
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),
411 ]
412endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700413
414# TODO: make this conditional
415dep_valgrind = dependency('valgrind', required : false)
416if dep_valgrind.found() and with_valgrind
417 pre_args += '-DHAVE_VALGRIND'
418endif
419
420# pthread stubs. Lets not and say we didn't
421
Dylan Baker32180562017-09-20 20:11:32 -0700422prog_bison = find_program('bison', required : with_any_opengl)
423prog_flex = find_program('flex', required : with_any_opengl)
424
Dylan Bakerd1992252017-09-14 17:57:17 -0700425# TODO: selinux
Dylan Baker32180562017-09-20 20:11:32 -0700426dep_selinux = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700427
428# TODO: llvm-prefix and llvm-shared-libs
429
Dylan Bakerd1992252017-09-14 17:57:17 -0700430# TODO: unwind (llvm [radeon, gallivm] and gallium)
431
432# TODO: flags for opengl, gles, dri
433
434# TODO: gallium-hud
435
436# TODO: glx provider
437
438# TODO: osmesa provider
439
440# TODO: flags for xa, egl, gbm, nin, xvmc, vdpau, omx, va, opencl,
441# gallium-tests,
442
443# TODO: gallium drivers
444
445# TODO: libglvnd
446
447# TODO: symbol mangling
448
449# TODO: dri handling
450
451# TODO: shared-glapi
452
453# TODO: libgl requirements
454
455# TODO: GLX configuration
456
457# TODO: egl configuration
458
459if 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')
464else
465 prog_wl_scanner = []
466 dep_wl_protocols = []
467 dep_wayland_client = []
468 dep_wayland_server = []
469endif
470
471dep_xcb_dri2 = []
472dep_xcb_dri3 = []
473if with_platform_x11
474 dep_xcb_dri2 = [
475 dependency('x11-xcb'),
476 dependency('xcb'),
477 dependency('xcb-dri2', version : '>= 1.8'),
478 dependency('xcb-xfixes'),
479 ]
Dylan Baker32180562017-09-20 20:11:32 -0700480 pre_args += '-DHAVE_X11_PLATFORM'
Dylan Bakerd1992252017-09-14 17:57:17 -0700481 if with_dri3
482 dep_xcb_dri3 = [
483 dep_xcb_dri2,
484 dependency('xcb-dri3'),
485 dependency('xcb-present'),
486 dependency('xcb-sync'),
487 dependency('xshmfence', version : '>= 1.1'),
488 ]
489 else
490 # TODO: dri3 is required for vulkan
491 endif
492endif
493
494# TODO: platforms for !vulkan
495
496# TODO: dri paths
497
498# TODO: dri drivers
499
500# TODO: osmesa
501
502# TODO: egl
503
504# TODO: xa
505
506# TODO: vallium G3DVL
507
508# TODO: nine
509
510# TODO: clover
511
512# TODO: egl sans x11
513
514# TODO: xvmc
515
516# TODO: gallium tests
517
518# TODO: various libdirs
519
520# TODO: swr
521
522# TODO: gallium driver dirs
523
524# FIXME: this is a workaround for #2326
525prog_touch = find_program('touch')
526dummy_cpp = custom_target(
527 'dummy_cpp',
528 output : 'dummy.cpp',
529 command : [prog_touch, '@OUTPUT@'],
530)
531
532foreach a : pre_args
533 add_project_arguments(a, language : ['c', 'cpp'])
534endforeach
535foreach a : c_args
536 add_project_arguments(a, language : ['c'])
537endforeach
538foreach a : cpp_args
539 add_project_arguments(a, language : ['cpp'])
540endforeach
541
542inc_include = include_directories('include')
543
Dylan Baker32180562017-09-20 20:11:32 -0700544pkg = import('pkgconfig')
545
Dylan Bakerd1992252017-09-14 17:57:17 -0700546subdir('include')
547subdir('src')