blob: 5c42102e12df51c21da60a533d3f205e1fdedf75 [file] [log] [blame]
Dylan Bakerd1992252017-09-14 17:57:17 -07001# 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
21project('mesa', ['c', 'cpp'], version : '17.3.0-devel', license : 'MIT',
Dylan Baker052c0d52017-09-30 20:04:09 -070022 default_options : ['c_std=c99', 'cpp_std=c++11'])
Dylan Bakerd1992252017-09-14 17:57:17 -070023
Dylan Baker32180562017-09-20 20:11:32 -070024# Arguments for the preprocessor, put these in a separate array from the C and
25# C++ (cpp in meson terminology) arguments since they need to be added to the
26# default arguments for both C and C++.
27pre_args = [
28 '-D__STDC_CONSTANT_MACROS',
29 '-D__STDC_FORMAT_MACROS',
30 '-D__STDC_LIMIT_MACROS',
31 '-DVERSION="@0@"'.format(meson.project_version()),
32 '-DPACKAGE_VERSION=VERSION',
33 '-DPACKAGE_BUGREPORT="https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa"',
Dylan Baker601bd722017-10-09 14:22:07 -070034 '-D_GNU_SOURCE',
Dylan Baker32180562017-09-20 20:11:32 -070035]
36
Dylan Bakere915b8d2017-09-28 14:02:51 -070037with_vulkan_icd_dir = get_option('vulkan-icd-dir')
Dylan Bakerd1992252017-09-14 17:57:17 -070038with_tests = get_option('build-tests')
39with_valgrind = get_option('valgrind')
Dylan Baker32180562017-09-20 20:11:32 -070040with_asm = get_option('asm')
Dylan Baker02cf3a82017-10-12 09:47:30 -070041with_llvm = get_option('llvm')
Dylan Baker3b209e92017-10-10 15:25:07 -070042if get_option('texture-float')
43 pre_args += '-DTEXTURE_FLOAT_ENABLED'
44 message('WARNING: Floating-point texture enabled. Please consult docs/patents.txt and your lawyer before building mesa.')
45endif
Dylan Baker32180562017-09-20 20:11:32 -070046
47# XXX: yeah, do these
48with_appledri = false
49with_windowsdri = false
50
Dylan Bakerdb978842017-09-28 13:59:04 -070051dri_drivers_path = get_option('dri-drivers-path')
52if dri_drivers_path == ''
53 dri_drivers_path = join_paths(get_option('libdir'), 'dri')
54endif
55
Dylan Baker32180562017-09-20 20:11:32 -070056with_gles1 = get_option('gles1')
57with_gles2 = get_option('gles2')
58with_opengl = get_option('opengl')
59with_any_opengl = with_opengl or with_gles1 or with_gles2
Dylan Bakera47c5252017-09-22 12:55:00 -070060# Only build shared_glapi if at least one OpenGL API is enabled
61with_shared_glapi = get_option('shared-glapi') and with_any_opengl
Dylan Baker32180562017-09-20 20:11:32 -070062
63# TODO: these will need options, but at the moment they just control header
64# installs
Dylan Baker32180562017-09-20 20:11:32 -070065with_osmesa = false
66
67# shared-glapi is required if at least two OpenGL APIs are being built
68if not with_shared_glapi
69 if ((with_gles1 and with_gles2) or (with_gles1 and with_opengl)
70 or (with_gles2 and with_opengl))
71 error('shared-glapi required for building two or more of OpenGL, OpenGL ES 1.x, OpenGL ES 2.x')
72 endif
73endif
74
75# We require OpenGL for OpenGL ES
76if (with_gles1 or with_gles2) and not with_opengl
77 error('building OpenGL ES without OpenGL is not supported.')
78endif
79
80with_dri = false
Ville Syrjälä22899642017-10-10 01:15:42 +030081with_dri_i915 = false
Dylan Baker32180562017-09-20 20:11:32 -070082with_dri_i965 = false
Dylan Bakerc2cd5802017-10-03 17:06:22 -070083with_dri_swrast = false
Dylan Baker32180562017-09-20 20:11:32 -070084_drivers = get_option('dri-drivers')
85if _drivers != ''
86 _split = _drivers.split(',')
Ville Syrjälä22899642017-10-10 01:15:42 +030087 with_dri_i915 = _split.contains('i915')
Dylan Baker32180562017-09-20 20:11:32 -070088 with_dri_i965 = _split.contains('i965')
Dylan Bakerc2cd5802017-10-03 17:06:22 -070089 with_dri_swrast = _split.contains('swrast')
Dylan Baker32180562017-09-20 20:11:32 -070090 with_dri = true
91endif
92
Dylan Bakeraf9d2762017-09-28 21:03:07 -070093with_gallium = false
Eric Anholt1918c9b2017-10-12 18:39:08 -070094with_gallium_pl111 = false
Dylan Bakeraf9d2762017-09-28 21:03:07 -070095with_gallium_radeonsi = false
Dylan Baker813b4b02017-10-09 14:59:35 -070096with_gallium_nouveau = false
Dylan Bakerf3d03a22017-10-10 11:57:50 -070097with_gallium_softpipe = false
Eric Anholt1ae80182017-10-12 13:53:12 -070098with_gallium_vc4 = false
Eric Anholt4f3e3802017-10-12 18:40:16 -070099with_gallium_vc5 = false
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700100_drivers = get_option('gallium-drivers')
101if _drivers != ''
102 _split = _drivers.split(',')
Eric Anholt1918c9b2017-10-12 18:39:08 -0700103 with_gallium_vc4 = _split.contains('pl111')
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700104 with_gallium_radeonsi = _split.contains('radeonsi')
Dylan Baker813b4b02017-10-09 14:59:35 -0700105 with_gallium_nouveau = _split.contains('nouveau')
Dylan Bakerde24d612017-10-10 14:27:19 -0700106 with_gallium_softpipe = _split.contains('swrast')
Eric Anholt1ae80182017-10-12 13:53:12 -0700107 with_gallium_vc4 = _split.contains('vc4')
Eric Anholt4f3e3802017-10-12 18:40:16 -0700108 with_gallium_vc5 = _split.contains('vc5')
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700109 with_gallium = true
110 with_dri = true
Ville Syrjälä22899642017-10-10 01:15:42 +0300111endif
112
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700113if not (with_dri or with_gallium)
Dylan Baker32180562017-09-20 20:11:32 -0700114 with_gles1 = false
115 with_gles2 = false
116 with_opengl = false
117 with_any_opengl = false
118 with_shared_glapi = false
119endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700120
Dylan Bakerde24d612017-10-10 14:27:19 -0700121if with_dri_swrast and with_gallium_softpipe
122 error('Only one swrast provider can be built')
123endif
124
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700125dep_libdrm_intel = []
126if with_dri_i915
127 dep_libdrm_intel = dependency('libdrm_intel', version : '>= 2.4.75')
128endif
129
Dylan Bakera47c5252017-09-22 12:55:00 -0700130# TODO: other OSes
131with_dri_platform = 'drm'
132
Dylan Bakerd1992252017-09-14 17:57:17 -0700133# TODO: there are more platforms required for non-vulkan drivers
134with_platform_wayland = false
135with_platform_x11 = false
Dylan Bakerb1b65392017-09-28 22:25:02 -0700136with_platform_drm = false
Dylan Bakerd1992252017-09-14 17:57:17 -0700137_platforms = get_option('platforms')
138if _platforms != ''
139 _split = _platforms.split(',')
140 with_platform_x11 = _split.contains('x11')
141 with_platform_wayland = _split.contains('wayland')
Dylan Bakerb1b65392017-09-28 22:25:02 -0700142 with_platform_drm = _split.contains('drm')
Dylan Bakerd1992252017-09-14 17:57:17 -0700143endif
144
Dylan Baker816bf7d12017-09-28 15:53:53 -0700145with_gbm = get_option('gbm')
146if with_gbm == 'auto' and with_dri # TODO: or gallium
147 with_gbm = host_machine.system() == 'linux'
148elif with_gbm == 'yes'
149 if not ['linux', 'bsd'].contains(host_machine.system())
150 error('GBM only supports unix-like platforms')
151 endif
152 with_gbm = true
153else
154 with_gbm = false
155endif
156
Dylan Baker8e611872017-10-11 12:49:31 -0700157pre_args += '-DGLX_USE_TLS'
Dylan Bakera47c5252017-09-22 12:55:00 -0700158with_glx = get_option('glx')
159if with_glx != 'disabled'
Dylan Bakera47c5252017-09-22 12:55:00 -0700160 if not (with_platform_x11 and with_any_opengl) and with_glx != 'auto'
161 error('Cannot build GLX support without X11 platform support and at least one OpenGL API')
162 elif with_glx == 'gallium-xlib'
163 if not with_gallium
164 error('Gallium-xlib based GLX requires at least one gallium driver')
165 elif with_dri
166 error('gallium-xlib conflicts with any dri driver')
167 endif
168 elif with_glx == 'dri' and not with_dri
169 error('dri based GLX requires at least one DRI driver')
170 elif with_glx == 'auto'
171 if with_dri
172 with_glx = 'dri'
173 elif with_gallium
174 with_glx = 'gallium-xlib'
175 elif with_platform_x11 and with_any_opengl
176 with_glx = 'xlib'
177 else
178 with_glx = 'disabled'
179 endif
180 endif
181endif
182
183with_glvnd = get_option('glvnd')
184if with_glvnd and with_glx != 'dri'
185 message('glvnd requires dri based glx')
186endif
187
188# TODO: toggle for this
189with_glx_direct = true
190
Dylan Bakerd1992252017-09-14 17:57:17 -0700191if with_vulkan_icd_dir == ''
192 with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
193endif
194
195with_intel_vk = false
196with_amd_vk = false
Dylan Bakera47c5252017-09-22 12:55:00 -0700197with_any_vk = false
Dylan Bakerd1992252017-09-14 17:57:17 -0700198_vulkan_drivers = get_option('vulkan-drivers')
199if _vulkan_drivers != ''
200 _split = _vulkan_drivers.split(',')
201 with_intel_vk = _split.contains('intel')
202 with_amd_vk = _split.contains('amd')
Dylan Bakera47c5252017-09-22 12:55:00 -0700203 with_any_vk = with_amd_vk or with_intel_vk
Dylan Bakerd1992252017-09-14 17:57:17 -0700204 if not (with_platform_x11 or with_platform_wayland)
205 error('Vulkan requires at least one platform (x11, wayland)')
206 endif
Dylan Bakera47c5252017-09-22 12:55:00 -0700207endif
208
Dylan Baker50c28df2017-09-29 17:53:01 -0700209with_dri2 = (with_dri or with_any_vk) and with_dri_platform == 'drm'
210with_dri3 = get_option('dri3')
211if with_dri3 == 'auto'
212 if host_machine.system() == 'linux' and with_dri2
213 with_dri3 = true
214 else
215 with_dri3 = false
216 endif
217elif with_dri3 == 'yes'
218 with_dri3 = true
219else
220 with_dri3 = false
221endif
222
223if with_any_vk and (with_platform_x11 and not with_dri3)
224 error('Vulkan drivers require dri3 for X11 support')
225endif
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700226if with_dri or with_gallium
Dylan Bakera47c5252017-09-22 12:55:00 -0700227 if with_glx == 'disabled' # TODO: or egl
228 error('building dri or gallium drivers require at least one window system')
229 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700230endif
231
Dylan Baker50c28df2017-09-29 17:53:01 -0700232with_gallium_xvmc = false
233with_gallium_vdpau = false
234with_gallium_omx = false # this is bellagio
235with_gallium_va = false
236with_gallium_media = false
237dep_va = []
238_drivers = get_option('gallium-media')
239if _drivers != ''
240 _split = _drivers.split(',')
241 with_gallium_xvmc = _split.contains('xvmc')
242 with_gallium_vdpau = _split.contains('vdpau')
243 with_gallium_omx = _split.contains('omx')
244 with_gallium_va = _split.contains('va')
245 with_gallium_media = (with_gallium_xvmc or with_gallium_vdpau or
246 with_gallium_omx or with_gallium_va)
247endif
248
249if with_platform_x11
250 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
251 pre_args += '-DHAVE_X11_PLATFORM'
252 endif
253 if with_glx == 'xlib'
254 # TODO
255 error('TODO')
256 elif with_glx == 'gallium-xlib'
257 # TODO
258 error('TODO')
259 else
260 pre_args += '-DGLX_INDIRECT_RENDERING'
261 if with_glx_direct
262 pre_args += '-DGLX_DIRECT_RENDERING'
263 endif
264 if with_dri_platform == 'drm'
265 pre_args += '-DGLX_USE_DRM'
266 endif
267 endif
268endif
269
Dylan Bakerd1992252017-09-14 17:57:17 -0700270prog_python2 = find_program('python2')
Dylan Baker9342a7d2017-09-28 10:48:30 -0700271has_mako = run_command(prog_python2, '-c', 'import mako')
272if has_mako.returncode() != 0
273 error('Python (2.x) mako module required to build mesa.')
274endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700275
276cc = meson.get_compiler('c')
277if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
Eric Engestrom1262e822017-09-29 15:25:18 +0100278 error('When using GCC, version 4.4.6 or later is required.')
Dylan Bakerd1992252017-09-14 17:57:17 -0700279endif
280
Dylan Bakerd1992252017-09-14 17:57:17 -0700281# Define DEBUG for debug and debugoptimized builds
282if get_option('buildtype').startswith('debug')
283 pre_args += '-DDEBUG'
284endif
285
Dylan Baker673dda82017-09-20 11:53:29 -0700286if get_option('shader-cache')
287 pre_args += '-DENABLE_SHADER_CACHE'
288elif with_amd_vk
289 error('Radv requires shader cache support')
290endif
291
Dylan Bakerd1992252017-09-14 17:57:17 -0700292# Check for GCC style builtins
293foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
294 'ffsll', 'popcount', 'popcountll', 'unreachable']
295 if cc.has_function(b)
296 pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
297 endif
298endforeach
299
Dylan Baker673dda82017-09-20 11:53:29 -0700300# check for GCC __attribute__
Dylan Bakerd1992252017-09-14 17:57:17 -0700301foreach a : ['const', 'flatten', 'malloc', 'pure', 'unused',
302 'warn_unused_result', 'weak',]
303 if cc.compiles('int foo(void) __attribute__((@0@));'.format(a),
304 name : '__attribute__((@0@))'.format(a))
305 pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
306 endif
307endforeach
308if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
309 name : '__attribute__((format(...)))')
310 pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
311endif
312if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
313 name : '__attribute__((packed))')
314 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
315endif
316if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
317 name : '__attribute__((returns_nonnull))')
318 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NONNULL'
319endif
320if cc.compiles('''int foo_def(void) __attribute__((visibility("default")));
321 int foo_hid(void) __attribute__((visibility("hidden")));
322 int foo_int(void) __attribute__((visibility("internal")));
323 int foo_pro(void) __attribute__((visibility("protected")));''',
324 name : '__attribute__((visibility(...)))')
325 pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISBILITY'
326endif
327if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
328 name : '__attribute__((alias(...)))')
329 pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
330endif
331
332# TODO: this is very incomplete
333if host_machine.system() == 'linux'
334 pre_args += '-D_GNU_SOURCE'
335endif
336
337# Check for generic C arguments
338c_args = []
339foreach a : ['-Wall', '-Werror=implicit-function-declaration',
340 '-Werror=missing-prototypes', '-fno-math-errno',
341 '-fno-trapping-math', '-Qunused-arguments']
342 if cc.has_argument(a)
343 c_args += a
344 endif
345endforeach
346c_vis_args = []
347if cc.has_argument('-fvisibility=hidden')
348 c_vis_args += '-fvisibility=hidden'
349endif
350
351# Check for generic C++ arguments
352cpp = meson.get_compiler('cpp')
353cpp_args = []
354foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math',
355 '-Qunused-arguments', '-Wno-non-virtual-dtor']
356 if cpp.has_argument(a)
357 cpp_args += a
358 endif
359endforeach
360cpp_vis_args = []
361if cpp.has_argument('-fvisibility=hidden')
362 cpp_vis_args += '-fvisibility=hidden'
363endif
364
365# Check for C and C++ arguments for MSVC2013 compatibility. These are only used
366# in parts of the mesa code base that need to compile with old versions of
367# MSVC, mainly common code
368c_msvc_compat_args = []
369cpp_msvc_compat_args = []
370foreach a : ['-Werror=pointer-arith', '-Werror=vla']
371 if cc.has_argument(a)
372 c_msvc_compat_args += a
373 endif
374 if cpp.has_argument(a)
375 cpp_msvc_compat_args += a
376 endif
377endforeach
378
379no_override_init_args = []
380foreach a : ['-Wno-override-init', '-Wno-initializer-overrides']
381 if cc.has_argument(a)
382 no_override_init_args += a
383 endif
384endforeach
385
386# TODO: SSE41 (which is only required for core mesa)
387
388# Check for GCC style atomics
389if cc.compiles('int main() { int n; return __atomic_load_n(&n, __ATOMIC_ACQUIRE); }',
390 name : 'GCC atomic builtins')
391 pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
392endif
393if not cc.links('''#include <stdint.h>
394 uint64_t v;
395 int main() {
396 return __sync_add_and_fetch(&v, (uint64_t)1);
397 }''',
398 name : 'GCC 64bit atomics')
399 pre_args += '-DMISSING_64_BIT_ATOMICS'
400endif
401
402# TODO: endian
403# TODO: powr8
404# TODO: shared/static? Is this even worth doing?
405
406# I don't think that I need to set any of the debug stuff, I think meson
407# handles that for us
408
409# TODO: ldflags
410
411# TODO: texture-float (gallium/mesa only)
412
413# TODO: cross-compiling. I don't think this is relavent to meson
414
Dylan Baker32180562017-09-20 20:11:32 -0700415# FIXME: enable asm when cross compiler
416# This is doable (autotools does it), but it's not of immediate concern
417if meson.is_cross_build()
418 message('Cross compiling, disabling asm')
419 with_asm = false
420endif
421
422with_asm_arch = ''
423if with_asm
424 # TODO: SPARC and PPC
425 if host_machine.cpu_family() == 'x86'
426 if ['linux', 'bsd'].contains(host_machine.system()) # FIXME: hurd?
427 with_asm_arch = 'x86'
428 pre_args += ['-DUSE_X86_ASM', '-DUSE_MMX_ASM', '-DUSE_3DNOW_ASM',
429 '-DUSE_SSE_ASM']
430 endif
431 elif host_machine.cpu_family() == 'x86_64'
432 if host_machine.system() == 'linux'
433 with_asm_arch = 'x86_64'
434 pre_args += ['-DUSE_X86_64_ASM']
435 endif
436 elif host_machine.cpu_family() == 'arm'
437 if host_machine.system() == 'linux'
438 with_asm_arch = 'arm'
439 pre_args += ['-DUSE_ARM_ASM']
440 endif
441 elif host_machine.cpu_family() == 'aarch64'
442 if host_machine.system() == 'linux'
443 with_asm_arch = 'aarch64'
444 pre_args += ['-DUSE_AARCH64_ASM']
445 endif
446 endif
447endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700448
449# Check for standard headers and functions
450if cc.has_header_symbol('sys/sysmacros.h', 'major')
451 pre_args += '-DMAJOR_IN_SYSMACROS'
452elif cc.has_header_symbol('sys/mkdev.h', 'major')
453 pre_args += '-DMAJOR_IN_MKDEV'
454endif
455
456foreach h : ['xlocale.h', 'sys/sysctl.h']
457 if cc.has_header(h)
458 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
459 endif
460endforeach
461
462foreach f : ['strtof', 'mkostemp', 'posix_memalign']
463 if cc.has_function(f)
464 pre_args += '-DHAVE_@0@'.format(f.to_upper())
465 endif
466endforeach
467
468# strtod locale support
469if cc.links('''
470 #define _GNU_SOURCE
471 #include <stdlib.h>
472 #include <locale.h>
473 #ifdef HAVE_XLOCALE_H
474 #include <xlocale.h>
475 #endif
476 int main() {
477 locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
478 const char *s = "1.0";
479 char *end;
480 double d = strtod_l(s, end, loc);
481 float f = strtod_l(s, end, loc);
482 freelocale(loc);
483 return 0;
484 }''',
485 extra_args : pre_args,
486 name : 'strtod has locale support')
487 pre_args += '-DHAVE_STRTOD_L'
488endif
489
490# Check for some linker flags
491ld_args_bsymbolic = []
Dylan Bakere21e0a62017-09-30 13:15:52 -0700492if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic', name : 'Bsymbolic')
Dylan Bakerd1992252017-09-14 17:57:17 -0700493 ld_args_bsymbolic += '-Wl,-Bsymbolic'
494endif
495ld_args_gc_sections = []
496if cc.links('static char unused() { return 5; } int main() { return 0; }',
Dylan Bakere21e0a62017-09-30 13:15:52 -0700497 args : '-Wl,--gc-sections', name : 'gc-sections')
Dylan Bakerd1992252017-09-14 17:57:17 -0700498 ld_args_gc_sections += '-Wl,--gc-sections'
499endif
Dylan Bakere21e0a62017-09-30 13:15:52 -0700500with_ld_version_script = false
501if cc.links('int main() { return 0; }',
502 args : '-Wl,--version-script=@0@'.format(
503 join_paths(meson.source_root(), 'build-support/conftest.map')),
504 name : 'version-script')
505 with_ld_version_script = true
506endif
507with_ld_dynamic_list = false
508if cc.links('int main() { return 0; }',
509 args : '-Wl,--dynamic-list=@0@'.format(
510 join_paths(meson.source_root(), 'build-support/conftest.dyn')),
511 name : 'dynamic-list')
512 with_ld_dynamic_list = true
513endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700514
515# check for dl support
516if cc.has_function('dlopen')
517 dep_dl = []
518else
519 dep_dl = cc.find_library('dl')
520endif
Dylan Baker32180562017-09-20 20:11:32 -0700521if cc.has_function('dladdr', dependencies : dep_dl)
522 # This is really only required for megadrivers
523 pre_args += '-DHAVE_DLADDR'
Dylan Bakerd1992252017-09-14 17:57:17 -0700524endif
525
526if cc.has_function('dl_iterate_phdr')
527 pre_args += '-DHAVE_DL_ITERATE_PHDR'
528else
529 # TODO: this is required for vulkan
530endif
531
532# Determine whether or not the rt library is needed for time functions
533if cc.has_function('clock_gettime')
534 dep_clock = []
535else
536 dep_clock = cc.find_library('rt')
537endif
538
Dylan Baker66c94b92017-09-30 13:48:34 -0700539with_gallium_drisw_kms = false
Dylan Baker50c28df2017-09-29 17:53:01 -0700540dep_libdrm = dependency('libdrm', version : '>= 2.4.75',
541 required : with_dri2 or with_dri3)
542if dep_libdrm.found()
543 pre_args += '-DHAVE_LIBDRM'
Dylan Baker66c94b92017-09-30 13:48:34 -0700544 if with_dri_platform == 'drm' and with_dri
545 with_gallium_drisw_kms = true
546 endif
Dylan Baker50c28df2017-09-29 17:53:01 -0700547endif
548
Dylan Bakerd1992252017-09-14 17:57:17 -0700549# TODO: some of these may be conditional
550dep_zlib = dependency('zlib', version : '>= 1.2.3')
551dep_thread = dependency('threads')
Dylan Baker50c28df2017-09-29 17:53:01 -0700552if dep_thread.found() and host_machine.system() == 'linux'
553 pre_args += '-DHAVE_PTHREAD'
554endif
Dylan Bakercc4f5872017-09-27 11:30:21 -0700555dep_elf = dependency('libelf', required : false)
Dylan Bakerb154b442017-09-30 14:04:28 -0700556if not dep_elf.found() and (with_amd_vk or with_gallium_radeonsi) # TODO: clover, r600
557 dep_elf = cc.find_library('elf')
Dylan Bakercc4f5872017-09-27 11:30:21 -0700558endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700559dep_expat = dependency('expat')
560# this only exists on linux so either this is linux and it will be found, or
561# its not linux and and wont
562dep_m = cc.find_library('m', required : false)
Dylan Baker66f97f62017-09-30 09:03:51 -0700563
564dep_libdrm_amdgpu = []
565dep_libdrm_radeon = []
Dylan Baker813b4b02017-10-09 14:59:35 -0700566dep_libdrm_nouveau = []
Dylan Baker66f97f62017-09-30 09:03:51 -0700567if with_amd_vk or with_gallium_radeonsi
568 dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.84')
569endif
570if with_gallium_radeonsi # older radeon too
571 dep_libdrm_radeon = dependency('libdrm_radeon', version : '>= 2.4.71')
572endif
Dylan Baker813b4b02017-10-09 14:59:35 -0700573if with_gallium_nouveau
574 dep_libdrm_nouveau = dependency('libdrm_nouveau', version : '>= 2.4.66')
575endif
Dylan Baker673dda82017-09-20 11:53:29 -0700576
577llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
578if with_amd_vk
579 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
580endif
581dep_llvm = dependency(
Dylan Baker50c28df2017-09-29 17:53:01 -0700582 'llvm', version : '>= 3.9.0', required : with_amd_vk, modules : llvm_modules,
Dylan Baker673dda82017-09-20 11:53:29 -0700583)
Dylan Baker02cf3a82017-10-12 09:47:30 -0700584if with_llvm
585 if dep_llvm.found()
586 _llvm_version = dep_llvm.version().split('.')
587 # Development versions of LLVM have an 'svn' suffix, we don't want that for
588 # our version checks.
589 _llvm_patch = _llvm_version[2]
590 if _llvm_patch.endswith('svn')
591 _llvm_patch = _llvm_patch.split('s')[0]
592 endif
593 pre_args += [
594 '-DHAVE_LLVM=0x0@0@@1@@2@'.format(_llvm_version[0], _llvm_version[1], _llvm_patch),
595 '-DMESA_LLVM_VERSION_PATCH=@0@'.format(_llvm_patch),
596 ]
597 else
Dylan Baker6a9ad202017-10-10 14:56:39 -0700598 if with_gallium_softpipe
599 error('Cannot find LLVM to build LLVMPipe. If you wanted softpipe pass -Dllvm=false to meson')
600 elif with_amd_vk or with_gallium_radeonsi # etc
Dylan Baker66f97f62017-09-30 09:03:51 -0700601 error('The following drivers requires LLVM: Radv, RadeonSI. One of these is enabled, but LLVM was not found.')
Dylan Baker02cf3a82017-10-12 09:47:30 -0700602 endif
Dylan Baker673dda82017-09-20 11:53:29 -0700603 endif
Dylan Baker66f97f62017-09-30 09:03:51 -0700604elif with_amd_vk or with_gallium_radeonsi
605 error('The following drivers requires LLVM: Radv, RadeonSI. One of these is enabled, but LLVM is disabled.')
Dylan Baker673dda82017-09-20 11:53:29 -0700606endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700607
Dylan Bakera47c5252017-09-22 12:55:00 -0700608dep_glvnd = []
609if with_glvnd
610 dep_glvnd = dependency('libglvnd', version : '>= 0.2.0')
611 pre_args += '-DUSE_LIBGLVND=1'
612endif
613
Dylan Bakerd1992252017-09-14 17:57:17 -0700614# TODO: make this conditional
615dep_valgrind = dependency('valgrind', required : false)
616if dep_valgrind.found() and with_valgrind
617 pre_args += '-DHAVE_VALGRIND'
618endif
619
620# pthread stubs. Lets not and say we didn't
621
Dylan Baker32180562017-09-20 20:11:32 -0700622prog_bison = find_program('bison', required : with_any_opengl)
623prog_flex = find_program('flex', required : with_any_opengl)
624
Dylan Bakerd1992252017-09-14 17:57:17 -0700625# TODO: selinux
Dylan Baker32180562017-09-20 20:11:32 -0700626dep_selinux = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700627
628# TODO: llvm-prefix and llvm-shared-libs
629
Dylan Bakerb1b65392017-09-28 22:25:02 -0700630dep_unwind = dependency('libunwind', required : false)
631if dep_unwind.found()
632 pre_args += '-DHAVE_LIBUNWIND'
633endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700634
635# TODO: flags for opengl, gles, dri
636
637# TODO: gallium-hud
638
639# TODO: glx provider
640
641# TODO: osmesa provider
642
Dylan Bakerd1992252017-09-14 17:57:17 -0700643# TODO: symbol mangling
644
Dylan Bakerd1992252017-09-14 17:57:17 -0700645# TODO: egl configuration
646
647if with_platform_wayland
648 prog_wl_scanner = find_program('wayland-scanner')
649 dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8')
650 dep_wayland_client = dependency('wayland-client', version : '>=1.11')
651 dep_wayland_server = dependency('wayland-server', version : '>=1.11')
652else
653 prog_wl_scanner = []
654 dep_wl_protocols = []
655 dep_wayland_client = []
656 dep_wayland_server = []
657endif
658
Dylan Baker50c28df2017-09-29 17:53:01 -0700659dep_x11 = []
660dep_xext = []
661dep_xdamage = []
662dep_xfixes = []
663dep_x11_xcb = []
664dep_xcb_glx = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700665dep_xcb_dri2 = []
666dep_xcb_dri3 = []
Dylan Bakera47c5252017-09-22 12:55:00 -0700667dep_dri2proto = []
668dep_glproto = []
Dylan Bakera47c5252017-09-22 12:55:00 -0700669dep_xf86vm = []
Dylan Baker50c28df2017-09-29 17:53:01 -0700670dep_xcb_dri3 = []
671dep_xcb_present = []
672dep_xcb_sync = []
673dep_xshmfence = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700674if with_platform_x11
Dylan Baker50c28df2017-09-29 17:53:01 -0700675 if with_glx == 'dri' and with_dri_platform == 'drm'
676 dep_x11 = dependency('x11')
677 dep_xext = dependency('xext')
678 dep_xdamage = dependency('xdamage', version : '>= 1.1')
679 dep_xfixes = dependency('xfixes')
680 dep_xcb_glx = dependency('xcb-glx', version : '>= 1.8.1')
681 dep_xf86vm = dependency('xf86vm', required : false)
Dylan Bakera47c5252017-09-22 12:55:00 -0700682 endif
683 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
Dylan Baker50c28df2017-09-29 17:53:01 -0700684 dep_xcb = dependency('xcb')
685 dep_x11_xcb = dependency('x11-xcb')
686 dep_xcb_dri2 = dependency('xcb-dri2', version : '>= 1.8')
687
Dylan Bakera47c5252017-09-22 12:55:00 -0700688 if with_dri3
689 pre_args += '-DHAVE_DRI3'
Dylan Baker50c28df2017-09-29 17:53:01 -0700690 dep_xcb_dri3 = dependency('xcb-dri3')
691 dep_xcb_present = dependency('xcb-present')
692 dep_xcb_sync = dependency('xcb-sync')
693 dep_xshmfence = dependency('xshmfence', version : '>= 1.1')
Dylan Bakera47c5252017-09-22 12:55:00 -0700694 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700695 endif
Dylan Baker50c28df2017-09-29 17:53:01 -0700696 if with_glx != 'disabled'
697 dep_dri2proto = dependency('dri2proto', version : '>= 2.8')
698 dep_glproto = dependency('glproto', version : '>= 1.4.14')
699 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700700endif
701
702# TODO: platforms for !vulkan
703
Dylan Bakerd1992252017-09-14 17:57:17 -0700704# TODO: osmesa
705
706# TODO: egl
707
Dylan Bakerd1992252017-09-14 17:57:17 -0700708# TODO: vallium G3DVL
709
710# TODO: nine
711
712# TODO: clover
713
714# TODO: egl sans x11
Dylan Bakerd1992252017-09-14 17:57:17 -0700715# TODO: gallium tests
716
717# TODO: various libdirs
718
719# TODO: swr
720
721# TODO: gallium driver dirs
722
723# FIXME: this is a workaround for #2326
724prog_touch = find_program('touch')
725dummy_cpp = custom_target(
726 'dummy_cpp',
727 output : 'dummy.cpp',
728 command : [prog_touch, '@OUTPUT@'],
729)
730
731foreach a : pre_args
732 add_project_arguments(a, language : ['c', 'cpp'])
733endforeach
734foreach a : c_args
735 add_project_arguments(a, language : ['c'])
736endforeach
737foreach a : cpp_args
738 add_project_arguments(a, language : ['cpp'])
739endforeach
740
741inc_include = include_directories('include')
742
Dylan Baker32180562017-09-20 20:11:32 -0700743pkg = import('pkgconfig')
744
Dylan Bakerd1992252017-09-14 17:57:17 -0700745subdir('include')
746subdir('src')