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