blob: a21781f3b8c82f008b9f18dda58b33654de090ad [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 Baker51558a12017-10-20 15:45:22 -0700100with_gallium_etnaviv = false
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700101_drivers = get_option('gallium-drivers')
102if _drivers != ''
103 _split = _drivers.split(',')
Dylan Bakerfbf39fd2017-10-17 14:44:15 -0700104 with_gallium_pl111 = _split.contains('pl111')
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700105 with_gallium_radeonsi = _split.contains('radeonsi')
Dylan Baker813b4b02017-10-09 14:59:35 -0700106 with_gallium_nouveau = _split.contains('nouveau')
Dylan Bakerde24d612017-10-10 14:27:19 -0700107 with_gallium_softpipe = _split.contains('swrast')
Eric Anholt1ae80182017-10-12 13:53:12 -0700108 with_gallium_vc4 = _split.contains('vc4')
Eric Anholt4f3e3802017-10-12 18:40:16 -0700109 with_gallium_vc5 = _split.contains('vc5')
Dylan Baker51558a12017-10-20 15:45:22 -0700110 with_gallium_etnaviv = _split.contains('etnaviv')
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700111 with_gallium = true
112 with_dri = true
Ville Syrjälä22899642017-10-10 01:15:42 +0300113endif
114
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700115if not (with_dri or with_gallium)
Dylan Baker32180562017-09-20 20:11:32 -0700116 with_gles1 = false
117 with_gles2 = false
118 with_opengl = false
119 with_any_opengl = false
120 with_shared_glapi = false
121endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700122
Dylan Bakerde24d612017-10-10 14:27:19 -0700123if with_dri_swrast and with_gallium_softpipe
124 error('Only one swrast provider can be built')
125endif
126
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700127dep_libdrm_intel = []
128if with_dri_i915
129 dep_libdrm_intel = dependency('libdrm_intel', version : '>= 2.4.75')
130endif
131
Dylan Bakera47c5252017-09-22 12:55:00 -0700132# TODO: other OSes
133with_dri_platform = 'drm'
134
Dylan Baker108d2572017-10-18 12:20:43 -0700135# TODO: android platform
Dylan Bakerd1992252017-09-14 17:57:17 -0700136with_platform_wayland = false
137with_platform_x11 = false
Dylan Bakerb1b65392017-09-28 22:25:02 -0700138with_platform_drm = false
Dylan Baker108d2572017-10-18 12:20:43 -0700139with_platform_surfaceless = false
140egl_native_platform = ''
Dylan Bakerd1992252017-09-14 17:57:17 -0700141_platforms = get_option('platforms')
142if _platforms != ''
143 _split = _platforms.split(',')
144 with_platform_x11 = _split.contains('x11')
145 with_platform_wayland = _split.contains('wayland')
Dylan Bakerb1b65392017-09-28 22:25:02 -0700146 with_platform_drm = _split.contains('drm')
Dylan Baker108d2572017-10-18 12:20:43 -0700147 with_platform_surfaceless = _split.contains('surfaceless')
148 egl_native_platform = _split[0]
Dylan Bakerd1992252017-09-14 17:57:17 -0700149endif
150
Dylan Baker816bf7d12017-09-28 15:53:53 -0700151with_gbm = get_option('gbm')
152if with_gbm == 'auto' and with_dri # TODO: or gallium
153 with_gbm = host_machine.system() == 'linux'
154elif with_gbm == 'yes'
155 if not ['linux', 'bsd'].contains(host_machine.system())
156 error('GBM only supports unix-like platforms')
157 endif
158 with_gbm = true
159else
160 with_gbm = false
161endif
162
Dylan Baker108d2572017-10-18 12:20:43 -0700163_egl = get_option('egl')
164if _egl == 'auto'
165 with_egl = with_dri and with_shared_glapi and egl_native_platform != ''
166elif _egl == 'yes'
167 if not with_dri
168 error('EGL requires dri')
169 elif not with_shared_glapi
170 error('EGL requires shared-glapi')
171 elif egl_native_platform == ''
172 error('No platforms specified, consider -Dplatforms=drm,x11 at least')
173 endif
174 with_egl = true
175else
176 with_egl = false
177endif
178
179# TODO: or virgl
180if with_egl and with_gallium_radeonsi and not (with_platform_drm or with_platform_surfaceless)
181 error('RadeonSI requires drm or surfaceless platform when using EGL')
182endif
183
Dylan Baker8e611872017-10-11 12:49:31 -0700184pre_args += '-DGLX_USE_TLS'
Dylan Bakera47c5252017-09-22 12:55:00 -0700185with_glx = get_option('glx')
186if with_glx != 'disabled'
Dylan Baker8d3b1212017-10-18 15:47:11 -0700187 if not (with_platform_x11 and with_any_opengl)
188 if with_glx == 'auto'
189 with_glx = 'disabled'
190 else
191 error('Cannot build GLX support without X11 platform support and at least one OpenGL API')
192 endif
Dylan Bakera47c5252017-09-22 12:55:00 -0700193 elif with_glx == 'gallium-xlib'
194 if not with_gallium
195 error('Gallium-xlib based GLX requires at least one gallium driver')
196 elif with_dri
197 error('gallium-xlib conflicts with any dri driver')
198 endif
199 elif with_glx == 'dri' and not with_dri
200 error('dri based GLX requires at least one DRI driver')
201 elif with_glx == 'auto'
202 if with_dri
203 with_glx = 'dri'
204 elif with_gallium
205 with_glx = 'gallium-xlib'
206 elif with_platform_x11 and with_any_opengl
207 with_glx = 'xlib'
208 else
209 with_glx = 'disabled'
210 endif
211 endif
212endif
213
214with_glvnd = get_option('glvnd')
215if with_glvnd and with_glx != 'dri'
216 message('glvnd requires dri based glx')
217endif
218
219# TODO: toggle for this
220with_glx_direct = true
221
Dylan Bakerd1992252017-09-14 17:57:17 -0700222if with_vulkan_icd_dir == ''
223 with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
224endif
225
226with_intel_vk = false
227with_amd_vk = false
Dylan Bakera47c5252017-09-22 12:55:00 -0700228with_any_vk = false
Dylan Bakerd1992252017-09-14 17:57:17 -0700229_vulkan_drivers = get_option('vulkan-drivers')
230if _vulkan_drivers != ''
231 _split = _vulkan_drivers.split(',')
232 with_intel_vk = _split.contains('intel')
233 with_amd_vk = _split.contains('amd')
Dylan Bakera47c5252017-09-22 12:55:00 -0700234 with_any_vk = with_amd_vk or with_intel_vk
Dylan Bakerd1992252017-09-14 17:57:17 -0700235 if not (with_platform_x11 or with_platform_wayland)
236 error('Vulkan requires at least one platform (x11, wayland)')
237 endif
Dylan Bakera47c5252017-09-22 12:55:00 -0700238endif
239
Dylan Baker50c28df2017-09-29 17:53:01 -0700240with_dri2 = (with_dri or with_any_vk) and with_dri_platform == 'drm'
241with_dri3 = get_option('dri3')
242if with_dri3 == 'auto'
243 if host_machine.system() == 'linux' and with_dri2
244 with_dri3 = true
245 else
246 with_dri3 = false
247 endif
248elif with_dri3 == 'yes'
249 with_dri3 = true
250else
251 with_dri3 = false
252endif
253
254if with_any_vk and (with_platform_x11 and not with_dri3)
255 error('Vulkan drivers require dri3 for X11 support')
256endif
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700257if with_dri or with_gallium
Dylan Baker108d2572017-10-18 12:20:43 -0700258 if with_glx == 'disabled' and not with_egl
Dylan Bakera47c5252017-09-22 12:55:00 -0700259 error('building dri or gallium drivers require at least one window system')
260 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700261endif
262
Dylan Baker50c28df2017-09-29 17:53:01 -0700263with_gallium_xvmc = false
264with_gallium_vdpau = false
265with_gallium_omx = false # this is bellagio
266with_gallium_va = false
267with_gallium_media = false
268dep_va = []
269_drivers = get_option('gallium-media')
270if _drivers != ''
271 _split = _drivers.split(',')
272 with_gallium_xvmc = _split.contains('xvmc')
273 with_gallium_vdpau = _split.contains('vdpau')
274 with_gallium_omx = _split.contains('omx')
275 with_gallium_va = _split.contains('va')
276 with_gallium_media = (with_gallium_xvmc or with_gallium_vdpau or
277 with_gallium_omx or with_gallium_va)
278endif
279
Dylan Baker108d2572017-10-18 12:20:43 -0700280gl_pkgconfig_c_flags = []
Dylan Baker50c28df2017-09-29 17:53:01 -0700281if with_platform_x11
282 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
283 pre_args += '-DHAVE_X11_PLATFORM'
284 endif
285 if with_glx == 'xlib'
286 # TODO
287 error('TODO')
288 elif with_glx == 'gallium-xlib'
289 # TODO
290 error('TODO')
291 else
292 pre_args += '-DGLX_INDIRECT_RENDERING'
293 if with_glx_direct
294 pre_args += '-DGLX_DIRECT_RENDERING'
295 endif
296 if with_dri_platform == 'drm'
297 pre_args += '-DGLX_USE_DRM'
298 endif
299 endif
Dylan Baker108d2572017-10-18 12:20:43 -0700300else
301 pre_args += '-DMESA_EGL_NO_X11_HEADERS'
302 gl_pkgconfig_c_flags += '-DMESA_EGL_NO_X11_HEADERS'
303endif
304if with_platform_drm
305 if with_egl and not with_gbm
306 error('EGL drm platform requires gbm')
307 endif
308 pre_args += '-DHAVE_DRM_PLATFORM'
309endif
310if with_platform_surfaceless
311 pre_args += '-DHAVE_SURFACELESS_PLATFORM'
Dylan Baker50c28df2017-09-29 17:53:01 -0700312endif
313
Dylan Bakerd1992252017-09-14 17:57:17 -0700314prog_python2 = find_program('python2')
Dylan Baker9342a7d2017-09-28 10:48:30 -0700315has_mako = run_command(prog_python2, '-c', 'import mako')
316if has_mako.returncode() != 0
317 error('Python (2.x) mako module required to build mesa.')
318endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700319
320cc = meson.get_compiler('c')
321if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
Eric Engestrom1262e822017-09-29 15:25:18 +0100322 error('When using GCC, version 4.4.6 or later is required.')
Dylan Bakerd1992252017-09-14 17:57:17 -0700323endif
324
Dylan Bakerd1992252017-09-14 17:57:17 -0700325# Define DEBUG for debug and debugoptimized builds
326if get_option('buildtype').startswith('debug')
327 pre_args += '-DDEBUG'
328endif
329
Dylan Baker673dda82017-09-20 11:53:29 -0700330if get_option('shader-cache')
331 pre_args += '-DENABLE_SHADER_CACHE'
332elif with_amd_vk
333 error('Radv requires shader cache support')
334endif
335
Dylan Bakerd1992252017-09-14 17:57:17 -0700336# Check for GCC style builtins
337foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
338 'ffsll', 'popcount', 'popcountll', 'unreachable']
339 if cc.has_function(b)
340 pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
341 endif
342endforeach
343
Dylan Baker673dda82017-09-20 11:53:29 -0700344# check for GCC __attribute__
Dylan Bakerd1992252017-09-14 17:57:17 -0700345foreach a : ['const', 'flatten', 'malloc', 'pure', 'unused',
346 'warn_unused_result', 'weak',]
347 if cc.compiles('int foo(void) __attribute__((@0@));'.format(a),
348 name : '__attribute__((@0@))'.format(a))
349 pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
350 endif
351endforeach
352if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
353 name : '__attribute__((format(...)))')
354 pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
355endif
356if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
357 name : '__attribute__((packed))')
358 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
359endif
360if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
361 name : '__attribute__((returns_nonnull))')
362 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NONNULL'
363endif
364if cc.compiles('''int foo_def(void) __attribute__((visibility("default")));
365 int foo_hid(void) __attribute__((visibility("hidden")));
366 int foo_int(void) __attribute__((visibility("internal")));
367 int foo_pro(void) __attribute__((visibility("protected")));''',
368 name : '__attribute__((visibility(...)))')
369 pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISBILITY'
370endif
371if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
372 name : '__attribute__((alias(...)))')
373 pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
374endif
375
376# TODO: this is very incomplete
377if host_machine.system() == 'linux'
378 pre_args += '-D_GNU_SOURCE'
379endif
380
381# Check for generic C arguments
382c_args = []
383foreach a : ['-Wall', '-Werror=implicit-function-declaration',
384 '-Werror=missing-prototypes', '-fno-math-errno',
385 '-fno-trapping-math', '-Qunused-arguments']
386 if cc.has_argument(a)
387 c_args += a
388 endif
389endforeach
390c_vis_args = []
391if cc.has_argument('-fvisibility=hidden')
392 c_vis_args += '-fvisibility=hidden'
393endif
394
395# Check for generic C++ arguments
396cpp = meson.get_compiler('cpp')
397cpp_args = []
398foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math',
399 '-Qunused-arguments', '-Wno-non-virtual-dtor']
400 if cpp.has_argument(a)
401 cpp_args += a
402 endif
403endforeach
404cpp_vis_args = []
405if cpp.has_argument('-fvisibility=hidden')
406 cpp_vis_args += '-fvisibility=hidden'
407endif
408
409# Check for C and C++ arguments for MSVC2013 compatibility. These are only used
410# in parts of the mesa code base that need to compile with old versions of
411# MSVC, mainly common code
412c_msvc_compat_args = []
413cpp_msvc_compat_args = []
414foreach a : ['-Werror=pointer-arith', '-Werror=vla']
415 if cc.has_argument(a)
416 c_msvc_compat_args += a
417 endif
418 if cpp.has_argument(a)
419 cpp_msvc_compat_args += a
420 endif
421endforeach
422
423no_override_init_args = []
424foreach a : ['-Wno-override-init', '-Wno-initializer-overrides']
425 if cc.has_argument(a)
426 no_override_init_args += a
427 endif
428endforeach
429
430# TODO: SSE41 (which is only required for core mesa)
431
432# Check for GCC style atomics
433if cc.compiles('int main() { int n; return __atomic_load_n(&n, __ATOMIC_ACQUIRE); }',
434 name : 'GCC atomic builtins')
435 pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
436endif
437if not cc.links('''#include <stdint.h>
438 uint64_t v;
439 int main() {
440 return __sync_add_and_fetch(&v, (uint64_t)1);
441 }''',
442 name : 'GCC 64bit atomics')
443 pre_args += '-DMISSING_64_BIT_ATOMICS'
444endif
445
446# TODO: endian
447# TODO: powr8
448# TODO: shared/static? Is this even worth doing?
449
450# I don't think that I need to set any of the debug stuff, I think meson
451# handles that for us
452
453# TODO: ldflags
454
455# TODO: texture-float (gallium/mesa only)
456
457# TODO: cross-compiling. I don't think this is relavent to meson
458
Dylan Baker32180562017-09-20 20:11:32 -0700459# FIXME: enable asm when cross compiler
460# This is doable (autotools does it), but it's not of immediate concern
461if meson.is_cross_build()
462 message('Cross compiling, disabling asm')
463 with_asm = false
464endif
465
466with_asm_arch = ''
467if with_asm
468 # TODO: SPARC and PPC
469 if host_machine.cpu_family() == 'x86'
470 if ['linux', 'bsd'].contains(host_machine.system()) # FIXME: hurd?
471 with_asm_arch = 'x86'
472 pre_args += ['-DUSE_X86_ASM', '-DUSE_MMX_ASM', '-DUSE_3DNOW_ASM',
473 '-DUSE_SSE_ASM']
474 endif
475 elif host_machine.cpu_family() == 'x86_64'
476 if host_machine.system() == 'linux'
477 with_asm_arch = 'x86_64'
478 pre_args += ['-DUSE_X86_64_ASM']
479 endif
480 elif host_machine.cpu_family() == 'arm'
481 if host_machine.system() == 'linux'
482 with_asm_arch = 'arm'
483 pre_args += ['-DUSE_ARM_ASM']
484 endif
485 elif host_machine.cpu_family() == 'aarch64'
486 if host_machine.system() == 'linux'
487 with_asm_arch = 'aarch64'
488 pre_args += ['-DUSE_AARCH64_ASM']
489 endif
490 endif
491endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700492
493# Check for standard headers and functions
494if cc.has_header_symbol('sys/sysmacros.h', 'major')
495 pre_args += '-DMAJOR_IN_SYSMACROS'
496elif cc.has_header_symbol('sys/mkdev.h', 'major')
497 pre_args += '-DMAJOR_IN_MKDEV'
498endif
499
500foreach h : ['xlocale.h', 'sys/sysctl.h']
501 if cc.has_header(h)
502 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
503 endif
504endforeach
505
506foreach f : ['strtof', 'mkostemp', 'posix_memalign']
507 if cc.has_function(f)
508 pre_args += '-DHAVE_@0@'.format(f.to_upper())
509 endif
510endforeach
511
512# strtod locale support
513if cc.links('''
514 #define _GNU_SOURCE
515 #include <stdlib.h>
516 #include <locale.h>
517 #ifdef HAVE_XLOCALE_H
518 #include <xlocale.h>
519 #endif
520 int main() {
521 locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
522 const char *s = "1.0";
523 char *end;
524 double d = strtod_l(s, end, loc);
525 float f = strtod_l(s, end, loc);
526 freelocale(loc);
527 return 0;
528 }''',
529 extra_args : pre_args,
530 name : 'strtod has locale support')
531 pre_args += '-DHAVE_STRTOD_L'
532endif
533
534# Check for some linker flags
535ld_args_bsymbolic = []
Dylan Bakere21e0a62017-09-30 13:15:52 -0700536if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic', name : 'Bsymbolic')
Dylan Bakerd1992252017-09-14 17:57:17 -0700537 ld_args_bsymbolic += '-Wl,-Bsymbolic'
538endif
539ld_args_gc_sections = []
540if cc.links('static char unused() { return 5; } int main() { return 0; }',
Dylan Bakere21e0a62017-09-30 13:15:52 -0700541 args : '-Wl,--gc-sections', name : 'gc-sections')
Dylan Bakerd1992252017-09-14 17:57:17 -0700542 ld_args_gc_sections += '-Wl,--gc-sections'
543endif
Dylan Bakere21e0a62017-09-30 13:15:52 -0700544with_ld_version_script = false
545if cc.links('int main() { return 0; }',
546 args : '-Wl,--version-script=@0@'.format(
547 join_paths(meson.source_root(), 'build-support/conftest.map')),
548 name : 'version-script')
549 with_ld_version_script = true
550endif
551with_ld_dynamic_list = false
552if cc.links('int main() { return 0; }',
553 args : '-Wl,--dynamic-list=@0@'.format(
554 join_paths(meson.source_root(), 'build-support/conftest.dyn')),
555 name : 'dynamic-list')
556 with_ld_dynamic_list = true
557endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700558
559# check for dl support
560if cc.has_function('dlopen')
561 dep_dl = []
562else
563 dep_dl = cc.find_library('dl')
564endif
Dylan Baker32180562017-09-20 20:11:32 -0700565if cc.has_function('dladdr', dependencies : dep_dl)
566 # This is really only required for megadrivers
567 pre_args += '-DHAVE_DLADDR'
Dylan Bakerd1992252017-09-14 17:57:17 -0700568endif
569
570if cc.has_function('dl_iterate_phdr')
571 pre_args += '-DHAVE_DL_ITERATE_PHDR'
572else
573 # TODO: this is required for vulkan
574endif
575
576# Determine whether or not the rt library is needed for time functions
577if cc.has_function('clock_gettime')
578 dep_clock = []
579else
580 dep_clock = cc.find_library('rt')
581endif
582
Dylan Baker66c94b92017-09-30 13:48:34 -0700583with_gallium_drisw_kms = false
Dylan Baker50c28df2017-09-29 17:53:01 -0700584dep_libdrm = dependency('libdrm', version : '>= 2.4.75',
585 required : with_dri2 or with_dri3)
586if dep_libdrm.found()
587 pre_args += '-DHAVE_LIBDRM'
Dylan Baker66c94b92017-09-30 13:48:34 -0700588 if with_dri_platform == 'drm' and with_dri
589 with_gallium_drisw_kms = true
590 endif
Dylan Baker50c28df2017-09-29 17:53:01 -0700591endif
592
Dylan Bakerd1992252017-09-14 17:57:17 -0700593# TODO: some of these may be conditional
594dep_zlib = dependency('zlib', version : '>= 1.2.3')
595dep_thread = dependency('threads')
Dylan Baker50c28df2017-09-29 17:53:01 -0700596if dep_thread.found() and host_machine.system() == 'linux'
597 pre_args += '-DHAVE_PTHREAD'
598endif
Dylan Bakercc4f5872017-09-27 11:30:21 -0700599dep_elf = dependency('libelf', required : false)
Dylan Bakerb154b442017-09-30 14:04:28 -0700600if not dep_elf.found() and (with_amd_vk or with_gallium_radeonsi) # TODO: clover, r600
601 dep_elf = cc.find_library('elf')
Dylan Bakercc4f5872017-09-27 11:30:21 -0700602endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700603dep_expat = dependency('expat')
604# this only exists on linux so either this is linux and it will be found, or
605# its not linux and and wont
606dep_m = cc.find_library('m', required : false)
Dylan Baker66f97f62017-09-30 09:03:51 -0700607
608dep_libdrm_amdgpu = []
609dep_libdrm_radeon = []
Dylan Baker813b4b02017-10-09 14:59:35 -0700610dep_libdrm_nouveau = []
Dylan Baker51558a12017-10-20 15:45:22 -0700611dep_libdrm_etnaviv = []
Dylan Baker66f97f62017-09-30 09:03:51 -0700612if with_amd_vk or with_gallium_radeonsi
Dylan Baker8792a9e2017-10-20 16:28:32 -0700613 dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.85')
Dylan Baker66f97f62017-09-30 09:03:51 -0700614endif
615if with_gallium_radeonsi # older radeon too
616 dep_libdrm_radeon = dependency('libdrm_radeon', version : '>= 2.4.71')
617endif
Dylan Baker813b4b02017-10-09 14:59:35 -0700618if with_gallium_nouveau
619 dep_libdrm_nouveau = dependency('libdrm_nouveau', version : '>= 2.4.66')
620endif
Dylan Baker51558a12017-10-20 15:45:22 -0700621if with_gallium_etnaviv
622 dep_libdrm_etnaviv = dependency('libdrm_etnaviv', version : '>= 2.4.82')
623endif
Dylan Baker673dda82017-09-20 11:53:29 -0700624
625llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
626if with_amd_vk
627 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
628endif
629dep_llvm = dependency(
Dylan Baker50c28df2017-09-29 17:53:01 -0700630 'llvm', version : '>= 3.9.0', required : with_amd_vk, modules : llvm_modules,
Dylan Baker673dda82017-09-20 11:53:29 -0700631)
Dylan Baker02cf3a82017-10-12 09:47:30 -0700632if with_llvm
633 if dep_llvm.found()
634 _llvm_version = dep_llvm.version().split('.')
635 # Development versions of LLVM have an 'svn' suffix, we don't want that for
636 # our version checks.
637 _llvm_patch = _llvm_version[2]
638 if _llvm_patch.endswith('svn')
639 _llvm_patch = _llvm_patch.split('s')[0]
640 endif
641 pre_args += [
642 '-DHAVE_LLVM=0x0@0@@1@@2@'.format(_llvm_version[0], _llvm_version[1], _llvm_patch),
643 '-DMESA_LLVM_VERSION_PATCH=@0@'.format(_llvm_patch),
644 ]
645 else
Dylan Baker6a9ad202017-10-10 14:56:39 -0700646 if with_gallium_softpipe
647 error('Cannot find LLVM to build LLVMPipe. If you wanted softpipe pass -Dllvm=false to meson')
648 elif with_amd_vk or with_gallium_radeonsi # etc
Dylan Baker66f97f62017-09-30 09:03:51 -0700649 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 -0700650 endif
Dylan Baker673dda82017-09-20 11:53:29 -0700651 endif
Dylan Baker66f97f62017-09-30 09:03:51 -0700652elif with_amd_vk or with_gallium_radeonsi
653 error('The following drivers requires LLVM: Radv, RadeonSI. One of these is enabled, but LLVM is disabled.')
Dylan Baker673dda82017-09-20 11:53:29 -0700654endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700655
Dylan Bakera47c5252017-09-22 12:55:00 -0700656dep_glvnd = []
657if with_glvnd
658 dep_glvnd = dependency('libglvnd', version : '>= 0.2.0')
659 pre_args += '-DUSE_LIBGLVND=1'
660endif
661
Dylan Bakerd1992252017-09-14 17:57:17 -0700662# TODO: make this conditional
663dep_valgrind = dependency('valgrind', required : false)
664if dep_valgrind.found() and with_valgrind
665 pre_args += '-DHAVE_VALGRIND'
666endif
667
668# pthread stubs. Lets not and say we didn't
669
Dylan Baker32180562017-09-20 20:11:32 -0700670prog_bison = find_program('bison', required : with_any_opengl)
671prog_flex = find_program('flex', required : with_any_opengl)
672
Dylan Bakerd1992252017-09-14 17:57:17 -0700673# TODO: selinux
Dylan Baker32180562017-09-20 20:11:32 -0700674dep_selinux = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700675
676# TODO: llvm-prefix and llvm-shared-libs
677
Dylan Bakerb1b65392017-09-28 22:25:02 -0700678dep_unwind = dependency('libunwind', required : false)
679if dep_unwind.found()
680 pre_args += '-DHAVE_LIBUNWIND'
681endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700682
683# TODO: flags for opengl, gles, dri
684
685# TODO: gallium-hud
686
687# TODO: glx provider
688
689# TODO: osmesa provider
690
Dylan Bakerd1992252017-09-14 17:57:17 -0700691# TODO: symbol mangling
692
Dylan Bakerd1992252017-09-14 17:57:17 -0700693if with_platform_wayland
694 prog_wl_scanner = find_program('wayland-scanner')
695 dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8')
696 dep_wayland_client = dependency('wayland-client', version : '>=1.11')
697 dep_wayland_server = dependency('wayland-server', version : '>=1.11')
Dylan Baker108d2572017-10-18 12:20:43 -0700698 wayland_dmabuf_xml = join_paths(
699 dep_wl_protocols.get_pkgconfig_variable('pkgdatadir'), 'unstable',
700 'linux-dmabuf', 'linux-dmabuf-unstable-v1.xml'
701 )
702 pre_args += ['-DHAVE_WAYLAND_PLATFORM', '-DWL_HIDE_DEPRECATED']
Dylan Bakerd1992252017-09-14 17:57:17 -0700703else
704 prog_wl_scanner = []
705 dep_wl_protocols = []
706 dep_wayland_client = []
707 dep_wayland_server = []
Dylan Baker108d2572017-10-18 12:20:43 -0700708 wayland_dmabuf_xml = ''
Dylan Bakerd1992252017-09-14 17:57:17 -0700709endif
710
Dylan Baker50c28df2017-09-29 17:53:01 -0700711dep_x11 = []
712dep_xext = []
713dep_xdamage = []
714dep_xfixes = []
715dep_x11_xcb = []
716dep_xcb_glx = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700717dep_xcb_dri2 = []
718dep_xcb_dri3 = []
Dylan Bakera47c5252017-09-22 12:55:00 -0700719dep_dri2proto = []
720dep_glproto = []
Dylan Bakera47c5252017-09-22 12:55:00 -0700721dep_xf86vm = []
Dylan Baker50c28df2017-09-29 17:53:01 -0700722dep_xcb_dri3 = []
723dep_xcb_present = []
724dep_xcb_sync = []
Dylan Baker108d2572017-10-18 12:20:43 -0700725dep_xcb_xfixes = []
Dylan Baker50c28df2017-09-29 17:53:01 -0700726dep_xshmfence = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700727if with_platform_x11
Dylan Baker50c28df2017-09-29 17:53:01 -0700728 if with_glx == 'dri' and with_dri_platform == 'drm'
729 dep_x11 = dependency('x11')
730 dep_xext = dependency('xext')
731 dep_xdamage = dependency('xdamage', version : '>= 1.1')
732 dep_xfixes = dependency('xfixes')
733 dep_xcb_glx = dependency('xcb-glx', version : '>= 1.8.1')
Nicholas Miell30128852017-10-17 18:04:16 -0700734 dep_xf86vm = dependency('xxf86vm', required : false)
Dylan Bakera47c5252017-09-22 12:55:00 -0700735 endif
736 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
Dylan Baker50c28df2017-09-29 17:53:01 -0700737 dep_xcb = dependency('xcb')
738 dep_x11_xcb = dependency('x11-xcb')
739 dep_xcb_dri2 = dependency('xcb-dri2', version : '>= 1.8')
740
Dylan Bakera47c5252017-09-22 12:55:00 -0700741 if with_dri3
742 pre_args += '-DHAVE_DRI3'
Dylan Baker50c28df2017-09-29 17:53:01 -0700743 dep_xcb_dri3 = dependency('xcb-dri3')
744 dep_xcb_present = dependency('xcb-present')
745 dep_xcb_sync = dependency('xcb-sync')
746 dep_xshmfence = dependency('xshmfence', version : '>= 1.1')
Dylan Bakera47c5252017-09-22 12:55:00 -0700747 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700748 endif
Dylan Baker50c28df2017-09-29 17:53:01 -0700749 if with_glx != 'disabled'
750 dep_dri2proto = dependency('dri2proto', version : '>= 2.8')
751 dep_glproto = dependency('glproto', version : '>= 1.4.14')
752 endif
Dylan Baker108d2572017-10-18 12:20:43 -0700753 if with_egl
754 dep_xcb_xfixes = dependency('xcb-xfixes')
755 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700756endif
757
Dylan Bakerd1992252017-09-14 17:57:17 -0700758# TODO: osmesa
759
Dylan Bakerd1992252017-09-14 17:57:17 -0700760# TODO: vallium G3DVL
761
762# TODO: nine
763
764# TODO: clover
765
Dylan Bakerd1992252017-09-14 17:57:17 -0700766# TODO: gallium tests
767
768# TODO: various libdirs
769
770# TODO: swr
771
772# TODO: gallium driver dirs
773
774# FIXME: this is a workaround for #2326
775prog_touch = find_program('touch')
776dummy_cpp = custom_target(
777 'dummy_cpp',
778 output : 'dummy.cpp',
779 command : [prog_touch, '@OUTPUT@'],
780)
781
782foreach a : pre_args
783 add_project_arguments(a, language : ['c', 'cpp'])
784endforeach
785foreach a : c_args
786 add_project_arguments(a, language : ['c'])
787endforeach
788foreach a : cpp_args
789 add_project_arguments(a, language : ['cpp'])
790endforeach
791
792inc_include = include_directories('include')
793
Dylan Baker108d2572017-10-18 12:20:43 -0700794gl_priv_reqs = [
795 'x11', 'xext', 'xdamage >= 1.1', 'xfixes', 'x11-xcb', 'xcb',
796 'xcb-glx >= 1.8.1', 'libdrm >= 2.4.75',
797]
798if dep_xf86vm != [] and dep_xf86vm.found()
799 gl_priv_reqs += 'xf86vm'
800endif
801if with_dri_platform == 'drm'
802 gl_priv_reqs += 'xcb-dri2 >= 1.8'
803endif
804
805gl_priv_libs = []
806if dep_thread.found()
807 gl_priv_libs += ['-lpthread', '-pthread']
808endif
809if dep_m.found()
810 gl_priv_libs += '-lm'
811endif
812if dep_dl.found()
813 gl_priv_libs += '-ldl'
814endif
815
Dylan Baker32180562017-09-20 20:11:32 -0700816pkg = import('pkgconfig')
817
Dylan Bakerd1992252017-09-14 17:57:17 -0700818subdir('include')
819subdir('src')