blob: 4d4f164087439883eb2865c0f6f8c63fe6199e30 [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')
Erik Faye-Lund9e5a5a12017-10-23 20:54:03 +020040with_libunwind = get_option('libunwind')
Dylan Baker32180562017-09-20 20:11:32 -070041with_asm = get_option('asm')
Dylan Baker02cf3a82017-10-12 09:47:30 -070042with_llvm = get_option('llvm')
Dylan Baker3b209e92017-10-10 15:25:07 -070043if get_option('texture-float')
44 pre_args += '-DTEXTURE_FLOAT_ENABLED'
45 message('WARNING: Floating-point texture enabled. Please consult docs/patents.txt and your lawyer before building mesa.')
46endif
Dylan Baker32180562017-09-20 20:11:32 -070047
48# XXX: yeah, do these
49with_appledri = false
50with_windowsdri = false
51
Dylan Bakerdb978842017-09-28 13:59:04 -070052dri_drivers_path = get_option('dri-drivers-path')
53if dri_drivers_path == ''
54 dri_drivers_path = join_paths(get_option('libdir'), 'dri')
55endif
56
Dylan Baker32180562017-09-20 20:11:32 -070057with_gles1 = get_option('gles1')
58with_gles2 = get_option('gles2')
59with_opengl = get_option('opengl')
60with_any_opengl = with_opengl or with_gles1 or with_gles2
Dylan Bakera47c5252017-09-22 12:55:00 -070061# Only build shared_glapi if at least one OpenGL API is enabled
62with_shared_glapi = get_option('shared-glapi') and with_any_opengl
Dylan Baker32180562017-09-20 20:11:32 -070063
64# TODO: these will need options, but at the moment they just control header
65# installs
Dylan Baker32180562017-09-20 20:11:32 -070066with_osmesa = false
67
68# shared-glapi is required if at least two OpenGL APIs are being built
69if not with_shared_glapi
70 if ((with_gles1 and with_gles2) or (with_gles1 and with_opengl)
71 or (with_gles2 and with_opengl))
72 error('shared-glapi required for building two or more of OpenGL, OpenGL ES 1.x, OpenGL ES 2.x')
73 endif
74endif
75
76# We require OpenGL for OpenGL ES
77if (with_gles1 or with_gles2) and not with_opengl
78 error('building OpenGL ES without OpenGL is not supported.')
79endif
80
81with_dri = false
Ville Syrjälä22899642017-10-10 01:15:42 +030082with_dri_i915 = false
Dylan Baker32180562017-09-20 20:11:32 -070083with_dri_i965 = false
Dylan Bakerc2cd5802017-10-03 17:06:22 -070084with_dri_swrast = false
Dylan Baker32180562017-09-20 20:11:32 -070085_drivers = get_option('dri-drivers')
86if _drivers != ''
87 _split = _drivers.split(',')
Ville Syrjälä22899642017-10-10 01:15:42 +030088 with_dri_i915 = _split.contains('i915')
Dylan Baker32180562017-09-20 20:11:32 -070089 with_dri_i965 = _split.contains('i965')
Dylan Bakerc2cd5802017-10-03 17:06:22 -070090 with_dri_swrast = _split.contains('swrast')
Dylan Baker32180562017-09-20 20:11:32 -070091 with_dri = true
92endif
93
Dylan Bakeraf9d2762017-09-28 21:03:07 -070094with_gallium = false
Eric Anholt1918c9b2017-10-12 18:39:08 -070095with_gallium_pl111 = false
Dylan Bakeraf9d2762017-09-28 21:03:07 -070096with_gallium_radeonsi = false
Dylan Baker813b4b02017-10-09 14:59:35 -070097with_gallium_nouveau = false
Rob Clark4aa69cc2017-10-14 10:08:50 -040098with_gallium_freedreno = false
Dylan Bakerf3d03a22017-10-10 11:57:50 -070099with_gallium_softpipe = false
Eric Anholt1ae80182017-10-12 13:53:12 -0700100with_gallium_vc4 = false
Eric Anholt4f3e3802017-10-12 18:40:16 -0700101with_gallium_vc5 = false
Dylan Baker51558a12017-10-20 15:45:22 -0700102with_gallium_etnaviv = false
Dylan Bakerd4567ef2017-10-20 15:57:15 -0700103with_gallium_imx = false
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700104_drivers = get_option('gallium-drivers')
105if _drivers != ''
106 _split = _drivers.split(',')
Dylan Bakerfbf39fd2017-10-17 14:44:15 -0700107 with_gallium_pl111 = _split.contains('pl111')
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700108 with_gallium_radeonsi = _split.contains('radeonsi')
Dylan Baker813b4b02017-10-09 14:59:35 -0700109 with_gallium_nouveau = _split.contains('nouveau')
Rob Clark4aa69cc2017-10-14 10:08:50 -0400110 with_gallium_freedreno = _split.contains('freedreno')
Dylan Bakerde24d612017-10-10 14:27:19 -0700111 with_gallium_softpipe = _split.contains('swrast')
Eric Anholt1ae80182017-10-12 13:53:12 -0700112 with_gallium_vc4 = _split.contains('vc4')
Eric Anholt4f3e3802017-10-12 18:40:16 -0700113 with_gallium_vc5 = _split.contains('vc5')
Dylan Baker51558a12017-10-20 15:45:22 -0700114 with_gallium_etnaviv = _split.contains('etnaviv')
Dylan Bakerd4567ef2017-10-20 15:57:15 -0700115 with_gallium_imx = _split.contains('imx')
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700116 with_gallium = true
117 with_dri = true
Ville Syrjälä22899642017-10-10 01:15:42 +0300118endif
119
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700120if not (with_dri or with_gallium)
Dylan Baker32180562017-09-20 20:11:32 -0700121 with_gles1 = false
122 with_gles2 = false
123 with_opengl = false
124 with_any_opengl = false
125 with_shared_glapi = false
126endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700127
Dylan Bakerde24d612017-10-10 14:27:19 -0700128if with_dri_swrast and with_gallium_softpipe
129 error('Only one swrast provider can be built')
130endif
Dylan Bakerd4567ef2017-10-20 15:57:15 -0700131if with_gallium_imx and not with_gallium_etnaviv
132 error('IMX driver requires etnaviv driver')
133endif
Dylan Bakerde24d612017-10-10 14:27:19 -0700134
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700135dep_libdrm_intel = []
136if with_dri_i915
137 dep_libdrm_intel = dependency('libdrm_intel', version : '>= 2.4.75')
138endif
139
Dylan Bakera47c5252017-09-22 12:55:00 -0700140# TODO: other OSes
141with_dri_platform = 'drm'
142
Dylan Baker108d2572017-10-18 12:20:43 -0700143# TODO: android platform
Dylan Bakerd1992252017-09-14 17:57:17 -0700144with_platform_wayland = false
145with_platform_x11 = false
Dylan Bakerb1b65392017-09-28 22:25:02 -0700146with_platform_drm = false
Dylan Baker108d2572017-10-18 12:20:43 -0700147with_platform_surfaceless = false
148egl_native_platform = ''
Dylan Bakerd1992252017-09-14 17:57:17 -0700149_platforms = get_option('platforms')
150if _platforms != ''
151 _split = _platforms.split(',')
152 with_platform_x11 = _split.contains('x11')
153 with_platform_wayland = _split.contains('wayland')
Dylan Bakerb1b65392017-09-28 22:25:02 -0700154 with_platform_drm = _split.contains('drm')
Dylan Baker108d2572017-10-18 12:20:43 -0700155 with_platform_surfaceless = _split.contains('surfaceless')
156 egl_native_platform = _split[0]
Dylan Bakerd1992252017-09-14 17:57:17 -0700157endif
158
Dylan Baker816bf7d12017-09-28 15:53:53 -0700159with_gbm = get_option('gbm')
160if with_gbm == 'auto' and with_dri # TODO: or gallium
161 with_gbm = host_machine.system() == 'linux'
162elif with_gbm == 'yes'
163 if not ['linux', 'bsd'].contains(host_machine.system())
164 error('GBM only supports unix-like platforms')
165 endif
166 with_gbm = true
167else
168 with_gbm = false
169endif
170
Dylan Baker108d2572017-10-18 12:20:43 -0700171_egl = get_option('egl')
172if _egl == 'auto'
173 with_egl = with_dri and with_shared_glapi and egl_native_platform != ''
174elif _egl == 'yes'
175 if not with_dri
176 error('EGL requires dri')
177 elif not with_shared_glapi
178 error('EGL requires shared-glapi')
179 elif egl_native_platform == ''
180 error('No platforms specified, consider -Dplatforms=drm,x11 at least')
181 endif
182 with_egl = true
183else
184 with_egl = false
185endif
186
187# TODO: or virgl
188if with_egl and with_gallium_radeonsi and not (with_platform_drm or with_platform_surfaceless)
189 error('RadeonSI requires drm or surfaceless platform when using EGL')
190endif
191
Dylan Baker8e611872017-10-11 12:49:31 -0700192pre_args += '-DGLX_USE_TLS'
Dylan Bakera47c5252017-09-22 12:55:00 -0700193with_glx = get_option('glx')
194if with_glx != 'disabled'
Dylan Baker8d3b1212017-10-18 15:47:11 -0700195 if not (with_platform_x11 and with_any_opengl)
196 if with_glx == 'auto'
197 with_glx = 'disabled'
198 else
199 error('Cannot build GLX support without X11 platform support and at least one OpenGL API')
200 endif
Dylan Bakera47c5252017-09-22 12:55:00 -0700201 elif with_glx == 'gallium-xlib'
202 if not with_gallium
203 error('Gallium-xlib based GLX requires at least one gallium driver')
204 elif with_dri
205 error('gallium-xlib conflicts with any dri driver')
206 endif
207 elif with_glx == 'dri' and not with_dri
208 error('dri based GLX requires at least one DRI driver')
209 elif with_glx == 'auto'
210 if with_dri
211 with_glx = 'dri'
212 elif with_gallium
213 with_glx = 'gallium-xlib'
214 elif with_platform_x11 and with_any_opengl
215 with_glx = 'xlib'
216 else
217 with_glx = 'disabled'
218 endif
219 endif
220endif
221
222with_glvnd = get_option('glvnd')
223if with_glvnd and with_glx != 'dri'
224 message('glvnd requires dri based glx')
225endif
226
227# TODO: toggle for this
228with_glx_direct = true
229
Dylan Bakerd1992252017-09-14 17:57:17 -0700230if with_vulkan_icd_dir == ''
231 with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
232endif
233
234with_intel_vk = false
235with_amd_vk = false
Dylan Bakera47c5252017-09-22 12:55:00 -0700236with_any_vk = false
Dylan Bakerd1992252017-09-14 17:57:17 -0700237_vulkan_drivers = get_option('vulkan-drivers')
238if _vulkan_drivers != ''
239 _split = _vulkan_drivers.split(',')
240 with_intel_vk = _split.contains('intel')
241 with_amd_vk = _split.contains('amd')
Dylan Bakera47c5252017-09-22 12:55:00 -0700242 with_any_vk = with_amd_vk or with_intel_vk
Dylan Bakerd1992252017-09-14 17:57:17 -0700243 if not (with_platform_x11 or with_platform_wayland)
244 error('Vulkan requires at least one platform (x11, wayland)')
245 endif
Dylan Bakera47c5252017-09-22 12:55:00 -0700246endif
247
Dylan Baker50c28df2017-09-29 17:53:01 -0700248with_dri2 = (with_dri or with_any_vk) and with_dri_platform == 'drm'
249with_dri3 = get_option('dri3')
250if with_dri3 == 'auto'
251 if host_machine.system() == 'linux' and with_dri2
252 with_dri3 = true
253 else
254 with_dri3 = false
255 endif
256elif with_dri3 == 'yes'
257 with_dri3 = true
258else
259 with_dri3 = false
260endif
261
262if with_any_vk and (with_platform_x11 and not with_dri3)
263 error('Vulkan drivers require dri3 for X11 support')
264endif
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700265if with_dri or with_gallium
Dylan Baker108d2572017-10-18 12:20:43 -0700266 if with_glx == 'disabled' and not with_egl
Dylan Bakera47c5252017-09-22 12:55:00 -0700267 error('building dri or gallium drivers require at least one window system')
268 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700269endif
270
Dylan Baker50c28df2017-09-29 17:53:01 -0700271with_gallium_xvmc = false
272with_gallium_vdpau = false
273with_gallium_omx = false # this is bellagio
274with_gallium_va = false
275with_gallium_media = false
276dep_va = []
277_drivers = get_option('gallium-media')
278if _drivers != ''
279 _split = _drivers.split(',')
280 with_gallium_xvmc = _split.contains('xvmc')
281 with_gallium_vdpau = _split.contains('vdpau')
282 with_gallium_omx = _split.contains('omx')
283 with_gallium_va = _split.contains('va')
284 with_gallium_media = (with_gallium_xvmc or with_gallium_vdpau or
285 with_gallium_omx or with_gallium_va)
286endif
287
Dylan Baker108d2572017-10-18 12:20:43 -0700288gl_pkgconfig_c_flags = []
Dylan Baker50c28df2017-09-29 17:53:01 -0700289if with_platform_x11
290 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
291 pre_args += '-DHAVE_X11_PLATFORM'
292 endif
293 if with_glx == 'xlib'
294 # TODO
295 error('TODO')
296 elif with_glx == 'gallium-xlib'
297 # TODO
298 error('TODO')
299 else
300 pre_args += '-DGLX_INDIRECT_RENDERING'
301 if with_glx_direct
302 pre_args += '-DGLX_DIRECT_RENDERING'
303 endif
304 if with_dri_platform == 'drm'
305 pre_args += '-DGLX_USE_DRM'
306 endif
307 endif
Dylan Baker108d2572017-10-18 12:20:43 -0700308else
309 pre_args += '-DMESA_EGL_NO_X11_HEADERS'
310 gl_pkgconfig_c_flags += '-DMESA_EGL_NO_X11_HEADERS'
311endif
312if with_platform_drm
313 if with_egl and not with_gbm
314 error('EGL drm platform requires gbm')
315 endif
316 pre_args += '-DHAVE_DRM_PLATFORM'
317endif
318if with_platform_surfaceless
319 pre_args += '-DHAVE_SURFACELESS_PLATFORM'
Dylan Baker50c28df2017-09-29 17:53:01 -0700320endif
321
Dylan Bakerd1992252017-09-14 17:57:17 -0700322prog_python2 = find_program('python2')
Dylan Baker9342a7d2017-09-28 10:48:30 -0700323has_mako = run_command(prog_python2, '-c', 'import mako')
324if has_mako.returncode() != 0
325 error('Python (2.x) mako module required to build mesa.')
326endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700327
328cc = meson.get_compiler('c')
329if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
Eric Engestrom1262e822017-09-29 15:25:18 +0100330 error('When using GCC, version 4.4.6 or later is required.')
Dylan Bakerd1992252017-09-14 17:57:17 -0700331endif
332
Dylan Bakerd1992252017-09-14 17:57:17 -0700333# Define DEBUG for debug and debugoptimized builds
334if get_option('buildtype').startswith('debug')
335 pre_args += '-DDEBUG'
336endif
337
Dylan Baker673dda82017-09-20 11:53:29 -0700338if get_option('shader-cache')
339 pre_args += '-DENABLE_SHADER_CACHE'
340elif with_amd_vk
341 error('Radv requires shader cache support')
342endif
343
Dylan Bakerd1992252017-09-14 17:57:17 -0700344# Check for GCC style builtins
345foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
346 'ffsll', 'popcount', 'popcountll', 'unreachable']
347 if cc.has_function(b)
348 pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
349 endif
350endforeach
351
Dylan Baker673dda82017-09-20 11:53:29 -0700352# check for GCC __attribute__
Dylan Bakerd1992252017-09-14 17:57:17 -0700353foreach a : ['const', 'flatten', 'malloc', 'pure', 'unused',
354 'warn_unused_result', 'weak',]
355 if cc.compiles('int foo(void) __attribute__((@0@));'.format(a),
356 name : '__attribute__((@0@))'.format(a))
357 pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
358 endif
359endforeach
360if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
361 name : '__attribute__((format(...)))')
362 pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
363endif
364if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
365 name : '__attribute__((packed))')
366 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
367endif
368if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
369 name : '__attribute__((returns_nonnull))')
370 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NONNULL'
371endif
372if cc.compiles('''int foo_def(void) __attribute__((visibility("default")));
373 int foo_hid(void) __attribute__((visibility("hidden")));
374 int foo_int(void) __attribute__((visibility("internal")));
375 int foo_pro(void) __attribute__((visibility("protected")));''',
376 name : '__attribute__((visibility(...)))')
377 pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISBILITY'
378endif
379if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
380 name : '__attribute__((alias(...)))')
381 pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
382endif
383
384# TODO: this is very incomplete
385if host_machine.system() == 'linux'
386 pre_args += '-D_GNU_SOURCE'
387endif
388
389# Check for generic C arguments
390c_args = []
391foreach a : ['-Wall', '-Werror=implicit-function-declaration',
392 '-Werror=missing-prototypes', '-fno-math-errno',
393 '-fno-trapping-math', '-Qunused-arguments']
394 if cc.has_argument(a)
395 c_args += a
396 endif
397endforeach
398c_vis_args = []
399if cc.has_argument('-fvisibility=hidden')
400 c_vis_args += '-fvisibility=hidden'
401endif
402
403# Check for generic C++ arguments
404cpp = meson.get_compiler('cpp')
405cpp_args = []
406foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math',
407 '-Qunused-arguments', '-Wno-non-virtual-dtor']
408 if cpp.has_argument(a)
409 cpp_args += a
410 endif
411endforeach
412cpp_vis_args = []
413if cpp.has_argument('-fvisibility=hidden')
414 cpp_vis_args += '-fvisibility=hidden'
415endif
416
417# Check for C and C++ arguments for MSVC2013 compatibility. These are only used
418# in parts of the mesa code base that need to compile with old versions of
419# MSVC, mainly common code
420c_msvc_compat_args = []
421cpp_msvc_compat_args = []
422foreach a : ['-Werror=pointer-arith', '-Werror=vla']
423 if cc.has_argument(a)
424 c_msvc_compat_args += a
425 endif
426 if cpp.has_argument(a)
427 cpp_msvc_compat_args += a
428 endif
429endforeach
430
431no_override_init_args = []
432foreach a : ['-Wno-override-init', '-Wno-initializer-overrides']
433 if cc.has_argument(a)
434 no_override_init_args += a
435 endif
436endforeach
437
438# TODO: SSE41 (which is only required for core mesa)
439
440# Check for GCC style atomics
441if cc.compiles('int main() { int n; return __atomic_load_n(&n, __ATOMIC_ACQUIRE); }',
442 name : 'GCC atomic builtins')
443 pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
444endif
445if not cc.links('''#include <stdint.h>
446 uint64_t v;
447 int main() {
448 return __sync_add_and_fetch(&v, (uint64_t)1);
449 }''',
450 name : 'GCC 64bit atomics')
451 pre_args += '-DMISSING_64_BIT_ATOMICS'
452endif
453
454# TODO: endian
455# TODO: powr8
456# TODO: shared/static? Is this even worth doing?
457
458# I don't think that I need to set any of the debug stuff, I think meson
459# handles that for us
460
461# TODO: ldflags
462
463# TODO: texture-float (gallium/mesa only)
464
465# TODO: cross-compiling. I don't think this is relavent to meson
466
Dylan Baker32180562017-09-20 20:11:32 -0700467# FIXME: enable asm when cross compiler
468# This is doable (autotools does it), but it's not of immediate concern
469if meson.is_cross_build()
470 message('Cross compiling, disabling asm')
471 with_asm = false
472endif
473
474with_asm_arch = ''
475if with_asm
476 # TODO: SPARC and PPC
477 if host_machine.cpu_family() == 'x86'
478 if ['linux', 'bsd'].contains(host_machine.system()) # FIXME: hurd?
479 with_asm_arch = 'x86'
480 pre_args += ['-DUSE_X86_ASM', '-DUSE_MMX_ASM', '-DUSE_3DNOW_ASM',
481 '-DUSE_SSE_ASM']
482 endif
483 elif host_machine.cpu_family() == 'x86_64'
484 if host_machine.system() == 'linux'
485 with_asm_arch = 'x86_64'
486 pre_args += ['-DUSE_X86_64_ASM']
487 endif
488 elif host_machine.cpu_family() == 'arm'
489 if host_machine.system() == 'linux'
490 with_asm_arch = 'arm'
491 pre_args += ['-DUSE_ARM_ASM']
492 endif
493 elif host_machine.cpu_family() == 'aarch64'
494 if host_machine.system() == 'linux'
495 with_asm_arch = 'aarch64'
496 pre_args += ['-DUSE_AARCH64_ASM']
497 endif
498 endif
499endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700500
501# Check for standard headers and functions
502if cc.has_header_symbol('sys/sysmacros.h', 'major')
503 pre_args += '-DMAJOR_IN_SYSMACROS'
504elif cc.has_header_symbol('sys/mkdev.h', 'major')
505 pre_args += '-DMAJOR_IN_MKDEV'
506endif
507
508foreach h : ['xlocale.h', 'sys/sysctl.h']
509 if cc.has_header(h)
510 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
511 endif
512endforeach
513
514foreach f : ['strtof', 'mkostemp', 'posix_memalign']
515 if cc.has_function(f)
516 pre_args += '-DHAVE_@0@'.format(f.to_upper())
517 endif
518endforeach
519
520# strtod locale support
521if cc.links('''
522 #define _GNU_SOURCE
523 #include <stdlib.h>
524 #include <locale.h>
525 #ifdef HAVE_XLOCALE_H
526 #include <xlocale.h>
527 #endif
528 int main() {
529 locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
530 const char *s = "1.0";
531 char *end;
532 double d = strtod_l(s, end, loc);
533 float f = strtod_l(s, end, loc);
534 freelocale(loc);
535 return 0;
536 }''',
537 extra_args : pre_args,
538 name : 'strtod has locale support')
539 pre_args += '-DHAVE_STRTOD_L'
540endif
541
542# Check for some linker flags
543ld_args_bsymbolic = []
Dylan Bakere21e0a62017-09-30 13:15:52 -0700544if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic', name : 'Bsymbolic')
Dylan Bakerd1992252017-09-14 17:57:17 -0700545 ld_args_bsymbolic += '-Wl,-Bsymbolic'
546endif
547ld_args_gc_sections = []
548if cc.links('static char unused() { return 5; } int main() { return 0; }',
Dylan Bakere21e0a62017-09-30 13:15:52 -0700549 args : '-Wl,--gc-sections', name : 'gc-sections')
Dylan Bakerd1992252017-09-14 17:57:17 -0700550 ld_args_gc_sections += '-Wl,--gc-sections'
551endif
Dylan Bakere21e0a62017-09-30 13:15:52 -0700552with_ld_version_script = false
553if cc.links('int main() { return 0; }',
554 args : '-Wl,--version-script=@0@'.format(
555 join_paths(meson.source_root(), 'build-support/conftest.map')),
556 name : 'version-script')
557 with_ld_version_script = true
558endif
559with_ld_dynamic_list = false
560if cc.links('int main() { return 0; }',
561 args : '-Wl,--dynamic-list=@0@'.format(
562 join_paths(meson.source_root(), 'build-support/conftest.dyn')),
563 name : 'dynamic-list')
564 with_ld_dynamic_list = true
565endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700566
567# check for dl support
568if cc.has_function('dlopen')
569 dep_dl = []
570else
571 dep_dl = cc.find_library('dl')
572endif
Dylan Baker32180562017-09-20 20:11:32 -0700573if cc.has_function('dladdr', dependencies : dep_dl)
574 # This is really only required for megadrivers
575 pre_args += '-DHAVE_DLADDR'
Dylan Bakerd1992252017-09-14 17:57:17 -0700576endif
577
578if cc.has_function('dl_iterate_phdr')
579 pre_args += '-DHAVE_DL_ITERATE_PHDR'
580else
581 # TODO: this is required for vulkan
582endif
583
584# Determine whether or not the rt library is needed for time functions
585if cc.has_function('clock_gettime')
586 dep_clock = []
587else
588 dep_clock = cc.find_library('rt')
589endif
590
Dylan Baker66c94b92017-09-30 13:48:34 -0700591with_gallium_drisw_kms = false
Dylan Baker50c28df2017-09-29 17:53:01 -0700592dep_libdrm = dependency('libdrm', version : '>= 2.4.75',
593 required : with_dri2 or with_dri3)
594if dep_libdrm.found()
595 pre_args += '-DHAVE_LIBDRM'
Dylan Baker66c94b92017-09-30 13:48:34 -0700596 if with_dri_platform == 'drm' and with_dri
597 with_gallium_drisw_kms = true
598 endif
Dylan Baker50c28df2017-09-29 17:53:01 -0700599endif
600
Dylan Bakerd1992252017-09-14 17:57:17 -0700601# TODO: some of these may be conditional
602dep_zlib = dependency('zlib', version : '>= 1.2.3')
603dep_thread = dependency('threads')
Dylan Baker50c28df2017-09-29 17:53:01 -0700604if dep_thread.found() and host_machine.system() == 'linux'
605 pre_args += '-DHAVE_PTHREAD'
606endif
Dylan Bakercc4f5872017-09-27 11:30:21 -0700607dep_elf = dependency('libelf', required : false)
Dylan Bakerb154b442017-09-30 14:04:28 -0700608if not dep_elf.found() and (with_amd_vk or with_gallium_radeonsi) # TODO: clover, r600
609 dep_elf = cc.find_library('elf')
Dylan Bakercc4f5872017-09-27 11:30:21 -0700610endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700611dep_expat = dependency('expat')
612# this only exists on linux so either this is linux and it will be found, or
613# its not linux and and wont
614dep_m = cc.find_library('m', required : false)
Dylan Baker66f97f62017-09-30 09:03:51 -0700615
616dep_libdrm_amdgpu = []
617dep_libdrm_radeon = []
Dylan Baker813b4b02017-10-09 14:59:35 -0700618dep_libdrm_nouveau = []
Dylan Baker51558a12017-10-20 15:45:22 -0700619dep_libdrm_etnaviv = []
Rob Clark4aa69cc2017-10-14 10:08:50 -0400620dep_libdrm_freedreno = []
Dylan Baker66f97f62017-09-30 09:03:51 -0700621if with_amd_vk or with_gallium_radeonsi
Dylan Baker8792a9e2017-10-20 16:28:32 -0700622 dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.85')
Dylan Baker66f97f62017-09-30 09:03:51 -0700623endif
624if with_gallium_radeonsi # older radeon too
625 dep_libdrm_radeon = dependency('libdrm_radeon', version : '>= 2.4.71')
626endif
Dylan Baker813b4b02017-10-09 14:59:35 -0700627if with_gallium_nouveau
628 dep_libdrm_nouveau = dependency('libdrm_nouveau', version : '>= 2.4.66')
629endif
Dylan Baker51558a12017-10-20 15:45:22 -0700630if with_gallium_etnaviv
631 dep_libdrm_etnaviv = dependency('libdrm_etnaviv', version : '>= 2.4.82')
632endif
Rob Clark4aa69cc2017-10-14 10:08:50 -0400633if with_gallium_freedreno
634 dep_libdrm_freedreno = dependency('libdrm_freedreno', version : '>= 2.4.74')
635endif
Dylan Baker673dda82017-09-20 11:53:29 -0700636
637llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
638if with_amd_vk
639 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
640endif
641dep_llvm = dependency(
Dylan Baker50c28df2017-09-29 17:53:01 -0700642 'llvm', version : '>= 3.9.0', required : with_amd_vk, modules : llvm_modules,
Dylan Baker673dda82017-09-20 11:53:29 -0700643)
Dylan Baker02cf3a82017-10-12 09:47:30 -0700644if with_llvm
645 if dep_llvm.found()
646 _llvm_version = dep_llvm.version().split('.')
647 # Development versions of LLVM have an 'svn' suffix, we don't want that for
648 # our version checks.
649 _llvm_patch = _llvm_version[2]
650 if _llvm_patch.endswith('svn')
651 _llvm_patch = _llvm_patch.split('s')[0]
652 endif
653 pre_args += [
654 '-DHAVE_LLVM=0x0@0@@1@@2@'.format(_llvm_version[0], _llvm_version[1], _llvm_patch),
655 '-DMESA_LLVM_VERSION_PATCH=@0@'.format(_llvm_patch),
656 ]
657 else
Dylan Baker6a9ad202017-10-10 14:56:39 -0700658 if with_gallium_softpipe
659 error('Cannot find LLVM to build LLVMPipe. If you wanted softpipe pass -Dllvm=false to meson')
660 elif with_amd_vk or with_gallium_radeonsi # etc
Dylan Baker66f97f62017-09-30 09:03:51 -0700661 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 -0700662 endif
Dylan Baker673dda82017-09-20 11:53:29 -0700663 endif
Dylan Baker66f97f62017-09-30 09:03:51 -0700664elif with_amd_vk or with_gallium_radeonsi
665 error('The following drivers requires LLVM: Radv, RadeonSI. One of these is enabled, but LLVM is disabled.')
Dylan Baker673dda82017-09-20 11:53:29 -0700666endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700667
Dylan Bakera47c5252017-09-22 12:55:00 -0700668dep_glvnd = []
669if with_glvnd
670 dep_glvnd = dependency('libglvnd', version : '>= 0.2.0')
671 pre_args += '-DUSE_LIBGLVND=1'
672endif
673
Dylan Bakerd1992252017-09-14 17:57:17 -0700674# TODO: make this conditional
675dep_valgrind = dependency('valgrind', required : false)
676if dep_valgrind.found() and with_valgrind
677 pre_args += '-DHAVE_VALGRIND'
678endif
679
680# pthread stubs. Lets not and say we didn't
681
Dylan Baker32180562017-09-20 20:11:32 -0700682prog_bison = find_program('bison', required : with_any_opengl)
683prog_flex = find_program('flex', required : with_any_opengl)
684
Dylan Bakerd1992252017-09-14 17:57:17 -0700685# TODO: selinux
Dylan Baker32180562017-09-20 20:11:32 -0700686dep_selinux = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700687
688# TODO: llvm-prefix and llvm-shared-libs
689
Dylan Bakerb1b65392017-09-28 22:25:02 -0700690dep_unwind = dependency('libunwind', required : false)
Erik Faye-Lund9e5a5a12017-10-23 20:54:03 +0200691if dep_unwind.found() and with_libunwind
Dylan Bakerb1b65392017-09-28 22:25:02 -0700692 pre_args += '-DHAVE_LIBUNWIND'
693endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700694
695# TODO: flags for opengl, gles, dri
696
697# TODO: gallium-hud
698
699# TODO: glx provider
700
701# TODO: osmesa provider
702
Dylan Bakerd1992252017-09-14 17:57:17 -0700703# TODO: symbol mangling
704
Dylan Bakerd1992252017-09-14 17:57:17 -0700705if with_platform_wayland
706 prog_wl_scanner = find_program('wayland-scanner')
707 dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8')
708 dep_wayland_client = dependency('wayland-client', version : '>=1.11')
709 dep_wayland_server = dependency('wayland-server', version : '>=1.11')
Dylan Baker108d2572017-10-18 12:20:43 -0700710 wayland_dmabuf_xml = join_paths(
711 dep_wl_protocols.get_pkgconfig_variable('pkgdatadir'), 'unstable',
712 'linux-dmabuf', 'linux-dmabuf-unstable-v1.xml'
713 )
714 pre_args += ['-DHAVE_WAYLAND_PLATFORM', '-DWL_HIDE_DEPRECATED']
Dylan Bakerd1992252017-09-14 17:57:17 -0700715else
716 prog_wl_scanner = []
717 dep_wl_protocols = []
718 dep_wayland_client = []
719 dep_wayland_server = []
Dylan Baker108d2572017-10-18 12:20:43 -0700720 wayland_dmabuf_xml = ''
Dylan Bakerd1992252017-09-14 17:57:17 -0700721endif
722
Dylan Baker50c28df2017-09-29 17:53:01 -0700723dep_x11 = []
724dep_xext = []
725dep_xdamage = []
726dep_xfixes = []
727dep_x11_xcb = []
728dep_xcb_glx = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700729dep_xcb_dri2 = []
730dep_xcb_dri3 = []
Dylan Bakera47c5252017-09-22 12:55:00 -0700731dep_dri2proto = []
732dep_glproto = []
Dylan Bakera47c5252017-09-22 12:55:00 -0700733dep_xf86vm = []
Dylan Baker50c28df2017-09-29 17:53:01 -0700734dep_xcb_dri3 = []
735dep_xcb_present = []
736dep_xcb_sync = []
Dylan Baker108d2572017-10-18 12:20:43 -0700737dep_xcb_xfixes = []
Dylan Baker50c28df2017-09-29 17:53:01 -0700738dep_xshmfence = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700739if with_platform_x11
Dylan Baker50c28df2017-09-29 17:53:01 -0700740 if with_glx == 'dri' and with_dri_platform == 'drm'
741 dep_x11 = dependency('x11')
742 dep_xext = dependency('xext')
743 dep_xdamage = dependency('xdamage', version : '>= 1.1')
744 dep_xfixes = dependency('xfixes')
745 dep_xcb_glx = dependency('xcb-glx', version : '>= 1.8.1')
Nicholas Miell30128852017-10-17 18:04:16 -0700746 dep_xf86vm = dependency('xxf86vm', required : false)
Dylan Bakera47c5252017-09-22 12:55:00 -0700747 endif
748 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
Dylan Baker50c28df2017-09-29 17:53:01 -0700749 dep_xcb = dependency('xcb')
750 dep_x11_xcb = dependency('x11-xcb')
751 dep_xcb_dri2 = dependency('xcb-dri2', version : '>= 1.8')
752
Dylan Bakera47c5252017-09-22 12:55:00 -0700753 if with_dri3
754 pre_args += '-DHAVE_DRI3'
Dylan Baker50c28df2017-09-29 17:53:01 -0700755 dep_xcb_dri3 = dependency('xcb-dri3')
756 dep_xcb_present = dependency('xcb-present')
757 dep_xcb_sync = dependency('xcb-sync')
758 dep_xshmfence = dependency('xshmfence', version : '>= 1.1')
Dylan Bakera47c5252017-09-22 12:55:00 -0700759 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700760 endif
Dylan Baker50c28df2017-09-29 17:53:01 -0700761 if with_glx != 'disabled'
762 dep_dri2proto = dependency('dri2proto', version : '>= 2.8')
763 dep_glproto = dependency('glproto', version : '>= 1.4.14')
764 endif
Dylan Baker108d2572017-10-18 12:20:43 -0700765 if with_egl
766 dep_xcb_xfixes = dependency('xcb-xfixes')
767 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700768endif
769
Dylan Bakerd1992252017-09-14 17:57:17 -0700770# TODO: osmesa
771
Dylan Bakerd1992252017-09-14 17:57:17 -0700772# TODO: vallium G3DVL
773
774# TODO: nine
775
776# TODO: clover
777
Dylan Bakerd1992252017-09-14 17:57:17 -0700778# TODO: gallium tests
779
780# TODO: various libdirs
781
782# TODO: swr
783
784# TODO: gallium driver dirs
785
786# FIXME: this is a workaround for #2326
787prog_touch = find_program('touch')
788dummy_cpp = custom_target(
789 'dummy_cpp',
790 output : 'dummy.cpp',
791 command : [prog_touch, '@OUTPUT@'],
792)
793
794foreach a : pre_args
795 add_project_arguments(a, language : ['c', 'cpp'])
796endforeach
797foreach a : c_args
798 add_project_arguments(a, language : ['c'])
799endforeach
800foreach a : cpp_args
801 add_project_arguments(a, language : ['cpp'])
802endforeach
803
804inc_include = include_directories('include')
805
Dylan Baker108d2572017-10-18 12:20:43 -0700806gl_priv_reqs = [
807 'x11', 'xext', 'xdamage >= 1.1', 'xfixes', 'x11-xcb', 'xcb',
808 'xcb-glx >= 1.8.1', 'libdrm >= 2.4.75',
809]
810if dep_xf86vm != [] and dep_xf86vm.found()
811 gl_priv_reqs += 'xf86vm'
812endif
813if with_dri_platform == 'drm'
814 gl_priv_reqs += 'xcb-dri2 >= 1.8'
815endif
816
817gl_priv_libs = []
818if dep_thread.found()
819 gl_priv_libs += ['-lpthread', '-pthread']
820endif
821if dep_m.found()
822 gl_priv_libs += '-lm'
823endif
824if dep_dl.found()
825 gl_priv_libs += '-ldl'
826endif
827
Dylan Baker32180562017-09-20 20:11:32 -0700828pkg = import('pkgconfig')
829
Dylan Bakerd1992252017-09-14 17:57:17 -0700830subdir('include')
831subdir('src')