1 # Copyright © 2017-2018 Intel Corporation
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:
10 # The above copyright notice and this permission notice shall be included in
11 # all copies or substantial portions of the Software.
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
26 meson_version : '>= 0.43',
27 default_options : ['buildtype=debugoptimized', 'c_std=gnu99'],
30 pkg = import('pkgconfig')
32 with_udev = get_option('udev')
33 with_freedreno_kgsl = get_option('freedreno-kgsl')
34 with_install_tests = get_option('install-test-programs')
35 with_cairo_tests = get_option('cairo-tests')
36 with_valgrind = get_option('valgrind')
38 config = configuration_data()
40 # TODO: openbsd is guess, the others are correct
41 if ['freebsd', 'dragonfly', 'netbsd', 'openbsd'].contains(host_machine.system())
42 dep_pthread_stubs = dependency('pthread-stubs', version : '>= 0.4')
44 dep_pthread_stubs = []
46 dep_threads = dependency('threads')
48 cc = meson.get_compiler('c')
55 int atomic_add(int *i) { return __sync_add_and_fetch (i, 1); }
56 int atomic_cmpxchg(int *i, int j, int k) { return __sync_val_compare_and_swap (i, j, k); }
58 name : 'Intel Atomics')
61 elif cc.has_header('atomic_ops.h')
64 elif cc.has_function('atomic_cas_uint')
70 config.set10('HAVE_LIBDRM_ATOMIC_PRIMITIVES', intel_atomics)
71 config.set10('HAVE_LIB_ATOMIC_OPS', lib_atomics)
74 _intel = get_option('intel')
76 if _intel == 'true' and not with_atomics
77 error('libdrm_intel requires atomics.')
79 with_intel = _intel == 'true' or host_machine.cpu_family().startswith('x86')
84 _radeon = get_option('radeon')
86 if _radeon == 'true' and not with_atomics
87 error('libdrm_radeon requires atomics.')
93 _amdgpu = get_option('amdgpu')
95 if _amdgpu == 'true' and not with_atomics
96 error('libdrm_amdgpu requires atomics.')
102 _nouveau = get_option('nouveau')
103 if _nouveau != 'false'
104 if _nouveau == 'true' and not with_atomics
105 error('libdrm_nouveau requires atomics.')
111 _vmwgfx = get_option('vmwgfx')
112 if _vmwgfx != 'false'
117 _omap = get_option('omap')
120 error('libdrm_omap requires atomics.')
125 with_freedreno = false
126 _freedreno = get_option('freedreno')
127 if _freedreno != 'false'
128 if _freedreno == 'true' and not with_atomics
129 error('libdrm_freedreno requires atomics.')
131 with_freedreno = _freedreno == 'true' or ['arm', 'aarch64'].contains(host_machine.cpu_family())
136 _tegra = get_option('tegra')
139 error('libdrm_tegra requires atomics.')
145 _etnaviv = get_option('etnaviv')
146 if _etnaviv == 'true'
148 error('libdrm_etnaviv requires atomics.')
153 with_exynos = get_option('exynos') == 'true'
156 _vc4 = get_option('vc4')
158 with_vc4 = _vc4 == 'true' or ['arm', 'aarch64'].contains(host_machine.cpu_family())
161 # XXX: Aparently only freebsd and dragonfly bsd actually need this (and
162 # gnu/kfreebsd), not openbsd and netbsd
164 _libkms = get_option('libkms')
165 if _libkms != 'false'
166 with_libkms = _libkms == 'true' or ['linux', 'freebsd', 'dragonfly'].contains(host_machine.system())
170 dep_udev = dependency('udev')
171 config.set10('UDEV', true)
176 # Among others FreeBSD does not have a separate dl library.
177 if not cc.has_function('dlsym')
178 dep_dl = cc.find_library('dl', required : with_nouveau)
182 # clock_gettime might require -rt, or it might not. find out
183 if not cc.has_function('clock_gettime', prefix : '#define _GNU_SOURCE\n#include <time.h>')
185 dep_rt = cc.find_library('rt')
189 dep_m = cc.find_library('m', required : false)
190 if cc.has_header('sys/sysctl.h')
191 config.set10('HAVE_SYS_SYSCTL_H', true)
193 if cc.has_header('sys/select.h')
194 config.set10('HAVE_SYS_SELECT_H', true)
196 if cc.has_header_symbol('sys/sysmacros.h', 'major')
197 config.set10('MAJOR_IN_SYSMACROS', true)
198 elif cc.has_header_symbol('sys/mkdev.h', 'major')
199 config.set10('MAJOR_IN_MKDEV', true)
201 if cc.has_function('open_memstream')
202 config.set10('HAVE_OPEN_MEMSTREAM', true)
206 foreach a : ['-Wall', '-Wextra', '-Wsign-compare',
207 '-Werror-implicit-function-declaration', '-Wpointer-arith',
208 '-Wwrite-strings', '-Wstrict-prototypes', '-Wmissing-prototypes',
209 '-Wmissing-declarations', '-Wnested-externs', '-Wpacked',
210 '-Wswitch-enum', '-Wmissing-format-attribute',
211 '-Wstrict-aliasing=2', '-Winit-self', '-Winline', '-Wshadow',
212 '-Wdeclaration-after-statement', '-Wold-style-definition']
213 if cc.has_argument(a)
217 # GCC will never error for -Wno-*, so check for -W* then add -Wno-* to the list
219 foreach a : ['unused-parameter', 'attributes', 'long-long',
220 'missing-field-initializers']
221 if cc.has_argument('-W@0@'.format(a))
222 warn_c_args += '-Wno-@0@'.format(a)
227 dep_pciaccess = dependency('pciaccess', version : '>= 0.10', required : with_intel)
228 dep_cunit = dependency('cunit', version : '>= 2.1', required : false)
229 dep_cairo = dependency('cairo', required : with_cairo_tests == 'true')
230 dep_valgrind = dependency('valgrind', required : with_valgrind == 'true')
232 with_man_pages = get_option('man-pages')
233 prog_xslt = find_program('xsltproc', required : with_man_pages == 'true')
234 prog_sed = find_program('sed', required : with_man_pages == 'true')
235 manpage_style = 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
237 if run_command(prog_xslt, '--nonet', manpage_style).returncode() != 0
238 if with_man_pages == 'true'
239 error('Manpage style sheet cannot be found')
241 with_man_pages = 'false'
244 with_man_pages = with_man_pages != 'false' and prog_xslt.found() and prog_sed.found()
247 prog_bash = find_program('bash')
249 if cc.compiles('''int foo_hidden(void) __attribute__((visibility(("hidden"))));''',
250 name : 'compiler supports __attribute__(("hidden"))')
251 config.set10('HAVE_VISIBILITY', true)
254 foreach t : [[with_intel, 'INTEL'], [with_vmwgfx, 'VMWGFX'],
255 [with_nouveau, 'NOUVEAU'],
256 [with_exynos, 'EXYNOS'],
258 [with_radeon, 'RADEON']]
260 config.set10('HAVE_@0@'.format(t[1]), true)
263 if with_freedreno_kgsl
264 if not with_freedreno
265 error('cannot enable freedreno-kgsl without freedreno support')
267 config.set10('HAVE_FREEDRENO_KGSL', true)
270 config.set10('HAVE_CAIRO', true)
272 if dep_valgrind.found()
273 config.set10('HAVE_VALGRIND', true)
276 config.set10('_GNU_SOURCE', true)
277 config_file = configure_file(
278 configuration : config,
281 add_project_arguments('-DHAVE_CONFIG_H', language : 'c')
283 inc_root = include_directories('.')
284 inc_drm = include_directories('include/drm')
286 libdrm = shared_library(
289 'xf86drm.c', 'xf86drmHash.c', 'xf86drmRandom.c', 'xf86drmSL.c',
294 c_args : warn_c_args,
295 dependencies : [dep_udev, dep_valgrind, dep_rt, dep_m],
296 include_directories : inc_drm,
301 ext_libdrm = declare_dependency(
303 include_directories : inc_drm,
306 install_headers('libsync.h', 'xf86drm.h', 'xf86drmMode.h')
308 'include/drm/drm.h', 'include/drm/drm_fourcc.h', 'include/drm/drm_mode.h',
309 'include/drm/drm_sarea.h', 'include/drm/i915_drm.h',
310 'include/drm/mach64_drm.h', 'include/drm/mga_drm.h',
311 'include/drm/nouveau_drm.h', 'include/drm/qxl_drm.h',
312 'include/drm/r128_drm.h', 'include/drm/radeon_drm.h',
313 'include/drm/amdgpu_drm.h', 'include/drm/savage_drm.h',
314 'include/drm/sis_drm.h', 'include/drm/tegra_drm.h', 'include/drm/vc4_drm.h',
315 'include/drm/via_drm.h', 'include/drm/virtgpu_drm.h',
319 install_headers('include/drm/vmwgfx_drm.h', subdir : 'libdrm')
325 subdirs : ['.', 'libdrm'],
326 version : meson.project_version(),
327 description : 'Userspace interface to kernel DRM services',