meson: de-tabularize meson_options.txt
[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', 'cpp_std=c++11'])
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 has_mako = run_command(prog_python2, '-c', 'import mako')
57 if has_mako.returncode() != 0
58 error('Python (2.x) mako module required to build mesa.')
59 endif
60
61 cc = meson.get_compiler('c')
62 if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
63 error('When using GCC, version 4.4.6 or later is required.')
64 endif
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++.
69 pre_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
74 if get_option('buildtype').startswith('debug')
75 pre_args += '-DDEBUG'
76 endif
77
78 if get_option('shader-cache')
79 pre_args += '-DENABLE_SHADER_CACHE'
80 elif with_amd_vk
81 error('Radv requires shader cache support')
82 endif
83
84 # Check for GCC style builtins
85 foreach 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
90 endforeach
91
92 # check for GCC __attribute__
93 foreach 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
99 endforeach
100 if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
101 name : '__attribute__((format(...)))')
102 pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
103 endif
104 if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
105 name : '__attribute__((packed))')
106 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
107 endif
108 if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
109 name : '__attribute__((returns_nonnull))')
110 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NONNULL'
111 endif
112 if 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'
118 endif
119 if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
120 name : '__attribute__((alias(...)))')
121 pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
122 endif
123
124 # TODO: this is very incomplete
125 if host_machine.system() == 'linux'
126 pre_args += '-D_GNU_SOURCE'
127 endif
128
129 # Check for generic C arguments
130 c_args = []
131 foreach 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
137 endforeach
138 c_vis_args = []
139 if cc.has_argument('-fvisibility=hidden')
140 c_vis_args += '-fvisibility=hidden'
141 endif
142
143 # Check for generic C++ arguments
144 cpp = meson.get_compiler('cpp')
145 cpp_args = []
146 foreach 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
151 endforeach
152 cpp_vis_args = []
153 if cpp.has_argument('-fvisibility=hidden')
154 cpp_vis_args += '-fvisibility=hidden'
155 endif
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
160 c_msvc_compat_args = []
161 cpp_msvc_compat_args = []
162 foreach 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
169 endforeach
170
171 no_override_init_args = []
172 foreach a : ['-Wno-override-init', '-Wno-initializer-overrides']
173 if cc.has_argument(a)
174 no_override_init_args += a
175 endif
176 endforeach
177
178 # TODO: SSE41 (which is only required for core mesa)
179
180 # Check for GCC style atomics
181 if 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'
184 endif
185 if 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'
192 endif
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
210 if cc.has_header_symbol('sys/sysmacros.h', 'major')
211 pre_args += '-DMAJOR_IN_SYSMACROS'
212 elif cc.has_header_symbol('sys/mkdev.h', 'major')
213 pre_args += '-DMAJOR_IN_MKDEV'
214 endif
215
216 foreach h : ['xlocale.h', 'sys/sysctl.h']
217 if cc.has_header(h)
218 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
219 endif
220 endforeach
221
222 foreach f : ['strtof', 'mkostemp', 'posix_memalign']
223 if cc.has_function(f)
224 pre_args += '-DHAVE_@0@'.format(f.to_upper())
225 endif
226 endforeach
227
228 # strtod locale support
229 if 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'
248 endif
249
250 # Check for some linker flags
251 ld_args_bsymbolic = []
252 if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic')
253 ld_args_bsymbolic += '-Wl,-Bsymbolic'
254 endif
255 ld_args_gc_sections = []
256 if cc.links('static char unused() { return 5; } int main() { return 0; }',
257 args : '-Wl,--gc-sections')
258 ld_args_gc_sections += '-Wl,--gc-sections'
259 endif
260
261 # check for dl support
262 if cc.has_function('dlopen')
263 dep_dl = []
264 else
265 dep_dl = cc.find_library('dl')
266 endif
267
268 if not cc.has_function('dladdr', dependencies : dep_dl)
269 error('dl library doesn\'t have dladdr')
270 endif
271
272 if cc.has_function('dl_iterate_phdr')
273 pre_args += '-DHAVE_DL_ITERATE_PHDR'
274 else
275 # TODO: this is required for vulkan
276 endif
277
278 # Determine whether or not the rt library is needed for time functions
279 if cc.has_function('clock_gettime')
280 dep_clock = []
281 else
282 dep_clock = cc.find_library('rt')
283 endif
284
285 # TODO: some of these may be conditional
286 dep_zlib = dependency('zlib', version : '>= 1.2.3')
287 dep_thread = dependency('threads')
288 pre_args += '-DHAVE_PTHREAD'
289 dep_elf = dependency('libelf', required : false)
290 if not dep_elf.found()
291 dep_elf = cc.find_library('elf', required : with_amd_vk) # TODO: clover, r600, radeonsi
292 endif
293 dep_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
296 dep_m = cc.find_library('m', required : false)
297
298 # TODO: conditionalize libdrm requirement
299 dep_libdrm = dependency('libdrm', version : '>= 2.4.75')
300 pre_args += '-DHAVE_LIBDRM'
301 dep_libdrm_amdgpu = []
302 if with_amd_vk
303 dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.82')
304 endif
305
306 llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
307 if with_amd_vk
308 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
309 endif
310 dep_llvm = dependency(
311 'llvm', version : '>= 3.9.0', required : false, modules : llvm_modules,
312 )
313 if not dep_llvm.found()
314 if with_amd_vk
315 error('Radv requires llvm.')
316 endif
317 else
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 ]
329 endif
330
331 # TODO: make this conditional
332 dep_valgrind = dependency('valgrind', required : false)
333 if dep_valgrind.found() and with_valgrind
334 pre_args += '-DHAVE_VALGRIND'
335 endif
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
343 # 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
372 if 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')
377 else
378 prog_wl_scanner = []
379 dep_wl_protocols = []
380 dep_wayland_client = []
381 dep_wayland_server = []
382 endif
383
384 dep_xcb_dri2 = []
385 dep_xcb_dri3 = []
386 if 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
404 endif
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
437 prog_touch = find_program('touch')
438 dummy_cpp = custom_target(
439 'dummy_cpp',
440 output : 'dummy.cpp',
441 command : [prog_touch, '@OUTPUT@'],
442 )
443
444 foreach a : pre_args
445 add_project_arguments(a, language : ['c', 'cpp'])
446 endforeach
447 foreach a : c_args
448 add_project_arguments(a, language : ['c'])
449 endforeach
450 foreach a : cpp_args
451 add_project_arguments(a, language : ['cpp'])
452 endforeach
453
454 inc_include = include_directories('include')
455
456 subdir('include')
457 subdir('src')