blob: 5ca5c64954a2ab9f6dc3b9943db3a893aed9af77 [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
Eric Engestrom7983adc2017-10-24 14:57:11 +010021project(
22 'mesa',
23 ['c', 'cpp'],
24 version : '17.3.0-devel',
25 license : 'MIT',
26 meson_version : '>= 0.42',
27 default_options : ['c_std=c99', 'cpp_std=c++11']
28)
Dylan Bakerd1992252017-09-14 17:57:17 -070029
Dylan Baker32180562017-09-20 20:11:32 -070030# Arguments for the preprocessor, put these in a separate array from the C and
31# C++ (cpp in meson terminology) arguments since they need to be added to the
32# default arguments for both C and C++.
33pre_args = [
34 '-D__STDC_CONSTANT_MACROS',
35 '-D__STDC_FORMAT_MACROS',
36 '-D__STDC_LIMIT_MACROS',
37 '-DVERSION="@0@"'.format(meson.project_version()),
38 '-DPACKAGE_VERSION=VERSION',
39 '-DPACKAGE_BUGREPORT="https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa"',
Dylan Baker601bd722017-10-09 14:22:07 -070040 '-D_GNU_SOURCE',
Dylan Baker32180562017-09-20 20:11:32 -070041]
42
Dylan Bakere915b8d2017-09-28 14:02:51 -070043with_vulkan_icd_dir = get_option('vulkan-icd-dir')
Dylan Bakerd1992252017-09-14 17:57:17 -070044with_tests = get_option('build-tests')
45with_valgrind = get_option('valgrind')
Erik Faye-Lund9e5a5a12017-10-23 20:54:03 +020046with_libunwind = get_option('libunwind')
Dylan Baker32180562017-09-20 20:11:32 -070047with_asm = get_option('asm')
Dylan Baker02cf3a82017-10-12 09:47:30 -070048with_llvm = get_option('llvm')
Dylan Baker3b209e92017-10-10 15:25:07 -070049if get_option('texture-float')
50 pre_args += '-DTEXTURE_FLOAT_ENABLED'
51 message('WARNING: Floating-point texture enabled. Please consult docs/patents.txt and your lawyer before building mesa.')
52endif
Dylan Baker32180562017-09-20 20:11:32 -070053
54# XXX: yeah, do these
55with_appledri = false
56with_windowsdri = false
57
Dylan Bakerdb978842017-09-28 13:59:04 -070058dri_drivers_path = get_option('dri-drivers-path')
59if dri_drivers_path == ''
60 dri_drivers_path = join_paths(get_option('libdir'), 'dri')
61endif
62
Dylan Baker32180562017-09-20 20:11:32 -070063with_gles1 = get_option('gles1')
64with_gles2 = get_option('gles2')
65with_opengl = get_option('opengl')
66with_any_opengl = with_opengl or with_gles1 or with_gles2
Dylan Bakera47c5252017-09-22 12:55:00 -070067# Only build shared_glapi if at least one OpenGL API is enabled
68with_shared_glapi = get_option('shared-glapi') and with_any_opengl
Dylan Baker32180562017-09-20 20:11:32 -070069
70# TODO: these will need options, but at the moment they just control header
71# installs
Dylan Baker32180562017-09-20 20:11:32 -070072with_osmesa = false
73
74# shared-glapi is required if at least two OpenGL APIs are being built
75if not with_shared_glapi
76 if ((with_gles1 and with_gles2) or (with_gles1 and with_opengl)
77 or (with_gles2 and with_opengl))
78 error('shared-glapi required for building two or more of OpenGL, OpenGL ES 1.x, OpenGL ES 2.x')
79 endif
80endif
81
82# We require OpenGL for OpenGL ES
83if (with_gles1 or with_gles2) and not with_opengl
84 error('building OpenGL ES without OpenGL is not supported.')
85endif
86
87with_dri = false
Ville Syrjälä22899642017-10-10 01:15:42 +030088with_dri_i915 = false
Dylan Baker32180562017-09-20 20:11:32 -070089with_dri_i965 = false
Dylan Baker191e7852017-10-16 17:12:52 -070090with_dri_r100 = false
Dylan Bakerc2cd5802017-10-03 17:06:22 -070091with_dri_swrast = false
Dylan Baker32180562017-09-20 20:11:32 -070092_drivers = get_option('dri-drivers')
93if _drivers != ''
94 _split = _drivers.split(',')
Ville Syrjälä22899642017-10-10 01:15:42 +030095 with_dri_i915 = _split.contains('i915')
Dylan Baker32180562017-09-20 20:11:32 -070096 with_dri_i965 = _split.contains('i965')
Dylan Baker191e7852017-10-16 17:12:52 -070097 with_dri_r100 = _split.contains('r100')
Dylan Bakerc2cd5802017-10-03 17:06:22 -070098 with_dri_swrast = _split.contains('swrast')
Dylan Baker32180562017-09-20 20:11:32 -070099 with_dri = true
100endif
101
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700102with_gallium = false
Eric Anholt1918c9b2017-10-12 18:39:08 -0700103with_gallium_pl111 = false
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700104with_gallium_radeonsi = false
Dylan Baker813b4b02017-10-09 14:59:35 -0700105with_gallium_nouveau = false
Rob Clark4aa69cc2017-10-14 10:08:50 -0400106with_gallium_freedreno = false
Dylan Bakerf3d03a22017-10-10 11:57:50 -0700107with_gallium_softpipe = false
Eric Anholt1ae80182017-10-12 13:53:12 -0700108with_gallium_vc4 = false
Eric Anholt4f3e3802017-10-12 18:40:16 -0700109with_gallium_vc5 = false
Dylan Baker51558a12017-10-20 15:45:22 -0700110with_gallium_etnaviv = false
Dylan Bakerd4567ef2017-10-20 15:57:15 -0700111with_gallium_imx = false
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700112_drivers = get_option('gallium-drivers')
113if _drivers != ''
114 _split = _drivers.split(',')
Dylan Bakerfbf39fd2017-10-17 14:44:15 -0700115 with_gallium_pl111 = _split.contains('pl111')
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700116 with_gallium_radeonsi = _split.contains('radeonsi')
Dylan Baker813b4b02017-10-09 14:59:35 -0700117 with_gallium_nouveau = _split.contains('nouveau')
Rob Clark4aa69cc2017-10-14 10:08:50 -0400118 with_gallium_freedreno = _split.contains('freedreno')
Dylan Bakerde24d612017-10-10 14:27:19 -0700119 with_gallium_softpipe = _split.contains('swrast')
Eric Anholt1ae80182017-10-12 13:53:12 -0700120 with_gallium_vc4 = _split.contains('vc4')
Eric Anholt4f3e3802017-10-12 18:40:16 -0700121 with_gallium_vc5 = _split.contains('vc5')
Dylan Baker51558a12017-10-20 15:45:22 -0700122 with_gallium_etnaviv = _split.contains('etnaviv')
Dylan Bakerd4567ef2017-10-20 15:57:15 -0700123 with_gallium_imx = _split.contains('imx')
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700124 with_gallium = true
125 with_dri = true
Ville Syrjälä22899642017-10-10 01:15:42 +0300126endif
127
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700128if not (with_dri or with_gallium)
Dylan Baker32180562017-09-20 20:11:32 -0700129 with_gles1 = false
130 with_gles2 = false
131 with_opengl = false
132 with_any_opengl = false
133 with_shared_glapi = false
134endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700135
Dylan Bakerde24d612017-10-10 14:27:19 -0700136if with_dri_swrast and with_gallium_softpipe
137 error('Only one swrast provider can be built')
138endif
Dylan Bakerd4567ef2017-10-20 15:57:15 -0700139if with_gallium_imx and not with_gallium_etnaviv
140 error('IMX driver requires etnaviv driver')
141endif
Dylan Bakerde24d612017-10-10 14:27:19 -0700142
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700143dep_libdrm_intel = []
144if with_dri_i915
145 dep_libdrm_intel = dependency('libdrm_intel', version : '>= 2.4.75')
146endif
147
Dylan Bakera47c5252017-09-22 12:55:00 -0700148# TODO: other OSes
149with_dri_platform = 'drm'
150
Dylan Baker108d2572017-10-18 12:20:43 -0700151# TODO: android platform
Dylan Bakerd1992252017-09-14 17:57:17 -0700152with_platform_wayland = false
153with_platform_x11 = false
Dylan Bakerb1b65392017-09-28 22:25:02 -0700154with_platform_drm = false
Dylan Baker108d2572017-10-18 12:20:43 -0700155with_platform_surfaceless = false
156egl_native_platform = ''
Dylan Bakerd1992252017-09-14 17:57:17 -0700157_platforms = get_option('platforms')
158if _platforms != ''
159 _split = _platforms.split(',')
160 with_platform_x11 = _split.contains('x11')
161 with_platform_wayland = _split.contains('wayland')
Dylan Bakerb1b65392017-09-28 22:25:02 -0700162 with_platform_drm = _split.contains('drm')
Dylan Baker108d2572017-10-18 12:20:43 -0700163 with_platform_surfaceless = _split.contains('surfaceless')
164 egl_native_platform = _split[0]
Dylan Bakerd1992252017-09-14 17:57:17 -0700165endif
166
Dylan Baker816bf7d12017-09-28 15:53:53 -0700167with_gbm = get_option('gbm')
168if with_gbm == 'auto' and with_dri # TODO: or gallium
169 with_gbm = host_machine.system() == 'linux'
170elif with_gbm == 'yes'
171 if not ['linux', 'bsd'].contains(host_machine.system())
172 error('GBM only supports unix-like platforms')
173 endif
174 with_gbm = true
175else
176 with_gbm = false
177endif
178
Dylan Baker108d2572017-10-18 12:20:43 -0700179_egl = get_option('egl')
180if _egl == 'auto'
181 with_egl = with_dri and with_shared_glapi and egl_native_platform != ''
182elif _egl == 'yes'
183 if not with_dri
184 error('EGL requires dri')
185 elif not with_shared_glapi
186 error('EGL requires shared-glapi')
187 elif egl_native_platform == ''
188 error('No platforms specified, consider -Dplatforms=drm,x11 at least')
189 endif
190 with_egl = true
191else
192 with_egl = false
193endif
194
195# TODO: or virgl
196if with_egl and with_gallium_radeonsi and not (with_platform_drm or with_platform_surfaceless)
197 error('RadeonSI requires drm or surfaceless platform when using EGL')
198endif
199
Dylan Baker8e611872017-10-11 12:49:31 -0700200pre_args += '-DGLX_USE_TLS'
Dylan Bakera47c5252017-09-22 12:55:00 -0700201with_glx = get_option('glx')
202if with_glx != 'disabled'
Dylan Baker8d3b1212017-10-18 15:47:11 -0700203 if not (with_platform_x11 and with_any_opengl)
204 if with_glx == 'auto'
205 with_glx = 'disabled'
206 else
207 error('Cannot build GLX support without X11 platform support and at least one OpenGL API')
208 endif
Dylan Bakera47c5252017-09-22 12:55:00 -0700209 elif with_glx == 'gallium-xlib'
210 if not with_gallium
211 error('Gallium-xlib based GLX requires at least one gallium driver')
212 elif with_dri
213 error('gallium-xlib conflicts with any dri driver')
214 endif
215 elif with_glx == 'dri' and not with_dri
216 error('dri based GLX requires at least one DRI driver')
217 elif with_glx == 'auto'
218 if with_dri
219 with_glx = 'dri'
220 elif with_gallium
221 with_glx = 'gallium-xlib'
222 elif with_platform_x11 and with_any_opengl
223 with_glx = 'xlib'
224 else
225 with_glx = 'disabled'
226 endif
227 endif
228endif
229
230with_glvnd = get_option('glvnd')
231if with_glvnd and with_glx != 'dri'
232 message('glvnd requires dri based glx')
233endif
234
235# TODO: toggle for this
236with_glx_direct = true
237
Dylan Bakerd1992252017-09-14 17:57:17 -0700238if with_vulkan_icd_dir == ''
239 with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
240endif
241
242with_intel_vk = false
243with_amd_vk = false
Dylan Bakera47c5252017-09-22 12:55:00 -0700244with_any_vk = false
Dylan Bakerd1992252017-09-14 17:57:17 -0700245_vulkan_drivers = get_option('vulkan-drivers')
246if _vulkan_drivers != ''
247 _split = _vulkan_drivers.split(',')
248 with_intel_vk = _split.contains('intel')
249 with_amd_vk = _split.contains('amd')
Dylan Bakera47c5252017-09-22 12:55:00 -0700250 with_any_vk = with_amd_vk or with_intel_vk
Dylan Bakerd1992252017-09-14 17:57:17 -0700251 if not (with_platform_x11 or with_platform_wayland)
252 error('Vulkan requires at least one platform (x11, wayland)')
253 endif
Dylan Bakera47c5252017-09-22 12:55:00 -0700254endif
255
Dylan Baker50c28df2017-09-29 17:53:01 -0700256with_dri2 = (with_dri or with_any_vk) and with_dri_platform == 'drm'
257with_dri3 = get_option('dri3')
258if with_dri3 == 'auto'
259 if host_machine.system() == 'linux' and with_dri2
260 with_dri3 = true
261 else
262 with_dri3 = false
263 endif
264elif with_dri3 == 'yes'
265 with_dri3 = true
266else
267 with_dri3 = false
268endif
269
270if with_any_vk and (with_platform_x11 and not with_dri3)
271 error('Vulkan drivers require dri3 for X11 support')
272endif
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700273if with_dri or with_gallium
Dylan Baker108d2572017-10-18 12:20:43 -0700274 if with_glx == 'disabled' and not with_egl
Dylan Bakera47c5252017-09-22 12:55:00 -0700275 error('building dri or gallium drivers require at least one window system')
276 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700277endif
278
Dylan Baker50c28df2017-09-29 17:53:01 -0700279with_gallium_xvmc = false
280with_gallium_vdpau = false
281with_gallium_omx = false # this is bellagio
282with_gallium_va = false
283with_gallium_media = false
284dep_va = []
285_drivers = get_option('gallium-media')
286if _drivers != ''
287 _split = _drivers.split(',')
288 with_gallium_xvmc = _split.contains('xvmc')
289 with_gallium_vdpau = _split.contains('vdpau')
290 with_gallium_omx = _split.contains('omx')
291 with_gallium_va = _split.contains('va')
292 with_gallium_media = (with_gallium_xvmc or with_gallium_vdpau or
293 with_gallium_omx or with_gallium_va)
294endif
295
Dylan Baker108d2572017-10-18 12:20:43 -0700296gl_pkgconfig_c_flags = []
Dylan Baker50c28df2017-09-29 17:53:01 -0700297if with_platform_x11
298 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
299 pre_args += '-DHAVE_X11_PLATFORM'
300 endif
301 if with_glx == 'xlib'
302 # TODO
303 error('TODO')
304 elif with_glx == 'gallium-xlib'
305 # TODO
306 error('TODO')
307 else
308 pre_args += '-DGLX_INDIRECT_RENDERING'
309 if with_glx_direct
310 pre_args += '-DGLX_DIRECT_RENDERING'
311 endif
312 if with_dri_platform == 'drm'
313 pre_args += '-DGLX_USE_DRM'
314 endif
315 endif
Dylan Baker108d2572017-10-18 12:20:43 -0700316else
317 pre_args += '-DMESA_EGL_NO_X11_HEADERS'
318 gl_pkgconfig_c_flags += '-DMESA_EGL_NO_X11_HEADERS'
319endif
320if with_platform_drm
321 if with_egl and not with_gbm
322 error('EGL drm platform requires gbm')
323 endif
324 pre_args += '-DHAVE_DRM_PLATFORM'
325endif
326if with_platform_surfaceless
327 pre_args += '-DHAVE_SURFACELESS_PLATFORM'
Dylan Baker50c28df2017-09-29 17:53:01 -0700328endif
329
Dylan Bakerd1992252017-09-14 17:57:17 -0700330prog_python2 = find_program('python2')
Dylan Baker9342a7d2017-09-28 10:48:30 -0700331has_mako = run_command(prog_python2, '-c', 'import mako')
332if has_mako.returncode() != 0
333 error('Python (2.x) mako module required to build mesa.')
334endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700335
336cc = meson.get_compiler('c')
337if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
Eric Engestrom1262e822017-09-29 15:25:18 +0100338 error('When using GCC, version 4.4.6 or later is required.')
Dylan Bakerd1992252017-09-14 17:57:17 -0700339endif
340
Dylan Bakerd1992252017-09-14 17:57:17 -0700341# Define DEBUG for debug and debugoptimized builds
342if get_option('buildtype').startswith('debug')
343 pre_args += '-DDEBUG'
344endif
345
Dylan Baker673dda82017-09-20 11:53:29 -0700346if get_option('shader-cache')
347 pre_args += '-DENABLE_SHADER_CACHE'
348elif with_amd_vk
349 error('Radv requires shader cache support')
350endif
351
Dylan Bakerd1992252017-09-14 17:57:17 -0700352# Check for GCC style builtins
353foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
354 'ffsll', 'popcount', 'popcountll', 'unreachable']
355 if cc.has_function(b)
356 pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
357 endif
358endforeach
359
Dylan Baker673dda82017-09-20 11:53:29 -0700360# check for GCC __attribute__
Dylan Bakerd1992252017-09-14 17:57:17 -0700361foreach a : ['const', 'flatten', 'malloc', 'pure', 'unused',
362 'warn_unused_result', 'weak',]
363 if cc.compiles('int foo(void) __attribute__((@0@));'.format(a),
364 name : '__attribute__((@0@))'.format(a))
365 pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
366 endif
367endforeach
368if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
369 name : '__attribute__((format(...)))')
370 pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
371endif
372if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
373 name : '__attribute__((packed))')
374 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
375endif
376if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
377 name : '__attribute__((returns_nonnull))')
378 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NONNULL'
379endif
380if cc.compiles('''int foo_def(void) __attribute__((visibility("default")));
381 int foo_hid(void) __attribute__((visibility("hidden")));
382 int foo_int(void) __attribute__((visibility("internal")));
383 int foo_pro(void) __attribute__((visibility("protected")));''',
384 name : '__attribute__((visibility(...)))')
385 pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISBILITY'
386endif
387if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
388 name : '__attribute__((alias(...)))')
389 pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
390endif
391
392# TODO: this is very incomplete
393if host_machine.system() == 'linux'
394 pre_args += '-D_GNU_SOURCE'
395endif
396
397# Check for generic C arguments
398c_args = []
399foreach a : ['-Wall', '-Werror=implicit-function-declaration',
400 '-Werror=missing-prototypes', '-fno-math-errno',
401 '-fno-trapping-math', '-Qunused-arguments']
402 if cc.has_argument(a)
403 c_args += a
404 endif
405endforeach
406c_vis_args = []
407if cc.has_argument('-fvisibility=hidden')
408 c_vis_args += '-fvisibility=hidden'
409endif
410
411# Check for generic C++ arguments
412cpp = meson.get_compiler('cpp')
413cpp_args = []
414foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math',
415 '-Qunused-arguments', '-Wno-non-virtual-dtor']
416 if cpp.has_argument(a)
417 cpp_args += a
418 endif
419endforeach
420cpp_vis_args = []
421if cpp.has_argument('-fvisibility=hidden')
422 cpp_vis_args += '-fvisibility=hidden'
423endif
424
425# Check for C and C++ arguments for MSVC2013 compatibility. These are only used
426# in parts of the mesa code base that need to compile with old versions of
427# MSVC, mainly common code
428c_msvc_compat_args = []
429cpp_msvc_compat_args = []
430foreach a : ['-Werror=pointer-arith', '-Werror=vla']
431 if cc.has_argument(a)
432 c_msvc_compat_args += a
433 endif
434 if cpp.has_argument(a)
435 cpp_msvc_compat_args += a
436 endif
437endforeach
438
439no_override_init_args = []
440foreach a : ['-Wno-override-init', '-Wno-initializer-overrides']
441 if cc.has_argument(a)
442 no_override_init_args += a
443 endif
444endforeach
445
446# TODO: SSE41 (which is only required for core mesa)
447
448# Check for GCC style atomics
449if cc.compiles('int main() { int n; return __atomic_load_n(&n, __ATOMIC_ACQUIRE); }',
450 name : 'GCC atomic builtins')
451 pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
452endif
453if not cc.links('''#include <stdint.h>
454 uint64_t v;
455 int main() {
456 return __sync_add_and_fetch(&v, (uint64_t)1);
457 }''',
458 name : 'GCC 64bit atomics')
459 pre_args += '-DMISSING_64_BIT_ATOMICS'
460endif
461
462# TODO: endian
463# TODO: powr8
464# TODO: shared/static? Is this even worth doing?
465
466# I don't think that I need to set any of the debug stuff, I think meson
467# handles that for us
468
469# TODO: ldflags
470
471# TODO: texture-float (gallium/mesa only)
472
473# TODO: cross-compiling. I don't think this is relavent to meson
474
Dylan Baker32180562017-09-20 20:11:32 -0700475# FIXME: enable asm when cross compiler
476# This is doable (autotools does it), but it's not of immediate concern
477if meson.is_cross_build()
478 message('Cross compiling, disabling asm')
479 with_asm = false
480endif
481
482with_asm_arch = ''
483if with_asm
484 # TODO: SPARC and PPC
485 if host_machine.cpu_family() == 'x86'
486 if ['linux', 'bsd'].contains(host_machine.system()) # FIXME: hurd?
487 with_asm_arch = 'x86'
488 pre_args += ['-DUSE_X86_ASM', '-DUSE_MMX_ASM', '-DUSE_3DNOW_ASM',
489 '-DUSE_SSE_ASM']
490 endif
491 elif host_machine.cpu_family() == 'x86_64'
492 if host_machine.system() == 'linux'
493 with_asm_arch = 'x86_64'
494 pre_args += ['-DUSE_X86_64_ASM']
495 endif
496 elif host_machine.cpu_family() == 'arm'
497 if host_machine.system() == 'linux'
498 with_asm_arch = 'arm'
499 pre_args += ['-DUSE_ARM_ASM']
500 endif
501 elif host_machine.cpu_family() == 'aarch64'
502 if host_machine.system() == 'linux'
503 with_asm_arch = 'aarch64'
504 pre_args += ['-DUSE_AARCH64_ASM']
505 endif
506 endif
507endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700508
509# Check for standard headers and functions
510if cc.has_header_symbol('sys/sysmacros.h', 'major')
511 pre_args += '-DMAJOR_IN_SYSMACROS'
512elif cc.has_header_symbol('sys/mkdev.h', 'major')
513 pre_args += '-DMAJOR_IN_MKDEV'
514endif
515
516foreach h : ['xlocale.h', 'sys/sysctl.h']
517 if cc.has_header(h)
518 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
519 endif
520endforeach
521
522foreach f : ['strtof', 'mkostemp', 'posix_memalign']
523 if cc.has_function(f)
524 pre_args += '-DHAVE_@0@'.format(f.to_upper())
525 endif
526endforeach
527
528# strtod locale support
529if cc.links('''
530 #define _GNU_SOURCE
531 #include <stdlib.h>
532 #include <locale.h>
533 #ifdef HAVE_XLOCALE_H
534 #include <xlocale.h>
535 #endif
536 int main() {
537 locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
538 const char *s = "1.0";
539 char *end;
540 double d = strtod_l(s, end, loc);
541 float f = strtod_l(s, end, loc);
542 freelocale(loc);
543 return 0;
544 }''',
545 extra_args : pre_args,
546 name : 'strtod has locale support')
547 pre_args += '-DHAVE_STRTOD_L'
548endif
549
550# Check for some linker flags
551ld_args_bsymbolic = []
Dylan Bakere21e0a62017-09-30 13:15:52 -0700552if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic', name : 'Bsymbolic')
Dylan Bakerd1992252017-09-14 17:57:17 -0700553 ld_args_bsymbolic += '-Wl,-Bsymbolic'
554endif
555ld_args_gc_sections = []
556if cc.links('static char unused() { return 5; } int main() { return 0; }',
Dylan Bakere21e0a62017-09-30 13:15:52 -0700557 args : '-Wl,--gc-sections', name : 'gc-sections')
Dylan Bakerd1992252017-09-14 17:57:17 -0700558 ld_args_gc_sections += '-Wl,--gc-sections'
559endif
Dylan Bakere21e0a62017-09-30 13:15:52 -0700560with_ld_version_script = false
561if cc.links('int main() { return 0; }',
562 args : '-Wl,--version-script=@0@'.format(
563 join_paths(meson.source_root(), 'build-support/conftest.map')),
564 name : 'version-script')
565 with_ld_version_script = true
566endif
567with_ld_dynamic_list = false
568if cc.links('int main() { return 0; }',
569 args : '-Wl,--dynamic-list=@0@'.format(
570 join_paths(meson.source_root(), 'build-support/conftest.dyn')),
571 name : 'dynamic-list')
572 with_ld_dynamic_list = true
573endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700574
575# check for dl support
576if cc.has_function('dlopen')
577 dep_dl = []
578else
579 dep_dl = cc.find_library('dl')
580endif
Dylan Baker32180562017-09-20 20:11:32 -0700581if cc.has_function('dladdr', dependencies : dep_dl)
582 # This is really only required for megadrivers
583 pre_args += '-DHAVE_DLADDR'
Dylan Bakerd1992252017-09-14 17:57:17 -0700584endif
585
586if cc.has_function('dl_iterate_phdr')
587 pre_args += '-DHAVE_DL_ITERATE_PHDR'
588else
589 # TODO: this is required for vulkan
590endif
591
592# Determine whether or not the rt library is needed for time functions
593if cc.has_function('clock_gettime')
594 dep_clock = []
595else
596 dep_clock = cc.find_library('rt')
597endif
598
Dylan Baker66c94b92017-09-30 13:48:34 -0700599with_gallium_drisw_kms = false
Dylan Baker50c28df2017-09-29 17:53:01 -0700600dep_libdrm = dependency('libdrm', version : '>= 2.4.75',
601 required : with_dri2 or with_dri3)
602if dep_libdrm.found()
603 pre_args += '-DHAVE_LIBDRM'
Dylan Baker66c94b92017-09-30 13:48:34 -0700604 if with_dri_platform == 'drm' and with_dri
605 with_gallium_drisw_kms = true
606 endif
Dylan Baker50c28df2017-09-29 17:53:01 -0700607endif
608
Dylan Bakerd1992252017-09-14 17:57:17 -0700609# TODO: some of these may be conditional
610dep_zlib = dependency('zlib', version : '>= 1.2.3')
611dep_thread = dependency('threads')
Dylan Baker50c28df2017-09-29 17:53:01 -0700612if dep_thread.found() and host_machine.system() == 'linux'
613 pre_args += '-DHAVE_PTHREAD'
614endif
Dylan Bakercc4f5872017-09-27 11:30:21 -0700615dep_elf = dependency('libelf', required : false)
Dylan Bakerb154b442017-09-30 14:04:28 -0700616if not dep_elf.found() and (with_amd_vk or with_gallium_radeonsi) # TODO: clover, r600
617 dep_elf = cc.find_library('elf')
Dylan Bakercc4f5872017-09-27 11:30:21 -0700618endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700619dep_expat = dependency('expat')
620# this only exists on linux so either this is linux and it will be found, or
621# its not linux and and wont
622dep_m = cc.find_library('m', required : false)
Dylan Baker66f97f62017-09-30 09:03:51 -0700623
624dep_libdrm_amdgpu = []
625dep_libdrm_radeon = []
Dylan Baker813b4b02017-10-09 14:59:35 -0700626dep_libdrm_nouveau = []
Dylan Baker51558a12017-10-20 15:45:22 -0700627dep_libdrm_etnaviv = []
Rob Clark4aa69cc2017-10-14 10:08:50 -0400628dep_libdrm_freedreno = []
Dylan Baker66f97f62017-09-30 09:03:51 -0700629if with_amd_vk or with_gallium_radeonsi
Dylan Baker8792a9e2017-10-20 16:28:32 -0700630 dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.85')
Dylan Baker66f97f62017-09-30 09:03:51 -0700631endif
Dylan Baker191e7852017-10-16 17:12:52 -0700632if with_gallium_radeonsi or with_dri_r100 # older radeon too
Dylan Baker66f97f62017-09-30 09:03:51 -0700633 dep_libdrm_radeon = dependency('libdrm_radeon', version : '>= 2.4.71')
634endif
Dylan Baker813b4b02017-10-09 14:59:35 -0700635if with_gallium_nouveau
636 dep_libdrm_nouveau = dependency('libdrm_nouveau', version : '>= 2.4.66')
637endif
Dylan Baker51558a12017-10-20 15:45:22 -0700638if with_gallium_etnaviv
639 dep_libdrm_etnaviv = dependency('libdrm_etnaviv', version : '>= 2.4.82')
640endif
Rob Clark4aa69cc2017-10-14 10:08:50 -0400641if with_gallium_freedreno
642 dep_libdrm_freedreno = dependency('libdrm_freedreno', version : '>= 2.4.74')
643endif
Dylan Baker673dda82017-09-20 11:53:29 -0700644
645llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
646if with_amd_vk
647 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
648endif
649dep_llvm = dependency(
Dylan Baker50c28df2017-09-29 17:53:01 -0700650 'llvm', version : '>= 3.9.0', required : with_amd_vk, modules : llvm_modules,
Dylan Baker673dda82017-09-20 11:53:29 -0700651)
Dylan Baker02cf3a82017-10-12 09:47:30 -0700652if with_llvm
653 if dep_llvm.found()
654 _llvm_version = dep_llvm.version().split('.')
655 # Development versions of LLVM have an 'svn' suffix, we don't want that for
656 # our version checks.
657 _llvm_patch = _llvm_version[2]
658 if _llvm_patch.endswith('svn')
659 _llvm_patch = _llvm_patch.split('s')[0]
660 endif
661 pre_args += [
662 '-DHAVE_LLVM=0x0@0@@1@@2@'.format(_llvm_version[0], _llvm_version[1], _llvm_patch),
663 '-DMESA_LLVM_VERSION_PATCH=@0@'.format(_llvm_patch),
664 ]
665 else
Dylan Baker6a9ad202017-10-10 14:56:39 -0700666 if with_gallium_softpipe
667 error('Cannot find LLVM to build LLVMPipe. If you wanted softpipe pass -Dllvm=false to meson')
668 elif with_amd_vk or with_gallium_radeonsi # etc
Dylan Baker66f97f62017-09-30 09:03:51 -0700669 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 -0700670 endif
Dylan Baker673dda82017-09-20 11:53:29 -0700671 endif
Dylan Baker66f97f62017-09-30 09:03:51 -0700672elif with_amd_vk or with_gallium_radeonsi
673 error('The following drivers requires LLVM: Radv, RadeonSI. One of these is enabled, but LLVM is disabled.')
Dylan Baker673dda82017-09-20 11:53:29 -0700674endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700675
Dylan Bakera47c5252017-09-22 12:55:00 -0700676dep_glvnd = []
677if with_glvnd
678 dep_glvnd = dependency('libglvnd', version : '>= 0.2.0')
679 pre_args += '-DUSE_LIBGLVND=1'
680endif
681
Dylan Bakerd1992252017-09-14 17:57:17 -0700682# TODO: make this conditional
683dep_valgrind = dependency('valgrind', required : false)
684if dep_valgrind.found() and with_valgrind
685 pre_args += '-DHAVE_VALGRIND'
686endif
687
688# pthread stubs. Lets not and say we didn't
689
Dylan Baker32180562017-09-20 20:11:32 -0700690prog_bison = find_program('bison', required : with_any_opengl)
691prog_flex = find_program('flex', required : with_any_opengl)
692
Dylan Bakerd1992252017-09-14 17:57:17 -0700693# TODO: selinux
Dylan Baker32180562017-09-20 20:11:32 -0700694dep_selinux = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700695
696# TODO: llvm-prefix and llvm-shared-libs
697
Dylan Bakerb1b65392017-09-28 22:25:02 -0700698dep_unwind = dependency('libunwind', required : false)
Erik Faye-Lund9e5a5a12017-10-23 20:54:03 +0200699if dep_unwind.found() and with_libunwind
Dylan Bakerb1b65392017-09-28 22:25:02 -0700700 pre_args += '-DHAVE_LIBUNWIND'
701endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700702
703# TODO: flags for opengl, gles, dri
704
705# TODO: gallium-hud
706
707# TODO: glx provider
708
709# TODO: osmesa provider
710
Dylan Bakerd1992252017-09-14 17:57:17 -0700711# TODO: symbol mangling
712
Dylan Bakerd1992252017-09-14 17:57:17 -0700713if with_platform_wayland
714 prog_wl_scanner = find_program('wayland-scanner')
715 dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8')
716 dep_wayland_client = dependency('wayland-client', version : '>=1.11')
717 dep_wayland_server = dependency('wayland-server', version : '>=1.11')
Dylan Baker108d2572017-10-18 12:20:43 -0700718 wayland_dmabuf_xml = join_paths(
719 dep_wl_protocols.get_pkgconfig_variable('pkgdatadir'), 'unstable',
720 'linux-dmabuf', 'linux-dmabuf-unstable-v1.xml'
721 )
722 pre_args += ['-DHAVE_WAYLAND_PLATFORM', '-DWL_HIDE_DEPRECATED']
Dylan Bakerd1992252017-09-14 17:57:17 -0700723else
724 prog_wl_scanner = []
725 dep_wl_protocols = []
726 dep_wayland_client = []
727 dep_wayland_server = []
Dylan Baker108d2572017-10-18 12:20:43 -0700728 wayland_dmabuf_xml = ''
Dylan Bakerd1992252017-09-14 17:57:17 -0700729endif
730
Dylan Baker50c28df2017-09-29 17:53:01 -0700731dep_x11 = []
732dep_xext = []
733dep_xdamage = []
734dep_xfixes = []
735dep_x11_xcb = []
736dep_xcb_glx = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700737dep_xcb_dri2 = []
738dep_xcb_dri3 = []
Dylan Bakera47c5252017-09-22 12:55:00 -0700739dep_dri2proto = []
740dep_glproto = []
Dylan Bakera47c5252017-09-22 12:55:00 -0700741dep_xf86vm = []
Dylan Baker50c28df2017-09-29 17:53:01 -0700742dep_xcb_dri3 = []
743dep_xcb_present = []
744dep_xcb_sync = []
Dylan Baker108d2572017-10-18 12:20:43 -0700745dep_xcb_xfixes = []
Dylan Baker50c28df2017-09-29 17:53:01 -0700746dep_xshmfence = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700747if with_platform_x11
Dylan Baker50c28df2017-09-29 17:53:01 -0700748 if with_glx == 'dri' and with_dri_platform == 'drm'
749 dep_x11 = dependency('x11')
750 dep_xext = dependency('xext')
751 dep_xdamage = dependency('xdamage', version : '>= 1.1')
752 dep_xfixes = dependency('xfixes')
753 dep_xcb_glx = dependency('xcb-glx', version : '>= 1.8.1')
Nicholas Miell30128852017-10-17 18:04:16 -0700754 dep_xf86vm = dependency('xxf86vm', required : false)
Dylan Bakera47c5252017-09-22 12:55:00 -0700755 endif
756 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
Dylan Baker50c28df2017-09-29 17:53:01 -0700757 dep_xcb = dependency('xcb')
758 dep_x11_xcb = dependency('x11-xcb')
759 dep_xcb_dri2 = dependency('xcb-dri2', version : '>= 1.8')
760
Dylan Bakera47c5252017-09-22 12:55:00 -0700761 if with_dri3
762 pre_args += '-DHAVE_DRI3'
Dylan Baker50c28df2017-09-29 17:53:01 -0700763 dep_xcb_dri3 = dependency('xcb-dri3')
764 dep_xcb_present = dependency('xcb-present')
765 dep_xcb_sync = dependency('xcb-sync')
766 dep_xshmfence = dependency('xshmfence', version : '>= 1.1')
Dylan Bakera47c5252017-09-22 12:55:00 -0700767 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700768 endif
Dylan Baker50c28df2017-09-29 17:53:01 -0700769 if with_glx != 'disabled'
770 dep_dri2proto = dependency('dri2proto', version : '>= 2.8')
771 dep_glproto = dependency('glproto', version : '>= 1.4.14')
772 endif
Dylan Baker108d2572017-10-18 12:20:43 -0700773 if with_egl
774 dep_xcb_xfixes = dependency('xcb-xfixes')
775 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700776endif
777
Dylan Bakerd1992252017-09-14 17:57:17 -0700778# TODO: osmesa
779
Dylan Bakerd1992252017-09-14 17:57:17 -0700780# TODO: vallium G3DVL
781
782# TODO: nine
783
784# TODO: clover
785
Dylan Bakerd1992252017-09-14 17:57:17 -0700786# TODO: gallium tests
787
788# TODO: various libdirs
789
790# TODO: swr
791
792# TODO: gallium driver dirs
793
794# FIXME: this is a workaround for #2326
795prog_touch = find_program('touch')
796dummy_cpp = custom_target(
797 'dummy_cpp',
798 output : 'dummy.cpp',
799 command : [prog_touch, '@OUTPUT@'],
800)
801
802foreach a : pre_args
803 add_project_arguments(a, language : ['c', 'cpp'])
804endforeach
805foreach a : c_args
806 add_project_arguments(a, language : ['c'])
807endforeach
808foreach a : cpp_args
809 add_project_arguments(a, language : ['cpp'])
810endforeach
811
812inc_include = include_directories('include')
813
Dylan Baker108d2572017-10-18 12:20:43 -0700814gl_priv_reqs = [
815 'x11', 'xext', 'xdamage >= 1.1', 'xfixes', 'x11-xcb', 'xcb',
816 'xcb-glx >= 1.8.1', 'libdrm >= 2.4.75',
817]
818if dep_xf86vm != [] and dep_xf86vm.found()
819 gl_priv_reqs += 'xf86vm'
820endif
821if with_dri_platform == 'drm'
822 gl_priv_reqs += 'xcb-dri2 >= 1.8'
823endif
824
825gl_priv_libs = []
826if dep_thread.found()
827 gl_priv_libs += ['-lpthread', '-pthread']
828endif
829if dep_m.found()
830 gl_priv_libs += '-lm'
831endif
832if dep_dl.found()
833 gl_priv_libs += '-ldl'
834endif
835
Dylan Baker32180562017-09-20 20:11:32 -0700836pkg = import('pkgconfig')
837
Dylan Bakerd1992252017-09-14 17:57:17 -0700838subdir('include')
839subdir('src')