blob: a8bcaf7621bd3a28cefd04cfc6d7bc28a5350c44 [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(',')
Dylan Bakerfbf39fd2017-10-17 14:44:15 -0700103 with_gallium_pl111 = _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 Baker8d3b1212017-10-18 15:47:11 -0700160 if not (with_platform_x11 and with_any_opengl)
161 if with_glx == 'auto'
162 with_glx = 'disabled'
163 else
164 error('Cannot build GLX support without X11 platform support and at least one OpenGL API')
165 endif
Dylan Bakera47c5252017-09-22 12:55:00 -0700166 elif with_glx == 'gallium-xlib'
167 if not with_gallium
168 error('Gallium-xlib based GLX requires at least one gallium driver')
169 elif with_dri
170 error('gallium-xlib conflicts with any dri driver')
171 endif
172 elif with_glx == 'dri' and not with_dri
173 error('dri based GLX requires at least one DRI driver')
174 elif with_glx == 'auto'
175 if with_dri
176 with_glx = 'dri'
177 elif with_gallium
178 with_glx = 'gallium-xlib'
179 elif with_platform_x11 and with_any_opengl
180 with_glx = 'xlib'
181 else
182 with_glx = 'disabled'
183 endif
184 endif
185endif
186
187with_glvnd = get_option('glvnd')
188if with_glvnd and with_glx != 'dri'
189 message('glvnd requires dri based glx')
190endif
191
192# TODO: toggle for this
193with_glx_direct = true
194
Dylan Bakerd1992252017-09-14 17:57:17 -0700195if with_vulkan_icd_dir == ''
196 with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
197endif
198
199with_intel_vk = false
200with_amd_vk = false
Dylan Bakera47c5252017-09-22 12:55:00 -0700201with_any_vk = false
Dylan Bakerd1992252017-09-14 17:57:17 -0700202_vulkan_drivers = get_option('vulkan-drivers')
203if _vulkan_drivers != ''
204 _split = _vulkan_drivers.split(',')
205 with_intel_vk = _split.contains('intel')
206 with_amd_vk = _split.contains('amd')
Dylan Bakera47c5252017-09-22 12:55:00 -0700207 with_any_vk = with_amd_vk or with_intel_vk
Dylan Bakerd1992252017-09-14 17:57:17 -0700208 if not (with_platform_x11 or with_platform_wayland)
209 error('Vulkan requires at least one platform (x11, wayland)')
210 endif
Dylan Bakera47c5252017-09-22 12:55:00 -0700211endif
212
Dylan Baker50c28df2017-09-29 17:53:01 -0700213with_dri2 = (with_dri or with_any_vk) and with_dri_platform == 'drm'
214with_dri3 = get_option('dri3')
215if with_dri3 == 'auto'
216 if host_machine.system() == 'linux' and with_dri2
217 with_dri3 = true
218 else
219 with_dri3 = false
220 endif
221elif with_dri3 == 'yes'
222 with_dri3 = true
223else
224 with_dri3 = false
225endif
226
227if with_any_vk and (with_platform_x11 and not with_dri3)
228 error('Vulkan drivers require dri3 for X11 support')
229endif
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700230if with_dri or with_gallium
Dylan Bakera47c5252017-09-22 12:55:00 -0700231 if with_glx == 'disabled' # TODO: or egl
232 error('building dri or gallium drivers require at least one window system')
233 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700234endif
235
Dylan Baker50c28df2017-09-29 17:53:01 -0700236with_gallium_xvmc = false
237with_gallium_vdpau = false
238with_gallium_omx = false # this is bellagio
239with_gallium_va = false
240with_gallium_media = false
241dep_va = []
242_drivers = get_option('gallium-media')
243if _drivers != ''
244 _split = _drivers.split(',')
245 with_gallium_xvmc = _split.contains('xvmc')
246 with_gallium_vdpau = _split.contains('vdpau')
247 with_gallium_omx = _split.contains('omx')
248 with_gallium_va = _split.contains('va')
249 with_gallium_media = (with_gallium_xvmc or with_gallium_vdpau or
250 with_gallium_omx or with_gallium_va)
251endif
252
253if with_platform_x11
254 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
255 pre_args += '-DHAVE_X11_PLATFORM'
256 endif
257 if with_glx == 'xlib'
258 # TODO
259 error('TODO')
260 elif with_glx == 'gallium-xlib'
261 # TODO
262 error('TODO')
263 else
264 pre_args += '-DGLX_INDIRECT_RENDERING'
265 if with_glx_direct
266 pre_args += '-DGLX_DIRECT_RENDERING'
267 endif
268 if with_dri_platform == 'drm'
269 pre_args += '-DGLX_USE_DRM'
270 endif
271 endif
272endif
273
Dylan Bakerd1992252017-09-14 17:57:17 -0700274prog_python2 = find_program('python2')
Dylan Baker9342a7d2017-09-28 10:48:30 -0700275has_mako = run_command(prog_python2, '-c', 'import mako')
276if has_mako.returncode() != 0
277 error('Python (2.x) mako module required to build mesa.')
278endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700279
280cc = meson.get_compiler('c')
281if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
Eric Engestrom1262e822017-09-29 15:25:18 +0100282 error('When using GCC, version 4.4.6 or later is required.')
Dylan Bakerd1992252017-09-14 17:57:17 -0700283endif
284
Dylan Bakerd1992252017-09-14 17:57:17 -0700285# Define DEBUG for debug and debugoptimized builds
286if get_option('buildtype').startswith('debug')
287 pre_args += '-DDEBUG'
288endif
289
Dylan Baker673dda82017-09-20 11:53:29 -0700290if get_option('shader-cache')
291 pre_args += '-DENABLE_SHADER_CACHE'
292elif with_amd_vk
293 error('Radv requires shader cache support')
294endif
295
Dylan Bakerd1992252017-09-14 17:57:17 -0700296# Check for GCC style builtins
297foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
298 'ffsll', 'popcount', 'popcountll', 'unreachable']
299 if cc.has_function(b)
300 pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
301 endif
302endforeach
303
Dylan Baker673dda82017-09-20 11:53:29 -0700304# check for GCC __attribute__
Dylan Bakerd1992252017-09-14 17:57:17 -0700305foreach a : ['const', 'flatten', 'malloc', 'pure', 'unused',
306 'warn_unused_result', 'weak',]
307 if cc.compiles('int foo(void) __attribute__((@0@));'.format(a),
308 name : '__attribute__((@0@))'.format(a))
309 pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
310 endif
311endforeach
312if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
313 name : '__attribute__((format(...)))')
314 pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
315endif
316if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
317 name : '__attribute__((packed))')
318 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
319endif
320if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
321 name : '__attribute__((returns_nonnull))')
322 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NONNULL'
323endif
324if cc.compiles('''int foo_def(void) __attribute__((visibility("default")));
325 int foo_hid(void) __attribute__((visibility("hidden")));
326 int foo_int(void) __attribute__((visibility("internal")));
327 int foo_pro(void) __attribute__((visibility("protected")));''',
328 name : '__attribute__((visibility(...)))')
329 pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISBILITY'
330endif
331if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
332 name : '__attribute__((alias(...)))')
333 pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
334endif
335
336# TODO: this is very incomplete
337if host_machine.system() == 'linux'
338 pre_args += '-D_GNU_SOURCE'
339endif
340
341# Check for generic C arguments
342c_args = []
343foreach a : ['-Wall', '-Werror=implicit-function-declaration',
344 '-Werror=missing-prototypes', '-fno-math-errno',
345 '-fno-trapping-math', '-Qunused-arguments']
346 if cc.has_argument(a)
347 c_args += a
348 endif
349endforeach
350c_vis_args = []
351if cc.has_argument('-fvisibility=hidden')
352 c_vis_args += '-fvisibility=hidden'
353endif
354
355# Check for generic C++ arguments
356cpp = meson.get_compiler('cpp')
357cpp_args = []
358foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math',
359 '-Qunused-arguments', '-Wno-non-virtual-dtor']
360 if cpp.has_argument(a)
361 cpp_args += a
362 endif
363endforeach
364cpp_vis_args = []
365if cpp.has_argument('-fvisibility=hidden')
366 cpp_vis_args += '-fvisibility=hidden'
367endif
368
369# Check for C and C++ arguments for MSVC2013 compatibility. These are only used
370# in parts of the mesa code base that need to compile with old versions of
371# MSVC, mainly common code
372c_msvc_compat_args = []
373cpp_msvc_compat_args = []
374foreach a : ['-Werror=pointer-arith', '-Werror=vla']
375 if cc.has_argument(a)
376 c_msvc_compat_args += a
377 endif
378 if cpp.has_argument(a)
379 cpp_msvc_compat_args += a
380 endif
381endforeach
382
383no_override_init_args = []
384foreach a : ['-Wno-override-init', '-Wno-initializer-overrides']
385 if cc.has_argument(a)
386 no_override_init_args += a
387 endif
388endforeach
389
390# TODO: SSE41 (which is only required for core mesa)
391
392# Check for GCC style atomics
393if cc.compiles('int main() { int n; return __atomic_load_n(&n, __ATOMIC_ACQUIRE); }',
394 name : 'GCC atomic builtins')
395 pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
396endif
397if not cc.links('''#include <stdint.h>
398 uint64_t v;
399 int main() {
400 return __sync_add_and_fetch(&v, (uint64_t)1);
401 }''',
402 name : 'GCC 64bit atomics')
403 pre_args += '-DMISSING_64_BIT_ATOMICS'
404endif
405
406# TODO: endian
407# TODO: powr8
408# TODO: shared/static? Is this even worth doing?
409
410# I don't think that I need to set any of the debug stuff, I think meson
411# handles that for us
412
413# TODO: ldflags
414
415# TODO: texture-float (gallium/mesa only)
416
417# TODO: cross-compiling. I don't think this is relavent to meson
418
Dylan Baker32180562017-09-20 20:11:32 -0700419# FIXME: enable asm when cross compiler
420# This is doable (autotools does it), but it's not of immediate concern
421if meson.is_cross_build()
422 message('Cross compiling, disabling asm')
423 with_asm = false
424endif
425
426with_asm_arch = ''
427if with_asm
428 # TODO: SPARC and PPC
429 if host_machine.cpu_family() == 'x86'
430 if ['linux', 'bsd'].contains(host_machine.system()) # FIXME: hurd?
431 with_asm_arch = 'x86'
432 pre_args += ['-DUSE_X86_ASM', '-DUSE_MMX_ASM', '-DUSE_3DNOW_ASM',
433 '-DUSE_SSE_ASM']
434 endif
435 elif host_machine.cpu_family() == 'x86_64'
436 if host_machine.system() == 'linux'
437 with_asm_arch = 'x86_64'
438 pre_args += ['-DUSE_X86_64_ASM']
439 endif
440 elif host_machine.cpu_family() == 'arm'
441 if host_machine.system() == 'linux'
442 with_asm_arch = 'arm'
443 pre_args += ['-DUSE_ARM_ASM']
444 endif
445 elif host_machine.cpu_family() == 'aarch64'
446 if host_machine.system() == 'linux'
447 with_asm_arch = 'aarch64'
448 pre_args += ['-DUSE_AARCH64_ASM']
449 endif
450 endif
451endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700452
453# Check for standard headers and functions
454if cc.has_header_symbol('sys/sysmacros.h', 'major')
455 pre_args += '-DMAJOR_IN_SYSMACROS'
456elif cc.has_header_symbol('sys/mkdev.h', 'major')
457 pre_args += '-DMAJOR_IN_MKDEV'
458endif
459
460foreach h : ['xlocale.h', 'sys/sysctl.h']
461 if cc.has_header(h)
462 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
463 endif
464endforeach
465
466foreach f : ['strtof', 'mkostemp', 'posix_memalign']
467 if cc.has_function(f)
468 pre_args += '-DHAVE_@0@'.format(f.to_upper())
469 endif
470endforeach
471
472# strtod locale support
473if cc.links('''
474 #define _GNU_SOURCE
475 #include <stdlib.h>
476 #include <locale.h>
477 #ifdef HAVE_XLOCALE_H
478 #include <xlocale.h>
479 #endif
480 int main() {
481 locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
482 const char *s = "1.0";
483 char *end;
484 double d = strtod_l(s, end, loc);
485 float f = strtod_l(s, end, loc);
486 freelocale(loc);
487 return 0;
488 }''',
489 extra_args : pre_args,
490 name : 'strtod has locale support')
491 pre_args += '-DHAVE_STRTOD_L'
492endif
493
494# Check for some linker flags
495ld_args_bsymbolic = []
Dylan Bakere21e0a62017-09-30 13:15:52 -0700496if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic', name : 'Bsymbolic')
Dylan Bakerd1992252017-09-14 17:57:17 -0700497 ld_args_bsymbolic += '-Wl,-Bsymbolic'
498endif
499ld_args_gc_sections = []
500if cc.links('static char unused() { return 5; } int main() { return 0; }',
Dylan Bakere21e0a62017-09-30 13:15:52 -0700501 args : '-Wl,--gc-sections', name : 'gc-sections')
Dylan Bakerd1992252017-09-14 17:57:17 -0700502 ld_args_gc_sections += '-Wl,--gc-sections'
503endif
Dylan Bakere21e0a62017-09-30 13:15:52 -0700504with_ld_version_script = false
505if cc.links('int main() { return 0; }',
506 args : '-Wl,--version-script=@0@'.format(
507 join_paths(meson.source_root(), 'build-support/conftest.map')),
508 name : 'version-script')
509 with_ld_version_script = true
510endif
511with_ld_dynamic_list = false
512if cc.links('int main() { return 0; }',
513 args : '-Wl,--dynamic-list=@0@'.format(
514 join_paths(meson.source_root(), 'build-support/conftest.dyn')),
515 name : 'dynamic-list')
516 with_ld_dynamic_list = true
517endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700518
519# check for dl support
520if cc.has_function('dlopen')
521 dep_dl = []
522else
523 dep_dl = cc.find_library('dl')
524endif
Dylan Baker32180562017-09-20 20:11:32 -0700525if cc.has_function('dladdr', dependencies : dep_dl)
526 # This is really only required for megadrivers
527 pre_args += '-DHAVE_DLADDR'
Dylan Bakerd1992252017-09-14 17:57:17 -0700528endif
529
530if cc.has_function('dl_iterate_phdr')
531 pre_args += '-DHAVE_DL_ITERATE_PHDR'
532else
533 # TODO: this is required for vulkan
534endif
535
536# Determine whether or not the rt library is needed for time functions
537if cc.has_function('clock_gettime')
538 dep_clock = []
539else
540 dep_clock = cc.find_library('rt')
541endif
542
Dylan Baker66c94b92017-09-30 13:48:34 -0700543with_gallium_drisw_kms = false
Dylan Baker50c28df2017-09-29 17:53:01 -0700544dep_libdrm = dependency('libdrm', version : '>= 2.4.75',
545 required : with_dri2 or with_dri3)
546if dep_libdrm.found()
547 pre_args += '-DHAVE_LIBDRM'
Dylan Baker66c94b92017-09-30 13:48:34 -0700548 if with_dri_platform == 'drm' and with_dri
549 with_gallium_drisw_kms = true
550 endif
Dylan Baker50c28df2017-09-29 17:53:01 -0700551endif
552
Dylan Bakerd1992252017-09-14 17:57:17 -0700553# TODO: some of these may be conditional
554dep_zlib = dependency('zlib', version : '>= 1.2.3')
555dep_thread = dependency('threads')
Dylan Baker50c28df2017-09-29 17:53:01 -0700556if dep_thread.found() and host_machine.system() == 'linux'
557 pre_args += '-DHAVE_PTHREAD'
558endif
Dylan Bakercc4f5872017-09-27 11:30:21 -0700559dep_elf = dependency('libelf', required : false)
Dylan Bakerb154b442017-09-30 14:04:28 -0700560if not dep_elf.found() and (with_amd_vk or with_gallium_radeonsi) # TODO: clover, r600
561 dep_elf = cc.find_library('elf')
Dylan Bakercc4f5872017-09-27 11:30:21 -0700562endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700563dep_expat = dependency('expat')
564# this only exists on linux so either this is linux and it will be found, or
565# its not linux and and wont
566dep_m = cc.find_library('m', required : false)
Dylan Baker66f97f62017-09-30 09:03:51 -0700567
568dep_libdrm_amdgpu = []
569dep_libdrm_radeon = []
Dylan Baker813b4b02017-10-09 14:59:35 -0700570dep_libdrm_nouveau = []
Dylan Baker66f97f62017-09-30 09:03:51 -0700571if with_amd_vk or with_gallium_radeonsi
Dylan Baker8792a9e2017-10-20 16:28:32 -0700572 dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.85')
Dylan Baker66f97f62017-09-30 09:03:51 -0700573endif
574if with_gallium_radeonsi # older radeon too
575 dep_libdrm_radeon = dependency('libdrm_radeon', version : '>= 2.4.71')
576endif
Dylan Baker813b4b02017-10-09 14:59:35 -0700577if with_gallium_nouveau
578 dep_libdrm_nouveau = dependency('libdrm_nouveau', version : '>= 2.4.66')
579endif
Dylan Baker673dda82017-09-20 11:53:29 -0700580
581llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
582if with_amd_vk
583 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
584endif
585dep_llvm = dependency(
Dylan Baker50c28df2017-09-29 17:53:01 -0700586 'llvm', version : '>= 3.9.0', required : with_amd_vk, modules : llvm_modules,
Dylan Baker673dda82017-09-20 11:53:29 -0700587)
Dylan Baker02cf3a82017-10-12 09:47:30 -0700588if with_llvm
589 if dep_llvm.found()
590 _llvm_version = dep_llvm.version().split('.')
591 # Development versions of LLVM have an 'svn' suffix, we don't want that for
592 # our version checks.
593 _llvm_patch = _llvm_version[2]
594 if _llvm_patch.endswith('svn')
595 _llvm_patch = _llvm_patch.split('s')[0]
596 endif
597 pre_args += [
598 '-DHAVE_LLVM=0x0@0@@1@@2@'.format(_llvm_version[0], _llvm_version[1], _llvm_patch),
599 '-DMESA_LLVM_VERSION_PATCH=@0@'.format(_llvm_patch),
600 ]
601 else
Dylan Baker6a9ad202017-10-10 14:56:39 -0700602 if with_gallium_softpipe
603 error('Cannot find LLVM to build LLVMPipe. If you wanted softpipe pass -Dllvm=false to meson')
604 elif with_amd_vk or with_gallium_radeonsi # etc
Dylan Baker66f97f62017-09-30 09:03:51 -0700605 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 -0700606 endif
Dylan Baker673dda82017-09-20 11:53:29 -0700607 endif
Dylan Baker66f97f62017-09-30 09:03:51 -0700608elif with_amd_vk or with_gallium_radeonsi
609 error('The following drivers requires LLVM: Radv, RadeonSI. One of these is enabled, but LLVM is disabled.')
Dylan Baker673dda82017-09-20 11:53:29 -0700610endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700611
Dylan Bakera47c5252017-09-22 12:55:00 -0700612dep_glvnd = []
613if with_glvnd
614 dep_glvnd = dependency('libglvnd', version : '>= 0.2.0')
615 pre_args += '-DUSE_LIBGLVND=1'
616endif
617
Dylan Bakerd1992252017-09-14 17:57:17 -0700618# TODO: make this conditional
619dep_valgrind = dependency('valgrind', required : false)
620if dep_valgrind.found() and with_valgrind
621 pre_args += '-DHAVE_VALGRIND'
622endif
623
624# pthread stubs. Lets not and say we didn't
625
Dylan Baker32180562017-09-20 20:11:32 -0700626prog_bison = find_program('bison', required : with_any_opengl)
627prog_flex = find_program('flex', required : with_any_opengl)
628
Dylan Bakerd1992252017-09-14 17:57:17 -0700629# TODO: selinux
Dylan Baker32180562017-09-20 20:11:32 -0700630dep_selinux = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700631
632# TODO: llvm-prefix and llvm-shared-libs
633
Dylan Bakerb1b65392017-09-28 22:25:02 -0700634dep_unwind = dependency('libunwind', required : false)
635if dep_unwind.found()
636 pre_args += '-DHAVE_LIBUNWIND'
637endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700638
639# TODO: flags for opengl, gles, dri
640
641# TODO: gallium-hud
642
643# TODO: glx provider
644
645# TODO: osmesa provider
646
Dylan Bakerd1992252017-09-14 17:57:17 -0700647# TODO: symbol mangling
648
Dylan Bakerd1992252017-09-14 17:57:17 -0700649# TODO: egl configuration
650
651if with_platform_wayland
652 prog_wl_scanner = find_program('wayland-scanner')
653 dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8')
654 dep_wayland_client = dependency('wayland-client', version : '>=1.11')
655 dep_wayland_server = dependency('wayland-server', version : '>=1.11')
656else
657 prog_wl_scanner = []
658 dep_wl_protocols = []
659 dep_wayland_client = []
660 dep_wayland_server = []
661endif
662
Dylan Baker50c28df2017-09-29 17:53:01 -0700663dep_x11 = []
664dep_xext = []
665dep_xdamage = []
666dep_xfixes = []
667dep_x11_xcb = []
668dep_xcb_glx = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700669dep_xcb_dri2 = []
670dep_xcb_dri3 = []
Dylan Bakera47c5252017-09-22 12:55:00 -0700671dep_dri2proto = []
672dep_glproto = []
Dylan Bakera47c5252017-09-22 12:55:00 -0700673dep_xf86vm = []
Dylan Baker50c28df2017-09-29 17:53:01 -0700674dep_xcb_dri3 = []
675dep_xcb_present = []
676dep_xcb_sync = []
677dep_xshmfence = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700678if with_platform_x11
Dylan Baker50c28df2017-09-29 17:53:01 -0700679 if with_glx == 'dri' and with_dri_platform == 'drm'
680 dep_x11 = dependency('x11')
681 dep_xext = dependency('xext')
682 dep_xdamage = dependency('xdamage', version : '>= 1.1')
683 dep_xfixes = dependency('xfixes')
684 dep_xcb_glx = dependency('xcb-glx', version : '>= 1.8.1')
Nicholas Miell30128852017-10-17 18:04:16 -0700685 dep_xf86vm = dependency('xxf86vm', required : false)
Dylan Bakera47c5252017-09-22 12:55:00 -0700686 endif
687 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
Dylan Baker50c28df2017-09-29 17:53:01 -0700688 dep_xcb = dependency('xcb')
689 dep_x11_xcb = dependency('x11-xcb')
690 dep_xcb_dri2 = dependency('xcb-dri2', version : '>= 1.8')
691
Dylan Bakera47c5252017-09-22 12:55:00 -0700692 if with_dri3
693 pre_args += '-DHAVE_DRI3'
Dylan Baker50c28df2017-09-29 17:53:01 -0700694 dep_xcb_dri3 = dependency('xcb-dri3')
695 dep_xcb_present = dependency('xcb-present')
696 dep_xcb_sync = dependency('xcb-sync')
697 dep_xshmfence = dependency('xshmfence', version : '>= 1.1')
Dylan Bakera47c5252017-09-22 12:55:00 -0700698 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700699 endif
Dylan Baker50c28df2017-09-29 17:53:01 -0700700 if with_glx != 'disabled'
701 dep_dri2proto = dependency('dri2proto', version : '>= 2.8')
702 dep_glproto = dependency('glproto', version : '>= 1.4.14')
703 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700704endif
705
706# TODO: platforms for !vulkan
707
Dylan Bakerd1992252017-09-14 17:57:17 -0700708# TODO: osmesa
709
710# TODO: egl
711
Dylan Bakerd1992252017-09-14 17:57:17 -0700712# TODO: vallium G3DVL
713
714# TODO: nine
715
716# TODO: clover
717
718# TODO: egl sans x11
Dylan Bakerd1992252017-09-14 17:57:17 -0700719# TODO: gallium tests
720
721# TODO: various libdirs
722
723# TODO: swr
724
725# TODO: gallium driver dirs
726
727# FIXME: this is a workaround for #2326
728prog_touch = find_program('touch')
729dummy_cpp = custom_target(
730 'dummy_cpp',
731 output : 'dummy.cpp',
732 command : [prog_touch, '@OUTPUT@'],
733)
734
735foreach a : pre_args
736 add_project_arguments(a, language : ['c', 'cpp'])
737endforeach
738foreach a : c_args
739 add_project_arguments(a, language : ['c'])
740endforeach
741foreach a : cpp_args
742 add_project_arguments(a, language : ['cpp'])
743endforeach
744
745inc_include = include_directories('include')
746
Dylan Baker32180562017-09-20 20:11:32 -0700747pkg = import('pkgconfig')
748
Dylan Bakerd1992252017-09-14 17:57:17 -0700749subdir('include')
750subdir('src')