meson.build revision 00a23bda
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
21project(
22  'libdrm',
23  ['c'],
24  version : '2.4.91',
25  license : 'MIT',
26  meson_version : '>= 0.43',
27  default_options : ['buildtype=debugoptimized', 'c_std=gnu99'],
28)
29
30pkg = import('pkgconfig')
31
32with_udev = get_option('udev')
33with_freedreno_kgsl = get_option('freedreno-kgsl')
34with_install_tests = get_option('install-test-programs')
35
36config = configuration_data()
37
38if ['freebsd', 'dragonfly', 'netbsd'].contains(host_machine.system())
39  dep_pthread_stubs = dependency('pthread-stubs', version : '>= 0.4')
40else
41  dep_pthread_stubs = []
42endif
43dep_threads = dependency('threads')
44
45cc = meson.get_compiler('c')
46
47# Check for atomics
48intel_atomics = false
49lib_atomics = false
50
51if 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
58elif cc.has_header('atomic_ops.h')
59  lib_atomics = true
60  with_atomics = true
61elif cc.has_function('atomic_cas_uint')
62  with_atomics = true
63else
64  with_atomics = false
65endif
66
67config.set10('HAVE_LIBDRM_ATOMIC_PRIMITIVES', intel_atomics)
68config.set10('HAVE_LIB_ATOMIC_OPS', lib_atomics)
69
70with_intel = false
71_intel = get_option('intel')
72if _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
78endif
79
80with_radeon = false
81_radeon = get_option('radeon')
82if _radeon != 'false'
83  if _radeon == 'true' and not with_atomics
84    error('libdrm_radeon requires atomics.')
85  endif
86  with_radeon = true
87endif
88
89with_amdgpu = false
90_amdgpu = get_option('amdgpu')
91if _amdgpu != 'false'
92  if _amdgpu == 'true' and not with_atomics
93    error('libdrm_amdgpu requires atomics.')
94  endif
95  with_amdgpu = true
96endif
97
98with_nouveau = false
99_nouveau = get_option('nouveau')
100if _nouveau != 'false'
101  if _nouveau == 'true' and not with_atomics
102    error('libdrm_nouveau requires atomics.')
103  endif
104  with_nouveau = true
105endif
106
107with_vmwgfx = false
108_vmwgfx = get_option('vmwgfx')
109if _vmwgfx != 'false'
110  with_vmwgfx = true
111endif
112
113with_omap = false
114_omap = get_option('omap')
115if _omap == 'true'
116  if not with_atomics
117    error('libdrm_omap requires atomics.')
118  endif
119  with_omap = true
120endif
121
122with_freedreno = false
123_freedreno = get_option('freedreno')
124if _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
130endif
131
132with_tegra = false
133_tegra = get_option('tegra')
134if _tegra == 'true'
135  if not with_atomics
136    error('libdrm_tegra requires atomics.')
137  endif
138  with_tegra = true
139endif
140
141with_etnaviv = false
142_etnaviv = get_option('etnaviv')
143if _etnaviv == 'true'
144  if not with_atomics
145    error('libdrm_etnaviv requires atomics.')
146  endif
147  with_etnaviv = true
148endif
149
150with_exynos = get_option('exynos') == 'true'
151
152with_vc4 = false
153_vc4 = get_option('vc4')
154if _vc4 != 'false'
155  with_vc4 = _vc4 == 'true' or ['arm', 'aarch64'].contains(host_machine.cpu_family())
156endif
157
158# XXX: Aparently only freebsd and dragonfly bsd actually need this (and
159# gnu/kfreebsd), not openbsd and netbsd
160with_libkms = false
161_libkms = get_option('libkms')
162if _libkms != 'false'
163  with_libkms = _libkms == 'true' or ['linux', 'freebsd', 'dragonfly'].contains(host_machine.system())
164endif
165
166if with_udev
167  dep_udev = dependency('udev')
168  config.set10('UDEV', true)
169else
170  dep_udev = []
171endif
172
173# Among others FreeBSD does not have a separate dl library.
174if not cc.has_function('dlsym')
175  dep_dl = cc.find_library('dl', required : with_nouveau)
176else
177  dep_dl = []
178endif
179# clock_gettime might require -rt, or it might not. find out
180if not cc.has_function('clock_gettime', prefix : '#define _GNU_SOURCE\n#include <time.h>')
181  # XXX: untested
182  dep_rt = cc.find_library('rt')
183else
184  dep_rt = []
185endif
186dep_m = cc.find_library('m', required : false)
187if cc.has_header('sys/sysctl.h')
188  config.set10('HAVE_SYS_SYSCTL_H', true)
189endif
190if cc.has_header('sys/select.h')
191  config.set10('HAVE_SYS_SELECT_H', true)
192endif
193if cc.has_header_symbol('sys/sysmacros.h', 'major')
194  config.set10('MAJOR_IN_SYSMACROS', true)
195elif cc.has_header_symbol('sys/mkdev.h', 'major')
196  config.set10('MAJOR_IN_MKDEV', true)
197endif
198if cc.has_function('open_memstream')
199  config.set10('HAVE_OPEN_MEMSTREAM', true)
200endif
201
202warn_c_args = []
203foreach 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
213endforeach
214# GCC will never error for -Wno-*, so check for -W* then add -Wno-* to the list
215# of options
216foreach 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
221endforeach
222
223
224dep_pciaccess = dependency('pciaccess', version : '>= 0.10', required : with_intel)
225dep_cunit = dependency('cunit', version : '>= 2.1', required : false)
226_cairo_tests = get_option('cairo-tests')
227if _cairo_tests != 'false'
228  dep_cairo = dependency('cairo', required : _cairo_tests == 'true')
229  with_cairo_tests = dep_cairo.found()
230else
231  dep_cairo = []
232  with_cairo_tests = false
233endif
234_valgrind = get_option('valgrind')
235if _valgrind != 'false'
236  dep_valgrind = dependency('valgrind', required : _valgrind == 'true')
237  with_valgrind = dep_valgrind.found()
238else
239  dep_valgrind = []
240  with_valgrind = false
241endif
242
243with_man_pages = get_option('man-pages')
244prog_xslt = find_program('xsltproc', required : with_man_pages == 'true')
245prog_sed = find_program('sed', required : with_man_pages == 'true')
246manpage_style = 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
247if 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
254endif
255with_man_pages = with_man_pages != 'false' and prog_xslt.found() and prog_sed.found()
256
257# Used for tets
258prog_bash = find_program('bash')
259
260if cc.compiles('''int foo_hidden(void) __attribute__((visibility(("hidden"))));''',
261               name : 'compiler supports __attribute__(("hidden"))')
262  config.set10('HAVE_VISIBILITY', true)
263endif
264
265foreach 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])
277endforeach
278if with_freedreno_kgsl and not with_freedreno
279  error('cannot enable freedreno-kgsl without freedreno support')
280endif
281config.set10('_GNU_SOURCE', true)
282config_file = configure_file(
283  configuration : config,
284  output : 'config.h',
285)
286add_project_arguments('-DHAVE_CONFIG_H', language : 'c')
287
288inc_root = include_directories('.')
289inc_drm = include_directories('include/drm')
290
291libdrm = 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
306ext_libdrm = declare_dependency(
307  link_with : libdrm,
308  include_directories : [inc_root, inc_drm],
309)
310
311install_headers('libsync.h', 'xf86drm.h', 'xf86drmMode.h')
312install_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)
323if with_vmwgfx
324  install_headers('include/drm/vmwgfx_drm.h', subdir : 'libdrm')
325endif
326
327pkg.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
335env_test = environment()
336env_test.set('NM', find_program('nm').path())
337
338if with_libkms
339  subdir('libkms')
340endif
341if with_intel
342  subdir('intel')
343endif
344if with_nouveau
345  subdir('nouveau')
346endif
347if with_radeon
348  subdir('radeon')
349endif
350if with_amdgpu
351  subdir('amdgpu')
352endif
353if with_omap
354  subdir('omap')
355endif
356if with_exynos
357  subdir('exynos')
358endif
359if with_freedreno
360  subdir('freedreno')
361endif
362if with_tegra
363  subdir('tegra')
364endif
365if with_vc4
366  subdir('vc4')
367endif
368if with_etnaviv
369  subdir('etnaviv')
370endif
371if with_man_pages
372  subdir('man')
373endif
374subdir('data')
375subdir('tests')
376
377message('')
378message('@0@ will be compiled with:'.format(meson.project_name()))
379message('')
380message('  libkms         @0@'.format(with_libkms))
381message('  Intel API      @0@'.format(with_intel))
382message('  vmwgfx API     @0@'.format(with_vmwgfx))
383message('  Radeon API     @0@'.format(with_radeon))
384message('  AMDGPU API     @0@'.format(with_amdgpu))
385message('  Nouveau API    @0@'.format(with_nouveau))
386message('  OMAP API       @0@'.format(with_omap))
387message('  EXYNOS API     @0@'.format(with_exynos))
388message('  Freedreno API  @0@ (kgsl: @1@)'.format(with_freedreno, with_freedreno_kgsl))
389message('  Tegra API      @0@'.format(with_tegra))
390message('  VC4 API        @0@'.format(with_vc4))
391message('  Etnaviv API    @0@'.format(with_etnaviv))
392message('')
393