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