OSDN Git Service

gitlab-ci: add PowerPC build
[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.100',
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.compiles('''
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     ''',
59     name : 'Intel Atomics')
60   intel_atomics = true
61   with_atomics = true
62   dep_atomic_ops = []
63 elif dep_atomic_ops.found()
64   lib_atomics = true
65   with_atomics = true
66 elif cc.has_function('atomic_cas_uint')
67   with_atomics = true
68 else
69   with_atomics = false
70 endif
71
72 config.set10('HAVE_LIBDRM_ATOMIC_PRIMITIVES', intel_atomics)
73 config.set10('HAVE_LIB_ATOMIC_OPS', lib_atomics)
74
75 with_intel = false
76 _intel = get_option('intel')
77 if _intel != 'false'
78   if _intel == 'true' and not with_atomics
79     error('libdrm_intel requires atomics.')
80   else
81     with_intel = _intel == 'true' or host_machine.cpu_family().startswith('x86')
82   endif
83 endif
84
85 with_radeon = false
86 _radeon = get_option('radeon')
87 if _radeon != 'false'
88   if _radeon == 'true' and not with_atomics
89     error('libdrm_radeon requires atomics.')
90   endif
91   with_radeon = true
92 endif
93
94 with_amdgpu = false
95 _amdgpu = get_option('amdgpu')
96 if _amdgpu != 'false'
97   if _amdgpu == 'true' and not with_atomics
98     error('libdrm_amdgpu requires atomics.')
99   endif
100   with_amdgpu = true
101 endif
102
103 with_nouveau = false
104 _nouveau = get_option('nouveau')
105 if _nouveau != 'false'
106   if _nouveau == 'true' and not with_atomics
107     error('libdrm_nouveau requires atomics.')
108   endif
109   with_nouveau = true
110 endif
111
112 with_vmwgfx = false
113 _vmwgfx = get_option('vmwgfx')
114 if _vmwgfx != 'false'
115   with_vmwgfx = true
116 endif
117
118 with_omap = false
119 _omap = get_option('omap')
120 if _omap == 'true'
121   if not with_atomics
122     error('libdrm_omap requires atomics.')
123   endif
124   with_omap = true
125 endif
126
127 with_freedreno = false
128 _freedreno = get_option('freedreno')
129 if _freedreno != 'false'
130   if _freedreno == 'true' and not with_atomics
131     error('libdrm_freedreno requires atomics.')
132   else
133     with_freedreno = _freedreno == 'true' or ['arm', 'aarch64'].contains(host_machine.cpu_family())
134   endif
135 endif
136
137 with_tegra = false
138 _tegra = get_option('tegra')
139 if _tegra == 'true'
140   if not with_atomics
141     error('libdrm_tegra requires atomics.')
142   endif
143   with_tegra = true
144 endif
145
146 with_etnaviv = false
147 _etnaviv = get_option('etnaviv')
148 if _etnaviv == 'true'
149   if not with_atomics
150     error('libdrm_etnaviv requires atomics.')
151   endif
152   with_etnaviv = true
153 endif
154
155 with_exynos = get_option('exynos') == 'true'
156
157 with_vc4 = false
158 _vc4 = get_option('vc4')
159 if _vc4 != 'false'
160   with_vc4 = _vc4 == 'true' or ['arm', 'aarch64'].contains(host_machine.cpu_family())
161 endif
162
163 # XXX: Apparently only freebsd and dragonfly bsd actually need this (and
164 # gnu/kfreebsd), not openbsd and netbsd
165 with_libkms = false
166 _libkms = get_option('libkms')
167 if _libkms != 'false'
168   with_libkms = _libkms == 'true' or ['linux', 'freebsd', 'dragonfly'].contains(host_machine.system())
169 endif
170
171 # Among others FreeBSD does not have a separate dl library.
172 if not cc.has_function('dlsym')
173   dep_dl = cc.find_library('dl', required : with_nouveau)
174 else
175   dep_dl = []
176 endif
177 # clock_gettime might require -rt, or it might not. find out
178 if not cc.has_function('clock_gettime', prefix : '#define _GNU_SOURCE\n#include <time.h>')
179   # XXX: untested
180   dep_rt = cc.find_library('rt')
181 else
182   dep_rt = []
183 endif
184 dep_m = cc.find_library('m', required : false)
185 # From Niclas Zeising:
186 # FreeBSD requires sys/types.h for sys/sysctl.h, add it as part of the
187 # includes when checking for headers.
188 foreach header : ['sys/sysctl.h', 'sys/select.h', 'alloca.h']
189   config.set('HAVE_' + header.underscorify().to_upper(),
190     cc.compiles('#include <sys/types.h>\n#include <@0@>'.format(header), name : '@0@ works'.format(header)))
191 endforeach
192 if (cc.has_header_symbol('sys/sysmacros.h', 'major') and
193   cc.has_header_symbol('sys/sysmacros.h', 'minor') and
194   cc.has_header_symbol('sys/sysmacros.h', 'makedev'))
195   config.set10('MAJOR_IN_SYSMACROS', true)
196 endif
197 if (cc.has_header_symbol('sys/mkdev.h', 'major') and
198   cc.has_header_symbol('sys/mkdev.h', 'minor') and
199   cc.has_header_symbol('sys/mkdev.h', 'makedev'))
200   config.set10('MAJOR_IN_MKDEV', true)
201 endif
202 config.set10('HAVE_OPEN_MEMSTREAM', cc.has_function('open_memstream'))
203
204 warn_c_args = []
205 foreach a : ['-Wall', '-Wextra', '-Wsign-compare', '-Werror=undef',
206              '-Werror=implicit-function-declaration', '-Wpointer-arith',
207              '-Wwrite-strings', '-Wstrict-prototypes', '-Wmissing-prototypes',
208              '-Wmissing-declarations', '-Wnested-externs', '-Wpacked',
209              '-Wswitch-enum', '-Wmissing-format-attribute',
210              '-Wstrict-aliasing=2', '-Winit-self', '-Winline', '-Wshadow',
211              '-Wdeclaration-after-statement', '-Wold-style-definition']
212   if cc.has_argument(a)
213     warn_c_args += a
214   endif
215 endforeach
216 # GCC will never error for -Wno-*, so check for -W* then add -Wno-* to the list
217 # of options
218 foreach a : ['unused-parameter', 'attributes', 'long-long',
219              'missing-field-initializers']
220   if cc.has_argument('-W@0@'.format(a))
221     warn_c_args += '-Wno-@0@'.format(a)
222   endif
223 endforeach
224
225 # all c args:
226 libdrm_c_args = warn_c_args + ['-fvisibility=hidden']
227
228
229 dep_pciaccess = dependency('pciaccess', version : '>= 0.10', required : with_intel)
230 dep_cunit = dependency('cunit', version : '>= 2.1', required : false)
231 _cairo_tests = get_option('cairo-tests')
232 if _cairo_tests != 'false'
233   dep_cairo = dependency('cairo', required : _cairo_tests == 'true')
234   with_cairo_tests = dep_cairo.found()
235 else
236   dep_cairo = []
237   with_cairo_tests = false
238 endif
239 _valgrind = get_option('valgrind')
240 if _valgrind != 'false'
241   dep_valgrind = dependency('valgrind', required : _valgrind == 'true')
242   with_valgrind = dep_valgrind.found()
243 else
244   dep_valgrind = []
245   with_valgrind = false
246 endif
247
248 with_man_pages = get_option('man-pages')
249 prog_xslt = find_program('xsltproc', required : with_man_pages == 'true')
250 prog_sed = find_program('sed', required : with_man_pages == 'true')
251 manpage_style = 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
252 if prog_xslt.found()
253   if run_command(prog_xslt, '--nonet', manpage_style).returncode() != 0
254     if with_man_pages == 'true'
255       error('Manpage style sheet cannot be found')
256     endif
257     with_man_pages = 'false'
258   endif
259 endif
260 with_man_pages = with_man_pages != 'false' and prog_xslt.found() and prog_sed.found()
261
262 config.set10('HAVE_VISIBILITY',
263   cc.compiles('''int foo_hidden(void) __attribute__((visibility(("hidden"))));''',
264               name : 'compiler supports __attribute__(("hidden"))'))
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('-include', '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 : libdrm_c_args,
301   dependencies : [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/msm_drm.h', 'include/drm/nouveau_drm.h',
318   'include/drm/qxl_drm.h', 'include/drm/r128_drm.h',
319   'include/drm/radeon_drm.h', 'include/drm/amdgpu_drm.h',
320   'include/drm/savage_drm.h', 'include/drm/sis_drm.h',
321   'include/drm/tegra_drm.h', 'include/drm/vc4_drm.h',
322   'include/drm/via_drm.h', 'include/drm/virtgpu_drm.h',
323   subdir : 'libdrm',
324 )
325 if with_vmwgfx
326   install_headers('include/drm/vmwgfx_drm.h', subdir : 'libdrm')
327 endif
328
329 pkg.generate(
330   name : 'libdrm',
331   libraries : libdrm,
332   subdirs : ['.', 'libdrm'],
333   version : meson.project_version(),
334   description : 'Userspace interface to kernel DRM services',
335 )
336
337 if with_libkms
338   subdir('libkms')
339 endif
340 if with_intel
341   subdir('intel')
342 endif
343 if with_nouveau
344   subdir('nouveau')
345 endif
346 if with_radeon
347   subdir('radeon')
348 endif
349 if with_amdgpu
350   subdir('amdgpu')
351 endif
352 if with_omap
353   subdir('omap')
354 endif
355 if with_exynos
356   subdir('exynos')
357 endif
358 if with_freedreno
359   subdir('freedreno')
360 endif
361 if with_tegra
362   subdir('tegra')
363 endif
364 if with_vc4
365   subdir('vc4')
366 endif
367 if with_etnaviv
368   subdir('etnaviv')
369 endif
370 if with_man_pages
371   subdir('man')
372 endif
373 subdir('data')
374 subdir('tests')
375
376 message('')
377 message('@0@ will be compiled with:'.format(meson.project_name()))
378 message('')
379 message('  libkms         @0@'.format(with_libkms))
380 message('  Intel API      @0@'.format(with_intel))
381 message('  vmwgfx API     @0@'.format(with_vmwgfx))
382 message('  Radeon API     @0@'.format(with_radeon))
383 message('  AMDGPU API     @0@'.format(with_amdgpu))
384 message('  Nouveau API    @0@'.format(with_nouveau))
385 message('  OMAP API       @0@'.format(with_omap))
386 message('  EXYNOS API     @0@'.format(with_exynos))
387 message('  Freedreno API  @0@ (kgsl: @1@)'.format(with_freedreno, with_freedreno_kgsl))
388 message('  Tegra API      @0@'.format(with_tegra))
389 message('  VC4 API        @0@'.format(with_vc4))
390 message('  Etnaviv API    @0@'.format(with_etnaviv))
391 message('')