meson: build gbm
[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_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
41 # XXX: yeah, do these
42 with_appledri = false
43 with_windowsdri = false
44
45 dri_drivers_path = get_option('dri-drivers-path')
46 if dri_drivers_path == ''
47 dri_drivers_path = join_paths(get_option('libdir'), 'dri')
48 endif
49
50 with_gles1 = get_option('gles1')
51 with_gles2 = get_option('gles2')
52 with_opengl = get_option('opengl')
53 with_any_opengl = with_opengl or with_gles1 or with_gles2
54 # Only build shared_glapi if at least one OpenGL API is enabled
55 with_shared_glapi = get_option('shared-glapi') and with_any_opengl
56
57 # TODO: these will need options, but at the moment they just control header
58 # installs
59 with_osmesa = false
60
61 # shared-glapi is required if at least two OpenGL APIs are being built
62 if not with_shared_glapi
63 if ((with_gles1 and with_gles2) or (with_gles1 and with_opengl)
64 or (with_gles2 and with_opengl))
65 error('shared-glapi required for building two or more of OpenGL, OpenGL ES 1.x, OpenGL ES 2.x')
66 endif
67 endif
68
69 # We require OpenGL for OpenGL ES
70 if (with_gles1 or with_gles2) and not with_opengl
71 error('building OpenGL ES without OpenGL is not supported.')
72 endif
73
74 with_dri = false
75 with_dri_i965 = false
76 _drivers = get_option('dri-drivers')
77 if _drivers != ''
78 _split = _drivers.split(',')
79 with_dri_i965 = _split.contains('i965')
80 with_dri = true
81 endif
82
83 if not with_dri
84 with_gles1 = false
85 with_gles2 = false
86 with_opengl = false
87 with_any_opengl = false
88 with_shared_glapi = false
89 endif
90
91 # TODO: other OSes
92 with_dri_platform = 'drm'
93
94 with_gallium = false
95 # TODO: gallium drivers
96
97 # TODO: conditionalize libdrm requirement
98 dep_libdrm = dependency('libdrm', version : '>= 2.4.75')
99 pre_args += '-DHAVE_LIBDRM'
100
101 with_dri2 = with_dri_platform == 'drm' and dep_libdrm.found()
102 with_dri3 = get_option('dri3')
103 if with_dri3 == 'auto'
104 if host_machine.system() == 'linux' and with_dri2
105 with_dri3 = true
106 else
107 with_dri3 = false
108 endif
109 elif with_dri3 == 'yes'
110 if not with_dri2
111 error('dri3 support requires libdrm')
112 endif
113 with_dri3 = true
114 else
115 with_dri3 = false
116 endif
117
118 # TODO: there are more platforms required for non-vulkan drivers
119 with_platform_wayland = false
120 with_platform_x11 = false
121 _platforms = get_option('platforms')
122 if _platforms != ''
123 _split = _platforms.split(',')
124 with_platform_x11 = _split.contains('x11')
125 with_platform_wayland = _split.contains('wayland')
126 endif
127
128 with_gbm = get_option('gbm')
129 if with_gbm == 'auto' and with_dri # TODO: or gallium
130 with_gbm = host_machine.system() == 'linux'
131 elif with_gbm == 'yes'
132 if not ['linux', 'bsd'].contains(host_machine.system())
133 error('GBM only supports unix-like platforms')
134 endif
135 with_gbm = true
136 else
137 with_gbm = false
138 endif
139
140 with_glx = get_option('glx')
141 if with_glx != 'disabled'
142 pre_args += '-DGLX_USE_TLS'
143 if not (with_platform_x11 and with_any_opengl) and with_glx != 'auto'
144 error('Cannot build GLX support without X11 platform support and at least one OpenGL API')
145 elif with_glx == 'gallium-xlib'
146 if not with_gallium
147 error('Gallium-xlib based GLX requires at least one gallium driver')
148 elif with_dri
149 error('gallium-xlib conflicts with any dri driver')
150 endif
151 elif with_glx == 'dri' and not with_dri
152 error('dri based GLX requires at least one DRI driver')
153 elif with_glx == 'auto'
154 if with_dri
155 with_glx = 'dri'
156 elif with_gallium
157 with_glx = 'gallium-xlib'
158 elif with_platform_x11 and with_any_opengl
159 with_glx = 'xlib'
160 else
161 with_glx = 'disabled'
162 endif
163 endif
164 endif
165
166 with_glvnd = get_option('glvnd')
167 if with_glvnd and with_glx != 'dri'
168 message('glvnd requires dri based glx')
169 endif
170
171 # TODO: toggle for this
172 with_glx_direct = true
173
174 if with_vulkan_icd_dir == ''
175 with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
176 endif
177
178 with_intel_vk = false
179 with_amd_vk = false
180 with_any_vk = false
181 _vulkan_drivers = get_option('vulkan-drivers')
182 if _vulkan_drivers != ''
183 _split = _vulkan_drivers.split(',')
184 with_intel_vk = _split.contains('intel')
185 with_amd_vk = _split.contains('amd')
186 with_any_vk = with_amd_vk or with_intel_vk
187 if not (with_platform_x11 or with_platform_wayland)
188 error('Vulkan requires at least one platform (x11, wayland)')
189 endif
190 if with_platform_x11 and not with_dri3
191 error('Vulkan drivers require dri3 for X11 support')
192 endif
193 endif
194
195 if with_dri # TODO: or gallium
196 if with_glx == 'disabled' # TODO: or egl
197 error('building dri or gallium drivers require at least one window system')
198 endif
199 endif
200
201 prog_python2 = find_program('python2')
202 has_mako = run_command(prog_python2, '-c', 'import mako')
203 if has_mako.returncode() != 0
204 error('Python (2.x) mako module required to build mesa.')
205 endif
206
207 cc = meson.get_compiler('c')
208 if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
209 error('When using GCC, version 4.4.6 or later is required.')
210 endif
211
212 # Define DEBUG for debug and debugoptimized builds
213 if get_option('buildtype').startswith('debug')
214 pre_args += '-DDEBUG'
215 endif
216
217 if get_option('shader-cache')
218 pre_args += '-DENABLE_SHADER_CACHE'
219 elif with_amd_vk
220 error('Radv requires shader cache support')
221 endif
222
223 # Check for GCC style builtins
224 foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
225 'ffsll', 'popcount', 'popcountll', 'unreachable']
226 if cc.has_function(b)
227 pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
228 endif
229 endforeach
230
231 # check for GCC __attribute__
232 foreach a : ['const', 'flatten', 'malloc', 'pure', 'unused',
233 'warn_unused_result', 'weak',]
234 if cc.compiles('int foo(void) __attribute__((@0@));'.format(a),
235 name : '__attribute__((@0@))'.format(a))
236 pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
237 endif
238 endforeach
239 if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
240 name : '__attribute__((format(...)))')
241 pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
242 endif
243 if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
244 name : '__attribute__((packed))')
245 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
246 endif
247 if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
248 name : '__attribute__((returns_nonnull))')
249 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NONNULL'
250 endif
251 if cc.compiles('''int foo_def(void) __attribute__((visibility("default")));
252 int foo_hid(void) __attribute__((visibility("hidden")));
253 int foo_int(void) __attribute__((visibility("internal")));
254 int foo_pro(void) __attribute__((visibility("protected")));''',
255 name : '__attribute__((visibility(...)))')
256 pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISBILITY'
257 endif
258 if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
259 name : '__attribute__((alias(...)))')
260 pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
261 endif
262
263 # TODO: this is very incomplete
264 if host_machine.system() == 'linux'
265 pre_args += '-D_GNU_SOURCE'
266 endif
267
268 # Check for generic C arguments
269 c_args = []
270 foreach a : ['-Wall', '-Werror=implicit-function-declaration',
271 '-Werror=missing-prototypes', '-fno-math-errno',
272 '-fno-trapping-math', '-Qunused-arguments']
273 if cc.has_argument(a)
274 c_args += a
275 endif
276 endforeach
277 c_vis_args = []
278 if cc.has_argument('-fvisibility=hidden')
279 c_vis_args += '-fvisibility=hidden'
280 endif
281
282 # Check for generic C++ arguments
283 cpp = meson.get_compiler('cpp')
284 cpp_args = []
285 foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math',
286 '-Qunused-arguments', '-Wno-non-virtual-dtor']
287 if cpp.has_argument(a)
288 cpp_args += a
289 endif
290 endforeach
291 cpp_vis_args = []
292 if cpp.has_argument('-fvisibility=hidden')
293 cpp_vis_args += '-fvisibility=hidden'
294 endif
295
296 # Check for C and C++ arguments for MSVC2013 compatibility. These are only used
297 # in parts of the mesa code base that need to compile with old versions of
298 # MSVC, mainly common code
299 c_msvc_compat_args = []
300 cpp_msvc_compat_args = []
301 foreach a : ['-Werror=pointer-arith', '-Werror=vla']
302 if cc.has_argument(a)
303 c_msvc_compat_args += a
304 endif
305 if cpp.has_argument(a)
306 cpp_msvc_compat_args += a
307 endif
308 endforeach
309
310 no_override_init_args = []
311 foreach a : ['-Wno-override-init', '-Wno-initializer-overrides']
312 if cc.has_argument(a)
313 no_override_init_args += a
314 endif
315 endforeach
316
317 # TODO: SSE41 (which is only required for core mesa)
318
319 # Check for GCC style atomics
320 if cc.compiles('int main() { int n; return __atomic_load_n(&n, __ATOMIC_ACQUIRE); }',
321 name : 'GCC atomic builtins')
322 pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
323 endif
324 if not cc.links('''#include <stdint.h>
325 uint64_t v;
326 int main() {
327 return __sync_add_and_fetch(&v, (uint64_t)1);
328 }''',
329 name : 'GCC 64bit atomics')
330 pre_args += '-DMISSING_64_BIT_ATOMICS'
331 endif
332
333 # TODO: endian
334 # TODO: powr8
335 # TODO: shared/static? Is this even worth doing?
336
337 # I don't think that I need to set any of the debug stuff, I think meson
338 # handles that for us
339
340 # TODO: ldflags
341
342 # TODO: texture-float (gallium/mesa only)
343
344 # TODO: cross-compiling. I don't think this is relavent to meson
345
346 # FIXME: enable asm when cross compiler
347 # This is doable (autotools does it), but it's not of immediate concern
348 if meson.is_cross_build()
349 message('Cross compiling, disabling asm')
350 with_asm = false
351 endif
352
353 with_asm_arch = ''
354 if with_asm
355 # TODO: SPARC and PPC
356 if host_machine.cpu_family() == 'x86'
357 if ['linux', 'bsd'].contains(host_machine.system()) # FIXME: hurd?
358 with_asm_arch = 'x86'
359 pre_args += ['-DUSE_X86_ASM', '-DUSE_MMX_ASM', '-DUSE_3DNOW_ASM',
360 '-DUSE_SSE_ASM']
361 endif
362 elif host_machine.cpu_family() == 'x86_64'
363 if host_machine.system() == 'linux'
364 with_asm_arch = 'x86_64'
365 pre_args += ['-DUSE_X86_64_ASM']
366 endif
367 elif host_machine.cpu_family() == 'arm'
368 if host_machine.system() == 'linux'
369 with_asm_arch = 'arm'
370 pre_args += ['-DUSE_ARM_ASM']
371 endif
372 elif host_machine.cpu_family() == 'aarch64'
373 if host_machine.system() == 'linux'
374 with_asm_arch = 'aarch64'
375 pre_args += ['-DUSE_AARCH64_ASM']
376 endif
377 endif
378 endif
379
380 # Check for standard headers and functions
381 if cc.has_header_symbol('sys/sysmacros.h', 'major')
382 pre_args += '-DMAJOR_IN_SYSMACROS'
383 elif cc.has_header_symbol('sys/mkdev.h', 'major')
384 pre_args += '-DMAJOR_IN_MKDEV'
385 endif
386
387 foreach h : ['xlocale.h', 'sys/sysctl.h']
388 if cc.has_header(h)
389 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
390 endif
391 endforeach
392
393 foreach f : ['strtof', 'mkostemp', 'posix_memalign']
394 if cc.has_function(f)
395 pre_args += '-DHAVE_@0@'.format(f.to_upper())
396 endif
397 endforeach
398
399 # strtod locale support
400 if cc.links('''
401 #define _GNU_SOURCE
402 #include <stdlib.h>
403 #include <locale.h>
404 #ifdef HAVE_XLOCALE_H
405 #include <xlocale.h>
406 #endif
407 int main() {
408 locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
409 const char *s = "1.0";
410 char *end;
411 double d = strtod_l(s, end, loc);
412 float f = strtod_l(s, end, loc);
413 freelocale(loc);
414 return 0;
415 }''',
416 extra_args : pre_args,
417 name : 'strtod has locale support')
418 pre_args += '-DHAVE_STRTOD_L'
419 endif
420
421 # Check for some linker flags
422 ld_args_bsymbolic = []
423 if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic')
424 ld_args_bsymbolic += '-Wl,-Bsymbolic'
425 endif
426 ld_args_gc_sections = []
427 if cc.links('static char unused() { return 5; } int main() { return 0; }',
428 args : '-Wl,--gc-sections')
429 ld_args_gc_sections += '-Wl,--gc-sections'
430 endif
431
432 # check for dl support
433 if cc.has_function('dlopen')
434 dep_dl = []
435 else
436 dep_dl = cc.find_library('dl')
437 endif
438 if cc.has_function('dladdr', dependencies : dep_dl)
439 # This is really only required for megadrivers
440 pre_args += '-DHAVE_DLADDR'
441 endif
442
443 if cc.has_function('dl_iterate_phdr')
444 pre_args += '-DHAVE_DL_ITERATE_PHDR'
445 else
446 # TODO: this is required for vulkan
447 endif
448
449 # Determine whether or not the rt library is needed for time functions
450 if cc.has_function('clock_gettime')
451 dep_clock = []
452 else
453 dep_clock = cc.find_library('rt')
454 endif
455
456 # TODO: some of these may be conditional
457 dep_zlib = dependency('zlib', version : '>= 1.2.3')
458 dep_thread = dependency('threads')
459 pre_args += '-DHAVE_PTHREAD'
460 dep_elf = dependency('libelf', required : false)
461 if not dep_elf.found()
462 dep_elf = cc.find_library('elf', required : with_amd_vk) # TODO: clover, r600, radeonsi
463 endif
464 dep_expat = dependency('expat')
465 # this only exists on linux so either this is linux and it will be found, or
466 # its not linux and and wont
467 dep_m = cc.find_library('m', required : false)
468
469 dep_libdrm_amdgpu = []
470 if with_amd_vk
471 dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.82')
472 endif
473
474 llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
475 if with_amd_vk
476 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
477 endif
478 dep_llvm = dependency(
479 'llvm', version : '>= 3.9.0', required : false, modules : llvm_modules,
480 )
481 if not dep_llvm.found()
482 if with_amd_vk
483 error('Radv requires llvm.')
484 endif
485 else
486 _llvm_version = dep_llvm.version().split('.')
487 # Development versions of LLVM have an 'svn' suffix, we don't want that for
488 # our version checks.
489 _llvm_patch = _llvm_version[2]
490 if _llvm_patch.endswith('svn')
491 _llvm_patch = _llvm_patch.split('s')[0]
492 endif
493 pre_args += [
494 '-DHAVE_LLVM=0x0@0@@1@@2@'.format(_llvm_version[0], _llvm_version[1], _llvm_patch),
495 '-DMESA_LLVM_VERSION_PATCH=@0@'.format(_llvm_patch),
496 ]
497 endif
498
499 dep_glvnd = []
500 if with_glvnd
501 dep_glvnd = dependency('libglvnd', version : '>= 0.2.0')
502 pre_args += '-DUSE_LIBGLVND=1'
503 endif
504
505 # TODO: make this conditional
506 dep_valgrind = dependency('valgrind', required : false)
507 if dep_valgrind.found() and with_valgrind
508 pre_args += '-DHAVE_VALGRIND'
509 endif
510
511 # pthread stubs. Lets not and say we didn't
512
513 prog_bison = find_program('bison', required : with_any_opengl)
514 prog_flex = find_program('flex', required : with_any_opengl)
515
516 # TODO: selinux
517 dep_selinux = []
518
519 # TODO: llvm-prefix and llvm-shared-libs
520
521 # TODO: unwind (llvm [radeon, gallivm] and gallium)
522
523 # TODO: flags for opengl, gles, dri
524
525 # TODO: gallium-hud
526
527 # TODO: glx provider
528
529 # TODO: osmesa provider
530
531 # TODO: flags for xa, egl, gbm, nin, xvmc, vdpau, omx, va, opencl,
532 # gallium-tests,
533
534 # TODO: gallium drivers
535
536 # TODO: symbol mangling
537
538 # TODO: egl configuration
539
540 if with_platform_wayland
541 prog_wl_scanner = find_program('wayland-scanner')
542 dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8')
543 dep_wayland_client = dependency('wayland-client', version : '>=1.11')
544 dep_wayland_server = dependency('wayland-server', version : '>=1.11')
545 else
546 prog_wl_scanner = []
547 dep_wl_protocols = []
548 dep_wayland_client = []
549 dep_wayland_server = []
550 endif
551
552 dep_xcb_dri2 = []
553 dep_xcb_dri3 = []
554 dep_dri2proto = []
555 dep_glproto = []
556 dep_x11 = []
557 dep_xf86vm = []
558 if with_platform_x11
559 if with_glx == 'xlib'
560 # TODO
561 error('TODO')
562 elif with_glx == 'gallium-xlib'
563 # TODO
564 error('TODO')
565 else
566 pre_args += '-DGLX_INDIRECT_RENDERING'
567 if with_glx_direct
568 pre_args += '-DGLX_DIRECT_RENDERING'
569 endif
570 if with_dri_platform == 'drm'
571 pre_args += '-DGLX_USE_DRM'
572 dep_dri2proto = dependency('dri2proto', version : '>= 2.8')
573 dep_x11 = [
574 dependency('x11'),
575 dependency('xext'),
576 dependency('xdamage', version : '>= 1.1'),
577 dependency('xfixes'),
578 dependency('x11-xcb'),
579 dependency('xcb'),
580 dependency('xcb-glx', version : '>= 1.8.1'),
581 ]
582
583 dep_xf86vm = dependency('xf86vm', required : false)
584 endif
585 # TODO: XF86VIDMODE
586 endif
587 if with_glx != 'disabled'
588 dep_glproto = dependency('glproto', version : '>= 1.4.14')
589 endif
590 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
591 dep_xcb_dri2 = [
592 dependency('x11-xcb'),
593 dependency('xcb'),
594 dependency('xcb-dri2', version : '>= 1.8'),
595 dependency('xcb-xfixes'),
596 ]
597 pre_args += '-DHAVE_X11_PLATFORM'
598 if with_dri3
599 pre_args += '-DHAVE_DRI3'
600 dep_xcb_dri3 = [
601 dep_xcb_dri2,
602 dependency('xcb-dri3'),
603 dependency('xcb-present'),
604 dependency('xcb-sync'),
605 dependency('xshmfence', version : '>= 1.1'),
606 ]
607 endif
608 endif
609 endif
610
611 # TODO: platforms for !vulkan
612
613 # TODO: osmesa
614
615 # TODO: egl
616
617 # TODO: xa
618
619 # TODO: vallium G3DVL
620
621 # TODO: nine
622
623 # TODO: clover
624
625 # TODO: egl sans x11
626
627 # TODO: xvmc
628
629 # TODO: gallium tests
630
631 # TODO: various libdirs
632
633 # TODO: swr
634
635 # TODO: gallium driver dirs
636
637 # FIXME: this is a workaround for #2326
638 prog_touch = find_program('touch')
639 dummy_cpp = custom_target(
640 'dummy_cpp',
641 output : 'dummy.cpp',
642 command : [prog_touch, '@OUTPUT@'],
643 )
644
645 foreach a : pre_args
646 add_project_arguments(a, language : ['c', 'cpp'])
647 endforeach
648 foreach a : c_args
649 add_project_arguments(a, language : ['c'])
650 endforeach
651 foreach a : cpp_args
652 add_project_arguments(a, language : ['cpp'])
653 endforeach
654
655 inc_include = include_directories('include')
656
657 pkg = import('pkgconfig')
658
659 subdir('include')
660 subdir('src')