blob: ef06ea8f6b755ccbb6ce567a972ccfcd5211a0e3 [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 Bakercbbd5bb2017-10-20 21:48:18 -070049with_osmesa = get_option('osmesa')
Dylan Baker3b209e92017-10-10 15:25:07 -070050if get_option('texture-float')
51 pre_args += '-DTEXTURE_FLOAT_ENABLED'
52 message('WARNING: Floating-point texture enabled. Please consult docs/patents.txt and your lawyer before building mesa.')
53endif
Dylan Baker32180562017-09-20 20:11:32 -070054
55# XXX: yeah, do these
56with_appledri = false
57with_windowsdri = false
58
Dylan Bakerdb978842017-09-28 13:59:04 -070059dri_drivers_path = get_option('dri-drivers-path')
60if dri_drivers_path == ''
61 dri_drivers_path = join_paths(get_option('libdir'), 'dri')
62endif
63
Dylan Baker32180562017-09-20 20:11:32 -070064with_gles1 = get_option('gles1')
65with_gles2 = get_option('gles2')
66with_opengl = get_option('opengl')
67with_any_opengl = with_opengl or with_gles1 or with_gles2
Dylan Bakera47c5252017-09-22 12:55:00 -070068# Only build shared_glapi if at least one OpenGL API is enabled
69with_shared_glapi = get_option('shared-glapi') and with_any_opengl
Dylan Baker32180562017-09-20 20:11:32 -070070
Dylan Baker32180562017-09-20 20:11:32 -070071
72# shared-glapi is required if at least two OpenGL APIs are being built
73if not with_shared_glapi
74 if ((with_gles1 and with_gles2) or (with_gles1 and with_opengl)
75 or (with_gles2 and with_opengl))
76 error('shared-glapi required for building two or more of OpenGL, OpenGL ES 1.x, OpenGL ES 2.x')
77 endif
78endif
79
80# We require OpenGL for OpenGL ES
81if (with_gles1 or with_gles2) and not with_opengl
82 error('building OpenGL ES without OpenGL is not supported.')
83endif
84
85with_dri = false
Ville Syrjälä22899642017-10-10 01:15:42 +030086with_dri_i915 = false
Dylan Baker32180562017-09-20 20:11:32 -070087with_dri_i965 = false
Dylan Baker191e7852017-10-16 17:12:52 -070088with_dri_r100 = false
Dylan Bakereecd2862017-10-16 17:24:56 -070089with_dri_r200 = false
Dylan Bakereb3bb032017-10-16 17:51:47 -070090with_dri_nouveau = 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 Bakereecd2862017-10-16 17:24:56 -070098 with_dri_r200 = _split.contains('r200')
Dylan Bakereb3bb032017-10-16 17:51:47 -070099 with_dri_nouveau = _split.contains('nouveau')
Dylan Bakerc2cd5802017-10-03 17:06:22 -0700100 with_dri_swrast = _split.contains('swrast')
Dylan Baker32180562017-09-20 20:11:32 -0700101 with_dri = true
102endif
103
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700104with_gallium = false
Eric Anholt1918c9b2017-10-12 18:39:08 -0700105with_gallium_pl111 = false
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700106with_gallium_radeonsi = false
Dylan Baker813b4b02017-10-09 14:59:35 -0700107with_gallium_nouveau = false
Rob Clark4aa69cc2017-10-14 10:08:50 -0400108with_gallium_freedreno = false
Dylan Bakerf3d03a22017-10-10 11:57:50 -0700109with_gallium_softpipe = false
Eric Anholt1ae80182017-10-12 13:53:12 -0700110with_gallium_vc4 = false
Eric Anholt4f3e3802017-10-12 18:40:16 -0700111with_gallium_vc5 = false
Dylan Baker51558a12017-10-20 15:45:22 -0700112with_gallium_etnaviv = false
Dylan Bakerd4567ef2017-10-20 15:57:15 -0700113with_gallium_imx = false
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700114_drivers = get_option('gallium-drivers')
115if _drivers != ''
116 _split = _drivers.split(',')
Dylan Bakerfbf39fd2017-10-17 14:44:15 -0700117 with_gallium_pl111 = _split.contains('pl111')
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700118 with_gallium_radeonsi = _split.contains('radeonsi')
Dylan Baker813b4b02017-10-09 14:59:35 -0700119 with_gallium_nouveau = _split.contains('nouveau')
Rob Clark4aa69cc2017-10-14 10:08:50 -0400120 with_gallium_freedreno = _split.contains('freedreno')
Dylan Bakerde24d612017-10-10 14:27:19 -0700121 with_gallium_softpipe = _split.contains('swrast')
Eric Anholt1ae80182017-10-12 13:53:12 -0700122 with_gallium_vc4 = _split.contains('vc4')
Eric Anholt4f3e3802017-10-12 18:40:16 -0700123 with_gallium_vc5 = _split.contains('vc5')
Dylan Baker51558a12017-10-20 15:45:22 -0700124 with_gallium_etnaviv = _split.contains('etnaviv')
Dylan Bakerd4567ef2017-10-20 15:57:15 -0700125 with_gallium_imx = _split.contains('imx')
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700126 with_gallium = true
127 with_dri = true
Ville Syrjälä22899642017-10-10 01:15:42 +0300128endif
129
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700130if not (with_dri or with_gallium)
Dylan Baker32180562017-09-20 20:11:32 -0700131 with_gles1 = false
132 with_gles2 = false
133 with_opengl = false
134 with_any_opengl = false
135 with_shared_glapi = false
136endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700137
Dylan Bakerde24d612017-10-10 14:27:19 -0700138if with_dri_swrast and with_gallium_softpipe
139 error('Only one swrast provider can be built')
140endif
Dylan Bakerd4567ef2017-10-20 15:57:15 -0700141if with_gallium_imx and not with_gallium_etnaviv
142 error('IMX driver requires etnaviv driver')
143endif
Dylan Bakerde24d612017-10-10 14:27:19 -0700144
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700145dep_libdrm_intel = []
146if with_dri_i915
147 dep_libdrm_intel = dependency('libdrm_intel', version : '>= 2.4.75')
148endif
149
Dylan Bakera47c5252017-09-22 12:55:00 -0700150# TODO: other OSes
151with_dri_platform = 'drm'
152
Dylan Baker108d2572017-10-18 12:20:43 -0700153# TODO: android platform
Dylan Bakerd1992252017-09-14 17:57:17 -0700154with_platform_wayland = false
155with_platform_x11 = false
Dylan Bakerb1b65392017-09-28 22:25:02 -0700156with_platform_drm = false
Dylan Baker108d2572017-10-18 12:20:43 -0700157with_platform_surfaceless = false
158egl_native_platform = ''
Dylan Bakerd1992252017-09-14 17:57:17 -0700159_platforms = get_option('platforms')
160if _platforms != ''
161 _split = _platforms.split(',')
162 with_platform_x11 = _split.contains('x11')
163 with_platform_wayland = _split.contains('wayland')
Dylan Bakerb1b65392017-09-28 22:25:02 -0700164 with_platform_drm = _split.contains('drm')
Dylan Baker108d2572017-10-18 12:20:43 -0700165 with_platform_surfaceless = _split.contains('surfaceless')
166 egl_native_platform = _split[0]
Dylan Bakerd1992252017-09-14 17:57:17 -0700167endif
168
Dylan Baker816bf7d12017-09-28 15:53:53 -0700169with_gbm = get_option('gbm')
170if with_gbm == 'auto' and with_dri # TODO: or gallium
171 with_gbm = host_machine.system() == 'linux'
172elif with_gbm == 'yes'
173 if not ['linux', 'bsd'].contains(host_machine.system())
174 error('GBM only supports unix-like platforms')
175 endif
176 with_gbm = true
177else
178 with_gbm = false
179endif
180
Dylan Baker108d2572017-10-18 12:20:43 -0700181_egl = get_option('egl')
182if _egl == 'auto'
183 with_egl = with_dri and with_shared_glapi and egl_native_platform != ''
184elif _egl == 'yes'
185 if not with_dri
186 error('EGL requires dri')
187 elif not with_shared_glapi
188 error('EGL requires shared-glapi')
189 elif egl_native_platform == ''
190 error('No platforms specified, consider -Dplatforms=drm,x11 at least')
191 endif
192 with_egl = true
193else
194 with_egl = false
195endif
196
197# TODO: or virgl
198if with_egl and with_gallium_radeonsi and not (with_platform_drm or with_platform_surfaceless)
199 error('RadeonSI requires drm or surfaceless platform when using EGL')
200endif
201
Dylan Baker8e611872017-10-11 12:49:31 -0700202pre_args += '-DGLX_USE_TLS'
Dylan Bakera47c5252017-09-22 12:55:00 -0700203with_glx = get_option('glx')
204if with_glx != 'disabled'
Dylan Baker8d3b1212017-10-18 15:47:11 -0700205 if not (with_platform_x11 and with_any_opengl)
206 if with_glx == 'auto'
207 with_glx = 'disabled'
208 else
209 error('Cannot build GLX support without X11 platform support and at least one OpenGL API')
210 endif
Dylan Bakera47c5252017-09-22 12:55:00 -0700211 elif with_glx == 'gallium-xlib'
212 if not with_gallium
213 error('Gallium-xlib based GLX requires at least one gallium driver')
214 elif with_dri
215 error('gallium-xlib conflicts with any dri driver')
216 endif
217 elif with_glx == 'dri' and not with_dri
218 error('dri based GLX requires at least one DRI driver')
219 elif with_glx == 'auto'
220 if with_dri
221 with_glx = 'dri'
222 elif with_gallium
223 with_glx = 'gallium-xlib'
224 elif with_platform_x11 and with_any_opengl
225 with_glx = 'xlib'
226 else
227 with_glx = 'disabled'
228 endif
229 endif
230endif
231
232with_glvnd = get_option('glvnd')
233if with_glvnd and with_glx != 'dri'
234 message('glvnd requires dri based glx')
235endif
236
237# TODO: toggle for this
238with_glx_direct = true
239
Dylan Bakerd1992252017-09-14 17:57:17 -0700240if with_vulkan_icd_dir == ''
241 with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
242endif
243
244with_intel_vk = false
245with_amd_vk = false
Dylan Bakera47c5252017-09-22 12:55:00 -0700246with_any_vk = false
Dylan Bakerd1992252017-09-14 17:57:17 -0700247_vulkan_drivers = get_option('vulkan-drivers')
248if _vulkan_drivers != ''
249 _split = _vulkan_drivers.split(',')
250 with_intel_vk = _split.contains('intel')
251 with_amd_vk = _split.contains('amd')
Dylan Bakera47c5252017-09-22 12:55:00 -0700252 with_any_vk = with_amd_vk or with_intel_vk
Dylan Bakerd1992252017-09-14 17:57:17 -0700253 if not (with_platform_x11 or with_platform_wayland)
254 error('Vulkan requires at least one platform (x11, wayland)')
255 endif
Dylan Bakera47c5252017-09-22 12:55:00 -0700256endif
257
Dylan Baker50c28df2017-09-29 17:53:01 -0700258with_dri2 = (with_dri or with_any_vk) and with_dri_platform == 'drm'
259with_dri3 = get_option('dri3')
260if with_dri3 == 'auto'
261 if host_machine.system() == 'linux' and with_dri2
262 with_dri3 = true
263 else
264 with_dri3 = false
265 endif
266elif with_dri3 == 'yes'
267 with_dri3 = true
268else
269 with_dri3 = false
270endif
271
272if with_any_vk and (with_platform_x11 and not with_dri3)
273 error('Vulkan drivers require dri3 for X11 support')
274endif
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700275if with_dri or with_gallium
Dylan Baker108d2572017-10-18 12:20:43 -0700276 if with_glx == 'disabled' and not with_egl
Dylan Bakera47c5252017-09-22 12:55:00 -0700277 error('building dri or gallium drivers require at least one window system')
278 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700279endif
280
Dylan Baker50c28df2017-09-29 17:53:01 -0700281with_gallium_xvmc = false
282with_gallium_vdpau = false
283with_gallium_omx = false # this is bellagio
284with_gallium_va = false
285with_gallium_media = false
286dep_va = []
287_drivers = get_option('gallium-media')
288if _drivers != ''
289 _split = _drivers.split(',')
290 with_gallium_xvmc = _split.contains('xvmc')
291 with_gallium_vdpau = _split.contains('vdpau')
292 with_gallium_omx = _split.contains('omx')
293 with_gallium_va = _split.contains('va')
294 with_gallium_media = (with_gallium_xvmc or with_gallium_vdpau or
295 with_gallium_omx or with_gallium_va)
296endif
297
Dylan Baker108d2572017-10-18 12:20:43 -0700298gl_pkgconfig_c_flags = []
Dylan Baker50c28df2017-09-29 17:53:01 -0700299if with_platform_x11
300 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
301 pre_args += '-DHAVE_X11_PLATFORM'
302 endif
303 if with_glx == 'xlib'
304 # TODO
305 error('TODO')
306 elif with_glx == 'gallium-xlib'
307 # TODO
308 error('TODO')
309 else
310 pre_args += '-DGLX_INDIRECT_RENDERING'
311 if with_glx_direct
312 pre_args += '-DGLX_DIRECT_RENDERING'
313 endif
314 if with_dri_platform == 'drm'
315 pre_args += '-DGLX_USE_DRM'
316 endif
317 endif
Dylan Baker108d2572017-10-18 12:20:43 -0700318else
319 pre_args += '-DMESA_EGL_NO_X11_HEADERS'
320 gl_pkgconfig_c_flags += '-DMESA_EGL_NO_X11_HEADERS'
321endif
322if with_platform_drm
323 if with_egl and not with_gbm
324 error('EGL drm platform requires gbm')
325 endif
326 pre_args += '-DHAVE_DRM_PLATFORM'
327endif
328if with_platform_surfaceless
329 pre_args += '-DHAVE_SURFACELESS_PLATFORM'
Dylan Baker50c28df2017-09-29 17:53:01 -0700330endif
331
Dylan Bakerd1992252017-09-14 17:57:17 -0700332prog_python2 = find_program('python2')
Dylan Baker9342a7d2017-09-28 10:48:30 -0700333has_mako = run_command(prog_python2, '-c', 'import mako')
334if has_mako.returncode() != 0
335 error('Python (2.x) mako module required to build mesa.')
336endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700337
338cc = meson.get_compiler('c')
339if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
Eric Engestrom1262e822017-09-29 15:25:18 +0100340 error('When using GCC, version 4.4.6 or later is required.')
Dylan Bakerd1992252017-09-14 17:57:17 -0700341endif
342
Dylan Bakerd1992252017-09-14 17:57:17 -0700343# Define DEBUG for debug and debugoptimized builds
344if get_option('buildtype').startswith('debug')
345 pre_args += '-DDEBUG'
346endif
347
Dylan Baker673dda82017-09-20 11:53:29 -0700348if get_option('shader-cache')
349 pre_args += '-DENABLE_SHADER_CACHE'
350elif with_amd_vk
351 error('Radv requires shader cache support')
352endif
353
Dylan Bakerd1992252017-09-14 17:57:17 -0700354# Check for GCC style builtins
355foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
356 'ffsll', 'popcount', 'popcountll', 'unreachable']
357 if cc.has_function(b)
358 pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
359 endif
360endforeach
361
Dylan Baker673dda82017-09-20 11:53:29 -0700362# check for GCC __attribute__
Dylan Bakerd1992252017-09-14 17:57:17 -0700363foreach a : ['const', 'flatten', 'malloc', 'pure', 'unused',
364 'warn_unused_result', 'weak',]
365 if cc.compiles('int foo(void) __attribute__((@0@));'.format(a),
366 name : '__attribute__((@0@))'.format(a))
367 pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
368 endif
369endforeach
370if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
371 name : '__attribute__((format(...)))')
372 pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
373endif
374if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
375 name : '__attribute__((packed))')
376 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
377endif
378if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
379 name : '__attribute__((returns_nonnull))')
380 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NONNULL'
381endif
382if cc.compiles('''int foo_def(void) __attribute__((visibility("default")));
383 int foo_hid(void) __attribute__((visibility("hidden")));
384 int foo_int(void) __attribute__((visibility("internal")));
385 int foo_pro(void) __attribute__((visibility("protected")));''',
386 name : '__attribute__((visibility(...)))')
387 pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISBILITY'
388endif
389if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
390 name : '__attribute__((alias(...)))')
391 pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
392endif
393
394# TODO: this is very incomplete
395if host_machine.system() == 'linux'
396 pre_args += '-D_GNU_SOURCE'
397endif
398
399# Check for generic C arguments
400c_args = []
401foreach a : ['-Wall', '-Werror=implicit-function-declaration',
402 '-Werror=missing-prototypes', '-fno-math-errno',
403 '-fno-trapping-math', '-Qunused-arguments']
404 if cc.has_argument(a)
405 c_args += a
406 endif
407endforeach
408c_vis_args = []
409if cc.has_argument('-fvisibility=hidden')
410 c_vis_args += '-fvisibility=hidden'
411endif
412
413# Check for generic C++ arguments
414cpp = meson.get_compiler('cpp')
415cpp_args = []
416foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math',
417 '-Qunused-arguments', '-Wno-non-virtual-dtor']
418 if cpp.has_argument(a)
419 cpp_args += a
420 endif
421endforeach
422cpp_vis_args = []
423if cpp.has_argument('-fvisibility=hidden')
424 cpp_vis_args += '-fvisibility=hidden'
425endif
426
427# Check for C and C++ arguments for MSVC2013 compatibility. These are only used
428# in parts of the mesa code base that need to compile with old versions of
429# MSVC, mainly common code
430c_msvc_compat_args = []
431cpp_msvc_compat_args = []
432foreach a : ['-Werror=pointer-arith', '-Werror=vla']
433 if cc.has_argument(a)
434 c_msvc_compat_args += a
435 endif
436 if cpp.has_argument(a)
437 cpp_msvc_compat_args += a
438 endif
439endforeach
440
441no_override_init_args = []
442foreach a : ['-Wno-override-init', '-Wno-initializer-overrides']
443 if cc.has_argument(a)
444 no_override_init_args += a
445 endif
446endforeach
447
448# TODO: SSE41 (which is only required for core mesa)
449
450# Check for GCC style atomics
451if cc.compiles('int main() { int n; return __atomic_load_n(&n, __ATOMIC_ACQUIRE); }',
452 name : 'GCC atomic builtins')
453 pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
454endif
455if not cc.links('''#include <stdint.h>
456 uint64_t v;
457 int main() {
458 return __sync_add_and_fetch(&v, (uint64_t)1);
459 }''',
460 name : 'GCC 64bit atomics')
461 pre_args += '-DMISSING_64_BIT_ATOMICS'
462endif
463
464# TODO: endian
465# TODO: powr8
466# TODO: shared/static? Is this even worth doing?
467
468# I don't think that I need to set any of the debug stuff, I think meson
469# handles that for us
470
471# TODO: ldflags
472
473# TODO: texture-float (gallium/mesa only)
474
475# TODO: cross-compiling. I don't think this is relavent to meson
476
Dylan Baker32180562017-09-20 20:11:32 -0700477# FIXME: enable asm when cross compiler
478# This is doable (autotools does it), but it's not of immediate concern
479if meson.is_cross_build()
480 message('Cross compiling, disabling asm')
481 with_asm = false
482endif
483
484with_asm_arch = ''
485if with_asm
486 # TODO: SPARC and PPC
487 if host_machine.cpu_family() == 'x86'
488 if ['linux', 'bsd'].contains(host_machine.system()) # FIXME: hurd?
489 with_asm_arch = 'x86'
490 pre_args += ['-DUSE_X86_ASM', '-DUSE_MMX_ASM', '-DUSE_3DNOW_ASM',
491 '-DUSE_SSE_ASM']
492 endif
493 elif host_machine.cpu_family() == 'x86_64'
494 if host_machine.system() == 'linux'
495 with_asm_arch = 'x86_64'
496 pre_args += ['-DUSE_X86_64_ASM']
497 endif
498 elif host_machine.cpu_family() == 'arm'
499 if host_machine.system() == 'linux'
500 with_asm_arch = 'arm'
501 pre_args += ['-DUSE_ARM_ASM']
502 endif
503 elif host_machine.cpu_family() == 'aarch64'
504 if host_machine.system() == 'linux'
505 with_asm_arch = 'aarch64'
506 pre_args += ['-DUSE_AARCH64_ASM']
507 endif
508 endif
509endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700510
511# Check for standard headers and functions
512if cc.has_header_symbol('sys/sysmacros.h', 'major')
513 pre_args += '-DMAJOR_IN_SYSMACROS'
514elif cc.has_header_symbol('sys/mkdev.h', 'major')
515 pre_args += '-DMAJOR_IN_MKDEV'
516endif
517
518foreach h : ['xlocale.h', 'sys/sysctl.h']
519 if cc.has_header(h)
520 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
521 endif
522endforeach
523
524foreach f : ['strtof', 'mkostemp', 'posix_memalign']
525 if cc.has_function(f)
526 pre_args += '-DHAVE_@0@'.format(f.to_upper())
527 endif
528endforeach
529
530# strtod locale support
531if cc.links('''
532 #define _GNU_SOURCE
533 #include <stdlib.h>
534 #include <locale.h>
535 #ifdef HAVE_XLOCALE_H
536 #include <xlocale.h>
537 #endif
538 int main() {
539 locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
540 const char *s = "1.0";
541 char *end;
542 double d = strtod_l(s, end, loc);
543 float f = strtod_l(s, end, loc);
544 freelocale(loc);
545 return 0;
546 }''',
547 extra_args : pre_args,
548 name : 'strtod has locale support')
549 pre_args += '-DHAVE_STRTOD_L'
550endif
551
552# Check for some linker flags
553ld_args_bsymbolic = []
Dylan Bakere21e0a62017-09-30 13:15:52 -0700554if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic', name : 'Bsymbolic')
Dylan Bakerd1992252017-09-14 17:57:17 -0700555 ld_args_bsymbolic += '-Wl,-Bsymbolic'
556endif
557ld_args_gc_sections = []
558if cc.links('static char unused() { return 5; } int main() { return 0; }',
Dylan Bakere21e0a62017-09-30 13:15:52 -0700559 args : '-Wl,--gc-sections', name : 'gc-sections')
Dylan Bakerd1992252017-09-14 17:57:17 -0700560 ld_args_gc_sections += '-Wl,--gc-sections'
561endif
Dylan Bakere21e0a62017-09-30 13:15:52 -0700562with_ld_version_script = false
563if cc.links('int main() { return 0; }',
564 args : '-Wl,--version-script=@0@'.format(
565 join_paths(meson.source_root(), 'build-support/conftest.map')),
566 name : 'version-script')
567 with_ld_version_script = true
568endif
569with_ld_dynamic_list = false
570if cc.links('int main() { return 0; }',
571 args : '-Wl,--dynamic-list=@0@'.format(
572 join_paths(meson.source_root(), 'build-support/conftest.dyn')),
573 name : 'dynamic-list')
574 with_ld_dynamic_list = true
575endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700576
577# check for dl support
578if cc.has_function('dlopen')
579 dep_dl = []
580else
581 dep_dl = cc.find_library('dl')
582endif
Dylan Baker32180562017-09-20 20:11:32 -0700583if cc.has_function('dladdr', dependencies : dep_dl)
584 # This is really only required for megadrivers
585 pre_args += '-DHAVE_DLADDR'
Dylan Bakerd1992252017-09-14 17:57:17 -0700586endif
587
588if cc.has_function('dl_iterate_phdr')
589 pre_args += '-DHAVE_DL_ITERATE_PHDR'
590else
591 # TODO: this is required for vulkan
592endif
593
594# Determine whether or not the rt library is needed for time functions
595if cc.has_function('clock_gettime')
596 dep_clock = []
597else
598 dep_clock = cc.find_library('rt')
599endif
600
Dylan Baker66c94b92017-09-30 13:48:34 -0700601with_gallium_drisw_kms = false
Dylan Baker50c28df2017-09-29 17:53:01 -0700602dep_libdrm = dependency('libdrm', version : '>= 2.4.75',
603 required : with_dri2 or with_dri3)
604if dep_libdrm.found()
605 pre_args += '-DHAVE_LIBDRM'
Dylan Baker66c94b92017-09-30 13:48:34 -0700606 if with_dri_platform == 'drm' and with_dri
607 with_gallium_drisw_kms = true
608 endif
Dylan Baker50c28df2017-09-29 17:53:01 -0700609endif
610
Dylan Bakerd1992252017-09-14 17:57:17 -0700611# TODO: some of these may be conditional
612dep_zlib = dependency('zlib', version : '>= 1.2.3')
613dep_thread = dependency('threads')
Dylan Baker50c28df2017-09-29 17:53:01 -0700614if dep_thread.found() and host_machine.system() == 'linux'
615 pre_args += '-DHAVE_PTHREAD'
616endif
Dylan Bakercc4f5872017-09-27 11:30:21 -0700617dep_elf = dependency('libelf', required : false)
Dylan Bakerb154b442017-09-30 14:04:28 -0700618if not dep_elf.found() and (with_amd_vk or with_gallium_radeonsi) # TODO: clover, r600
619 dep_elf = cc.find_library('elf')
Dylan Bakercc4f5872017-09-27 11:30:21 -0700620endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700621dep_expat = dependency('expat')
622# this only exists on linux so either this is linux and it will be found, or
623# its not linux and and wont
624dep_m = cc.find_library('m', required : false)
Dylan Baker66f97f62017-09-30 09:03:51 -0700625
626dep_libdrm_amdgpu = []
627dep_libdrm_radeon = []
Dylan Baker813b4b02017-10-09 14:59:35 -0700628dep_libdrm_nouveau = []
Dylan Baker51558a12017-10-20 15:45:22 -0700629dep_libdrm_etnaviv = []
Rob Clark4aa69cc2017-10-14 10:08:50 -0400630dep_libdrm_freedreno = []
Dylan Baker66f97f62017-09-30 09:03:51 -0700631if with_amd_vk or with_gallium_radeonsi
Dylan Baker8792a9e2017-10-20 16:28:32 -0700632 dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.85')
Dylan Baker66f97f62017-09-30 09:03:51 -0700633endif
Dylan Bakereecd2862017-10-16 17:24:56 -0700634if with_gallium_radeonsi or with_dri_r100 or with_dri_r200
Dylan Baker66f97f62017-09-30 09:03:51 -0700635 dep_libdrm_radeon = dependency('libdrm_radeon', version : '>= 2.4.71')
636endif
Dylan Bakereb3bb032017-10-16 17:51:47 -0700637if with_gallium_nouveau or with_dri_nouveau
Dylan Baker813b4b02017-10-09 14:59:35 -0700638 dep_libdrm_nouveau = dependency('libdrm_nouveau', version : '>= 2.4.66')
639endif
Dylan Baker51558a12017-10-20 15:45:22 -0700640if with_gallium_etnaviv
641 dep_libdrm_etnaviv = dependency('libdrm_etnaviv', version : '>= 2.4.82')
642endif
Rob Clark4aa69cc2017-10-14 10:08:50 -0400643if with_gallium_freedreno
644 dep_libdrm_freedreno = dependency('libdrm_freedreno', version : '>= 2.4.74')
645endif
Dylan Baker673dda82017-09-20 11:53:29 -0700646
647llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
648if with_amd_vk
649 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
650endif
651dep_llvm = dependency(
Dylan Baker50c28df2017-09-29 17:53:01 -0700652 'llvm', version : '>= 3.9.0', required : with_amd_vk, modules : llvm_modules,
Dylan Baker673dda82017-09-20 11:53:29 -0700653)
Dylan Baker02cf3a82017-10-12 09:47:30 -0700654if with_llvm
655 if dep_llvm.found()
656 _llvm_version = dep_llvm.version().split('.')
657 # Development versions of LLVM have an 'svn' suffix, we don't want that for
658 # our version checks.
659 _llvm_patch = _llvm_version[2]
660 if _llvm_patch.endswith('svn')
661 _llvm_patch = _llvm_patch.split('s')[0]
662 endif
663 pre_args += [
664 '-DHAVE_LLVM=0x0@0@@1@@2@'.format(_llvm_version[0], _llvm_version[1], _llvm_patch),
665 '-DMESA_LLVM_VERSION_PATCH=@0@'.format(_llvm_patch),
666 ]
667 else
Dylan Baker6a9ad202017-10-10 14:56:39 -0700668 if with_gallium_softpipe
669 error('Cannot find LLVM to build LLVMPipe. If you wanted softpipe pass -Dllvm=false to meson')
670 elif with_amd_vk or with_gallium_radeonsi # etc
Dylan Baker66f97f62017-09-30 09:03:51 -0700671 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 -0700672 endif
Dylan Baker673dda82017-09-20 11:53:29 -0700673 endif
Dylan Baker66f97f62017-09-30 09:03:51 -0700674elif with_amd_vk or with_gallium_radeonsi
675 error('The following drivers requires LLVM: Radv, RadeonSI. One of these is enabled, but LLVM is disabled.')
Dylan Baker673dda82017-09-20 11:53:29 -0700676endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700677
Dylan Bakera47c5252017-09-22 12:55:00 -0700678dep_glvnd = []
679if with_glvnd
680 dep_glvnd = dependency('libglvnd', version : '>= 0.2.0')
681 pre_args += '-DUSE_LIBGLVND=1'
682endif
683
Dylan Bakerd1992252017-09-14 17:57:17 -0700684# TODO: make this conditional
685dep_valgrind = dependency('valgrind', required : false)
686if dep_valgrind.found() and with_valgrind
687 pre_args += '-DHAVE_VALGRIND'
688endif
689
690# pthread stubs. Lets not and say we didn't
691
Dylan Baker32180562017-09-20 20:11:32 -0700692prog_bison = find_program('bison', required : with_any_opengl)
693prog_flex = find_program('flex', required : with_any_opengl)
694
Dylan Baker32180562017-09-20 20:11:32 -0700695dep_selinux = []
Eric Engestrom4b9421d2017-10-26 16:19:41 +0100696if get_option('selinux')
697 dep_selinux = dependency('libselinux')
698 pre_args += '-DMESA_SELINUX'
699endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700700
701# TODO: llvm-prefix and llvm-shared-libs
702
Dylan Bakerb1b65392017-09-28 22:25:02 -0700703dep_unwind = dependency('libunwind', required : false)
Erik Faye-Lund9e5a5a12017-10-23 20:54:03 +0200704if dep_unwind.found() and with_libunwind
Dylan Bakerb1b65392017-09-28 22:25:02 -0700705 pre_args += '-DHAVE_LIBUNWIND'
706endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700707
708# TODO: flags for opengl, gles, dri
709
710# TODO: gallium-hud
711
712# TODO: glx provider
713
Dylan Bakercbbd5bb2017-10-20 21:48:18 -0700714if with_osmesa != 'none'
715 if with_osmesa == 'classic' and not with_dri_swrast
716 error('OSMesa classic requires dri (classic) swrast.')
717 endif
718 osmesa_lib_name = 'OSMesa'
719 osmesa_bits = get_option('osmesa-bits')
720 if osmesa_bits != '8'
721 if with_dri or with_glx != 'disabled'
722 error('OSMesa bits must be 8 if building glx or dir based drivers')
723 endif
724 osmesa_lib_name = osmesa_lib_name + osmesa_bits
725 pre_args += [
726 '-DCHAN_BITS=@0@'.format(osmesa_bits), '-DDEFAULT_SOFTWARE_DEPTH_BITS=31'
727 ]
728 endif
729endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700730
Dylan Bakerd1992252017-09-14 17:57:17 -0700731# TODO: symbol mangling
732
Dylan Bakerd1992252017-09-14 17:57:17 -0700733if with_platform_wayland
734 prog_wl_scanner = find_program('wayland-scanner')
735 dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8')
736 dep_wayland_client = dependency('wayland-client', version : '>=1.11')
737 dep_wayland_server = dependency('wayland-server', version : '>=1.11')
Dylan Baker108d2572017-10-18 12:20:43 -0700738 wayland_dmabuf_xml = join_paths(
739 dep_wl_protocols.get_pkgconfig_variable('pkgdatadir'), 'unstable',
740 'linux-dmabuf', 'linux-dmabuf-unstable-v1.xml'
741 )
742 pre_args += ['-DHAVE_WAYLAND_PLATFORM', '-DWL_HIDE_DEPRECATED']
Dylan Bakerd1992252017-09-14 17:57:17 -0700743else
744 prog_wl_scanner = []
745 dep_wl_protocols = []
746 dep_wayland_client = []
747 dep_wayland_server = []
Dylan Baker108d2572017-10-18 12:20:43 -0700748 wayland_dmabuf_xml = ''
Dylan Bakerd1992252017-09-14 17:57:17 -0700749endif
750
Dylan Baker50c28df2017-09-29 17:53:01 -0700751dep_x11 = []
752dep_xext = []
753dep_xdamage = []
754dep_xfixes = []
755dep_x11_xcb = []
Dylan Bakercbbd5bb2017-10-20 21:48:18 -0700756dep_xcb = []
Dylan Baker50c28df2017-09-29 17:53:01 -0700757dep_xcb_glx = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700758dep_xcb_dri2 = []
759dep_xcb_dri3 = []
Dylan Bakera47c5252017-09-22 12:55:00 -0700760dep_dri2proto = []
761dep_glproto = []
Dylan Baker1f11ac42017-10-24 11:34:04 -0700762dep_xxf86vm = []
Dylan Baker50c28df2017-09-29 17:53:01 -0700763dep_xcb_dri3 = []
764dep_xcb_present = []
765dep_xcb_sync = []
Dylan Baker108d2572017-10-18 12:20:43 -0700766dep_xcb_xfixes = []
Dylan Baker50c28df2017-09-29 17:53:01 -0700767dep_xshmfence = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700768if with_platform_x11
Dylan Baker50c28df2017-09-29 17:53:01 -0700769 if with_glx == 'dri' and with_dri_platform == 'drm'
770 dep_x11 = dependency('x11')
771 dep_xext = dependency('xext')
772 dep_xdamage = dependency('xdamage', version : '>= 1.1')
773 dep_xfixes = dependency('xfixes')
774 dep_xcb_glx = dependency('xcb-glx', version : '>= 1.8.1')
Dylan Baker1f11ac42017-10-24 11:34:04 -0700775 dep_xxf86vm = dependency('xxf86vm', required : false)
Dylan Bakera47c5252017-09-22 12:55:00 -0700776 endif
777 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
Dylan Baker50c28df2017-09-29 17:53:01 -0700778 dep_xcb = dependency('xcb')
779 dep_x11_xcb = dependency('x11-xcb')
780 dep_xcb_dri2 = dependency('xcb-dri2', version : '>= 1.8')
781
Dylan Bakera47c5252017-09-22 12:55:00 -0700782 if with_dri3
783 pre_args += '-DHAVE_DRI3'
Dylan Baker50c28df2017-09-29 17:53:01 -0700784 dep_xcb_dri3 = dependency('xcb-dri3')
785 dep_xcb_present = dependency('xcb-present')
786 dep_xcb_sync = dependency('xcb-sync')
787 dep_xshmfence = dependency('xshmfence', version : '>= 1.1')
Dylan Bakera47c5252017-09-22 12:55:00 -0700788 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700789 endif
Dylan Baker50c28df2017-09-29 17:53:01 -0700790 if with_glx != 'disabled'
791 dep_dri2proto = dependency('dri2proto', version : '>= 2.8')
792 dep_glproto = dependency('glproto', version : '>= 1.4.14')
793 endif
Dylan Baker108d2572017-10-18 12:20:43 -0700794 if with_egl
795 dep_xcb_xfixes = dependency('xcb-xfixes')
796 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700797endif
798
Dylan Bakerd1992252017-09-14 17:57:17 -0700799# TODO: osmesa
800
Dylan Bakerd1992252017-09-14 17:57:17 -0700801# TODO: vallium G3DVL
802
803# TODO: nine
804
805# TODO: clover
806
Dylan Bakerd1992252017-09-14 17:57:17 -0700807# TODO: gallium tests
808
809# TODO: various libdirs
810
811# TODO: swr
812
813# TODO: gallium driver dirs
814
815# FIXME: this is a workaround for #2326
816prog_touch = find_program('touch')
817dummy_cpp = custom_target(
818 'dummy_cpp',
819 output : 'dummy.cpp',
820 command : [prog_touch, '@OUTPUT@'],
821)
822
823foreach a : pre_args
824 add_project_arguments(a, language : ['c', 'cpp'])
825endforeach
826foreach a : c_args
827 add_project_arguments(a, language : ['c'])
828endforeach
829foreach a : cpp_args
830 add_project_arguments(a, language : ['cpp'])
831endforeach
832
833inc_include = include_directories('include')
834
Dylan Baker108d2572017-10-18 12:20:43 -0700835gl_priv_reqs = [
836 'x11', 'xext', 'xdamage >= 1.1', 'xfixes', 'x11-xcb', 'xcb',
837 'xcb-glx >= 1.8.1', 'libdrm >= 2.4.75',
838]
Dylan Baker1f11ac42017-10-24 11:34:04 -0700839if dep_xxf86vm != [] and dep_xxf86vm.found()
Dylan Bakerb92992e2017-10-24 11:28:42 -0700840 gl_priv_reqs += 'xxf86vm'
Dylan Baker108d2572017-10-18 12:20:43 -0700841endif
842if with_dri_platform == 'drm'
843 gl_priv_reqs += 'xcb-dri2 >= 1.8'
844endif
845
846gl_priv_libs = []
847if dep_thread.found()
848 gl_priv_libs += ['-lpthread', '-pthread']
849endif
850if dep_m.found()
851 gl_priv_libs += '-lm'
852endif
853if dep_dl.found()
854 gl_priv_libs += '-ldl'
855endif
856
Dylan Baker32180562017-09-20 20:11:32 -0700857pkg = import('pkgconfig')
858
Dylan Bakerd1992252017-09-14 17:57:17 -0700859subdir('include')
Eric Engestrom05a94a42017-10-24 18:03:39 +0100860subdir('bin')
Dylan Bakerd1992252017-09-14 17:57:17 -0700861subdir('src')