blob: 5353a4174849334b6db5a7f027543e937e413868 [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
25with_vulkan_icd_dir = get_option('vulkan_icd_dir')
26with_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')
56
57cc = meson.get_compiler('c')
58if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
59 error('When using GCC version 4.2.0 or later required.')
60endif
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++.
65pre_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
70if get_option('buildtype').startswith('debug')
71 pre_args += '-DDEBUG'
72endif
73
Dylan Baker673dda82017-09-20 11:53:29 -070074if get_option('shader-cache')
75 pre_args += '-DENABLE_SHADER_CACHE'
76elif with_amd_vk
77 error('Radv requires shader cache support')
78endif
79
Dylan Bakerd1992252017-09-14 17:57:17 -070080# Check for GCC style builtins
81foreach 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
86endforeach
87
Dylan Baker673dda82017-09-20 11:53:29 -070088# check for GCC __attribute__
Dylan Bakerd1992252017-09-14 17:57:17 -070089foreach 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
95endforeach
96if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
97 name : '__attribute__((format(...)))')
98 pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
99endif
100if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
101 name : '__attribute__((packed))')
102 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
103endif
104if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
105 name : '__attribute__((returns_nonnull))')
106 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NONNULL'
107endif
108if 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'
114endif
115if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
116 name : '__attribute__((alias(...)))')
117 pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
118endif
119
120# TODO: this is very incomplete
121if host_machine.system() == 'linux'
122 pre_args += '-D_GNU_SOURCE'
123endif
124
125# Check for generic C arguments
126c_args = []
127foreach 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
133endforeach
134c_vis_args = []
135if cc.has_argument('-fvisibility=hidden')
136 c_vis_args += '-fvisibility=hidden'
137endif
138
139# Check for generic C++ arguments
140cpp = meson.get_compiler('cpp')
141cpp_args = []
142foreach 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
147endforeach
148cpp_vis_args = []
149if cpp.has_argument('-fvisibility=hidden')
150 cpp_vis_args += '-fvisibility=hidden'
151endif
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
156c_msvc_compat_args = []
157cpp_msvc_compat_args = []
158foreach 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
165endforeach
166
167no_override_init_args = []
168foreach a : ['-Wno-override-init', '-Wno-initializer-overrides']
169 if cc.has_argument(a)
170 no_override_init_args += a
171 endif
172endforeach
173
174# TODO: SSE41 (which is only required for core mesa)
175
176# Check for GCC style atomics
177if 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'
180endif
181if 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'
188endif
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
206if cc.has_header_symbol('sys/sysmacros.h', 'major')
207 pre_args += '-DMAJOR_IN_SYSMACROS'
208elif cc.has_header_symbol('sys/mkdev.h', 'major')
209 pre_args += '-DMAJOR_IN_MKDEV'
210endif
211
212foreach h : ['xlocale.h', 'sys/sysctl.h']
213 if cc.has_header(h)
214 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
215 endif
216endforeach
217
218foreach f : ['strtof', 'mkostemp', 'posix_memalign']
219 if cc.has_function(f)
220 pre_args += '-DHAVE_@0@'.format(f.to_upper())
221 endif
222endforeach
223
224# strtod locale support
225if 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'
244endif
245
246# Check for some linker flags
247ld_args_bsymbolic = []
248if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic')
249 ld_args_bsymbolic += '-Wl,-Bsymbolic'
250endif
251ld_args_gc_sections = []
252if cc.links('static char unused() { return 5; } int main() { return 0; }',
253 args : '-Wl,--gc-sections')
254 ld_args_gc_sections += '-Wl,--gc-sections'
255endif
256
257# check for dl support
258if cc.has_function('dlopen')
259 dep_dl = []
260else
261 dep_dl = cc.find_library('dl')
262endif
263pre_args += '-DHAVE_DLOPEN'
264
265if not cc.has_function('dladdr', dependencies : dep_dl)
266 error('dl library doesn\'t have dladdr')
267endif
268
269if cc.has_function('dl_iterate_phdr')
270 pre_args += '-DHAVE_DL_ITERATE_PHDR'
271else
272 # TODO: this is required for vulkan
273endif
274
275# Determine whether or not the rt library is needed for time functions
276if cc.has_function('clock_gettime')
277 dep_clock = []
278else
279 dep_clock = cc.find_library('rt')
280endif
281
282# TODO: some of these may be conditional
283dep_zlib = dependency('zlib', version : '>= 1.2.3')
284dep_thread = dependency('threads')
285pre_args += '-DHAVE_PTHREAD'
286dep_elf = dependency('libelf')
287dep_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
290dep_m = cc.find_library('m', required : false)
291
292# TODO: conditionalize libdrm requirement
293dep_libdrm = dependency('libdrm', version : '>= 2.4.75')
294pre_args += '-DHAVE_LIBDRM'
Dylan Baker673dda82017-09-20 11:53:29 -0700295dep_libdrm_amdgpu = []
296if with_amd_vk
297 dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.82')
298endif
299
300llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
301if with_amd_vk
302 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
303endif
304dep_llvm = dependency(
305 'llvm', version : '>= 3.9.0', required : false, modules : llvm_modules,
306)
307if not dep_llvm.found()
308 if with_amd_vk
309 error('Radv requires llvm.')
310 endif
311else
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 ]
323endif
Dylan Bakerd1992252017-09-14 17:57:17 -0700324
325# TODO: make this conditional
326dep_valgrind = dependency('valgrind', required : false)
327if dep_valgrind.found() and with_valgrind
328 pre_args += '-DHAVE_VALGRIND'
329endif
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
Dylan Bakerd1992252017-09-14 17:57:17 -0700337# 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
366if 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')
371else
372 prog_wl_scanner = []
373 dep_wl_protocols = []
374 dep_wayland_client = []
375 dep_wayland_server = []
376endif
377
378dep_xcb_dri2 = []
379dep_xcb_dri3 = []
380if 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
398endif
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
431prog_touch = find_program('touch')
432dummy_cpp = custom_target(
433 'dummy_cpp',
434 output : 'dummy.cpp',
435 command : [prog_touch, '@OUTPUT@'],
436)
437
438foreach a : pre_args
439 add_project_arguments(a, language : ['c', 'cpp'])
440endforeach
441foreach a : c_args
442 add_project_arguments(a, language : ['c'])
443endforeach
444foreach a : cpp_args
445 add_project_arguments(a, language : ['cpp'])
446endforeach
447
448inc_include = include_directories('include')
449
450subdir('include')
451subdir('src')