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