meson: Build i965 and dri stack
[mesa.git] / meson.build
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', 'cpp_std=c++11'])
23
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++.
27 pre_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
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')
41
42 # XXX: yeah, do these
43 with_appledri = false
44 with_windowsdri = false
45
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')
51
52 # TODO: these will need options, but at the moment they just control header
53 # installs
54 with_glx = false
55 with_osmesa = false
56
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')
62 endif
63 endif
64
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.')
68 endif
69
70 with_dri = false
71 with_dri_i965 = false
72 _drivers = get_option('dri-drivers')
73 if _drivers != ''
74 _split = _drivers.split(',')
75 with_dri_i965 = _split.contains('i965')
76 with_dri = true
77 endif
78
79 if 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
85 endif
86
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')
91 if _platforms != ''
92 _split = _platforms.split(',')
93 with_platform_x11 = _split.contains('x11')
94 with_platform_wayland = _split.contains('wayland')
95 endif
96
97 if with_vulkan_icd_dir == ''
98 with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
99 endif
100
101 with_intel_vk = false
102 with_amd_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)')
110 endif
111 endif
112
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.')
117 endif
118
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.')
122 endif
123
124 # Define DEBUG for debug and debugoptimized builds
125 if get_option('buildtype').startswith('debug')
126 pre_args += '-DDEBUG'
127 endif
128
129 if get_option('shader-cache')
130 pre_args += '-DENABLE_SHADER_CACHE'
131 elif with_amd_vk
132 error('Radv requires shader cache support')
133 endif
134
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())
140 endif
141 endforeach
142
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())
149 endif
150 endforeach
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'
154 endif
155 if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
156 name : '__attribute__((packed))')
157 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
158 endif
159 if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
160 name : '__attribute__((returns_nonnull))')
161 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NONNULL'
162 endif
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'
169 endif
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'
173 endif
174
175 # TODO: this is very incomplete
176 if host_machine.system() == 'linux'
177 pre_args += '-D_GNU_SOURCE'
178 endif
179
180 # Check for generic C arguments
181 c_args = []
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)
186 c_args += a
187 endif
188 endforeach
189 c_vis_args = []
190 if cc.has_argument('-fvisibility=hidden')
191 c_vis_args += '-fvisibility=hidden'
192 endif
193
194 # Check for generic C++ arguments
195 cpp = meson.get_compiler('cpp')
196 cpp_args = []
197 foreach 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
202 endforeach
203 cpp_vis_args = []
204 if cpp.has_argument('-fvisibility=hidden')
205 cpp_vis_args += '-fvisibility=hidden'
206 endif
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
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
216 endif
217 if cpp.has_argument(a)
218 cpp_msvc_compat_args += a
219 endif
220 endforeach
221
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
226 endif
227 endforeach
228
229 # TODO: SSE41 (which is only required for core mesa)
230
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'
235 endif
236 if 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'
243 endif
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
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')
262 with_asm = false
263 endif
264
265 with_asm_arch = ''
266 if 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
290 endif
291
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'
297 endif
298
299 foreach h : ['xlocale.h', 'sys/sysctl.h']
300 if cc.has_header(h)
301 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
302 endif
303 endforeach
304
305 foreach f : ['strtof', 'mkostemp', 'posix_memalign']
306 if cc.has_function(f)
307 pre_args += '-DHAVE_@0@'.format(f.to_upper())
308 endif
309 endforeach
310
311 # strtod locale support
312 if 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'
331 endif
332
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'
337 endif
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'
342 endif
343
344 # check for dl support
345 if cc.has_function('dlopen')
346 dep_dl = []
347 else
348 dep_dl = cc.find_library('dl')
349 endif
350 if cc.has_function('dladdr', dependencies : dep_dl)
351 # This is really only required for megadrivers
352 pre_args += '-DHAVE_DLADDR'
353 endif
354
355 if cc.has_function('dl_iterate_phdr')
356 pre_args += '-DHAVE_DL_ITERATE_PHDR'
357 else
358 # TODO: this is required for vulkan
359 endif
360
361 # Determine whether or not the rt library is needed for time functions
362 if cc.has_function('clock_gettime')
363 dep_clock = []
364 else
365 dep_clock = cc.find_library('rt')
366 endif
367
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
375 endif
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)
380
381 # TODO: conditionalize libdrm requirement
382 dep_libdrm = dependency('libdrm', version : '>= 2.4.75')
383 pre_args += '-DHAVE_LIBDRM'
384 dep_libdrm_amdgpu = []
385 if with_amd_vk
386 dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.82')
387 endif
388
389 llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
390 if with_amd_vk
391 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
392 endif
393 dep_llvm = dependency(
394 'llvm', version : '>= 3.9.0', required : false, modules : llvm_modules,
395 )
396 if not dep_llvm.found()
397 if with_amd_vk
398 error('Radv requires llvm.')
399 endif
400 else
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 ]
412 endif
413
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'
418 endif
419
420 # pthread stubs. Lets not and say we didn't
421
422 prog_bison = find_program('bison', required : with_any_opengl)
423 prog_flex = find_program('flex', required : with_any_opengl)
424
425 # TODO: selinux
426 dep_selinux = []
427
428 # TODO: llvm-prefix and llvm-shared-libs
429
430 # 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
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')
464 else
465 prog_wl_scanner = []
466 dep_wl_protocols = []
467 dep_wayland_client = []
468 dep_wayland_server = []
469 endif
470
471 dep_xcb_dri2 = []
472 dep_xcb_dri3 = []
473 if 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 ]
480 pre_args += '-DHAVE_X11_PLATFORM'
481 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
492 endif
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
525 prog_touch = find_program('touch')
526 dummy_cpp = custom_target(
527 'dummy_cpp',
528 output : 'dummy.cpp',
529 command : [prog_touch, '@OUTPUT@'],
530 )
531
532 foreach a : pre_args
533 add_project_arguments(a, language : ['c', 'cpp'])
534 endforeach
535 foreach a : c_args
536 add_project_arguments(a, language : ['c'])
537 endforeach
538 foreach a : cpp_args
539 add_project_arguments(a, language : ['cpp'])
540 endforeach
541
542 inc_include = include_directories('include')
543
544 pkg = import('pkgconfig')
545
546 subdir('include')
547 subdir('src')