OSDN Git Service

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