blob: b1bd73691ee6f8e7ab2f594baec6f39680dee9dc [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',
22 default_options : ['c_std=c99'])
23
24with_dri3 = true # XXX: need a switch for this
Dylan Bakere915b8d2017-09-28 14:02:51 -070025with_vulkan_icd_dir = get_option('vulkan-icd-dir')
Dylan Bakerd1992252017-09-14 17:57:17 -070026with_tests = get_option('build-tests')
27with_valgrind = get_option('valgrind')
28
29# TODO: there are more platforms required for non-vulkan drivers
30with_platform_wayland = false
31with_platform_x11 = false
32_platforms = get_option('platforms')
33if _platforms != ''
34 _split = _platforms.split(',')
35 with_platform_x11 = _split.contains('x11')
36 with_platform_wayland = _split.contains('wayland')
37endif
38
39if with_vulkan_icd_dir == ''
40 with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
41endif
42
43with_intel_vk = false
44with_amd_vk = false
45_vulkan_drivers = get_option('vulkan-drivers')
46if _vulkan_drivers != ''
47 _split = _vulkan_drivers.split(',')
48 with_intel_vk = _split.contains('intel')
49 with_amd_vk = _split.contains('amd')
50 if not (with_platform_x11 or with_platform_wayland)
51 error('Vulkan requires at least one platform (x11, wayland)')
52 endif
53endif
54
55prog_python2 = find_program('python2')
Dylan Baker9342a7d2017-09-28 10:48:30 -070056has_mako = run_command(prog_python2, '-c', 'import mako')
57if has_mako.returncode() != 0
58 error('Python (2.x) mako module required to build mesa.')
59endif
Dylan Bakerd1992252017-09-14 17:57:17 -070060
61cc = meson.get_compiler('c')
62if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
Eric Engestrom1262e822017-09-29 15:25:18 +010063 error('When using GCC, version 4.4.6 or later is required.')
Dylan Bakerd1992252017-09-14 17:57:17 -070064endif
65
66# Arguments for the preprocessor, put these in a separate array from the C and
67# C++ (cpp in meson terminology) arguments since they need to be added to the
68# default arguments for both C and C++.
69pre_args = ['-D__STDC_CONSTANT_MACROS', '-D__STDC_FORMAT_MACROS',
70 '-D__STDC_LIMIT_MACROS',
71 '-DVERSION="@0@"'.format(meson.project_version())]
72
73# Define DEBUG for debug and debugoptimized builds
74if get_option('buildtype').startswith('debug')
75 pre_args += '-DDEBUG'
76endif
77
Dylan Baker673dda82017-09-20 11:53:29 -070078if get_option('shader-cache')
79 pre_args += '-DENABLE_SHADER_CACHE'
80elif with_amd_vk
81 error('Radv requires shader cache support')
82endif
83
Dylan Bakerd1992252017-09-14 17:57:17 -070084# Check for GCC style builtins
85foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
86 'ffsll', 'popcount', 'popcountll', 'unreachable']
87 if cc.has_function(b)
88 pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
89 endif
90endforeach
91
Dylan Baker673dda82017-09-20 11:53:29 -070092# check for GCC __attribute__
Dylan Bakerd1992252017-09-14 17:57:17 -070093foreach a : ['const', 'flatten', 'malloc', 'pure', 'unused',
94 'warn_unused_result', 'weak',]
95 if cc.compiles('int foo(void) __attribute__((@0@));'.format(a),
96 name : '__attribute__((@0@))'.format(a))
97 pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
98 endif
99endforeach
100if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
101 name : '__attribute__((format(...)))')
102 pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
103endif
104if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
105 name : '__attribute__((packed))')
106 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
107endif
108if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
109 name : '__attribute__((returns_nonnull))')
110 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NONNULL'
111endif
112if cc.compiles('''int foo_def(void) __attribute__((visibility("default")));
113 int foo_hid(void) __attribute__((visibility("hidden")));
114 int foo_int(void) __attribute__((visibility("internal")));
115 int foo_pro(void) __attribute__((visibility("protected")));''',
116 name : '__attribute__((visibility(...)))')
117 pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISBILITY'
118endif
119if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
120 name : '__attribute__((alias(...)))')
121 pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
122endif
123
124# TODO: this is very incomplete
125if host_machine.system() == 'linux'
126 pre_args += '-D_GNU_SOURCE'
127endif
128
129# Check for generic C arguments
130c_args = []
131foreach a : ['-Wall', '-Werror=implicit-function-declaration',
132 '-Werror=missing-prototypes', '-fno-math-errno',
133 '-fno-trapping-math', '-Qunused-arguments']
134 if cc.has_argument(a)
135 c_args += a
136 endif
137endforeach
138c_vis_args = []
139if cc.has_argument('-fvisibility=hidden')
140 c_vis_args += '-fvisibility=hidden'
141endif
142
143# Check for generic C++ arguments
144cpp = meson.get_compiler('cpp')
145cpp_args = []
146foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math',
147 '-Qunused-arguments', '-Wno-non-virtual-dtor']
148 if cpp.has_argument(a)
149 cpp_args += a
150 endif
151endforeach
152cpp_vis_args = []
153if cpp.has_argument('-fvisibility=hidden')
154 cpp_vis_args += '-fvisibility=hidden'
155endif
156
157# Check for C and C++ arguments for MSVC2013 compatibility. These are only used
158# in parts of the mesa code base that need to compile with old versions of
159# MSVC, mainly common code
160c_msvc_compat_args = []
161cpp_msvc_compat_args = []
162foreach a : ['-Werror=pointer-arith', '-Werror=vla']
163 if cc.has_argument(a)
164 c_msvc_compat_args += a
165 endif
166 if cpp.has_argument(a)
167 cpp_msvc_compat_args += a
168 endif
169endforeach
170
171no_override_init_args = []
172foreach a : ['-Wno-override-init', '-Wno-initializer-overrides']
173 if cc.has_argument(a)
174 no_override_init_args += a
175 endif
176endforeach
177
178# TODO: SSE41 (which is only required for core mesa)
179
180# Check for GCC style atomics
181if cc.compiles('int main() { int n; return __atomic_load_n(&n, __ATOMIC_ACQUIRE); }',
182 name : 'GCC atomic builtins')
183 pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
184endif
185if not cc.links('''#include <stdint.h>
186 uint64_t v;
187 int main() {
188 return __sync_add_and_fetch(&v, (uint64_t)1);
189 }''',
190 name : 'GCC 64bit atomics')
191 pre_args += '-DMISSING_64_BIT_ATOMICS'
192endif
193
194# TODO: endian
195# TODO: powr8
196# TODO: shared/static? Is this even worth doing?
197
198# I don't think that I need to set any of the debug stuff, I think meson
199# handles that for us
200
201# TODO: ldflags
202
203# TODO: texture-float (gallium/mesa only)
204
205# TODO: cross-compiling. I don't think this is relavent to meson
206
207# TODO: assembly support. mesa and vc4
208
209# Check for standard headers and functions
210if cc.has_header_symbol('sys/sysmacros.h', 'major')
211 pre_args += '-DMAJOR_IN_SYSMACROS'
212elif cc.has_header_symbol('sys/mkdev.h', 'major')
213 pre_args += '-DMAJOR_IN_MKDEV'
214endif
215
216foreach h : ['xlocale.h', 'sys/sysctl.h']
217 if cc.has_header(h)
218 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
219 endif
220endforeach
221
222foreach f : ['strtof', 'mkostemp', 'posix_memalign']
223 if cc.has_function(f)
224 pre_args += '-DHAVE_@0@'.format(f.to_upper())
225 endif
226endforeach
227
228# strtod locale support
229if cc.links('''
230 #define _GNU_SOURCE
231 #include <stdlib.h>
232 #include <locale.h>
233 #ifdef HAVE_XLOCALE_H
234 #include <xlocale.h>
235 #endif
236 int main() {
237 locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
238 const char *s = "1.0";
239 char *end;
240 double d = strtod_l(s, end, loc);
241 float f = strtod_l(s, end, loc);
242 freelocale(loc);
243 return 0;
244 }''',
245 extra_args : pre_args,
246 name : 'strtod has locale support')
247 pre_args += '-DHAVE_STRTOD_L'
248endif
249
250# Check for some linker flags
251ld_args_bsymbolic = []
252if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic')
253 ld_args_bsymbolic += '-Wl,-Bsymbolic'
254endif
255ld_args_gc_sections = []
256if cc.links('static char unused() { return 5; } int main() { return 0; }',
257 args : '-Wl,--gc-sections')
258 ld_args_gc_sections += '-Wl,--gc-sections'
259endif
260
261# check for dl support
262if cc.has_function('dlopen')
263 dep_dl = []
264else
265 dep_dl = cc.find_library('dl')
266endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700267
268if not cc.has_function('dladdr', dependencies : dep_dl)
269 error('dl library doesn\'t have dladdr')
270endif
271
272if cc.has_function('dl_iterate_phdr')
273 pre_args += '-DHAVE_DL_ITERATE_PHDR'
274else
275 # TODO: this is required for vulkan
276endif
277
278# Determine whether or not the rt library is needed for time functions
279if cc.has_function('clock_gettime')
280 dep_clock = []
281else
282 dep_clock = cc.find_library('rt')
283endif
284
285# TODO: some of these may be conditional
286dep_zlib = dependency('zlib', version : '>= 1.2.3')
287dep_thread = dependency('threads')
288pre_args += '-DHAVE_PTHREAD'
Dylan Bakercc4f5872017-09-27 11:30:21 -0700289dep_elf = dependency('libelf', required : false)
290if not dep_elf.found()
291 dep_elf = cc.find_library('elf')
292endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700293dep_expat = dependency('expat')
294# this only exists on linux so either this is linux and it will be found, or
295# its not linux and and wont
296dep_m = cc.find_library('m', required : false)
297
298# TODO: conditionalize libdrm requirement
299dep_libdrm = dependency('libdrm', version : '>= 2.4.75')
300pre_args += '-DHAVE_LIBDRM'
Dylan Baker673dda82017-09-20 11:53:29 -0700301dep_libdrm_amdgpu = []
302if with_amd_vk
303 dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.82')
304endif
305
306llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
307if with_amd_vk
308 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
309endif
310dep_llvm = dependency(
311 'llvm', version : '>= 3.9.0', required : false, modules : llvm_modules,
312)
313if not dep_llvm.found()
314 if with_amd_vk
315 error('Radv requires llvm.')
316 endif
317else
318 _llvm_version = dep_llvm.version().split('.')
319 # Development versions of LLVM have an 'svn' suffix, we don't want that for
320 # our version checks.
321 _llvm_patch = _llvm_version[2]
322 if _llvm_patch.endswith('svn')
323 _llvm_patch = _llvm_patch.split('s')[0]
324 endif
325 pre_args += [
326 '-DHAVE_LLVM=0x0@0@@1@@2@'.format(_llvm_version[0], _llvm_version[1], _llvm_patch),
327 '-DMESA_LLVM_VERSION_PATCH=@0@'.format(_llvm_patch),
328 ]
329endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700330
331# TODO: make this conditional
332dep_valgrind = dependency('valgrind', required : false)
333if dep_valgrind.found() and with_valgrind
334 pre_args += '-DHAVE_VALGRIND'
335endif
336
337# pthread stubs. Lets not and say we didn't
338
339# TODO: selinux
340
341# TODO: llvm-prefix and llvm-shared-libs
342
Dylan Bakerd1992252017-09-14 17:57:17 -0700343# TODO: unwind (llvm [radeon, gallivm] and gallium)
344
345# TODO: flags for opengl, gles, dri
346
347# TODO: gallium-hud
348
349# TODO: glx provider
350
351# TODO: osmesa provider
352
353# TODO: flags for xa, egl, gbm, nin, xvmc, vdpau, omx, va, opencl,
354# gallium-tests,
355
356# TODO: gallium drivers
357
358# TODO: libglvnd
359
360# TODO: symbol mangling
361
362# TODO: dri handling
363
364# TODO: shared-glapi
365
366# TODO: libgl requirements
367
368# TODO: GLX configuration
369
370# TODO: egl configuration
371
372if with_platform_wayland
373 prog_wl_scanner = find_program('wayland-scanner')
374 dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8')
375 dep_wayland_client = dependency('wayland-client', version : '>=1.11')
376 dep_wayland_server = dependency('wayland-server', version : '>=1.11')
377else
378 prog_wl_scanner = []
379 dep_wl_protocols = []
380 dep_wayland_client = []
381 dep_wayland_server = []
382endif
383
384dep_xcb_dri2 = []
385dep_xcb_dri3 = []
386if with_platform_x11
387 dep_xcb_dri2 = [
388 dependency('x11-xcb'),
389 dependency('xcb'),
390 dependency('xcb-dri2', version : '>= 1.8'),
391 dependency('xcb-xfixes'),
392 ]
393 if with_dri3
394 dep_xcb_dri3 = [
395 dep_xcb_dri2,
396 dependency('xcb-dri3'),
397 dependency('xcb-present'),
398 dependency('xcb-sync'),
399 dependency('xshmfence', version : '>= 1.1'),
400 ]
401 else
402 # TODO: dri3 is required for vulkan
403 endif
404endif
405
406# TODO: platforms for !vulkan
407
408# TODO: dri paths
409
410# TODO: dri drivers
411
412# TODO: osmesa
413
414# TODO: egl
415
416# TODO: xa
417
418# TODO: vallium G3DVL
419
420# TODO: nine
421
422# TODO: clover
423
424# TODO: egl sans x11
425
426# TODO: xvmc
427
428# TODO: gallium tests
429
430# TODO: various libdirs
431
432# TODO: swr
433
434# TODO: gallium driver dirs
435
436# FIXME: this is a workaround for #2326
437prog_touch = find_program('touch')
438dummy_cpp = custom_target(
439 'dummy_cpp',
440 output : 'dummy.cpp',
441 command : [prog_touch, '@OUTPUT@'],
442)
443
444foreach a : pre_args
445 add_project_arguments(a, language : ['c', 'cpp'])
446endforeach
447foreach a : c_args
448 add_project_arguments(a, language : ['c'])
449endforeach
450foreach a : cpp_args
451 add_project_arguments(a, language : ['cpp'])
452endforeach
453
454inc_include = include_directories('include')
455
456subdir('include')
457subdir('src')