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