blob: 8db4699ec5c0fbdc9ae9dd7acd632c6ce121b23f [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
Rob Clark4aa69cc2017-10-14 10:08:50 -040097with_gallium_freedreno = false
Dylan Bakerf3d03a22017-10-10 11:57:50 -070098with_gallium_softpipe = false
Eric Anholt1ae80182017-10-12 13:53:12 -070099with_gallium_vc4 = false
Eric Anholt4f3e3802017-10-12 18:40:16 -0700100with_gallium_vc5 = false
Dylan Baker51558a12017-10-20 15:45:22 -0700101with_gallium_etnaviv = false
Dylan Bakerd4567ef2017-10-20 15:57:15 -0700102with_gallium_imx = false
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700103_drivers = get_option('gallium-drivers')
104if _drivers != ''
105 _split = _drivers.split(',')
Dylan Bakerfbf39fd2017-10-17 14:44:15 -0700106 with_gallium_pl111 = _split.contains('pl111')
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700107 with_gallium_radeonsi = _split.contains('radeonsi')
Dylan Baker813b4b02017-10-09 14:59:35 -0700108 with_gallium_nouveau = _split.contains('nouveau')
Rob Clark4aa69cc2017-10-14 10:08:50 -0400109 with_gallium_freedreno = _split.contains('freedreno')
Dylan Bakerde24d612017-10-10 14:27:19 -0700110 with_gallium_softpipe = _split.contains('swrast')
Eric Anholt1ae80182017-10-12 13:53:12 -0700111 with_gallium_vc4 = _split.contains('vc4')
Eric Anholt4f3e3802017-10-12 18:40:16 -0700112 with_gallium_vc5 = _split.contains('vc5')
Dylan Baker51558a12017-10-20 15:45:22 -0700113 with_gallium_etnaviv = _split.contains('etnaviv')
Dylan Bakerd4567ef2017-10-20 15:57:15 -0700114 with_gallium_imx = _split.contains('imx')
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700115 with_gallium = true
116 with_dri = true
Ville Syrjälä22899642017-10-10 01:15:42 +0300117endif
118
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700119if not (with_dri or with_gallium)
Dylan Baker32180562017-09-20 20:11:32 -0700120 with_gles1 = false
121 with_gles2 = false
122 with_opengl = false
123 with_any_opengl = false
124 with_shared_glapi = false
125endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700126
Dylan Bakerde24d612017-10-10 14:27:19 -0700127if with_dri_swrast and with_gallium_softpipe
128 error('Only one swrast provider can be built')
129endif
Dylan Bakerd4567ef2017-10-20 15:57:15 -0700130if with_gallium_imx and not with_gallium_etnaviv
131 error('IMX driver requires etnaviv driver')
132endif
Dylan Bakerde24d612017-10-10 14:27:19 -0700133
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700134dep_libdrm_intel = []
135if with_dri_i915
136 dep_libdrm_intel = dependency('libdrm_intel', version : '>= 2.4.75')
137endif
138
Dylan Bakera47c5252017-09-22 12:55:00 -0700139# TODO: other OSes
140with_dri_platform = 'drm'
141
Dylan Baker108d2572017-10-18 12:20:43 -0700142# TODO: android platform
Dylan Bakerd1992252017-09-14 17:57:17 -0700143with_platform_wayland = false
144with_platform_x11 = false
Dylan Bakerb1b65392017-09-28 22:25:02 -0700145with_platform_drm = false
Dylan Baker108d2572017-10-18 12:20:43 -0700146with_platform_surfaceless = false
147egl_native_platform = ''
Dylan Bakerd1992252017-09-14 17:57:17 -0700148_platforms = get_option('platforms')
149if _platforms != ''
150 _split = _platforms.split(',')
151 with_platform_x11 = _split.contains('x11')
152 with_platform_wayland = _split.contains('wayland')
Dylan Bakerb1b65392017-09-28 22:25:02 -0700153 with_platform_drm = _split.contains('drm')
Dylan Baker108d2572017-10-18 12:20:43 -0700154 with_platform_surfaceless = _split.contains('surfaceless')
155 egl_native_platform = _split[0]
Dylan Bakerd1992252017-09-14 17:57:17 -0700156endif
157
Dylan Baker816bf7d12017-09-28 15:53:53 -0700158with_gbm = get_option('gbm')
159if with_gbm == 'auto' and with_dri # TODO: or gallium
160 with_gbm = host_machine.system() == 'linux'
161elif with_gbm == 'yes'
162 if not ['linux', 'bsd'].contains(host_machine.system())
163 error('GBM only supports unix-like platforms')
164 endif
165 with_gbm = true
166else
167 with_gbm = false
168endif
169
Dylan Baker108d2572017-10-18 12:20:43 -0700170_egl = get_option('egl')
171if _egl == 'auto'
172 with_egl = with_dri and with_shared_glapi and egl_native_platform != ''
173elif _egl == 'yes'
174 if not with_dri
175 error('EGL requires dri')
176 elif not with_shared_glapi
177 error('EGL requires shared-glapi')
178 elif egl_native_platform == ''
179 error('No platforms specified, consider -Dplatforms=drm,x11 at least')
180 endif
181 with_egl = true
182else
183 with_egl = false
184endif
185
186# TODO: or virgl
187if with_egl and with_gallium_radeonsi and not (with_platform_drm or with_platform_surfaceless)
188 error('RadeonSI requires drm or surfaceless platform when using EGL')
189endif
190
Dylan Baker8e611872017-10-11 12:49:31 -0700191pre_args += '-DGLX_USE_TLS'
Dylan Bakera47c5252017-09-22 12:55:00 -0700192with_glx = get_option('glx')
193if with_glx != 'disabled'
Dylan Baker8d3b1212017-10-18 15:47:11 -0700194 if not (with_platform_x11 and with_any_opengl)
195 if with_glx == 'auto'
196 with_glx = 'disabled'
197 else
198 error('Cannot build GLX support without X11 platform support and at least one OpenGL API')
199 endif
Dylan Bakera47c5252017-09-22 12:55:00 -0700200 elif with_glx == 'gallium-xlib'
201 if not with_gallium
202 error('Gallium-xlib based GLX requires at least one gallium driver')
203 elif with_dri
204 error('gallium-xlib conflicts with any dri driver')
205 endif
206 elif with_glx == 'dri' and not with_dri
207 error('dri based GLX requires at least one DRI driver')
208 elif with_glx == 'auto'
209 if with_dri
210 with_glx = 'dri'
211 elif with_gallium
212 with_glx = 'gallium-xlib'
213 elif with_platform_x11 and with_any_opengl
214 with_glx = 'xlib'
215 else
216 with_glx = 'disabled'
217 endif
218 endif
219endif
220
221with_glvnd = get_option('glvnd')
222if with_glvnd and with_glx != 'dri'
223 message('glvnd requires dri based glx')
224endif
225
226# TODO: toggle for this
227with_glx_direct = true
228
Dylan Bakerd1992252017-09-14 17:57:17 -0700229if with_vulkan_icd_dir == ''
230 with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
231endif
232
233with_intel_vk = false
234with_amd_vk = false
Dylan Bakera47c5252017-09-22 12:55:00 -0700235with_any_vk = false
Dylan Bakerd1992252017-09-14 17:57:17 -0700236_vulkan_drivers = get_option('vulkan-drivers')
237if _vulkan_drivers != ''
238 _split = _vulkan_drivers.split(',')
239 with_intel_vk = _split.contains('intel')
240 with_amd_vk = _split.contains('amd')
Dylan Bakera47c5252017-09-22 12:55:00 -0700241 with_any_vk = with_amd_vk or with_intel_vk
Dylan Bakerd1992252017-09-14 17:57:17 -0700242 if not (with_platform_x11 or with_platform_wayland)
243 error('Vulkan requires at least one platform (x11, wayland)')
244 endif
Dylan Bakera47c5252017-09-22 12:55:00 -0700245endif
246
Dylan Baker50c28df2017-09-29 17:53:01 -0700247with_dri2 = (with_dri or with_any_vk) and with_dri_platform == 'drm'
248with_dri3 = get_option('dri3')
249if with_dri3 == 'auto'
250 if host_machine.system() == 'linux' and with_dri2
251 with_dri3 = true
252 else
253 with_dri3 = false
254 endif
255elif with_dri3 == 'yes'
256 with_dri3 = true
257else
258 with_dri3 = false
259endif
260
261if with_any_vk and (with_platform_x11 and not with_dri3)
262 error('Vulkan drivers require dri3 for X11 support')
263endif
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700264if with_dri or with_gallium
Dylan Baker108d2572017-10-18 12:20:43 -0700265 if with_glx == 'disabled' and not with_egl
Dylan Bakera47c5252017-09-22 12:55:00 -0700266 error('building dri or gallium drivers require at least one window system')
267 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700268endif
269
Dylan Baker50c28df2017-09-29 17:53:01 -0700270with_gallium_xvmc = false
271with_gallium_vdpau = false
272with_gallium_omx = false # this is bellagio
273with_gallium_va = false
274with_gallium_media = false
275dep_va = []
276_drivers = get_option('gallium-media')
277if _drivers != ''
278 _split = _drivers.split(',')
279 with_gallium_xvmc = _split.contains('xvmc')
280 with_gallium_vdpau = _split.contains('vdpau')
281 with_gallium_omx = _split.contains('omx')
282 with_gallium_va = _split.contains('va')
283 with_gallium_media = (with_gallium_xvmc or with_gallium_vdpau or
284 with_gallium_omx or with_gallium_va)
285endif
286
Dylan Baker108d2572017-10-18 12:20:43 -0700287gl_pkgconfig_c_flags = []
Dylan Baker50c28df2017-09-29 17:53:01 -0700288if with_platform_x11
289 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
290 pre_args += '-DHAVE_X11_PLATFORM'
291 endif
292 if with_glx == 'xlib'
293 # TODO
294 error('TODO')
295 elif with_glx == 'gallium-xlib'
296 # TODO
297 error('TODO')
298 else
299 pre_args += '-DGLX_INDIRECT_RENDERING'
300 if with_glx_direct
301 pre_args += '-DGLX_DIRECT_RENDERING'
302 endif
303 if with_dri_platform == 'drm'
304 pre_args += '-DGLX_USE_DRM'
305 endif
306 endif
Dylan Baker108d2572017-10-18 12:20:43 -0700307else
308 pre_args += '-DMESA_EGL_NO_X11_HEADERS'
309 gl_pkgconfig_c_flags += '-DMESA_EGL_NO_X11_HEADERS'
310endif
311if with_platform_drm
312 if with_egl and not with_gbm
313 error('EGL drm platform requires gbm')
314 endif
315 pre_args += '-DHAVE_DRM_PLATFORM'
316endif
317if with_platform_surfaceless
318 pre_args += '-DHAVE_SURFACELESS_PLATFORM'
Dylan Baker50c28df2017-09-29 17:53:01 -0700319endif
320
Dylan Bakerd1992252017-09-14 17:57:17 -0700321prog_python2 = find_program('python2')
Dylan Baker9342a7d2017-09-28 10:48:30 -0700322has_mako = run_command(prog_python2, '-c', 'import mako')
323if has_mako.returncode() != 0
324 error('Python (2.x) mako module required to build mesa.')
325endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700326
327cc = meson.get_compiler('c')
328if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
Eric Engestrom1262e822017-09-29 15:25:18 +0100329 error('When using GCC, version 4.4.6 or later is required.')
Dylan Bakerd1992252017-09-14 17:57:17 -0700330endif
331
Dylan Bakerd1992252017-09-14 17:57:17 -0700332# Define DEBUG for debug and debugoptimized builds
333if get_option('buildtype').startswith('debug')
334 pre_args += '-DDEBUG'
335endif
336
Dylan Baker673dda82017-09-20 11:53:29 -0700337if get_option('shader-cache')
338 pre_args += '-DENABLE_SHADER_CACHE'
339elif with_amd_vk
340 error('Radv requires shader cache support')
341endif
342
Dylan Bakerd1992252017-09-14 17:57:17 -0700343# Check for GCC style builtins
344foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
345 'ffsll', 'popcount', 'popcountll', 'unreachable']
346 if cc.has_function(b)
347 pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
348 endif
349endforeach
350
Dylan Baker673dda82017-09-20 11:53:29 -0700351# check for GCC __attribute__
Dylan Bakerd1992252017-09-14 17:57:17 -0700352foreach a : ['const', 'flatten', 'malloc', 'pure', 'unused',
353 'warn_unused_result', 'weak',]
354 if cc.compiles('int foo(void) __attribute__((@0@));'.format(a),
355 name : '__attribute__((@0@))'.format(a))
356 pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
357 endif
358endforeach
359if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
360 name : '__attribute__((format(...)))')
361 pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
362endif
363if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
364 name : '__attribute__((packed))')
365 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
366endif
367if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
368 name : '__attribute__((returns_nonnull))')
369 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NONNULL'
370endif
371if cc.compiles('''int foo_def(void) __attribute__((visibility("default")));
372 int foo_hid(void) __attribute__((visibility("hidden")));
373 int foo_int(void) __attribute__((visibility("internal")));
374 int foo_pro(void) __attribute__((visibility("protected")));''',
375 name : '__attribute__((visibility(...)))')
376 pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISBILITY'
377endif
378if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
379 name : '__attribute__((alias(...)))')
380 pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
381endif
382
383# TODO: this is very incomplete
384if host_machine.system() == 'linux'
385 pre_args += '-D_GNU_SOURCE'
386endif
387
388# Check for generic C arguments
389c_args = []
390foreach a : ['-Wall', '-Werror=implicit-function-declaration',
391 '-Werror=missing-prototypes', '-fno-math-errno',
392 '-fno-trapping-math', '-Qunused-arguments']
393 if cc.has_argument(a)
394 c_args += a
395 endif
396endforeach
397c_vis_args = []
398if cc.has_argument('-fvisibility=hidden')
399 c_vis_args += '-fvisibility=hidden'
400endif
401
402# Check for generic C++ arguments
403cpp = meson.get_compiler('cpp')
404cpp_args = []
405foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math',
406 '-Qunused-arguments', '-Wno-non-virtual-dtor']
407 if cpp.has_argument(a)
408 cpp_args += a
409 endif
410endforeach
411cpp_vis_args = []
412if cpp.has_argument('-fvisibility=hidden')
413 cpp_vis_args += '-fvisibility=hidden'
414endif
415
416# Check for C and C++ arguments for MSVC2013 compatibility. These are only used
417# in parts of the mesa code base that need to compile with old versions of
418# MSVC, mainly common code
419c_msvc_compat_args = []
420cpp_msvc_compat_args = []
421foreach a : ['-Werror=pointer-arith', '-Werror=vla']
422 if cc.has_argument(a)
423 c_msvc_compat_args += a
424 endif
425 if cpp.has_argument(a)
426 cpp_msvc_compat_args += a
427 endif
428endforeach
429
430no_override_init_args = []
431foreach a : ['-Wno-override-init', '-Wno-initializer-overrides']
432 if cc.has_argument(a)
433 no_override_init_args += a
434 endif
435endforeach
436
437# TODO: SSE41 (which is only required for core mesa)
438
439# Check for GCC style atomics
440if cc.compiles('int main() { int n; return __atomic_load_n(&n, __ATOMIC_ACQUIRE); }',
441 name : 'GCC atomic builtins')
442 pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
443endif
444if not cc.links('''#include <stdint.h>
445 uint64_t v;
446 int main() {
447 return __sync_add_and_fetch(&v, (uint64_t)1);
448 }''',
449 name : 'GCC 64bit atomics')
450 pre_args += '-DMISSING_64_BIT_ATOMICS'
451endif
452
453# TODO: endian
454# TODO: powr8
455# TODO: shared/static? Is this even worth doing?
456
457# I don't think that I need to set any of the debug stuff, I think meson
458# handles that for us
459
460# TODO: ldflags
461
462# TODO: texture-float (gallium/mesa only)
463
464# TODO: cross-compiling. I don't think this is relavent to meson
465
Dylan Baker32180562017-09-20 20:11:32 -0700466# FIXME: enable asm when cross compiler
467# This is doable (autotools does it), but it's not of immediate concern
468if meson.is_cross_build()
469 message('Cross compiling, disabling asm')
470 with_asm = false
471endif
472
473with_asm_arch = ''
474if with_asm
475 # TODO: SPARC and PPC
476 if host_machine.cpu_family() == 'x86'
477 if ['linux', 'bsd'].contains(host_machine.system()) # FIXME: hurd?
478 with_asm_arch = 'x86'
479 pre_args += ['-DUSE_X86_ASM', '-DUSE_MMX_ASM', '-DUSE_3DNOW_ASM',
480 '-DUSE_SSE_ASM']
481 endif
482 elif host_machine.cpu_family() == 'x86_64'
483 if host_machine.system() == 'linux'
484 with_asm_arch = 'x86_64'
485 pre_args += ['-DUSE_X86_64_ASM']
486 endif
487 elif host_machine.cpu_family() == 'arm'
488 if host_machine.system() == 'linux'
489 with_asm_arch = 'arm'
490 pre_args += ['-DUSE_ARM_ASM']
491 endif
492 elif host_machine.cpu_family() == 'aarch64'
493 if host_machine.system() == 'linux'
494 with_asm_arch = 'aarch64'
495 pre_args += ['-DUSE_AARCH64_ASM']
496 endif
497 endif
498endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700499
500# Check for standard headers and functions
501if cc.has_header_symbol('sys/sysmacros.h', 'major')
502 pre_args += '-DMAJOR_IN_SYSMACROS'
503elif cc.has_header_symbol('sys/mkdev.h', 'major')
504 pre_args += '-DMAJOR_IN_MKDEV'
505endif
506
507foreach h : ['xlocale.h', 'sys/sysctl.h']
508 if cc.has_header(h)
509 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
510 endif
511endforeach
512
513foreach f : ['strtof', 'mkostemp', 'posix_memalign']
514 if cc.has_function(f)
515 pre_args += '-DHAVE_@0@'.format(f.to_upper())
516 endif
517endforeach
518
519# strtod locale support
520if cc.links('''
521 #define _GNU_SOURCE
522 #include <stdlib.h>
523 #include <locale.h>
524 #ifdef HAVE_XLOCALE_H
525 #include <xlocale.h>
526 #endif
527 int main() {
528 locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
529 const char *s = "1.0";
530 char *end;
531 double d = strtod_l(s, end, loc);
532 float f = strtod_l(s, end, loc);
533 freelocale(loc);
534 return 0;
535 }''',
536 extra_args : pre_args,
537 name : 'strtod has locale support')
538 pre_args += '-DHAVE_STRTOD_L'
539endif
540
541# Check for some linker flags
542ld_args_bsymbolic = []
Dylan Bakere21e0a62017-09-30 13:15:52 -0700543if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic', name : 'Bsymbolic')
Dylan Bakerd1992252017-09-14 17:57:17 -0700544 ld_args_bsymbolic += '-Wl,-Bsymbolic'
545endif
546ld_args_gc_sections = []
547if cc.links('static char unused() { return 5; } int main() { return 0; }',
Dylan Bakere21e0a62017-09-30 13:15:52 -0700548 args : '-Wl,--gc-sections', name : 'gc-sections')
Dylan Bakerd1992252017-09-14 17:57:17 -0700549 ld_args_gc_sections += '-Wl,--gc-sections'
550endif
Dylan Bakere21e0a62017-09-30 13:15:52 -0700551with_ld_version_script = false
552if cc.links('int main() { return 0; }',
553 args : '-Wl,--version-script=@0@'.format(
554 join_paths(meson.source_root(), 'build-support/conftest.map')),
555 name : 'version-script')
556 with_ld_version_script = true
557endif
558with_ld_dynamic_list = false
559if cc.links('int main() { return 0; }',
560 args : '-Wl,--dynamic-list=@0@'.format(
561 join_paths(meson.source_root(), 'build-support/conftest.dyn')),
562 name : 'dynamic-list')
563 with_ld_dynamic_list = true
564endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700565
566# check for dl support
567if cc.has_function('dlopen')
568 dep_dl = []
569else
570 dep_dl = cc.find_library('dl')
571endif
Dylan Baker32180562017-09-20 20:11:32 -0700572if cc.has_function('dladdr', dependencies : dep_dl)
573 # This is really only required for megadrivers
574 pre_args += '-DHAVE_DLADDR'
Dylan Bakerd1992252017-09-14 17:57:17 -0700575endif
576
577if cc.has_function('dl_iterate_phdr')
578 pre_args += '-DHAVE_DL_ITERATE_PHDR'
579else
580 # TODO: this is required for vulkan
581endif
582
583# Determine whether or not the rt library is needed for time functions
584if cc.has_function('clock_gettime')
585 dep_clock = []
586else
587 dep_clock = cc.find_library('rt')
588endif
589
Dylan Baker66c94b92017-09-30 13:48:34 -0700590with_gallium_drisw_kms = false
Dylan Baker50c28df2017-09-29 17:53:01 -0700591dep_libdrm = dependency('libdrm', version : '>= 2.4.75',
592 required : with_dri2 or with_dri3)
593if dep_libdrm.found()
594 pre_args += '-DHAVE_LIBDRM'
Dylan Baker66c94b92017-09-30 13:48:34 -0700595 if with_dri_platform == 'drm' and with_dri
596 with_gallium_drisw_kms = true
597 endif
Dylan Baker50c28df2017-09-29 17:53:01 -0700598endif
599
Dylan Bakerd1992252017-09-14 17:57:17 -0700600# TODO: some of these may be conditional
601dep_zlib = dependency('zlib', version : '>= 1.2.3')
602dep_thread = dependency('threads')
Dylan Baker50c28df2017-09-29 17:53:01 -0700603if dep_thread.found() and host_machine.system() == 'linux'
604 pre_args += '-DHAVE_PTHREAD'
605endif
Dylan Bakercc4f5872017-09-27 11:30:21 -0700606dep_elf = dependency('libelf', required : false)
Dylan Bakerb154b442017-09-30 14:04:28 -0700607if not dep_elf.found() and (with_amd_vk or with_gallium_radeonsi) # TODO: clover, r600
608 dep_elf = cc.find_library('elf')
Dylan Bakercc4f5872017-09-27 11:30:21 -0700609endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700610dep_expat = dependency('expat')
611# this only exists on linux so either this is linux and it will be found, or
612# its not linux and and wont
613dep_m = cc.find_library('m', required : false)
Dylan Baker66f97f62017-09-30 09:03:51 -0700614
615dep_libdrm_amdgpu = []
616dep_libdrm_radeon = []
Dylan Baker813b4b02017-10-09 14:59:35 -0700617dep_libdrm_nouveau = []
Dylan Baker51558a12017-10-20 15:45:22 -0700618dep_libdrm_etnaviv = []
Rob Clark4aa69cc2017-10-14 10:08:50 -0400619dep_libdrm_freedreno = []
Dylan Baker66f97f62017-09-30 09:03:51 -0700620if with_amd_vk or with_gallium_radeonsi
Dylan Baker8792a9e2017-10-20 16:28:32 -0700621 dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.85')
Dylan Baker66f97f62017-09-30 09:03:51 -0700622endif
623if with_gallium_radeonsi # older radeon too
624 dep_libdrm_radeon = dependency('libdrm_radeon', version : '>= 2.4.71')
625endif
Dylan Baker813b4b02017-10-09 14:59:35 -0700626if with_gallium_nouveau
627 dep_libdrm_nouveau = dependency('libdrm_nouveau', version : '>= 2.4.66')
628endif
Dylan Baker51558a12017-10-20 15:45:22 -0700629if with_gallium_etnaviv
630 dep_libdrm_etnaviv = dependency('libdrm_etnaviv', version : '>= 2.4.82')
631endif
Rob Clark4aa69cc2017-10-14 10:08:50 -0400632if with_gallium_freedreno
633 dep_libdrm_freedreno = dependency('libdrm_freedreno', version : '>= 2.4.74')
634endif
Dylan Baker673dda82017-09-20 11:53:29 -0700635
636llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
637if with_amd_vk
638 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
639endif
640dep_llvm = dependency(
Dylan Baker50c28df2017-09-29 17:53:01 -0700641 'llvm', version : '>= 3.9.0', required : with_amd_vk, modules : llvm_modules,
Dylan Baker673dda82017-09-20 11:53:29 -0700642)
Dylan Baker02cf3a82017-10-12 09:47:30 -0700643if with_llvm
644 if dep_llvm.found()
645 _llvm_version = dep_llvm.version().split('.')
646 # Development versions of LLVM have an 'svn' suffix, we don't want that for
647 # our version checks.
648 _llvm_patch = _llvm_version[2]
649 if _llvm_patch.endswith('svn')
650 _llvm_patch = _llvm_patch.split('s')[0]
651 endif
652 pre_args += [
653 '-DHAVE_LLVM=0x0@0@@1@@2@'.format(_llvm_version[0], _llvm_version[1], _llvm_patch),
654 '-DMESA_LLVM_VERSION_PATCH=@0@'.format(_llvm_patch),
655 ]
656 else
Dylan Baker6a9ad202017-10-10 14:56:39 -0700657 if with_gallium_softpipe
658 error('Cannot find LLVM to build LLVMPipe. If you wanted softpipe pass -Dllvm=false to meson')
659 elif with_amd_vk or with_gallium_radeonsi # etc
Dylan Baker66f97f62017-09-30 09:03:51 -0700660 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 -0700661 endif
Dylan Baker673dda82017-09-20 11:53:29 -0700662 endif
Dylan Baker66f97f62017-09-30 09:03:51 -0700663elif with_amd_vk or with_gallium_radeonsi
664 error('The following drivers requires LLVM: Radv, RadeonSI. One of these is enabled, but LLVM is disabled.')
Dylan Baker673dda82017-09-20 11:53:29 -0700665endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700666
Dylan Bakera47c5252017-09-22 12:55:00 -0700667dep_glvnd = []
668if with_glvnd
669 dep_glvnd = dependency('libglvnd', version : '>= 0.2.0')
670 pre_args += '-DUSE_LIBGLVND=1'
671endif
672
Dylan Bakerd1992252017-09-14 17:57:17 -0700673# TODO: make this conditional
674dep_valgrind = dependency('valgrind', required : false)
675if dep_valgrind.found() and with_valgrind
676 pre_args += '-DHAVE_VALGRIND'
677endif
678
679# pthread stubs. Lets not and say we didn't
680
Dylan Baker32180562017-09-20 20:11:32 -0700681prog_bison = find_program('bison', required : with_any_opengl)
682prog_flex = find_program('flex', required : with_any_opengl)
683
Dylan Bakerd1992252017-09-14 17:57:17 -0700684# TODO: selinux
Dylan Baker32180562017-09-20 20:11:32 -0700685dep_selinux = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700686
687# TODO: llvm-prefix and llvm-shared-libs
688
Dylan Bakerb1b65392017-09-28 22:25:02 -0700689dep_unwind = dependency('libunwind', required : false)
690if dep_unwind.found()
691 pre_args += '-DHAVE_LIBUNWIND'
692endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700693
694# TODO: flags for opengl, gles, dri
695
696# TODO: gallium-hud
697
698# TODO: glx provider
699
700# TODO: osmesa provider
701
Dylan Bakerd1992252017-09-14 17:57:17 -0700702# TODO: symbol mangling
703
Dylan Bakerd1992252017-09-14 17:57:17 -0700704if with_platform_wayland
705 prog_wl_scanner = find_program('wayland-scanner')
706 dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8')
707 dep_wayland_client = dependency('wayland-client', version : '>=1.11')
708 dep_wayland_server = dependency('wayland-server', version : '>=1.11')
Dylan Baker108d2572017-10-18 12:20:43 -0700709 wayland_dmabuf_xml = join_paths(
710 dep_wl_protocols.get_pkgconfig_variable('pkgdatadir'), 'unstable',
711 'linux-dmabuf', 'linux-dmabuf-unstable-v1.xml'
712 )
713 pre_args += ['-DHAVE_WAYLAND_PLATFORM', '-DWL_HIDE_DEPRECATED']
Dylan Bakerd1992252017-09-14 17:57:17 -0700714else
715 prog_wl_scanner = []
716 dep_wl_protocols = []
717 dep_wayland_client = []
718 dep_wayland_server = []
Dylan Baker108d2572017-10-18 12:20:43 -0700719 wayland_dmabuf_xml = ''
Dylan Bakerd1992252017-09-14 17:57:17 -0700720endif
721
Dylan Baker50c28df2017-09-29 17:53:01 -0700722dep_x11 = []
723dep_xext = []
724dep_xdamage = []
725dep_xfixes = []
726dep_x11_xcb = []
727dep_xcb_glx = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700728dep_xcb_dri2 = []
729dep_xcb_dri3 = []
Dylan Bakera47c5252017-09-22 12:55:00 -0700730dep_dri2proto = []
731dep_glproto = []
Dylan Bakera47c5252017-09-22 12:55:00 -0700732dep_xf86vm = []
Dylan Baker50c28df2017-09-29 17:53:01 -0700733dep_xcb_dri3 = []
734dep_xcb_present = []
735dep_xcb_sync = []
Dylan Baker108d2572017-10-18 12:20:43 -0700736dep_xcb_xfixes = []
Dylan Baker50c28df2017-09-29 17:53:01 -0700737dep_xshmfence = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700738if with_platform_x11
Dylan Baker50c28df2017-09-29 17:53:01 -0700739 if with_glx == 'dri' and with_dri_platform == 'drm'
740 dep_x11 = dependency('x11')
741 dep_xext = dependency('xext')
742 dep_xdamage = dependency('xdamage', version : '>= 1.1')
743 dep_xfixes = dependency('xfixes')
744 dep_xcb_glx = dependency('xcb-glx', version : '>= 1.8.1')
Nicholas Miell30128852017-10-17 18:04:16 -0700745 dep_xf86vm = dependency('xxf86vm', required : false)
Dylan Bakera47c5252017-09-22 12:55:00 -0700746 endif
747 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
Dylan Baker50c28df2017-09-29 17:53:01 -0700748 dep_xcb = dependency('xcb')
749 dep_x11_xcb = dependency('x11-xcb')
750 dep_xcb_dri2 = dependency('xcb-dri2', version : '>= 1.8')
751
Dylan Bakera47c5252017-09-22 12:55:00 -0700752 if with_dri3
753 pre_args += '-DHAVE_DRI3'
Dylan Baker50c28df2017-09-29 17:53:01 -0700754 dep_xcb_dri3 = dependency('xcb-dri3')
755 dep_xcb_present = dependency('xcb-present')
756 dep_xcb_sync = dependency('xcb-sync')
757 dep_xshmfence = dependency('xshmfence', version : '>= 1.1')
Dylan Bakera47c5252017-09-22 12:55:00 -0700758 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700759 endif
Dylan Baker50c28df2017-09-29 17:53:01 -0700760 if with_glx != 'disabled'
761 dep_dri2proto = dependency('dri2proto', version : '>= 2.8')
762 dep_glproto = dependency('glproto', version : '>= 1.4.14')
763 endif
Dylan Baker108d2572017-10-18 12:20:43 -0700764 if with_egl
765 dep_xcb_xfixes = dependency('xcb-xfixes')
766 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700767endif
768
Dylan Bakerd1992252017-09-14 17:57:17 -0700769# TODO: osmesa
770
Dylan Bakerd1992252017-09-14 17:57:17 -0700771# TODO: vallium G3DVL
772
773# TODO: nine
774
775# TODO: clover
776
Dylan Bakerd1992252017-09-14 17:57:17 -0700777# TODO: gallium tests
778
779# TODO: various libdirs
780
781# TODO: swr
782
783# TODO: gallium driver dirs
784
785# FIXME: this is a workaround for #2326
786prog_touch = find_program('touch')
787dummy_cpp = custom_target(
788 'dummy_cpp',
789 output : 'dummy.cpp',
790 command : [prog_touch, '@OUTPUT@'],
791)
792
793foreach a : pre_args
794 add_project_arguments(a, language : ['c', 'cpp'])
795endforeach
796foreach a : c_args
797 add_project_arguments(a, language : ['c'])
798endforeach
799foreach a : cpp_args
800 add_project_arguments(a, language : ['cpp'])
801endforeach
802
803inc_include = include_directories('include')
804
Dylan Baker108d2572017-10-18 12:20:43 -0700805gl_priv_reqs = [
806 'x11', 'xext', 'xdamage >= 1.1', 'xfixes', 'x11-xcb', 'xcb',
807 'xcb-glx >= 1.8.1', 'libdrm >= 2.4.75',
808]
809if dep_xf86vm != [] and dep_xf86vm.found()
810 gl_priv_reqs += 'xf86vm'
811endif
812if with_dri_platform == 'drm'
813 gl_priv_reqs += 'xcb-dri2 >= 1.8'
814endif
815
816gl_priv_libs = []
817if dep_thread.found()
818 gl_priv_libs += ['-lpthread', '-pthread']
819endif
820if dep_m.found()
821 gl_priv_libs += '-lm'
822endif
823if dep_dl.found()
824 gl_priv_libs += '-ldl'
825endif
826
Dylan Baker32180562017-09-20 20:11:32 -0700827pkg = import('pkgconfig')
828
Dylan Bakerd1992252017-09-14 17:57:17 -0700829subdir('include')
830subdir('src')