blob: 875f9d4d294d1911f239f88c02342cdd9a5f2583 [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 Bakereecd2862017-10-16 17:24:56 -070091with_dri_r200 = false
Dylan Bakereb3bb032017-10-16 17:51:47 -070092with_dri_nouveau = false
Dylan Bakerc2cd5802017-10-03 17:06:22 -070093with_dri_swrast = false
Dylan Baker32180562017-09-20 20:11:32 -070094_drivers = get_option('dri-drivers')
95if _drivers != ''
96 _split = _drivers.split(',')
Ville Syrjälä22899642017-10-10 01:15:42 +030097 with_dri_i915 = _split.contains('i915')
Dylan Baker32180562017-09-20 20:11:32 -070098 with_dri_i965 = _split.contains('i965')
Dylan Baker191e7852017-10-16 17:12:52 -070099 with_dri_r100 = _split.contains('r100')
Dylan Bakereecd2862017-10-16 17:24:56 -0700100 with_dri_r200 = _split.contains('r200')
Dylan Bakereb3bb032017-10-16 17:51:47 -0700101 with_dri_nouveau = _split.contains('nouveau')
Dylan Bakerc2cd5802017-10-03 17:06:22 -0700102 with_dri_swrast = _split.contains('swrast')
Dylan Baker32180562017-09-20 20:11:32 -0700103 with_dri = true
104endif
105
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700106with_gallium = false
Eric Anholt1918c9b2017-10-12 18:39:08 -0700107with_gallium_pl111 = false
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700108with_gallium_radeonsi = false
Dylan Baker813b4b02017-10-09 14:59:35 -0700109with_gallium_nouveau = false
Rob Clark4aa69cc2017-10-14 10:08:50 -0400110with_gallium_freedreno = false
Dylan Bakerf3d03a22017-10-10 11:57:50 -0700111with_gallium_softpipe = false
Eric Anholt1ae80182017-10-12 13:53:12 -0700112with_gallium_vc4 = false
Eric Anholt4f3e3802017-10-12 18:40:16 -0700113with_gallium_vc5 = false
Dylan Baker51558a12017-10-20 15:45:22 -0700114with_gallium_etnaviv = false
Dylan Bakerd4567ef2017-10-20 15:57:15 -0700115with_gallium_imx = false
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700116_drivers = get_option('gallium-drivers')
117if _drivers != ''
118 _split = _drivers.split(',')
Dylan Bakerfbf39fd2017-10-17 14:44:15 -0700119 with_gallium_pl111 = _split.contains('pl111')
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700120 with_gallium_radeonsi = _split.contains('radeonsi')
Dylan Baker813b4b02017-10-09 14:59:35 -0700121 with_gallium_nouveau = _split.contains('nouveau')
Rob Clark4aa69cc2017-10-14 10:08:50 -0400122 with_gallium_freedreno = _split.contains('freedreno')
Dylan Bakerde24d612017-10-10 14:27:19 -0700123 with_gallium_softpipe = _split.contains('swrast')
Eric Anholt1ae80182017-10-12 13:53:12 -0700124 with_gallium_vc4 = _split.contains('vc4')
Eric Anholt4f3e3802017-10-12 18:40:16 -0700125 with_gallium_vc5 = _split.contains('vc5')
Dylan Baker51558a12017-10-20 15:45:22 -0700126 with_gallium_etnaviv = _split.contains('etnaviv')
Dylan Bakerd4567ef2017-10-20 15:57:15 -0700127 with_gallium_imx = _split.contains('imx')
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700128 with_gallium = true
129 with_dri = true
Ville Syrjälä22899642017-10-10 01:15:42 +0300130endif
131
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700132if not (with_dri or with_gallium)
Dylan Baker32180562017-09-20 20:11:32 -0700133 with_gles1 = false
134 with_gles2 = false
135 with_opengl = false
136 with_any_opengl = false
137 with_shared_glapi = false
138endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700139
Dylan Bakerde24d612017-10-10 14:27:19 -0700140if with_dri_swrast and with_gallium_softpipe
141 error('Only one swrast provider can be built')
142endif
Dylan Bakerd4567ef2017-10-20 15:57:15 -0700143if with_gallium_imx and not with_gallium_etnaviv
144 error('IMX driver requires etnaviv driver')
145endif
Dylan Bakerde24d612017-10-10 14:27:19 -0700146
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700147dep_libdrm_intel = []
148if with_dri_i915
149 dep_libdrm_intel = dependency('libdrm_intel', version : '>= 2.4.75')
150endif
151
Dylan Bakera47c5252017-09-22 12:55:00 -0700152# TODO: other OSes
153with_dri_platform = 'drm'
154
Dylan Baker108d2572017-10-18 12:20:43 -0700155# TODO: android platform
Dylan Bakerd1992252017-09-14 17:57:17 -0700156with_platform_wayland = false
157with_platform_x11 = false
Dylan Bakerb1b65392017-09-28 22:25:02 -0700158with_platform_drm = false
Dylan Baker108d2572017-10-18 12:20:43 -0700159with_platform_surfaceless = false
160egl_native_platform = ''
Dylan Bakerd1992252017-09-14 17:57:17 -0700161_platforms = get_option('platforms')
162if _platforms != ''
163 _split = _platforms.split(',')
164 with_platform_x11 = _split.contains('x11')
165 with_platform_wayland = _split.contains('wayland')
Dylan Bakerb1b65392017-09-28 22:25:02 -0700166 with_platform_drm = _split.contains('drm')
Dylan Baker108d2572017-10-18 12:20:43 -0700167 with_platform_surfaceless = _split.contains('surfaceless')
168 egl_native_platform = _split[0]
Dylan Bakerd1992252017-09-14 17:57:17 -0700169endif
170
Dylan Baker816bf7d12017-09-28 15:53:53 -0700171with_gbm = get_option('gbm')
172if with_gbm == 'auto' and with_dri # TODO: or gallium
173 with_gbm = host_machine.system() == 'linux'
174elif with_gbm == 'yes'
175 if not ['linux', 'bsd'].contains(host_machine.system())
176 error('GBM only supports unix-like platforms')
177 endif
178 with_gbm = true
179else
180 with_gbm = false
181endif
182
Dylan Baker108d2572017-10-18 12:20:43 -0700183_egl = get_option('egl')
184if _egl == 'auto'
185 with_egl = with_dri and with_shared_glapi and egl_native_platform != ''
186elif _egl == 'yes'
187 if not with_dri
188 error('EGL requires dri')
189 elif not with_shared_glapi
190 error('EGL requires shared-glapi')
191 elif egl_native_platform == ''
192 error('No platforms specified, consider -Dplatforms=drm,x11 at least')
193 endif
194 with_egl = true
195else
196 with_egl = false
197endif
198
199# TODO: or virgl
200if with_egl and with_gallium_radeonsi and not (with_platform_drm or with_platform_surfaceless)
201 error('RadeonSI requires drm or surfaceless platform when using EGL')
202endif
203
Dylan Baker8e611872017-10-11 12:49:31 -0700204pre_args += '-DGLX_USE_TLS'
Dylan Bakera47c5252017-09-22 12:55:00 -0700205with_glx = get_option('glx')
206if with_glx != 'disabled'
Dylan Baker8d3b1212017-10-18 15:47:11 -0700207 if not (with_platform_x11 and with_any_opengl)
208 if with_glx == 'auto'
209 with_glx = 'disabled'
210 else
211 error('Cannot build GLX support without X11 platform support and at least one OpenGL API')
212 endif
Dylan Bakera47c5252017-09-22 12:55:00 -0700213 elif with_glx == 'gallium-xlib'
214 if not with_gallium
215 error('Gallium-xlib based GLX requires at least one gallium driver')
216 elif with_dri
217 error('gallium-xlib conflicts with any dri driver')
218 endif
219 elif with_glx == 'dri' and not with_dri
220 error('dri based GLX requires at least one DRI driver')
221 elif with_glx == 'auto'
222 if with_dri
223 with_glx = 'dri'
224 elif with_gallium
225 with_glx = 'gallium-xlib'
226 elif with_platform_x11 and with_any_opengl
227 with_glx = 'xlib'
228 else
229 with_glx = 'disabled'
230 endif
231 endif
232endif
233
234with_glvnd = get_option('glvnd')
235if with_glvnd and with_glx != 'dri'
236 message('glvnd requires dri based glx')
237endif
238
239# TODO: toggle for this
240with_glx_direct = true
241
Dylan Bakerd1992252017-09-14 17:57:17 -0700242if with_vulkan_icd_dir == ''
243 with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
244endif
245
246with_intel_vk = false
247with_amd_vk = false
Dylan Bakera47c5252017-09-22 12:55:00 -0700248with_any_vk = false
Dylan Bakerd1992252017-09-14 17:57:17 -0700249_vulkan_drivers = get_option('vulkan-drivers')
250if _vulkan_drivers != ''
251 _split = _vulkan_drivers.split(',')
252 with_intel_vk = _split.contains('intel')
253 with_amd_vk = _split.contains('amd')
Dylan Bakera47c5252017-09-22 12:55:00 -0700254 with_any_vk = with_amd_vk or with_intel_vk
Dylan Bakerd1992252017-09-14 17:57:17 -0700255 if not (with_platform_x11 or with_platform_wayland)
256 error('Vulkan requires at least one platform (x11, wayland)')
257 endif
Dylan Bakera47c5252017-09-22 12:55:00 -0700258endif
259
Dylan Baker50c28df2017-09-29 17:53:01 -0700260with_dri2 = (with_dri or with_any_vk) and with_dri_platform == 'drm'
261with_dri3 = get_option('dri3')
262if with_dri3 == 'auto'
263 if host_machine.system() == 'linux' and with_dri2
264 with_dri3 = true
265 else
266 with_dri3 = false
267 endif
268elif with_dri3 == 'yes'
269 with_dri3 = true
270else
271 with_dri3 = false
272endif
273
274if with_any_vk and (with_platform_x11 and not with_dri3)
275 error('Vulkan drivers require dri3 for X11 support')
276endif
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700277if with_dri or with_gallium
Dylan Baker108d2572017-10-18 12:20:43 -0700278 if with_glx == 'disabled' and not with_egl
Dylan Bakera47c5252017-09-22 12:55:00 -0700279 error('building dri or gallium drivers require at least one window system')
280 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700281endif
282
Dylan Baker50c28df2017-09-29 17:53:01 -0700283with_gallium_xvmc = false
284with_gallium_vdpau = false
285with_gallium_omx = false # this is bellagio
286with_gallium_va = false
287with_gallium_media = false
288dep_va = []
289_drivers = get_option('gallium-media')
290if _drivers != ''
291 _split = _drivers.split(',')
292 with_gallium_xvmc = _split.contains('xvmc')
293 with_gallium_vdpau = _split.contains('vdpau')
294 with_gallium_omx = _split.contains('omx')
295 with_gallium_va = _split.contains('va')
296 with_gallium_media = (with_gallium_xvmc or with_gallium_vdpau or
297 with_gallium_omx or with_gallium_va)
298endif
299
Dylan Baker108d2572017-10-18 12:20:43 -0700300gl_pkgconfig_c_flags = []
Dylan Baker50c28df2017-09-29 17:53:01 -0700301if with_platform_x11
302 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
303 pre_args += '-DHAVE_X11_PLATFORM'
304 endif
305 if with_glx == 'xlib'
306 # TODO
307 error('TODO')
308 elif with_glx == 'gallium-xlib'
309 # TODO
310 error('TODO')
311 else
312 pre_args += '-DGLX_INDIRECT_RENDERING'
313 if with_glx_direct
314 pre_args += '-DGLX_DIRECT_RENDERING'
315 endif
316 if with_dri_platform == 'drm'
317 pre_args += '-DGLX_USE_DRM'
318 endif
319 endif
Dylan Baker108d2572017-10-18 12:20:43 -0700320else
321 pre_args += '-DMESA_EGL_NO_X11_HEADERS'
322 gl_pkgconfig_c_flags += '-DMESA_EGL_NO_X11_HEADERS'
323endif
324if with_platform_drm
325 if with_egl and not with_gbm
326 error('EGL drm platform requires gbm')
327 endif
328 pre_args += '-DHAVE_DRM_PLATFORM'
329endif
330if with_platform_surfaceless
331 pre_args += '-DHAVE_SURFACELESS_PLATFORM'
Dylan Baker50c28df2017-09-29 17:53:01 -0700332endif
333
Dylan Bakerd1992252017-09-14 17:57:17 -0700334prog_python2 = find_program('python2')
Dylan Baker9342a7d2017-09-28 10:48:30 -0700335has_mako = run_command(prog_python2, '-c', 'import mako')
336if has_mako.returncode() != 0
337 error('Python (2.x) mako module required to build mesa.')
338endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700339
340cc = meson.get_compiler('c')
341if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
Eric Engestrom1262e822017-09-29 15:25:18 +0100342 error('When using GCC, version 4.4.6 or later is required.')
Dylan Bakerd1992252017-09-14 17:57:17 -0700343endif
344
Dylan Bakerd1992252017-09-14 17:57:17 -0700345# Define DEBUG for debug and debugoptimized builds
346if get_option('buildtype').startswith('debug')
347 pre_args += '-DDEBUG'
348endif
349
Dylan Baker673dda82017-09-20 11:53:29 -0700350if get_option('shader-cache')
351 pre_args += '-DENABLE_SHADER_CACHE'
352elif with_amd_vk
353 error('Radv requires shader cache support')
354endif
355
Dylan Bakerd1992252017-09-14 17:57:17 -0700356# Check for GCC style builtins
357foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
358 'ffsll', 'popcount', 'popcountll', 'unreachable']
359 if cc.has_function(b)
360 pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
361 endif
362endforeach
363
Dylan Baker673dda82017-09-20 11:53:29 -0700364# check for GCC __attribute__
Dylan Bakerd1992252017-09-14 17:57:17 -0700365foreach a : ['const', 'flatten', 'malloc', 'pure', 'unused',
366 'warn_unused_result', 'weak',]
367 if cc.compiles('int foo(void) __attribute__((@0@));'.format(a),
368 name : '__attribute__((@0@))'.format(a))
369 pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
370 endif
371endforeach
372if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
373 name : '__attribute__((format(...)))')
374 pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
375endif
376if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
377 name : '__attribute__((packed))')
378 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
379endif
380if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
381 name : '__attribute__((returns_nonnull))')
382 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NONNULL'
383endif
384if cc.compiles('''int foo_def(void) __attribute__((visibility("default")));
385 int foo_hid(void) __attribute__((visibility("hidden")));
386 int foo_int(void) __attribute__((visibility("internal")));
387 int foo_pro(void) __attribute__((visibility("protected")));''',
388 name : '__attribute__((visibility(...)))')
389 pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISBILITY'
390endif
391if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
392 name : '__attribute__((alias(...)))')
393 pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
394endif
395
396# TODO: this is very incomplete
397if host_machine.system() == 'linux'
398 pre_args += '-D_GNU_SOURCE'
399endif
400
401# Check for generic C arguments
402c_args = []
403foreach a : ['-Wall', '-Werror=implicit-function-declaration',
404 '-Werror=missing-prototypes', '-fno-math-errno',
405 '-fno-trapping-math', '-Qunused-arguments']
406 if cc.has_argument(a)
407 c_args += a
408 endif
409endforeach
410c_vis_args = []
411if cc.has_argument('-fvisibility=hidden')
412 c_vis_args += '-fvisibility=hidden'
413endif
414
415# Check for generic C++ arguments
416cpp = meson.get_compiler('cpp')
417cpp_args = []
418foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math',
419 '-Qunused-arguments', '-Wno-non-virtual-dtor']
420 if cpp.has_argument(a)
421 cpp_args += a
422 endif
423endforeach
424cpp_vis_args = []
425if cpp.has_argument('-fvisibility=hidden')
426 cpp_vis_args += '-fvisibility=hidden'
427endif
428
429# Check for C and C++ arguments for MSVC2013 compatibility. These are only used
430# in parts of the mesa code base that need to compile with old versions of
431# MSVC, mainly common code
432c_msvc_compat_args = []
433cpp_msvc_compat_args = []
434foreach a : ['-Werror=pointer-arith', '-Werror=vla']
435 if cc.has_argument(a)
436 c_msvc_compat_args += a
437 endif
438 if cpp.has_argument(a)
439 cpp_msvc_compat_args += a
440 endif
441endforeach
442
443no_override_init_args = []
444foreach a : ['-Wno-override-init', '-Wno-initializer-overrides']
445 if cc.has_argument(a)
446 no_override_init_args += a
447 endif
448endforeach
449
450# TODO: SSE41 (which is only required for core mesa)
451
452# Check for GCC style atomics
453if cc.compiles('int main() { int n; return __atomic_load_n(&n, __ATOMIC_ACQUIRE); }',
454 name : 'GCC atomic builtins')
455 pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
456endif
457if not cc.links('''#include <stdint.h>
458 uint64_t v;
459 int main() {
460 return __sync_add_and_fetch(&v, (uint64_t)1);
461 }''',
462 name : 'GCC 64bit atomics')
463 pre_args += '-DMISSING_64_BIT_ATOMICS'
464endif
465
466# TODO: endian
467# TODO: powr8
468# TODO: shared/static? Is this even worth doing?
469
470# I don't think that I need to set any of the debug stuff, I think meson
471# handles that for us
472
473# TODO: ldflags
474
475# TODO: texture-float (gallium/mesa only)
476
477# TODO: cross-compiling. I don't think this is relavent to meson
478
Dylan Baker32180562017-09-20 20:11:32 -0700479# FIXME: enable asm when cross compiler
480# This is doable (autotools does it), but it's not of immediate concern
481if meson.is_cross_build()
482 message('Cross compiling, disabling asm')
483 with_asm = false
484endif
485
486with_asm_arch = ''
487if with_asm
488 # TODO: SPARC and PPC
489 if host_machine.cpu_family() == 'x86'
490 if ['linux', 'bsd'].contains(host_machine.system()) # FIXME: hurd?
491 with_asm_arch = 'x86'
492 pre_args += ['-DUSE_X86_ASM', '-DUSE_MMX_ASM', '-DUSE_3DNOW_ASM',
493 '-DUSE_SSE_ASM']
494 endif
495 elif host_machine.cpu_family() == 'x86_64'
496 if host_machine.system() == 'linux'
497 with_asm_arch = 'x86_64'
498 pre_args += ['-DUSE_X86_64_ASM']
499 endif
500 elif host_machine.cpu_family() == 'arm'
501 if host_machine.system() == 'linux'
502 with_asm_arch = 'arm'
503 pre_args += ['-DUSE_ARM_ASM']
504 endif
505 elif host_machine.cpu_family() == 'aarch64'
506 if host_machine.system() == 'linux'
507 with_asm_arch = 'aarch64'
508 pre_args += ['-DUSE_AARCH64_ASM']
509 endif
510 endif
511endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700512
513# Check for standard headers and functions
514if cc.has_header_symbol('sys/sysmacros.h', 'major')
515 pre_args += '-DMAJOR_IN_SYSMACROS'
516elif cc.has_header_symbol('sys/mkdev.h', 'major')
517 pre_args += '-DMAJOR_IN_MKDEV'
518endif
519
520foreach h : ['xlocale.h', 'sys/sysctl.h']
521 if cc.has_header(h)
522 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
523 endif
524endforeach
525
526foreach f : ['strtof', 'mkostemp', 'posix_memalign']
527 if cc.has_function(f)
528 pre_args += '-DHAVE_@0@'.format(f.to_upper())
529 endif
530endforeach
531
532# strtod locale support
533if cc.links('''
534 #define _GNU_SOURCE
535 #include <stdlib.h>
536 #include <locale.h>
537 #ifdef HAVE_XLOCALE_H
538 #include <xlocale.h>
539 #endif
540 int main() {
541 locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
542 const char *s = "1.0";
543 char *end;
544 double d = strtod_l(s, end, loc);
545 float f = strtod_l(s, end, loc);
546 freelocale(loc);
547 return 0;
548 }''',
549 extra_args : pre_args,
550 name : 'strtod has locale support')
551 pre_args += '-DHAVE_STRTOD_L'
552endif
553
554# Check for some linker flags
555ld_args_bsymbolic = []
Dylan Bakere21e0a62017-09-30 13:15:52 -0700556if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic', name : 'Bsymbolic')
Dylan Bakerd1992252017-09-14 17:57:17 -0700557 ld_args_bsymbolic += '-Wl,-Bsymbolic'
558endif
559ld_args_gc_sections = []
560if cc.links('static char unused() { return 5; } int main() { return 0; }',
Dylan Bakere21e0a62017-09-30 13:15:52 -0700561 args : '-Wl,--gc-sections', name : 'gc-sections')
Dylan Bakerd1992252017-09-14 17:57:17 -0700562 ld_args_gc_sections += '-Wl,--gc-sections'
563endif
Dylan Bakere21e0a62017-09-30 13:15:52 -0700564with_ld_version_script = false
565if cc.links('int main() { return 0; }',
566 args : '-Wl,--version-script=@0@'.format(
567 join_paths(meson.source_root(), 'build-support/conftest.map')),
568 name : 'version-script')
569 with_ld_version_script = true
570endif
571with_ld_dynamic_list = false
572if cc.links('int main() { return 0; }',
573 args : '-Wl,--dynamic-list=@0@'.format(
574 join_paths(meson.source_root(), 'build-support/conftest.dyn')),
575 name : 'dynamic-list')
576 with_ld_dynamic_list = true
577endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700578
579# check for dl support
580if cc.has_function('dlopen')
581 dep_dl = []
582else
583 dep_dl = cc.find_library('dl')
584endif
Dylan Baker32180562017-09-20 20:11:32 -0700585if cc.has_function('dladdr', dependencies : dep_dl)
586 # This is really only required for megadrivers
587 pre_args += '-DHAVE_DLADDR'
Dylan Bakerd1992252017-09-14 17:57:17 -0700588endif
589
590if cc.has_function('dl_iterate_phdr')
591 pre_args += '-DHAVE_DL_ITERATE_PHDR'
592else
593 # TODO: this is required for vulkan
594endif
595
596# Determine whether or not the rt library is needed for time functions
597if cc.has_function('clock_gettime')
598 dep_clock = []
599else
600 dep_clock = cc.find_library('rt')
601endif
602
Dylan Baker66c94b92017-09-30 13:48:34 -0700603with_gallium_drisw_kms = false
Dylan Baker50c28df2017-09-29 17:53:01 -0700604dep_libdrm = dependency('libdrm', version : '>= 2.4.75',
605 required : with_dri2 or with_dri3)
606if dep_libdrm.found()
607 pre_args += '-DHAVE_LIBDRM'
Dylan Baker66c94b92017-09-30 13:48:34 -0700608 if with_dri_platform == 'drm' and with_dri
609 with_gallium_drisw_kms = true
610 endif
Dylan Baker50c28df2017-09-29 17:53:01 -0700611endif
612
Dylan Bakerd1992252017-09-14 17:57:17 -0700613# TODO: some of these may be conditional
614dep_zlib = dependency('zlib', version : '>= 1.2.3')
615dep_thread = dependency('threads')
Dylan Baker50c28df2017-09-29 17:53:01 -0700616if dep_thread.found() and host_machine.system() == 'linux'
617 pre_args += '-DHAVE_PTHREAD'
618endif
Dylan Bakercc4f5872017-09-27 11:30:21 -0700619dep_elf = dependency('libelf', required : false)
Dylan Bakerb154b442017-09-30 14:04:28 -0700620if not dep_elf.found() and (with_amd_vk or with_gallium_radeonsi) # TODO: clover, r600
621 dep_elf = cc.find_library('elf')
Dylan Bakercc4f5872017-09-27 11:30:21 -0700622endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700623dep_expat = dependency('expat')
624# this only exists on linux so either this is linux and it will be found, or
625# its not linux and and wont
626dep_m = cc.find_library('m', required : false)
Dylan Baker66f97f62017-09-30 09:03:51 -0700627
628dep_libdrm_amdgpu = []
629dep_libdrm_radeon = []
Dylan Baker813b4b02017-10-09 14:59:35 -0700630dep_libdrm_nouveau = []
Dylan Baker51558a12017-10-20 15:45:22 -0700631dep_libdrm_etnaviv = []
Rob Clark4aa69cc2017-10-14 10:08:50 -0400632dep_libdrm_freedreno = []
Dylan Baker66f97f62017-09-30 09:03:51 -0700633if with_amd_vk or with_gallium_radeonsi
Dylan Baker8792a9e2017-10-20 16:28:32 -0700634 dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.85')
Dylan Baker66f97f62017-09-30 09:03:51 -0700635endif
Dylan Bakereecd2862017-10-16 17:24:56 -0700636if with_gallium_radeonsi or with_dri_r100 or with_dri_r200
Dylan Baker66f97f62017-09-30 09:03:51 -0700637 dep_libdrm_radeon = dependency('libdrm_radeon', version : '>= 2.4.71')
638endif
Dylan Bakereb3bb032017-10-16 17:51:47 -0700639if with_gallium_nouveau or with_dri_nouveau
Dylan Baker813b4b02017-10-09 14:59:35 -0700640 dep_libdrm_nouveau = dependency('libdrm_nouveau', version : '>= 2.4.66')
641endif
Dylan Baker51558a12017-10-20 15:45:22 -0700642if with_gallium_etnaviv
643 dep_libdrm_etnaviv = dependency('libdrm_etnaviv', version : '>= 2.4.82')
644endif
Rob Clark4aa69cc2017-10-14 10:08:50 -0400645if with_gallium_freedreno
646 dep_libdrm_freedreno = dependency('libdrm_freedreno', version : '>= 2.4.74')
647endif
Dylan Baker673dda82017-09-20 11:53:29 -0700648
649llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
650if with_amd_vk
651 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
652endif
653dep_llvm = dependency(
Dylan Baker50c28df2017-09-29 17:53:01 -0700654 'llvm', version : '>= 3.9.0', required : with_amd_vk, modules : llvm_modules,
Dylan Baker673dda82017-09-20 11:53:29 -0700655)
Dylan Baker02cf3a82017-10-12 09:47:30 -0700656if with_llvm
657 if dep_llvm.found()
658 _llvm_version = dep_llvm.version().split('.')
659 # Development versions of LLVM have an 'svn' suffix, we don't want that for
660 # our version checks.
661 _llvm_patch = _llvm_version[2]
662 if _llvm_patch.endswith('svn')
663 _llvm_patch = _llvm_patch.split('s')[0]
664 endif
665 pre_args += [
666 '-DHAVE_LLVM=0x0@0@@1@@2@'.format(_llvm_version[0], _llvm_version[1], _llvm_patch),
667 '-DMESA_LLVM_VERSION_PATCH=@0@'.format(_llvm_patch),
668 ]
669 else
Dylan Baker6a9ad202017-10-10 14:56:39 -0700670 if with_gallium_softpipe
671 error('Cannot find LLVM to build LLVMPipe. If you wanted softpipe pass -Dllvm=false to meson')
672 elif with_amd_vk or with_gallium_radeonsi # etc
Dylan Baker66f97f62017-09-30 09:03:51 -0700673 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 -0700674 endif
Dylan Baker673dda82017-09-20 11:53:29 -0700675 endif
Dylan Baker66f97f62017-09-30 09:03:51 -0700676elif with_amd_vk or with_gallium_radeonsi
677 error('The following drivers requires LLVM: Radv, RadeonSI. One of these is enabled, but LLVM is disabled.')
Dylan Baker673dda82017-09-20 11:53:29 -0700678endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700679
Dylan Bakera47c5252017-09-22 12:55:00 -0700680dep_glvnd = []
681if with_glvnd
682 dep_glvnd = dependency('libglvnd', version : '>= 0.2.0')
683 pre_args += '-DUSE_LIBGLVND=1'
684endif
685
Dylan Bakerd1992252017-09-14 17:57:17 -0700686# TODO: make this conditional
687dep_valgrind = dependency('valgrind', required : false)
688if dep_valgrind.found() and with_valgrind
689 pre_args += '-DHAVE_VALGRIND'
690endif
691
692# pthread stubs. Lets not and say we didn't
693
Dylan Baker32180562017-09-20 20:11:32 -0700694prog_bison = find_program('bison', required : with_any_opengl)
695prog_flex = find_program('flex', required : with_any_opengl)
696
Dylan Baker32180562017-09-20 20:11:32 -0700697dep_selinux = []
Eric Engestrom4b9421d2017-10-26 16:19:41 +0100698if get_option('selinux')
699 dep_selinux = dependency('libselinux')
700 pre_args += '-DMESA_SELINUX'
701endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700702
703# TODO: llvm-prefix and llvm-shared-libs
704
Dylan Bakerb1b65392017-09-28 22:25:02 -0700705dep_unwind = dependency('libunwind', required : false)
Erik Faye-Lund9e5a5a12017-10-23 20:54:03 +0200706if dep_unwind.found() and with_libunwind
Dylan Bakerb1b65392017-09-28 22:25:02 -0700707 pre_args += '-DHAVE_LIBUNWIND'
708endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700709
710# TODO: flags for opengl, gles, dri
711
712# TODO: gallium-hud
713
714# TODO: glx provider
715
716# TODO: osmesa provider
717
Dylan Bakerd1992252017-09-14 17:57:17 -0700718# TODO: symbol mangling
719
Dylan Bakerd1992252017-09-14 17:57:17 -0700720if with_platform_wayland
721 prog_wl_scanner = find_program('wayland-scanner')
722 dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8')
723 dep_wayland_client = dependency('wayland-client', version : '>=1.11')
724 dep_wayland_server = dependency('wayland-server', version : '>=1.11')
Dylan Baker108d2572017-10-18 12:20:43 -0700725 wayland_dmabuf_xml = join_paths(
726 dep_wl_protocols.get_pkgconfig_variable('pkgdatadir'), 'unstable',
727 'linux-dmabuf', 'linux-dmabuf-unstable-v1.xml'
728 )
729 pre_args += ['-DHAVE_WAYLAND_PLATFORM', '-DWL_HIDE_DEPRECATED']
Dylan Bakerd1992252017-09-14 17:57:17 -0700730else
731 prog_wl_scanner = []
732 dep_wl_protocols = []
733 dep_wayland_client = []
734 dep_wayland_server = []
Dylan Baker108d2572017-10-18 12:20:43 -0700735 wayland_dmabuf_xml = ''
Dylan Bakerd1992252017-09-14 17:57:17 -0700736endif
737
Dylan Baker50c28df2017-09-29 17:53:01 -0700738dep_x11 = []
739dep_xext = []
740dep_xdamage = []
741dep_xfixes = []
742dep_x11_xcb = []
743dep_xcb_glx = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700744dep_xcb_dri2 = []
745dep_xcb_dri3 = []
Dylan Bakera47c5252017-09-22 12:55:00 -0700746dep_dri2proto = []
747dep_glproto = []
Dylan Bakera47c5252017-09-22 12:55:00 -0700748dep_xf86vm = []
Dylan Baker50c28df2017-09-29 17:53:01 -0700749dep_xcb_dri3 = []
750dep_xcb_present = []
751dep_xcb_sync = []
Dylan Baker108d2572017-10-18 12:20:43 -0700752dep_xcb_xfixes = []
Dylan Baker50c28df2017-09-29 17:53:01 -0700753dep_xshmfence = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700754if with_platform_x11
Dylan Baker50c28df2017-09-29 17:53:01 -0700755 if with_glx == 'dri' and with_dri_platform == 'drm'
756 dep_x11 = dependency('x11')
757 dep_xext = dependency('xext')
758 dep_xdamage = dependency('xdamage', version : '>= 1.1')
759 dep_xfixes = dependency('xfixes')
760 dep_xcb_glx = dependency('xcb-glx', version : '>= 1.8.1')
Nicholas Miell30128852017-10-17 18:04:16 -0700761 dep_xf86vm = dependency('xxf86vm', required : false)
Dylan Bakera47c5252017-09-22 12:55:00 -0700762 endif
763 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
Dylan Baker50c28df2017-09-29 17:53:01 -0700764 dep_xcb = dependency('xcb')
765 dep_x11_xcb = dependency('x11-xcb')
766 dep_xcb_dri2 = dependency('xcb-dri2', version : '>= 1.8')
767
Dylan Bakera47c5252017-09-22 12:55:00 -0700768 if with_dri3
769 pre_args += '-DHAVE_DRI3'
Dylan Baker50c28df2017-09-29 17:53:01 -0700770 dep_xcb_dri3 = dependency('xcb-dri3')
771 dep_xcb_present = dependency('xcb-present')
772 dep_xcb_sync = dependency('xcb-sync')
773 dep_xshmfence = dependency('xshmfence', version : '>= 1.1')
Dylan Bakera47c5252017-09-22 12:55:00 -0700774 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700775 endif
Dylan Baker50c28df2017-09-29 17:53:01 -0700776 if with_glx != 'disabled'
777 dep_dri2proto = dependency('dri2proto', version : '>= 2.8')
778 dep_glproto = dependency('glproto', version : '>= 1.4.14')
779 endif
Dylan Baker108d2572017-10-18 12:20:43 -0700780 if with_egl
781 dep_xcb_xfixes = dependency('xcb-xfixes')
782 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700783endif
784
Dylan Bakerd1992252017-09-14 17:57:17 -0700785# TODO: osmesa
786
Dylan Bakerd1992252017-09-14 17:57:17 -0700787# TODO: vallium G3DVL
788
789# TODO: nine
790
791# TODO: clover
792
Dylan Bakerd1992252017-09-14 17:57:17 -0700793# TODO: gallium tests
794
795# TODO: various libdirs
796
797# TODO: swr
798
799# TODO: gallium driver dirs
800
801# FIXME: this is a workaround for #2326
802prog_touch = find_program('touch')
803dummy_cpp = custom_target(
804 'dummy_cpp',
805 output : 'dummy.cpp',
806 command : [prog_touch, '@OUTPUT@'],
807)
808
809foreach a : pre_args
810 add_project_arguments(a, language : ['c', 'cpp'])
811endforeach
812foreach a : c_args
813 add_project_arguments(a, language : ['c'])
814endforeach
815foreach a : cpp_args
816 add_project_arguments(a, language : ['cpp'])
817endforeach
818
819inc_include = include_directories('include')
820
Dylan Baker108d2572017-10-18 12:20:43 -0700821gl_priv_reqs = [
822 'x11', 'xext', 'xdamage >= 1.1', 'xfixes', 'x11-xcb', 'xcb',
823 'xcb-glx >= 1.8.1', 'libdrm >= 2.4.75',
824]
825if dep_xf86vm != [] and dep_xf86vm.found()
826 gl_priv_reqs += 'xf86vm'
827endif
828if with_dri_platform == 'drm'
829 gl_priv_reqs += 'xcb-dri2 >= 1.8'
830endif
831
832gl_priv_libs = []
833if dep_thread.found()
834 gl_priv_libs += ['-lpthread', '-pthread']
835endif
836if dep_m.found()
837 gl_priv_libs += '-lm'
838endif
839if dep_dl.found()
840 gl_priv_libs += '-ldl'
841endif
842
Dylan Baker32180562017-09-20 20:11:32 -0700843pkg = import('pkgconfig')
844
Dylan Bakerd1992252017-09-14 17:57:17 -0700845subdir('include')
Eric Engestrom05a94a42017-10-24 18:03:39 +0100846subdir('bin')
Dylan Bakerd1992252017-09-14 17:57:17 -0700847subdir('src')