OSDN Git Service

modetest: set atomic cap, _only_ when needed
[android-x86/external-libdrm.git] / meson.build
1 # Copyright © 2017-2018 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(
22   'libdrm',
23   ['c'],
24   version : '2.4.101',
25   license : 'MIT',
26   meson_version : '>= 0.43',
27   default_options : ['buildtype=debugoptimized', 'c_std=gnu99'],
28 )
29
30 pkg = import('pkgconfig')
31
32 config = configuration_data()
33
34 config.set10('UDEV', get_option('udev'))
35 with_freedreno_kgsl = get_option('freedreno-kgsl')
36 with_install_tests = get_option('install-test-programs')
37
38 if ['freebsd', 'dragonfly', 'netbsd'].contains(host_machine.system())
39   dep_pthread_stubs = dependency('pthread-stubs', version : '>= 0.4')
40 else
41   dep_pthread_stubs = []
42 endif
43 dep_threads = dependency('threads')
44
45 cc = meson.get_compiler('c')
46
47 symbols_check = find_program('symbols-check.py')
48 prog_nm = find_program('nm')
49
50 # Check for atomics
51 intel_atomics = false
52 lib_atomics = false
53
54 dep_atomic_ops = dependency('atomic_ops', required : false)
55 if cc.links('''
56     int atomic_add(int *i) { return __sync_add_and_fetch (i, 1); }
57     int atomic_cmpxchg(int *i, int j, int k) { return __sync_val_compare_and_swap (i, j, k); }
58     int main() { }
59     ''',
60     name : 'Intel Atomics')
61   intel_atomics = true
62   with_atomics = true
63   dep_atomic_ops = []
64 elif dep_atomic_ops.found()
65   lib_atomics = true
66   with_atomics = true
67 elif cc.has_function('atomic_cas_uint')
68   with_atomics = true
69 else
70   with_atomics = false
71 endif
72
73 config.set10('HAVE_LIBDRM_ATOMIC_PRIMITIVES', intel_atomics)
74 config.set10('HAVE_LIB_ATOMIC_OPS', lib_atomics)
75
76 with_intel = false
77 _intel = get_option('intel')
78 if _intel != 'false'
79   if _intel == 'true' and not with_atomics
80     error('libdrm_intel requires atomics.')
81   else
82     with_intel = _intel == 'true' or host_machine.cpu_family().startswith('x86')
83   endif
84 endif
85
86 with_radeon = false
87 _radeon = get_option('radeon')
88 if _radeon != 'false'
89   if _radeon == 'true' and not with_atomics
90     error('libdrm_radeon requires atomics.')
91   endif
92   with_radeon = true
93 endif
94
95 with_amdgpu = false
96 _amdgpu = get_option('amdgpu')
97 if _amdgpu != 'false'
98   if _amdgpu == 'true' and not with_atomics
99     error('libdrm_amdgpu requires atomics.')
100   endif
101   with_amdgpu = true
102 endif
103
104 with_nouveau = false
105 _nouveau = get_option('nouveau')
106 if _nouveau != 'false'
107   if _nouveau == 'true' and not with_atomics
108     error('libdrm_nouveau requires atomics.')
109   endif
110   with_nouveau = true
111 endif
112
113 with_vmwgfx = false
114 _vmwgfx = get_option('vmwgfx')
115 if _vmwgfx != 'false'
116   with_vmwgfx = true
117 endif
118
119 with_omap = false
120 _omap = get_option('omap')
121 if _omap == 'true'
122   if not with_atomics
123     error('libdrm_omap requires atomics.')
124   endif
125   with_omap = true
126 endif
127
128 with_freedreno = false
129 _freedreno = get_option('freedreno')
130 if _freedreno != 'false'
131   if _freedreno == 'true' and not with_atomics
132     error('libdrm_freedreno requires atomics.')
133   else
134     with_freedreno = _freedreno == 'true' or ['arm', 'aarch64'].contains(host_machine.cpu_family())
135   endif
136 endif
137
138 with_tegra = false
139 _tegra = get_option('tegra')
140 if _tegra == 'true'
141   if not with_atomics
142     error('libdrm_tegra requires atomics.')
143   endif
144   with_tegra = true
145 endif
146
147 with_etnaviv = false
148 _etnaviv = get_option('etnaviv')
149 if _etnaviv == 'true'
150   if not with_atomics
151     error('libdrm_etnaviv requires atomics.')
152   endif
153   with_etnaviv = true
154 endif
155
156 with_exynos = get_option('exynos') == 'true'
157
158 with_vc4 = false
159 _vc4 = get_option('vc4')
160 if _vc4 != 'false'
161   with_vc4 = _vc4 == 'true' or ['arm', 'aarch64'].contains(host_machine.cpu_family())
162 endif
163
164 # XXX: Apparently only freebsd and dragonfly bsd actually need this (and
165 # gnu/kfreebsd), not openbsd and netbsd
166 with_libkms = false
167 _libkms = get_option('libkms')
168 if _libkms != 'false'
169   with_libkms = _libkms == 'true' or ['linux', 'freebsd', 'dragonfly'].contains(host_machine.system())
170 endif
171
172 # Among others FreeBSD does not have a separate dl library.
173 if not cc.has_function('dlsym')
174   dep_dl = cc.find_library('dl', required : with_nouveau)
175 else
176   dep_dl = []
177 endif
178 # clock_gettime might require -rt, or it might not. find out
179 if not cc.has_function('clock_gettime', prefix : '#define _GNU_SOURCE\n#include <time.h>')
180   # XXX: untested
181   dep_rt = cc.find_library('rt')
182 else
183   dep_rt = []
184 endif
185 dep_m = cc.find_library('m', required : false)
186
187 # The header is not required on Linux, and is in fact deprecated in glibc 2.30+
188 if ['linux'].contains(host_machine.system())
189   config.set10('HAVE_SYS_SYSCTL_H', false)
190 else
191   # From Niclas Zeising:
192   # FreeBSD requires sys/types.h for sys/sysctl.h, so add it as part of
193   # the includes when checking for headers.
194   config.set10('HAVE_SYS_SYSCTL_H',
195     cc.compiles('#include <sys/types.h>\n#include <sys/sysctl.h>', name : 'sys/sysctl.h works'))
196 endif
197
198 foreach header : ['sys/select.h', 'alloca.h']
199   config.set10('HAVE_' + header.underscorify().to_upper(),
200     cc.compiles('#include <@0@>'.format(header), name : '@0@ works'.format(header)))
201 endforeach
202
203 if (cc.has_header_symbol('sys/sysmacros.h', 'major') and
204   cc.has_header_symbol('sys/sysmacros.h', 'minor') and
205   cc.has_header_symbol('sys/sysmacros.h', 'makedev'))
206   config.set10('MAJOR_IN_SYSMACROS', true)
207 endif
208 if (cc.has_header_symbol('sys/mkdev.h', 'major') and
209   cc.has_header_symbol('sys/mkdev.h', 'minor') and
210   cc.has_header_symbol('sys/mkdev.h', 'makedev'))
211   config.set10('MAJOR_IN_MKDEV', true)
212 endif
213 config.set10('HAVE_OPEN_MEMSTREAM', cc.has_function('open_memstream'))
214
215 warn_c_args = []
216 foreach a : ['-Wall', '-Wextra', '-Wsign-compare', '-Werror=undef',
217              '-Werror=implicit-function-declaration', '-Wpointer-arith',
218              '-Wwrite-strings', '-Wstrict-prototypes', '-Wmissing-prototypes',
219              '-Wmissing-declarations', '-Wnested-externs', '-Wpacked',
220              '-Wswitch-enum', '-Wmissing-format-attribute',
221              '-Wstrict-aliasing=2', '-Winit-self', '-Winline', '-Wshadow',
222              '-Wdeclaration-after-statement', '-Wold-style-definition']
223   if cc.has_argument(a)
224     warn_c_args += a
225   endif
226 endforeach
227 # GCC will never error for -Wno-*, so check for -W* then add -Wno-* to the list
228 # of options
229 foreach a : ['unused-parameter', 'attributes', 'long-long',
230              'missing-field-initializers']
231   if cc.has_argument('-W@0@'.format(a))
232     warn_c_args += '-Wno-@0@'.format(a)
233   endif
234 endforeach
235
236 # all c args:
237 libdrm_c_args = warn_c_args + ['-fvisibility=hidden']
238
239
240 dep_pciaccess = dependency('pciaccess', version : '>= 0.10', required : with_intel)
241 dep_cunit = dependency('cunit', version : '>= 2.1', required : false)
242 _cairo_tests = get_option('cairo-tests')
243 if _cairo_tests != 'false'
244   dep_cairo = dependency('cairo', required : _cairo_tests == 'true')
245   with_cairo_tests = dep_cairo.found()
246 else
247   dep_cairo = []
248   with_cairo_tests = false
249 endif
250 _valgrind = get_option('valgrind')
251 if _valgrind != 'false'
252   if with_freedreno
253     dep_valgrind = dependency('valgrind', required : _valgrind == 'true', version : '>=3.10.0')
254   else
255     dep_valgrind = dependency('valgrind', required : _valgrind == 'true')
256   endif
257   with_valgrind = dep_valgrind.found()
258 else
259   dep_valgrind = []
260   with_valgrind = false
261 endif
262
263 with_man_pages = get_option('man-pages')
264 prog_xslt = find_program('xsltproc', required : with_man_pages == 'true')
265 prog_sed = find_program('sed', required : with_man_pages == 'true')
266 manpage_style = 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
267 if prog_xslt.found()
268   if run_command(prog_xslt, '--nonet', manpage_style).returncode() != 0
269     if with_man_pages == 'true'
270       error('Manpage style sheet cannot be found')
271     endif
272     with_man_pages = 'false'
273   endif
274 endif
275 with_man_pages = with_man_pages != 'false' and prog_xslt.found() and prog_sed.found()
276
277 config.set10('HAVE_VISIBILITY',
278   cc.compiles('''int foo_hidden(void) __attribute__((visibility(("hidden"))));''',
279               name : 'compiler supports __attribute__(("hidden"))'))
280
281 foreach t : [
282              [with_exynos, 'EXYNOS'],
283              [with_freedreno_kgsl, 'FREEDRENO_KGSL'],
284              [with_intel, 'INTEL'],
285              [with_nouveau, 'NOUVEAU'],
286              [with_radeon, 'RADEON'],
287              [with_vc4, 'VC4'],
288              [with_vmwgfx, 'VMWGFX'],
289              [with_cairo_tests, 'CAIRO'],
290              [with_valgrind, 'VALGRIND'],
291             ]
292   config.set10('HAVE_@0@'.format(t[1]), t[0])
293 endforeach
294 if with_freedreno_kgsl and not with_freedreno
295   error('cannot enable freedreno-kgsl without freedreno support')
296 endif
297 config.set10('_GNU_SOURCE', true)
298 config_file = configure_file(
299   configuration : config,
300   output : 'config.h',
301 )
302 add_project_arguments('-include', '@0@'.format(config_file), language : 'c')
303
304 inc_root = include_directories('.')
305 inc_drm = include_directories('include/drm')
306
307 libdrm = shared_library(
308   'drm',
309   [files(
310      'xf86drm.c', 'xf86drmHash.c', 'xf86drmRandom.c', 'xf86drmSL.c',
311      'xf86drmMode.c'
312    ),
313    config_file,
314   ],
315   c_args : libdrm_c_args,
316   dependencies : [dep_valgrind, dep_rt, dep_m],
317   include_directories : inc_drm,
318   version : '2.4.0',
319   install : true,
320 )
321
322 test(
323   'core-symbols-check',
324   symbols_check,
325   args : [
326     '--lib', libdrm,
327     '--symbols-file', files('core-symbols.txt'),
328     '--nm', prog_nm.path(),
329   ],
330 )
331
332 ext_libdrm = declare_dependency(
333   link_with : libdrm,
334   include_directories : [inc_root, inc_drm],
335 )
336
337 install_headers('libsync.h', 'xf86drm.h', 'xf86drmMode.h')
338 install_headers(
339   'include/drm/drm.h', 'include/drm/drm_fourcc.h', 'include/drm/drm_mode.h',
340   'include/drm/drm_sarea.h', 'include/drm/i915_drm.h',
341   'include/drm/mach64_drm.h', 'include/drm/mga_drm.h',
342   'include/drm/msm_drm.h', 'include/drm/nouveau_drm.h',
343   'include/drm/qxl_drm.h', 'include/drm/r128_drm.h',
344   'include/drm/radeon_drm.h', 'include/drm/amdgpu_drm.h',
345   'include/drm/savage_drm.h', 'include/drm/sis_drm.h',
346   'include/drm/tegra_drm.h', 'include/drm/vc4_drm.h',
347   'include/drm/via_drm.h', 'include/drm/virtgpu_drm.h',
348   subdir : 'libdrm',
349 )
350 if with_vmwgfx
351   install_headers('include/drm/vmwgfx_drm.h', subdir : 'libdrm')
352 endif
353
354 pkg.generate(
355   name : 'libdrm',
356   libraries : libdrm,
357   subdirs : ['.', 'libdrm'],
358   version : meson.project_version(),
359   description : 'Userspace interface to kernel DRM services',
360 )
361
362 if with_libkms
363   subdir('libkms')
364 endif
365 if with_intel
366   subdir('intel')
367 endif
368 if with_nouveau
369   subdir('nouveau')
370 endif
371 if with_radeon
372   subdir('radeon')
373 endif
374 if with_amdgpu
375   subdir('amdgpu')
376 endif
377 if with_omap
378   subdir('omap')
379 endif
380 if with_exynos
381   subdir('exynos')
382 endif
383 if with_freedreno
384   subdir('freedreno')
385 endif
386 if with_tegra
387   subdir('tegra')
388 endif
389 if with_vc4
390   subdir('vc4')
391 endif
392 if with_etnaviv
393   subdir('etnaviv')
394 endif
395 if with_man_pages
396   subdir('man')
397 endif
398 subdir('data')
399 subdir('tests')
400
401 message('')
402 message('@0@ will be compiled with:'.format(meson.project_name()))
403 message('')
404 message('  libkms         @0@'.format(with_libkms))
405 message('  Intel API      @0@'.format(with_intel))
406 message('  vmwgfx API     @0@'.format(with_vmwgfx))
407 message('  Radeon API     @0@'.format(with_radeon))
408 message('  AMDGPU API     @0@'.format(with_amdgpu))
409 message('  Nouveau API    @0@'.format(with_nouveau))
410 message('  OMAP API       @0@'.format(with_omap))
411 message('  EXYNOS API     @0@'.format(with_exynos))
412 message('  Freedreno API  @0@ (kgsl: @1@)'.format(with_freedreno, with_freedreno_kgsl))
413 message('  Tegra API      @0@'.format(with_tegra))
414 message('  VC4 API        @0@'.format(with_vc4))
415 message('  Etnaviv API    @0@'.format(with_etnaviv))
416 message('')