meson: Convert platform to auto
[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(
22 'mesa',
23 ['c', 'cpp'],
24 version : run_command(
25 [find_program('python', 'python2', 'python3'), 'bin/meson_get_version.py']
26 ).stdout(),
27 license : 'MIT',
28 meson_version : '>= 0.42',
29 default_options : ['buildtype=debugoptimized', 'c_std=c99', 'cpp_std=c++11']
30 )
31
32 # Arguments for the preprocessor, put these in a separate array from the C and
33 # C++ (cpp in meson terminology) arguments since they need to be added to the
34 # default arguments for both C and C++.
35 pre_args = [
36 '-D__STDC_CONSTANT_MACROS',
37 '-D__STDC_FORMAT_MACROS',
38 '-D__STDC_LIMIT_MACROS',
39 '-DVERSION="@0@"'.format(meson.project_version()),
40 '-DPACKAGE_VERSION=VERSION',
41 '-DPACKAGE_BUGREPORT="https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa"',
42 ]
43
44 with_vulkan_icd_dir = get_option('vulkan-icd-dir')
45 with_tests = get_option('build-tests')
46 with_valgrind = get_option('valgrind')
47 with_libunwind = get_option('libunwind')
48 with_asm = get_option('asm')
49 with_llvm = get_option('llvm')
50 with_osmesa = get_option('osmesa')
51 if get_option('texture-float')
52 pre_args += '-DTEXTURE_FLOAT_ENABLED'
53 message('WARNING: Floating-point texture enabled. Please consult docs/patents.txt and your lawyer before building mesa.')
54 endif
55
56 # XXX: yeah, do these
57 with_appledri = false
58 with_windowsdri = false
59
60 dri_drivers_path = get_option('dri-drivers-path')
61 if dri_drivers_path == ''
62 dri_drivers_path = join_paths(get_option('libdir'), 'dri')
63 endif
64
65 with_gles1 = get_option('gles1')
66 with_gles2 = get_option('gles2')
67 with_opengl = get_option('opengl')
68 with_any_opengl = with_opengl or with_gles1 or with_gles2
69 # Only build shared_glapi if at least one OpenGL API is enabled
70 with_shared_glapi = get_option('shared-glapi') and with_any_opengl
71
72
73 # shared-glapi is required if at least two OpenGL APIs are being built
74 if not with_shared_glapi
75 if ((with_gles1 and with_gles2) or (with_gles1 and with_opengl)
76 or (with_gles2 and with_opengl))
77 error('shared-glapi required for building two or more of OpenGL, OpenGL ES 1.x, OpenGL ES 2.x')
78 endif
79 endif
80
81 # We require OpenGL for OpenGL ES
82 if (with_gles1 or with_gles2) and not with_opengl
83 error('building OpenGL ES without OpenGL is not supported.')
84 endif
85
86 with_dri = false
87 with_dri_i915 = false
88 with_dri_i965 = false
89 with_dri_r100 = false
90 with_dri_r200 = false
91 with_dri_nouveau = false
92 with_dri_swrast = false
93 _drivers = get_option('dri-drivers')
94 if _drivers == 'auto'
95 # TODO: PPC, Sparc
96 if not ['darwin', 'windows'].contains(host_machine.system())
97 if ['x86', 'x86_64'].contains(host_machine.cpu_family())
98 _drivers = 'i915,i965,r100,r200,nouveau'
99 else
100 error('Unknown architecture. Please pass -Ddri-drivers to set driver options. Patches gladly accepted to fix this.')
101 endif
102 else
103 error('Unknown OS. Please pass -Ddri-drivers to set driver options. Patches gladly accepted to fix this.')
104 endif
105 endif
106 if _drivers != ''
107 _split = _drivers.split(',')
108 with_dri_i915 = _split.contains('i915')
109 with_dri_i965 = _split.contains('i965')
110 with_dri_r100 = _split.contains('r100')
111 with_dri_r200 = _split.contains('r200')
112 with_dri_nouveau = _split.contains('nouveau')
113 with_dri_swrast = _split.contains('swrast')
114 with_dri = true
115 endif
116
117 with_gallium = false
118 with_gallium_pl111 = false
119 with_gallium_radeonsi = false
120 with_gallium_nouveau = false
121 with_gallium_freedreno = false
122 with_gallium_softpipe = false
123 with_gallium_vc4 = false
124 with_gallium_vc5 = false
125 with_gallium_etnaviv = false
126 with_gallium_imx = false
127 _drivers = get_option('gallium-drivers')
128 if _drivers == 'auto'
129 if not ['darwin', 'windows'].contains(host_machine.system())
130 # TODO: PPC, Sparc
131 if ['x86', 'x86_64'].contains(host_machine.cpu_family())
132 _drivers = 'radeonsi,nouveau,swrast'
133 elif ['arm', 'aarch64'].contains(host_machine.cpu_family())
134 _drivers = 'pl111,vc4,vc5,freedreno,etnaviv,imx,swrast'
135 else
136 error('Unknown architecture. Please pass -Dgallium-drivers to set driver options. Patches gladly accepted to fix this.')
137 endif
138 else
139 error('Unknown OS. Please pass -Dgallium-drivers to set driver options. Patches gladly accepted to fix this.')
140 endif
141 endif
142 if _drivers != ''
143 _split = _drivers.split(',')
144 with_gallium_pl111 = _split.contains('pl111')
145 with_gallium_radeonsi = _split.contains('radeonsi')
146 with_gallium_nouveau = _split.contains('nouveau')
147 with_gallium_freedreno = _split.contains('freedreno')
148 with_gallium_softpipe = _split.contains('swrast')
149 with_gallium_vc4 = _split.contains('vc4')
150 with_gallium_vc5 = _split.contains('vc5')
151 with_gallium_etnaviv = _split.contains('etnaviv')
152 with_gallium_imx = _split.contains('imx')
153 with_gallium = true
154 endif
155
156 with_intel_vk = false
157 with_amd_vk = false
158 with_any_vk = false
159 _vulkan_drivers = get_option('vulkan-drivers')
160 if _vulkan_drivers == 'auto'
161 if not ['darwin', 'windows'].contains(host_machine.system())
162 if host_machine.cpu_family().startswith('x86')
163 _vulkan_drivers = 'amd,intel'
164 else
165 error('Unknown architecture. Please pass -Dvulkan-drivers to set driver options. Patches gladly accepted to fix this.')
166 endif
167 else
168 # No vulkan driver supports windows or macOS currently
169 _vulkan_drivers = ''
170 endif
171 endif
172 if _vulkan_drivers != ''
173 _split = _vulkan_drivers.split(',')
174 with_intel_vk = _split.contains('intel')
175 with_amd_vk = _split.contains('amd')
176 with_any_vk = with_amd_vk or with_intel_vk
177 endif
178
179 if with_dri_swrast and with_gallium_softpipe
180 error('Only one swrast provider can be built')
181 endif
182 if with_gallium_imx and not with_gallium_etnaviv
183 error('IMX driver requires etnaviv driver')
184 endif
185
186 dep_libdrm_intel = []
187 if with_dri_i915
188 dep_libdrm_intel = dependency('libdrm_intel', version : '>= 2.4.75')
189 endif
190
191 # TODO: other OSes
192 with_dri_platform = 'drm'
193
194 with_platform_android = false
195 with_platform_wayland = false
196 with_platform_x11 = false
197 with_platform_drm = false
198 with_platform_surfaceless = false
199 egl_native_platform = ''
200 _platforms = get_option('platforms')
201 if _platforms == 'auto'
202 if ['linux'].contains(host_machine.system())
203 _platforms = 'x11,wayland,drm,surfaceless'
204 else
205 error('Unknown OS, no platforms enabled. Patches gladly accepted to fix this.')
206 endif
207 endif
208 if _platforms != ''
209 _split = _platforms.split(',')
210 with_platform_android = _split.contains('android')
211 with_platform_x11 = _split.contains('x11')
212 with_platform_wayland = _split.contains('wayland')
213 with_platform_drm = _split.contains('drm')
214 with_platform_surfaceless = _split.contains('surfaceless')
215 egl_native_platform = _split[0]
216 endif
217
218 with_glx = get_option('glx')
219 if with_glx == 'auto'
220 if with_dri
221 with_glx = 'dri'
222 elif with_gallium
223 # Even when building just gallium drivers the user probably wants dri
224 with_glx = 'dri'
225 with_dri = true
226 elif with_platform_x11 and with_any_opengl and not with_any_vk
227 # The automatic behavior should not be to turn on xlib based glx when
228 # building only vulkan drivers
229 with_glx = 'xlib'
230 else
231 with_glx = 'disabled'
232 endif
233 endif
234
235 if not (with_dri or with_gallium or with_glx == 'xlib' or with_glx == 'gallium-xlib')
236 with_gles1 = false
237 with_gles2 = false
238 with_opengl = false
239 with_any_opengl = false
240 with_shared_glapi = false
241 endif
242
243 with_gbm = get_option('gbm')
244 if with_gbm == 'auto' and with_dri # TODO: or gallium
245 with_gbm = host_machine.system() == 'linux'
246 elif with_gbm == 'true'
247 if not ['linux', 'bsd'].contains(host_machine.system())
248 error('GBM only supports unix-like platforms')
249 endif
250 with_gbm = true
251 else
252 with_gbm = false
253 endif
254
255 _egl = get_option('egl')
256 if _egl == 'auto'
257 with_egl = with_dri and with_shared_glapi and egl_native_platform != ''
258 elif _egl == 'true'
259 if not with_dri
260 error('EGL requires dri')
261 elif not with_shared_glapi
262 error('EGL requires shared-glapi')
263 elif egl_native_platform == ''
264 error('No platforms specified, consider -Dplatforms=drm,x11 at least')
265 endif
266 with_egl = true
267 else
268 with_egl = false
269 endif
270
271 # TODO: or virgl
272 if with_egl and with_gallium_radeonsi and not (with_platform_drm or with_platform_surfaceless)
273 error('RadeonSI requires drm or surfaceless platform when using EGL')
274 endif
275
276 pre_args += '-DGLX_USE_TLS'
277 if with_glx != 'disabled'
278 if not (with_platform_x11 and with_any_opengl)
279 if with_glx == 'auto'
280 with_glx = 'disabled'
281 else
282 error('Cannot build GLX support without X11 platform support and at least one OpenGL API')
283 endif
284 elif with_glx == 'gallium-xlib'
285 if not with_gallium
286 error('Gallium-xlib based GLX requires at least one gallium driver')
287 elif not with_gallium_softpipe
288 error('Gallium-xlib based GLX requires softpipe or llvmpipe.')
289 elif with_dri
290 error('gallium-xlib conflicts with any dri driver')
291 endif
292 elif with_glx == 'xlib'
293 if with_dri
294 error('xlib conflicts with any dri driver')
295 endif
296 elif with_glx == 'dri' and not with_dri
297 error('dri based GLX requires at least one DRI driver')
298 endif
299 endif
300
301 with_glvnd = get_option('glvnd')
302 if with_glvnd
303 if with_glx == 'xlib' or with_glx == 'gallium-xlib'
304 error('Cannot build glvnd support for GLX that is not DRI based.')
305 elif with_glx == 'disabled' and not with_egl
306 error('glvnd requires DRI based GLX and/or EGL')
307 endif
308 endif
309
310 # TODO: toggle for this
311 with_glx_direct = true
312
313 if with_vulkan_icd_dir == ''
314 with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
315 endif
316
317 with_dri2 = (with_dri or with_any_vk) and with_dri_platform == 'drm'
318 with_dri3 = get_option('dri3')
319 if with_dri3 == 'auto'
320 if host_machine.system() == 'linux' and with_dri2
321 with_dri3 = true
322 else
323 with_dri3 = false
324 endif
325 elif with_dri3 == 'true'
326 with_dri3 = true
327 else
328 with_dri3 = false
329 endif
330
331 if with_any_vk and (with_platform_x11 and not with_dri3)
332 error('Vulkan drivers require dri3 for X11 support')
333 endif
334 if with_dri or with_gallium
335 if with_glx == 'disabled' and not with_egl
336 error('building dri or gallium drivers require at least one window system')
337 endif
338 endif
339
340 with_gallium_xvmc = false
341 with_gallium_vdpau = false
342 with_gallium_omx = false # this is bellagio
343 with_gallium_va = false
344 with_gallium_media = false
345 dep_va = []
346 _drivers = get_option('gallium-media')
347 if _drivers != ''
348 _split = _drivers.split(',')
349 with_gallium_xvmc = _split.contains('xvmc')
350 with_gallium_vdpau = _split.contains('vdpau')
351 with_gallium_omx = _split.contains('omx')
352 with_gallium_va = _split.contains('va')
353 with_gallium_media = (with_gallium_xvmc or with_gallium_vdpau or
354 with_gallium_omx or with_gallium_va)
355 endif
356
357 gl_pkgconfig_c_flags = []
358 if with_platform_x11
359 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
360 pre_args += '-DHAVE_X11_PLATFORM'
361 endif
362 if with_glx == 'xlib' or with_glx == 'gallium-xlib'
363 pre_args += '-DUSE_XSHM'
364 else
365 pre_args += '-DGLX_INDIRECT_RENDERING'
366 if with_glx_direct
367 pre_args += '-DGLX_DIRECT_RENDERING'
368 endif
369 if with_dri_platform == 'drm'
370 pre_args += '-DGLX_USE_DRM'
371 endif
372 endif
373 else
374 pre_args += '-DMESA_EGL_NO_X11_HEADERS'
375 gl_pkgconfig_c_flags += '-DMESA_EGL_NO_X11_HEADERS'
376 endif
377 if with_platform_drm
378 if with_egl and not with_gbm
379 error('EGL drm platform requires gbm')
380 endif
381 pre_args += '-DHAVE_DRM_PLATFORM'
382 endif
383 if with_platform_surfaceless
384 pre_args += '-DHAVE_SURFACELESS_PLATFORM'
385 endif
386 if with_platform_android
387 dep_android = [
388 dependency('cutils'),
389 dependency('hardware'),
390 dependency('sync'),
391 ]
392 pre_args += '-DHAVE_ANDROID_PLATFORM'
393 endif
394
395 prog_python2 = find_program('python2')
396 has_mako = run_command(prog_python2, '-c', 'import mako')
397 if has_mako.returncode() != 0
398 error('Python (2.x) mako module required to build mesa.')
399 endif
400
401 cc = meson.get_compiler('c')
402 if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
403 error('When using GCC, version 4.4.6 or later is required.')
404 endif
405
406 # Define DEBUG for debug builds only (debugoptimized is not included on this one)
407 if get_option('buildtype') == 'debug'
408 pre_args += '-DDEBUG'
409 endif
410
411 if get_option('shader-cache')
412 pre_args += '-DENABLE_SHADER_CACHE'
413 elif with_amd_vk
414 error('Radv requires shader cache support')
415 endif
416
417 # Check for GCC style builtins
418 foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
419 'ffsll', 'popcount', 'popcountll', 'unreachable']
420 if cc.has_function(b)
421 pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
422 endif
423 endforeach
424
425 # check for GCC __attribute__
426 foreach a : ['const', 'flatten', 'malloc', 'pure', 'unused',
427 'warn_unused_result', 'weak',]
428 if cc.compiles('int foo(void) __attribute__((@0@));'.format(a),
429 name : '__attribute__((@0@))'.format(a))
430 pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
431 endif
432 endforeach
433 if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
434 name : '__attribute__((format(...)))')
435 pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
436 endif
437 if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
438 name : '__attribute__((packed))')
439 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
440 endif
441 if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
442 name : '__attribute__((returns_nonnull))')
443 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NONNULL'
444 endif
445 if cc.compiles('''int foo_def(void) __attribute__((visibility("default")));
446 int foo_hid(void) __attribute__((visibility("hidden")));
447 int foo_int(void) __attribute__((visibility("internal")));
448 int foo_pro(void) __attribute__((visibility("protected")));''',
449 name : '__attribute__((visibility(...)))')
450 pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISBILITY'
451 endif
452 if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
453 name : '__attribute__((alias(...)))')
454 pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
455 endif
456
457 # TODO: this is very incomplete
458 if host_machine.system() == 'linux'
459 pre_args += '-D_GNU_SOURCE'
460 endif
461
462 # Check for generic C arguments
463 c_args = []
464 foreach a : ['-Wall', '-Werror=implicit-function-declaration',
465 '-Werror=missing-prototypes', '-fno-math-errno',
466 '-fno-trapping-math', '-Qunused-arguments']
467 if cc.has_argument(a)
468 c_args += a
469 endif
470 endforeach
471 c_vis_args = []
472 if cc.has_argument('-fvisibility=hidden')
473 c_vis_args += '-fvisibility=hidden'
474 endif
475
476 # Check for generic C++ arguments
477 cpp = meson.get_compiler('cpp')
478 cpp_args = []
479 foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math',
480 '-Qunused-arguments', '-Wno-non-virtual-dtor']
481 if cpp.has_argument(a)
482 cpp_args += a
483 endif
484 endforeach
485 cpp_vis_args = []
486 if cpp.has_argument('-fvisibility=hidden')
487 cpp_vis_args += '-fvisibility=hidden'
488 endif
489
490 # Check for C and C++ arguments for MSVC2013 compatibility. These are only used
491 # in parts of the mesa code base that need to compile with old versions of
492 # MSVC, mainly common code
493 c_msvc_compat_args = []
494 cpp_msvc_compat_args = []
495 foreach a : ['-Werror=pointer-arith', '-Werror=vla']
496 if cc.has_argument(a)
497 c_msvc_compat_args += a
498 endif
499 if cpp.has_argument(a)
500 cpp_msvc_compat_args += a
501 endif
502 endforeach
503
504 no_override_init_args = []
505 foreach a : ['-Wno-override-init', '-Wno-initializer-overrides']
506 if cc.has_argument(a)
507 no_override_init_args += a
508 endif
509 endforeach
510
511 if host_machine.cpu_family().startswith('x86')
512 pre_args += '-DHAVE_SSE41'
513 with_sse41 = true
514 sse41_args = ['-msse4.1']
515
516 # GCC on x86 (not x86_64) with -msse* assumes a 16 byte aligned stack, but
517 # that's not guaranteed
518 if host_machine.cpu_family() == 'x86'
519 sse41_args += '-mstackrealign'
520 endif
521 else
522 with_sse41 = false
523 sse41_args = []
524 endif
525
526 # Check for GCC style atomics
527 if cc.compiles('int main() { int n; return __atomic_load_n(&n, __ATOMIC_ACQUIRE); }',
528 name : 'GCC atomic builtins')
529 pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
530 endif
531 if not cc.links('''#include <stdint.h>
532 uint64_t v;
533 int main() {
534 return __sync_add_and_fetch(&v, (uint64_t)1);
535 }''',
536 name : 'GCC 64bit atomics')
537 pre_args += '-DMISSING_64_BIT_ATOMICS'
538 endif
539
540 # TODO: endian
541 # TODO: powr8
542 # TODO: shared/static? Is this even worth doing?
543
544 # Building x86 assembly code requires running x86 binaries. It is possible for
545 # x86_64 OSes to run x86 binaries, so don't disable asm in those cases
546 # TODO: it should be possible to use an exe_wrapper to run the binary during
547 # the build.
548 if meson.is_cross_build()
549 if not (build_machine.cpu_family() == 'x86_64' and host_machine.cpu_family() == 'x86'
550 and build_machine.system() == host_machine.system())
551 message('Cross compiling to x86 from non-x86, disabling asm')
552 with_asm = false
553 endif
554 endif
555
556 with_asm_arch = ''
557 if with_asm
558 # TODO: SPARC and PPC
559 if host_machine.cpu_family() == 'x86'
560 if ['linux', 'bsd'].contains(host_machine.system()) # FIXME: hurd?
561 with_asm_arch = 'x86'
562 pre_args += ['-DUSE_X86_ASM', '-DUSE_MMX_ASM', '-DUSE_3DNOW_ASM',
563 '-DUSE_SSE_ASM']
564 endif
565 elif host_machine.cpu_family() == 'x86_64'
566 if host_machine.system() == 'linux'
567 with_asm_arch = 'x86_64'
568 pre_args += ['-DUSE_X86_64_ASM']
569 endif
570 elif host_machine.cpu_family() == 'arm'
571 if host_machine.system() == 'linux'
572 with_asm_arch = 'arm'
573 pre_args += ['-DUSE_ARM_ASM']
574 endif
575 elif host_machine.cpu_family() == 'aarch64'
576 if host_machine.system() == 'linux'
577 with_asm_arch = 'aarch64'
578 pre_args += ['-DUSE_AARCH64_ASM']
579 endif
580 endif
581 endif
582
583 # Check for standard headers and functions
584 if cc.has_header_symbol('sys/sysmacros.h', 'major')
585 pre_args += '-DMAJOR_IN_SYSMACROS'
586 elif cc.has_header_symbol('sys/mkdev.h', 'major')
587 pre_args += '-DMAJOR_IN_MKDEV'
588 endif
589
590 foreach h : ['xlocale.h', 'sys/sysctl.h', 'linux/futex.h']
591 if cc.has_header(h)
592 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
593 endif
594 endforeach
595
596 foreach f : ['strtof', 'mkostemp', 'posix_memalign', 'timespec_get']
597 if cc.has_function(f)
598 pre_args += '-DHAVE_@0@'.format(f.to_upper())
599 endif
600 endforeach
601
602 # strtod locale support
603 if cc.links('''
604 #define _GNU_SOURCE
605 #include <stdlib.h>
606 #include <locale.h>
607 #ifdef HAVE_XLOCALE_H
608 #include <xlocale.h>
609 #endif
610 int main() {
611 locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
612 const char *s = "1.0";
613 char *end;
614 double d = strtod_l(s, end, loc);
615 float f = strtod_l(s, end, loc);
616 freelocale(loc);
617 return 0;
618 }''',
619 extra_args : pre_args,
620 name : 'strtod has locale support')
621 pre_args += '-DHAVE_STRTOD_L'
622 endif
623
624 # Check for some linker flags
625 ld_args_bsymbolic = []
626 if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic', name : 'Bsymbolic')
627 ld_args_bsymbolic += '-Wl,-Bsymbolic'
628 endif
629 ld_args_gc_sections = []
630 if cc.links('static char unused() { return 5; } int main() { return 0; }',
631 args : '-Wl,--gc-sections', name : 'gc-sections')
632 ld_args_gc_sections += '-Wl,--gc-sections'
633 endif
634 with_ld_version_script = false
635 if cc.links('int main() { return 0; }',
636 args : '-Wl,--version-script=@0@'.format(
637 join_paths(meson.source_root(), 'build-support/conftest.map')),
638 name : 'version-script')
639 with_ld_version_script = true
640 endif
641 with_ld_dynamic_list = false
642 if cc.links('int main() { return 0; }',
643 args : '-Wl,--dynamic-list=@0@'.format(
644 join_paths(meson.source_root(), 'build-support/conftest.dyn')),
645 name : 'dynamic-list')
646 with_ld_dynamic_list = true
647 endif
648
649 # check for dl support
650 if cc.has_function('dlopen')
651 dep_dl = []
652 else
653 dep_dl = cc.find_library('dl')
654 endif
655 if cc.has_function('dladdr', dependencies : dep_dl)
656 # This is really only required for megadrivers
657 pre_args += '-DHAVE_DLADDR'
658 endif
659
660 if cc.has_function('dl_iterate_phdr')
661 pre_args += '-DHAVE_DL_ITERATE_PHDR'
662 elif with_intel_vk
663 error('Intel "Anvil" Vulkan driver requires the dl_iterate_phdr function')
664 elif with_dri_i965 and get_option('shader-cache')
665 error('Intel i965 GL driver requires dl_iterate_phdr when built with shader caching.')
666 endif
667
668 # Determine whether or not the rt library is needed for time functions
669 if cc.has_function('clock_gettime')
670 dep_clock = []
671 else
672 dep_clock = cc.find_library('rt')
673 endif
674
675 with_gallium_drisw_kms = false
676 dep_libdrm = dependency('libdrm', version : '>= 2.4.75',
677 required : with_dri2 or with_dri3)
678 if dep_libdrm.found()
679 pre_args += '-DHAVE_LIBDRM'
680 if with_dri_platform == 'drm' and with_dri
681 with_gallium_drisw_kms = true
682 endif
683 endif
684
685 # TODO: some of these may be conditional
686 dep_zlib = dependency('zlib', version : '>= 1.2.3')
687 dep_thread = dependency('threads')
688 if dep_thread.found() and host_machine.system() != 'windows'
689 pre_args += '-DHAVE_PTHREAD'
690 endif
691 dep_elf = dependency('libelf', required : false)
692 if not dep_elf.found() and (with_amd_vk or with_gallium_radeonsi) # TODO: clover, r600
693 dep_elf = cc.find_library('elf')
694 endif
695 dep_expat = dependency('expat')
696 # this only exists on linux so either this is linux and it will be found, or
697 # its not linux and and wont
698 dep_m = cc.find_library('m', required : false)
699
700 dep_libdrm_amdgpu = []
701 dep_libdrm_radeon = []
702 dep_libdrm_nouveau = []
703 dep_libdrm_etnaviv = []
704 dep_libdrm_freedreno = []
705 if with_amd_vk or with_gallium_radeonsi
706 dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.88')
707 endif
708 if with_gallium_radeonsi or with_dri_r100 or with_dri_r200
709 dep_libdrm_radeon = dependency('libdrm_radeon', version : '>= 2.4.71')
710 endif
711 if with_gallium_nouveau or with_dri_nouveau
712 dep_libdrm_nouveau = dependency('libdrm_nouveau', version : '>= 2.4.66')
713 endif
714 if with_gallium_etnaviv
715 dep_libdrm_etnaviv = dependency('libdrm_etnaviv', version : '>= 2.4.82')
716 endif
717 if with_gallium_freedreno
718 dep_libdrm_freedreno = dependency('libdrm_freedreno', version : '>= 2.4.74')
719 endif
720
721 llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
722 if with_amd_vk
723 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
724 endif
725 dep_llvm = []
726 if with_llvm
727 dep_llvm = dependency(
728 'llvm', version : '>= 3.9.0', required : with_amd_vk, modules : llvm_modules,
729 )
730 if dep_llvm.found()
731 _llvm_version = dep_llvm.version().split('.')
732 # Development versions of LLVM have an 'svn' suffix, we don't want that for
733 # our version checks.
734 _llvm_patch = _llvm_version[2]
735 if _llvm_patch.endswith('svn')
736 _llvm_patch = _llvm_patch.split('s')[0]
737 endif
738 pre_args += [
739 '-DHAVE_LLVM=0x0@0@@1@@2@'.format(_llvm_version[0], _llvm_version[1], _llvm_patch),
740 '-DMESA_LLVM_VERSION_PATCH=@0@'.format(_llvm_patch),
741 ]
742 else
743 if with_gallium_softpipe
744 error('Cannot find LLVM to build LLVMPipe. If you wanted softpipe pass -Dllvm=false to meson')
745 elif with_amd_vk or with_gallium_radeonsi # etc
746 error('The following drivers requires LLVM: Radv, RadeonSI. One of these is enabled, but LLVM was not found.')
747 endif
748 endif
749 elif with_amd_vk or with_gallium_radeonsi
750 error('The following drivers requires LLVM: Radv, RadeonSI. One of these is enabled, but LLVM is disabled.')
751 endif
752
753 dep_glvnd = []
754 if with_glvnd
755 dep_glvnd = dependency('libglvnd', version : '>= 0.2.0')
756 pre_args += '-DUSE_LIBGLVND=1'
757 endif
758
759 if with_valgrind != 'false'
760 dep_valgrind = dependency('valgrind', required : with_valgrind == 'true')
761 if dep_valgrind.found()
762 pre_args += '-DHAVE_VALGRIND'
763 endif
764 else
765 dep_valgrind = []
766 endif
767
768 # pthread stubs. Lets not and say we didn't
769
770 prog_bison = find_program('bison', required : with_any_opengl)
771 prog_flex = find_program('flex', required : with_any_opengl)
772
773 dep_selinux = []
774 if get_option('selinux')
775 dep_selinux = dependency('libselinux')
776 pre_args += '-DMESA_SELINUX'
777 endif
778
779 # TODO: llvm-prefix and llvm-shared-libs
780
781 if with_libunwind != 'false'
782 dep_unwind = dependency('libunwind', required : with_libunwind == 'true')
783 if dep_unwind.found()
784 pre_args += '-DHAVE_LIBUNWIND'
785 endif
786 else
787 dep_unwind = []
788 endif
789
790 # TODO: gallium-hud
791
792 if with_osmesa != 'none'
793 if with_osmesa == 'classic' and not with_dri_swrast
794 error('OSMesa classic requires dri (classic) swrast.')
795 endif
796 if with_osmesa == 'gallium' and not with_gallium_softpipe
797 error('OSMesa gallium requires gallium softpipe or llvmpipe.')
798 endif
799 osmesa_lib_name = 'OSMesa'
800 osmesa_bits = get_option('osmesa-bits')
801 if osmesa_bits != '8'
802 if with_dri or with_glx != 'disabled'
803 error('OSMesa bits must be 8 if building glx or dir based drivers')
804 endif
805 osmesa_lib_name = osmesa_lib_name + osmesa_bits
806 pre_args += [
807 '-DCHAN_BITS=@0@'.format(osmesa_bits), '-DDEFAULT_SOFTWARE_DEPTH_BITS=31'
808 ]
809 endif
810 endif
811
812 # TODO: symbol mangling
813
814 if with_platform_wayland
815 prog_wl_scanner = find_program('wayland-scanner')
816 dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8')
817 dep_wayland_client = dependency('wayland-client', version : '>=1.11')
818 dep_wayland_server = dependency('wayland-server', version : '>=1.11')
819 wayland_dmabuf_xml = join_paths(
820 dep_wl_protocols.get_pkgconfig_variable('pkgdatadir'), 'unstable',
821 'linux-dmabuf', 'linux-dmabuf-unstable-v1.xml'
822 )
823 pre_args += ['-DHAVE_WAYLAND_PLATFORM', '-DWL_HIDE_DEPRECATED']
824 else
825 prog_wl_scanner = []
826 dep_wl_protocols = []
827 dep_wayland_client = []
828 dep_wayland_server = []
829 wayland_dmabuf_xml = ''
830 endif
831
832 dep_x11 = []
833 dep_xext = []
834 dep_xdamage = []
835 dep_xfixes = []
836 dep_x11_xcb = []
837 dep_xcb = []
838 dep_xcb_glx = []
839 dep_xcb_dri2 = []
840 dep_xcb_dri3 = []
841 dep_dri2proto = []
842 dep_glproto = []
843 dep_xxf86vm = []
844 dep_xcb_dri3 = []
845 dep_xcb_present = []
846 dep_xcb_sync = []
847 dep_xcb_xfixes = []
848 dep_xshmfence = []
849 if with_platform_x11
850 if with_glx == 'xlib' or with_glx == 'gallium-xlib'
851 dep_x11 = dependency('x11')
852 dep_xext = dependency('xext')
853 dep_xcb = dependency('xcb')
854 elif with_glx == 'dri' and with_dri_platform == 'drm'
855 dep_x11 = dependency('x11')
856 dep_xext = dependency('xext')
857 dep_xdamage = dependency('xdamage', version : '>= 1.1')
858 dep_xfixes = dependency('xfixes')
859 dep_xcb_glx = dependency('xcb-glx', version : '>= 1.8.1')
860 dep_xxf86vm = dependency('xxf86vm', required : false)
861 endif
862 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
863 dep_xcb = dependency('xcb')
864 dep_x11_xcb = dependency('x11-xcb')
865 dep_xcb_dri2 = dependency('xcb-dri2', version : '>= 1.8')
866
867 if with_dri3
868 pre_args += '-DHAVE_DRI3'
869 dep_xcb_dri3 = dependency('xcb-dri3')
870 dep_xcb_present = dependency('xcb-present')
871 dep_xcb_sync = dependency('xcb-sync')
872 dep_xshmfence = dependency('xshmfence', version : '>= 1.1')
873 endif
874 endif
875 if with_glx == 'dri'
876 dep_dri2proto = dependency('dri2proto', version : '>= 2.8')
877 dep_glproto = dependency('glproto', version : '>= 1.4.14')
878 endif
879 if with_egl
880 dep_xcb_xfixes = dependency('xcb-xfixes')
881 endif
882 endif
883
884 # TODO: nine
885
886 # TODO: clover
887
888 # TODO: gallium tests
889
890 # TODO: various libdirs
891
892 # TODO: swr
893
894 # TODO: gallium driver dirs
895
896 # FIXME: this is a workaround for #2326
897 prog_touch = find_program('touch')
898 dummy_cpp = custom_target(
899 'dummy_cpp',
900 output : 'dummy.cpp',
901 command : [prog_touch, '@OUTPUT@'],
902 )
903
904 foreach a : pre_args
905 add_project_arguments(a, language : ['c', 'cpp'])
906 endforeach
907 foreach a : c_args
908 add_project_arguments(a, language : ['c'])
909 endforeach
910 foreach a : cpp_args
911 add_project_arguments(a, language : ['cpp'])
912 endforeach
913
914 inc_include = include_directories('include')
915
916 gl_priv_reqs = [
917 'x11', 'xext', 'xdamage >= 1.1', 'xfixes', 'x11-xcb', 'xcb',
918 'xcb-glx >= 1.8.1', 'libdrm >= 2.4.75',
919 ]
920 if dep_xxf86vm != [] and dep_xxf86vm.found()
921 gl_priv_reqs += 'xxf86vm'
922 endif
923 if with_dri_platform == 'drm'
924 gl_priv_reqs += 'xcb-dri2 >= 1.8'
925 endif
926
927 gl_priv_libs = []
928 if dep_thread.found()
929 gl_priv_libs += ['-lpthread', '-pthread']
930 endif
931 if dep_m.found()
932 gl_priv_libs += '-lm'
933 endif
934 if dep_dl != [] and dep_dl.found()
935 gl_priv_libs += '-ldl'
936 endif
937
938 pkg = import('pkgconfig')
939
940 subdir('include')
941 subdir('bin')
942 subdir('src')