OSDN Git Service

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