OSDN Git Service

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