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