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