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