blob: ff5666c207ee38167736860072b98d2383dbc42a [file] [log] [blame]
Dylan Bakerd1992252017-09-14 17:57:17 -07001# Copyright © 2017 Intel Corporation
2
3# Permission is hereby granted, free of charge, to any person obtaining a copy
4# of this software and associated documentation files (the "Software"), to deal
5# in the Software without restriction, including without limitation the rights
6# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7# copies of the Software, and to permit persons to whom the Software is
8# furnished to do so, subject to the following conditions:
9
10# The above copyright notice and this permission notice shall be included in
11# all copies or substantial portions of the Software.
12
13# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19# SOFTWARE.
20
21project('mesa', ['c', 'cpp'], version : '17.3.0-devel', license : 'MIT',
Dylan Baker052c0d52017-09-30 20:04:09 -070022 default_options : ['c_std=c99', 'cpp_std=c++11'])
Dylan Bakerd1992252017-09-14 17:57:17 -070023
Dylan Baker32180562017-09-20 20:11:32 -070024# Arguments for the preprocessor, put these in a separate array from the C and
25# C++ (cpp in meson terminology) arguments since they need to be added to the
26# default arguments for both C and C++.
27pre_args = [
28 '-D__STDC_CONSTANT_MACROS',
29 '-D__STDC_FORMAT_MACROS',
30 '-D__STDC_LIMIT_MACROS',
31 '-DVERSION="@0@"'.format(meson.project_version()),
32 '-DPACKAGE_VERSION=VERSION',
33 '-DPACKAGE_BUGREPORT="https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa"',
Dylan Baker601bd722017-10-09 14:22:07 -070034 '-D_GNU_SOURCE',
Dylan Baker32180562017-09-20 20:11:32 -070035]
36
Dylan Bakere915b8d2017-09-28 14:02:51 -070037with_vulkan_icd_dir = get_option('vulkan-icd-dir')
Dylan Bakerd1992252017-09-14 17:57:17 -070038with_tests = get_option('build-tests')
39with_valgrind = get_option('valgrind')
Dylan Baker32180562017-09-20 20:11:32 -070040with_asm = get_option('asm')
Dylan Baker02cf3a82017-10-12 09:47:30 -070041with_llvm = get_option('llvm')
Dylan Baker3b209e92017-10-10 15:25:07 -070042if get_option('texture-float')
43 pre_args += '-DTEXTURE_FLOAT_ENABLED'
44 message('WARNING: Floating-point texture enabled. Please consult docs/patents.txt and your lawyer before building mesa.')
45endif
Dylan Baker32180562017-09-20 20:11:32 -070046
47# XXX: yeah, do these
48with_appledri = false
49with_windowsdri = false
50
Dylan Bakerdb978842017-09-28 13:59:04 -070051dri_drivers_path = get_option('dri-drivers-path')
52if dri_drivers_path == ''
53 dri_drivers_path = join_paths(get_option('libdir'), 'dri')
54endif
55
Dylan Baker32180562017-09-20 20:11:32 -070056with_gles1 = get_option('gles1')
57with_gles2 = get_option('gles2')
58with_opengl = get_option('opengl')
59with_any_opengl = with_opengl or with_gles1 or with_gles2
Dylan Bakera47c5252017-09-22 12:55:00 -070060# Only build shared_glapi if at least one OpenGL API is enabled
61with_shared_glapi = get_option('shared-glapi') and with_any_opengl
Dylan Baker32180562017-09-20 20:11:32 -070062
63# TODO: these will need options, but at the moment they just control header
64# installs
Dylan Baker32180562017-09-20 20:11:32 -070065with_osmesa = false
66
67# shared-glapi is required if at least two OpenGL APIs are being built
68if not with_shared_glapi
69 if ((with_gles1 and with_gles2) or (with_gles1 and with_opengl)
70 or (with_gles2 and with_opengl))
71 error('shared-glapi required for building two or more of OpenGL, OpenGL ES 1.x, OpenGL ES 2.x')
72 endif
73endif
74
75# We require OpenGL for OpenGL ES
76if (with_gles1 or with_gles2) and not with_opengl
77 error('building OpenGL ES without OpenGL is not supported.')
78endif
79
80with_dri = false
Ville Syrjälä22899642017-10-10 01:15:42 +030081with_dri_i915 = false
Dylan Baker32180562017-09-20 20:11:32 -070082with_dri_i965 = false
Dylan Bakerc2cd5802017-10-03 17:06:22 -070083with_dri_swrast = false
Dylan Baker32180562017-09-20 20:11:32 -070084_drivers = get_option('dri-drivers')
85if _drivers != ''
86 _split = _drivers.split(',')
Ville Syrjälä22899642017-10-10 01:15:42 +030087 with_dri_i915 = _split.contains('i915')
Dylan Baker32180562017-09-20 20:11:32 -070088 with_dri_i965 = _split.contains('i965')
Dylan Bakerc2cd5802017-10-03 17:06:22 -070089 with_dri_swrast = _split.contains('swrast')
Dylan Baker32180562017-09-20 20:11:32 -070090 with_dri = true
91endif
92
Dylan Bakeraf9d2762017-09-28 21:03:07 -070093with_gallium = false
94with_gallium_radeonsi = false
Dylan Baker813b4b02017-10-09 14:59:35 -070095with_gallium_nouveau = false
Dylan Bakerf3d03a22017-10-10 11:57:50 -070096with_gallium_softpipe = false
Dylan Bakeraf9d2762017-09-28 21:03:07 -070097_drivers = get_option('gallium-drivers')
98if _drivers != ''
99 _split = _drivers.split(',')
100 with_gallium_radeonsi = _split.contains('radeonsi')
Dylan Baker813b4b02017-10-09 14:59:35 -0700101 with_gallium_nouveau = _split.contains('nouveau')
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700102 with_gallium = true
103 with_dri = true
Ville Syrjälä22899642017-10-10 01:15:42 +0300104endif
105
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700106if not (with_dri or with_gallium)
Dylan Baker32180562017-09-20 20:11:32 -0700107 with_gles1 = false
108 with_gles2 = false
109 with_opengl = false
110 with_any_opengl = false
111 with_shared_glapi = false
112endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700113
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700114dep_libdrm_intel = []
115if with_dri_i915
116 dep_libdrm_intel = dependency('libdrm_intel', version : '>= 2.4.75')
117endif
118
Dylan Bakera47c5252017-09-22 12:55:00 -0700119# TODO: other OSes
120with_dri_platform = 'drm'
121
Dylan Bakerd1992252017-09-14 17:57:17 -0700122# TODO: there are more platforms required for non-vulkan drivers
123with_platform_wayland = false
124with_platform_x11 = false
Dylan Bakerb1b65392017-09-28 22:25:02 -0700125with_platform_drm = false
Dylan Bakerd1992252017-09-14 17:57:17 -0700126_platforms = get_option('platforms')
127if _platforms != ''
128 _split = _platforms.split(',')
129 with_platform_x11 = _split.contains('x11')
130 with_platform_wayland = _split.contains('wayland')
Dylan Bakerb1b65392017-09-28 22:25:02 -0700131 with_platform_drm = _split.contains('drm')
Dylan Bakerd1992252017-09-14 17:57:17 -0700132endif
133
Dylan Baker816bf7d12017-09-28 15:53:53 -0700134with_gbm = get_option('gbm')
135if with_gbm == 'auto' and with_dri # TODO: or gallium
136 with_gbm = host_machine.system() == 'linux'
137elif with_gbm == 'yes'
138 if not ['linux', 'bsd'].contains(host_machine.system())
139 error('GBM only supports unix-like platforms')
140 endif
141 with_gbm = true
142else
143 with_gbm = false
144endif
145
Dylan Baker8e611872017-10-11 12:49:31 -0700146pre_args += '-DGLX_USE_TLS'
Dylan Bakera47c5252017-09-22 12:55:00 -0700147with_glx = get_option('glx')
148if with_glx != 'disabled'
Dylan Bakera47c5252017-09-22 12:55:00 -0700149 if not (with_platform_x11 and with_any_opengl) and with_glx != 'auto'
150 error('Cannot build GLX support without X11 platform support and at least one OpenGL API')
151 elif with_glx == 'gallium-xlib'
152 if not with_gallium
153 error('Gallium-xlib based GLX requires at least one gallium driver')
154 elif with_dri
155 error('gallium-xlib conflicts with any dri driver')
156 endif
157 elif with_glx == 'dri' and not with_dri
158 error('dri based GLX requires at least one DRI driver')
159 elif with_glx == 'auto'
160 if with_dri
161 with_glx = 'dri'
162 elif with_gallium
163 with_glx = 'gallium-xlib'
164 elif with_platform_x11 and with_any_opengl
165 with_glx = 'xlib'
166 else
167 with_glx = 'disabled'
168 endif
169 endif
170endif
171
172with_glvnd = get_option('glvnd')
173if with_glvnd and with_glx != 'dri'
174 message('glvnd requires dri based glx')
175endif
176
177# TODO: toggle for this
178with_glx_direct = true
179
Dylan Bakerd1992252017-09-14 17:57:17 -0700180if with_vulkan_icd_dir == ''
181 with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
182endif
183
184with_intel_vk = false
185with_amd_vk = false
Dylan Bakera47c5252017-09-22 12:55:00 -0700186with_any_vk = false
Dylan Bakerd1992252017-09-14 17:57:17 -0700187_vulkan_drivers = get_option('vulkan-drivers')
188if _vulkan_drivers != ''
189 _split = _vulkan_drivers.split(',')
190 with_intel_vk = _split.contains('intel')
191 with_amd_vk = _split.contains('amd')
Dylan Bakera47c5252017-09-22 12:55:00 -0700192 with_any_vk = with_amd_vk or with_intel_vk
Dylan Bakerd1992252017-09-14 17:57:17 -0700193 if not (with_platform_x11 or with_platform_wayland)
194 error('Vulkan requires at least one platform (x11, wayland)')
195 endif
Dylan Bakera47c5252017-09-22 12:55:00 -0700196endif
197
Dylan Baker50c28df2017-09-29 17:53:01 -0700198with_dri2 = (with_dri or with_any_vk) and with_dri_platform == 'drm'
199with_dri3 = get_option('dri3')
200if with_dri3 == 'auto'
201 if host_machine.system() == 'linux' and with_dri2
202 with_dri3 = true
203 else
204 with_dri3 = false
205 endif
206elif with_dri3 == 'yes'
207 with_dri3 = true
208else
209 with_dri3 = false
210endif
211
212if with_any_vk and (with_platform_x11 and not with_dri3)
213 error('Vulkan drivers require dri3 for X11 support')
214endif
Dylan Bakeraf9d2762017-09-28 21:03:07 -0700215if with_dri or with_gallium
Dylan Bakera47c5252017-09-22 12:55:00 -0700216 if with_glx == 'disabled' # TODO: or egl
217 error('building dri or gallium drivers require at least one window system')
218 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700219endif
220
Dylan Baker50c28df2017-09-29 17:53:01 -0700221with_gallium_xvmc = false
222with_gallium_vdpau = false
223with_gallium_omx = false # this is bellagio
224with_gallium_va = false
225with_gallium_media = false
226dep_va = []
227_drivers = get_option('gallium-media')
228if _drivers != ''
229 _split = _drivers.split(',')
230 with_gallium_xvmc = _split.contains('xvmc')
231 with_gallium_vdpau = _split.contains('vdpau')
232 with_gallium_omx = _split.contains('omx')
233 with_gallium_va = _split.contains('va')
234 with_gallium_media = (with_gallium_xvmc or with_gallium_vdpau or
235 with_gallium_omx or with_gallium_va)
236endif
237
238if with_platform_x11
239 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
240 pre_args += '-DHAVE_X11_PLATFORM'
241 endif
242 if with_glx == 'xlib'
243 # TODO
244 error('TODO')
245 elif with_glx == 'gallium-xlib'
246 # TODO
247 error('TODO')
248 else
249 pre_args += '-DGLX_INDIRECT_RENDERING'
250 if with_glx_direct
251 pre_args += '-DGLX_DIRECT_RENDERING'
252 endif
253 if with_dri_platform == 'drm'
254 pre_args += '-DGLX_USE_DRM'
255 endif
256 endif
257endif
258
Dylan Bakerd1992252017-09-14 17:57:17 -0700259prog_python2 = find_program('python2')
Dylan Baker9342a7d2017-09-28 10:48:30 -0700260has_mako = run_command(prog_python2, '-c', 'import mako')
261if has_mako.returncode() != 0
262 error('Python (2.x) mako module required to build mesa.')
263endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700264
265cc = meson.get_compiler('c')
266if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
Eric Engestrom1262e822017-09-29 15:25:18 +0100267 error('When using GCC, version 4.4.6 or later is required.')
Dylan Bakerd1992252017-09-14 17:57:17 -0700268endif
269
Dylan Bakerd1992252017-09-14 17:57:17 -0700270# Define DEBUG for debug and debugoptimized builds
271if get_option('buildtype').startswith('debug')
272 pre_args += '-DDEBUG'
273endif
274
Dylan Baker673dda82017-09-20 11:53:29 -0700275if get_option('shader-cache')
276 pre_args += '-DENABLE_SHADER_CACHE'
277elif with_amd_vk
278 error('Radv requires shader cache support')
279endif
280
Dylan Bakerd1992252017-09-14 17:57:17 -0700281# Check for GCC style builtins
282foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
283 'ffsll', 'popcount', 'popcountll', 'unreachable']
284 if cc.has_function(b)
285 pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
286 endif
287endforeach
288
Dylan Baker673dda82017-09-20 11:53:29 -0700289# check for GCC __attribute__
Dylan Bakerd1992252017-09-14 17:57:17 -0700290foreach a : ['const', 'flatten', 'malloc', 'pure', 'unused',
291 'warn_unused_result', 'weak',]
292 if cc.compiles('int foo(void) __attribute__((@0@));'.format(a),
293 name : '__attribute__((@0@))'.format(a))
294 pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
295 endif
296endforeach
297if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
298 name : '__attribute__((format(...)))')
299 pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
300endif
301if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
302 name : '__attribute__((packed))')
303 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
304endif
305if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
306 name : '__attribute__((returns_nonnull))')
307 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NONNULL'
308endif
309if cc.compiles('''int foo_def(void) __attribute__((visibility("default")));
310 int foo_hid(void) __attribute__((visibility("hidden")));
311 int foo_int(void) __attribute__((visibility("internal")));
312 int foo_pro(void) __attribute__((visibility("protected")));''',
313 name : '__attribute__((visibility(...)))')
314 pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISBILITY'
315endif
316if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
317 name : '__attribute__((alias(...)))')
318 pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
319endif
320
321# TODO: this is very incomplete
322if host_machine.system() == 'linux'
323 pre_args += '-D_GNU_SOURCE'
324endif
325
326# Check for generic C arguments
327c_args = []
328foreach a : ['-Wall', '-Werror=implicit-function-declaration',
329 '-Werror=missing-prototypes', '-fno-math-errno',
330 '-fno-trapping-math', '-Qunused-arguments']
331 if cc.has_argument(a)
332 c_args += a
333 endif
334endforeach
335c_vis_args = []
336if cc.has_argument('-fvisibility=hidden')
337 c_vis_args += '-fvisibility=hidden'
338endif
339
340# Check for generic C++ arguments
341cpp = meson.get_compiler('cpp')
342cpp_args = []
343foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math',
344 '-Qunused-arguments', '-Wno-non-virtual-dtor']
345 if cpp.has_argument(a)
346 cpp_args += a
347 endif
348endforeach
349cpp_vis_args = []
350if cpp.has_argument('-fvisibility=hidden')
351 cpp_vis_args += '-fvisibility=hidden'
352endif
353
354# Check for C and C++ arguments for MSVC2013 compatibility. These are only used
355# in parts of the mesa code base that need to compile with old versions of
356# MSVC, mainly common code
357c_msvc_compat_args = []
358cpp_msvc_compat_args = []
359foreach a : ['-Werror=pointer-arith', '-Werror=vla']
360 if cc.has_argument(a)
361 c_msvc_compat_args += a
362 endif
363 if cpp.has_argument(a)
364 cpp_msvc_compat_args += a
365 endif
366endforeach
367
368no_override_init_args = []
369foreach a : ['-Wno-override-init', '-Wno-initializer-overrides']
370 if cc.has_argument(a)
371 no_override_init_args += a
372 endif
373endforeach
374
375# TODO: SSE41 (which is only required for core mesa)
376
377# Check for GCC style atomics
378if cc.compiles('int main() { int n; return __atomic_load_n(&n, __ATOMIC_ACQUIRE); }',
379 name : 'GCC atomic builtins')
380 pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
381endif
382if not cc.links('''#include <stdint.h>
383 uint64_t v;
384 int main() {
385 return __sync_add_and_fetch(&v, (uint64_t)1);
386 }''',
387 name : 'GCC 64bit atomics')
388 pre_args += '-DMISSING_64_BIT_ATOMICS'
389endif
390
391# TODO: endian
392# TODO: powr8
393# TODO: shared/static? Is this even worth doing?
394
395# I don't think that I need to set any of the debug stuff, I think meson
396# handles that for us
397
398# TODO: ldflags
399
400# TODO: texture-float (gallium/mesa only)
401
402# TODO: cross-compiling. I don't think this is relavent to meson
403
Dylan Baker32180562017-09-20 20:11:32 -0700404# FIXME: enable asm when cross compiler
405# This is doable (autotools does it), but it's not of immediate concern
406if meson.is_cross_build()
407 message('Cross compiling, disabling asm')
408 with_asm = false
409endif
410
411with_asm_arch = ''
412if with_asm
413 # TODO: SPARC and PPC
414 if host_machine.cpu_family() == 'x86'
415 if ['linux', 'bsd'].contains(host_machine.system()) # FIXME: hurd?
416 with_asm_arch = 'x86'
417 pre_args += ['-DUSE_X86_ASM', '-DUSE_MMX_ASM', '-DUSE_3DNOW_ASM',
418 '-DUSE_SSE_ASM']
419 endif
420 elif host_machine.cpu_family() == 'x86_64'
421 if host_machine.system() == 'linux'
422 with_asm_arch = 'x86_64'
423 pre_args += ['-DUSE_X86_64_ASM']
424 endif
425 elif host_machine.cpu_family() == 'arm'
426 if host_machine.system() == 'linux'
427 with_asm_arch = 'arm'
428 pre_args += ['-DUSE_ARM_ASM']
429 endif
430 elif host_machine.cpu_family() == 'aarch64'
431 if host_machine.system() == 'linux'
432 with_asm_arch = 'aarch64'
433 pre_args += ['-DUSE_AARCH64_ASM']
434 endif
435 endif
436endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700437
438# Check for standard headers and functions
439if cc.has_header_symbol('sys/sysmacros.h', 'major')
440 pre_args += '-DMAJOR_IN_SYSMACROS'
441elif cc.has_header_symbol('sys/mkdev.h', 'major')
442 pre_args += '-DMAJOR_IN_MKDEV'
443endif
444
445foreach h : ['xlocale.h', 'sys/sysctl.h']
446 if cc.has_header(h)
447 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
448 endif
449endforeach
450
451foreach f : ['strtof', 'mkostemp', 'posix_memalign']
452 if cc.has_function(f)
453 pre_args += '-DHAVE_@0@'.format(f.to_upper())
454 endif
455endforeach
456
457# strtod locale support
458if cc.links('''
459 #define _GNU_SOURCE
460 #include <stdlib.h>
461 #include <locale.h>
462 #ifdef HAVE_XLOCALE_H
463 #include <xlocale.h>
464 #endif
465 int main() {
466 locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
467 const char *s = "1.0";
468 char *end;
469 double d = strtod_l(s, end, loc);
470 float f = strtod_l(s, end, loc);
471 freelocale(loc);
472 return 0;
473 }''',
474 extra_args : pre_args,
475 name : 'strtod has locale support')
476 pre_args += '-DHAVE_STRTOD_L'
477endif
478
479# Check for some linker flags
480ld_args_bsymbolic = []
Dylan Bakere21e0a62017-09-30 13:15:52 -0700481if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic', name : 'Bsymbolic')
Dylan Bakerd1992252017-09-14 17:57:17 -0700482 ld_args_bsymbolic += '-Wl,-Bsymbolic'
483endif
484ld_args_gc_sections = []
485if cc.links('static char unused() { return 5; } int main() { return 0; }',
Dylan Bakere21e0a62017-09-30 13:15:52 -0700486 args : '-Wl,--gc-sections', name : 'gc-sections')
Dylan Bakerd1992252017-09-14 17:57:17 -0700487 ld_args_gc_sections += '-Wl,--gc-sections'
488endif
Dylan Bakere21e0a62017-09-30 13:15:52 -0700489with_ld_version_script = false
490if cc.links('int main() { return 0; }',
491 args : '-Wl,--version-script=@0@'.format(
492 join_paths(meson.source_root(), 'build-support/conftest.map')),
493 name : 'version-script')
494 with_ld_version_script = true
495endif
496with_ld_dynamic_list = false
497if cc.links('int main() { return 0; }',
498 args : '-Wl,--dynamic-list=@0@'.format(
499 join_paths(meson.source_root(), 'build-support/conftest.dyn')),
500 name : 'dynamic-list')
501 with_ld_dynamic_list = true
502endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700503
504# check for dl support
505if cc.has_function('dlopen')
506 dep_dl = []
507else
508 dep_dl = cc.find_library('dl')
509endif
Dylan Baker32180562017-09-20 20:11:32 -0700510if cc.has_function('dladdr', dependencies : dep_dl)
511 # This is really only required for megadrivers
512 pre_args += '-DHAVE_DLADDR'
Dylan Bakerd1992252017-09-14 17:57:17 -0700513endif
514
515if cc.has_function('dl_iterate_phdr')
516 pre_args += '-DHAVE_DL_ITERATE_PHDR'
517else
518 # TODO: this is required for vulkan
519endif
520
521# Determine whether or not the rt library is needed for time functions
522if cc.has_function('clock_gettime')
523 dep_clock = []
524else
525 dep_clock = cc.find_library('rt')
526endif
527
Dylan Baker66c94b92017-09-30 13:48:34 -0700528with_gallium_drisw_kms = false
Dylan Baker50c28df2017-09-29 17:53:01 -0700529dep_libdrm = dependency('libdrm', version : '>= 2.4.75',
530 required : with_dri2 or with_dri3)
531if dep_libdrm.found()
532 pre_args += '-DHAVE_LIBDRM'
Dylan Baker66c94b92017-09-30 13:48:34 -0700533 if with_dri_platform == 'drm' and with_dri
534 with_gallium_drisw_kms = true
535 endif
Dylan Baker50c28df2017-09-29 17:53:01 -0700536endif
537
Dylan Bakerd1992252017-09-14 17:57:17 -0700538# TODO: some of these may be conditional
539dep_zlib = dependency('zlib', version : '>= 1.2.3')
540dep_thread = dependency('threads')
Dylan Baker50c28df2017-09-29 17:53:01 -0700541if dep_thread.found() and host_machine.system() == 'linux'
542 pre_args += '-DHAVE_PTHREAD'
543endif
Dylan Bakercc4f5872017-09-27 11:30:21 -0700544dep_elf = dependency('libelf', required : false)
Dylan Bakerb154b442017-09-30 14:04:28 -0700545if not dep_elf.found() and (with_amd_vk or with_gallium_radeonsi) # TODO: clover, r600
546 dep_elf = cc.find_library('elf')
Dylan Bakercc4f5872017-09-27 11:30:21 -0700547endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700548dep_expat = dependency('expat')
549# this only exists on linux so either this is linux and it will be found, or
550# its not linux and and wont
551dep_m = cc.find_library('m', required : false)
Dylan Baker66f97f62017-09-30 09:03:51 -0700552
553dep_libdrm_amdgpu = []
554dep_libdrm_radeon = []
Dylan Baker813b4b02017-10-09 14:59:35 -0700555dep_libdrm_nouveau = []
Dylan Baker66f97f62017-09-30 09:03:51 -0700556if with_amd_vk or with_gallium_radeonsi
557 dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.84')
558endif
559if with_gallium_radeonsi # older radeon too
560 dep_libdrm_radeon = dependency('libdrm_radeon', version : '>= 2.4.71')
561endif
Dylan Baker813b4b02017-10-09 14:59:35 -0700562if with_gallium_nouveau
563 dep_libdrm_nouveau = dependency('libdrm_nouveau', version : '>= 2.4.66')
564endif
Dylan Baker673dda82017-09-20 11:53:29 -0700565
566llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
567if with_amd_vk
568 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
569endif
570dep_llvm = dependency(
Dylan Baker50c28df2017-09-29 17:53:01 -0700571 'llvm', version : '>= 3.9.0', required : with_amd_vk, modules : llvm_modules,
Dylan Baker673dda82017-09-20 11:53:29 -0700572)
Dylan Baker02cf3a82017-10-12 09:47:30 -0700573if with_llvm
574 if dep_llvm.found()
575 _llvm_version = dep_llvm.version().split('.')
576 # Development versions of LLVM have an 'svn' suffix, we don't want that for
577 # our version checks.
578 _llvm_patch = _llvm_version[2]
579 if _llvm_patch.endswith('svn')
580 _llvm_patch = _llvm_patch.split('s')[0]
581 endif
582 pre_args += [
583 '-DHAVE_LLVM=0x0@0@@1@@2@'.format(_llvm_version[0], _llvm_version[1], _llvm_patch),
584 '-DMESA_LLVM_VERSION_PATCH=@0@'.format(_llvm_patch),
585 ]
586 else
Dylan Baker66f97f62017-09-30 09:03:51 -0700587 if with_amd_vk or with_gallium_radeonsi
588 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 -0700589 endif
Dylan Baker673dda82017-09-20 11:53:29 -0700590 endif
Dylan Baker66f97f62017-09-30 09:03:51 -0700591elif with_amd_vk or with_gallium_radeonsi
592 error('The following drivers requires LLVM: Radv, RadeonSI. One of these is enabled, but LLVM is disabled.')
Dylan Baker673dda82017-09-20 11:53:29 -0700593endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700594
Dylan Bakera47c5252017-09-22 12:55:00 -0700595dep_glvnd = []
596if with_glvnd
597 dep_glvnd = dependency('libglvnd', version : '>= 0.2.0')
598 pre_args += '-DUSE_LIBGLVND=1'
599endif
600
Dylan Bakerd1992252017-09-14 17:57:17 -0700601# TODO: make this conditional
602dep_valgrind = dependency('valgrind', required : false)
603if dep_valgrind.found() and with_valgrind
604 pre_args += '-DHAVE_VALGRIND'
605endif
606
607# pthread stubs. Lets not and say we didn't
608
Dylan Baker32180562017-09-20 20:11:32 -0700609prog_bison = find_program('bison', required : with_any_opengl)
610prog_flex = find_program('flex', required : with_any_opengl)
611
Dylan Bakerd1992252017-09-14 17:57:17 -0700612# TODO: selinux
Dylan Baker32180562017-09-20 20:11:32 -0700613dep_selinux = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700614
615# TODO: llvm-prefix and llvm-shared-libs
616
Dylan Bakerb1b65392017-09-28 22:25:02 -0700617dep_unwind = dependency('libunwind', required : false)
618if dep_unwind.found()
619 pre_args += '-DHAVE_LIBUNWIND'
620endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700621
622# TODO: flags for opengl, gles, dri
623
624# TODO: gallium-hud
625
626# TODO: glx provider
627
628# TODO: osmesa provider
629
Dylan Bakerd1992252017-09-14 17:57:17 -0700630# TODO: symbol mangling
631
Dylan Bakerd1992252017-09-14 17:57:17 -0700632# TODO: egl configuration
633
634if with_platform_wayland
635 prog_wl_scanner = find_program('wayland-scanner')
636 dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8')
637 dep_wayland_client = dependency('wayland-client', version : '>=1.11')
638 dep_wayland_server = dependency('wayland-server', version : '>=1.11')
639else
640 prog_wl_scanner = []
641 dep_wl_protocols = []
642 dep_wayland_client = []
643 dep_wayland_server = []
644endif
645
Dylan Baker50c28df2017-09-29 17:53:01 -0700646dep_x11 = []
647dep_xext = []
648dep_xdamage = []
649dep_xfixes = []
650dep_x11_xcb = []
651dep_xcb_glx = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700652dep_xcb_dri2 = []
653dep_xcb_dri3 = []
Dylan Bakera47c5252017-09-22 12:55:00 -0700654dep_dri2proto = []
655dep_glproto = []
Dylan Bakera47c5252017-09-22 12:55:00 -0700656dep_xf86vm = []
Dylan Baker50c28df2017-09-29 17:53:01 -0700657dep_xcb_dri3 = []
658dep_xcb_present = []
659dep_xcb_sync = []
660dep_xshmfence = []
Dylan Bakerd1992252017-09-14 17:57:17 -0700661if with_platform_x11
Dylan Baker50c28df2017-09-29 17:53:01 -0700662 if with_glx == 'dri' and with_dri_platform == 'drm'
663 dep_x11 = dependency('x11')
664 dep_xext = dependency('xext')
665 dep_xdamage = dependency('xdamage', version : '>= 1.1')
666 dep_xfixes = dependency('xfixes')
667 dep_xcb_glx = dependency('xcb-glx', version : '>= 1.8.1')
668 dep_xf86vm = dependency('xf86vm', required : false)
Dylan Bakera47c5252017-09-22 12:55:00 -0700669 endif
670 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
Dylan Baker50c28df2017-09-29 17:53:01 -0700671 dep_xcb = dependency('xcb')
672 dep_x11_xcb = dependency('x11-xcb')
673 dep_xcb_dri2 = dependency('xcb-dri2', version : '>= 1.8')
674
Dylan Bakera47c5252017-09-22 12:55:00 -0700675 if with_dri3
676 pre_args += '-DHAVE_DRI3'
Dylan Baker50c28df2017-09-29 17:53:01 -0700677 dep_xcb_dri3 = dependency('xcb-dri3')
678 dep_xcb_present = dependency('xcb-present')
679 dep_xcb_sync = dependency('xcb-sync')
680 dep_xshmfence = dependency('xshmfence', version : '>= 1.1')
Dylan Bakera47c5252017-09-22 12:55:00 -0700681 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700682 endif
Dylan Baker50c28df2017-09-29 17:53:01 -0700683 if with_glx != 'disabled'
684 dep_dri2proto = dependency('dri2proto', version : '>= 2.8')
685 dep_glproto = dependency('glproto', version : '>= 1.4.14')
686 endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700687endif
688
689# TODO: platforms for !vulkan
690
Dylan Bakerd1992252017-09-14 17:57:17 -0700691# TODO: osmesa
692
693# TODO: egl
694
Dylan Bakerd1992252017-09-14 17:57:17 -0700695# TODO: vallium G3DVL
696
697# TODO: nine
698
699# TODO: clover
700
701# TODO: egl sans x11
Dylan Bakerd1992252017-09-14 17:57:17 -0700702# TODO: gallium tests
703
704# TODO: various libdirs
705
706# TODO: swr
707
708# TODO: gallium driver dirs
709
710# FIXME: this is a workaround for #2326
711prog_touch = find_program('touch')
712dummy_cpp = custom_target(
713 'dummy_cpp',
714 output : 'dummy.cpp',
715 command : [prog_touch, '@OUTPUT@'],
716)
717
718foreach a : pre_args
719 add_project_arguments(a, language : ['c', 'cpp'])
720endforeach
721foreach a : c_args
722 add_project_arguments(a, language : ['c'])
723endforeach
724foreach a : cpp_args
725 add_project_arguments(a, language : ['cpp'])
726endforeach
727
728inc_include = include_directories('include')
729
Dylan Baker32180562017-09-20 20:11:32 -0700730pkg = import('pkgconfig')
731
Dylan Bakerd1992252017-09-14 17:57:17 -0700732subdir('include')
733subdir('src')