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.53',
27 default_options : ['buildtype=debugoptimized', 'c_std=c11'],
30 if ['windows', 'darwin'].contains(host_machine.system())
31 error('unsupported OS: @0@'.format(host_machine.system()))
34 pkg = import('pkgconfig')
36 config = configuration_data()
38 config.set10('UDEV', get_option('udev'))
39 with_freedreno_kgsl = get_option('freedreno-kgsl')
40 with_install_tests = get_option('install-test-programs')
41 with_tests = get_option('tests')
43 dep_threads = dependency('threads')
45 cc = meson.get_compiler('c')
47 android = cc.compiles('''int func() { return __ANDROID__; }''')
49 symbols_check = find_program('symbols-check.py')
50 prog_nm = find_program('nm')
56 python3 = import('python').find_installation()
57 format_mod_static_table = custom_target(
58 'format_mod_static_table',
59 output : 'generated_static_table_fourcc.h',
60 input : 'include/drm/drm_fourcc.h',
61 command : [python3, files('gen_table_fourcc.py'), '@INPUT@', '@OUTPUT@'])
63 dep_atomic_ops = dependency('atomic_ops', required : false)
65 int atomic_add(int *i) { return __sync_add_and_fetch (i, 1); }
66 int atomic_cmpxchg(int *i, int j, int k) { return __sync_val_compare_and_swap (i, j, k); }
69 name : 'Intel Atomics')
73 elif dep_atomic_ops.found()
76 elif cc.has_function('atomic_cas_uint')
82 config.set10('HAVE_LIBDRM_ATOMIC_PRIMITIVES', intel_atomics)
83 config.set10('HAVE_LIB_ATOMIC_OPS', lib_atomics)
85 dep_pciaccess = dependency('pciaccess', version : '>= 0.10', required : get_option('intel'))
88 _intel = get_option('intel')
89 if not _intel.disabled()
90 if _intel.enabled() and not with_atomics
91 error('libdrm_intel requires atomics.')
93 with_intel = (_intel.enabled() or host_machine.cpu_family().startswith('x86')) and with_atomics and dep_pciaccess.found()
96 summary('Intel', with_intel)
99 _radeon = get_option('radeon')
100 if not _radeon.disabled()
101 if _radeon.enabled() and not with_atomics
102 error('libdrm_radeon requires atomics.')
104 with_radeon = with_atomics
106 summary('Radeon', with_radeon)
109 _amdgpu = get_option('amdgpu')
110 if not _amdgpu.disabled()
111 if _amdgpu.enabled() and not with_atomics
112 error('libdrm_amdgpu requires atomics.')
114 with_amdgpu = with_atomics
116 summary('AMDGPU', with_amdgpu)
119 _nouveau = get_option('nouveau')
120 if not _nouveau.disabled()
121 if _nouveau.enabled() and not with_atomics
122 error('libdrm_nouveau requires atomics.')
124 with_nouveau = with_atomics
126 summary('Nouveau', with_nouveau)
129 _vmwgfx = get_option('vmwgfx')
130 if not _vmwgfx.disabled()
133 summary('vmwgfx', with_vmwgfx)
136 _omap = get_option('omap')
139 error('libdrm_omap requires atomics.')
143 summary('OMAP', with_omap)
145 with_freedreno = false
146 _freedreno = get_option('freedreno')
147 if not _freedreno.disabled()
148 if _freedreno.enabled() and not with_atomics
149 error('libdrm_freedreno requires atomics.')
151 with_freedreno = (_freedreno.enabled() or ['arm', 'aarch64'].contains(host_machine.cpu_family())) and with_atomics
154 summary('Freedreno', with_freedreno)
155 summary('Freedreon-kgsl', with_freedreno_kgsl)
158 _tegra = get_option('tegra')
161 error('libdrm_tegra requires atomics.')
165 summary('Tegra', with_tegra)
168 _etnaviv = get_option('etnaviv')
169 if not _etnaviv.disabled()
170 if _etnaviv.enabled() and not with_atomics
171 error('libdrm_etnaviv requires atomics.')
173 with_etnaviv = _etnaviv.enabled() or (
175 'loongarch64', 'mips', 'mips64',
176 'arm', 'aarch64', 'arc',
177 ].contains(host_machine.cpu_family())
180 summary('Etnaviv', with_etnaviv)
182 with_exynos = get_option('exynos').enabled()
183 summary('EXYNOS', with_exynos)
186 _vc4 = get_option('vc4')
187 if not _vc4.disabled()
188 with_vc4 = _vc4.enabled() or ['arm', 'aarch64'].contains(host_machine.cpu_family())
190 summary('VC4', with_vc4)
192 # Among others FreeBSD does not have a separate dl library.
193 if not cc.has_function('dlsym')
194 dep_dl = cc.find_library('dl', required : with_nouveau)
198 # clock_gettime might require -rt, or it might not. find out
199 if not cc.has_function('clock_gettime', prefix : '#define _GNU_SOURCE\n#include <time.h>')
201 dep_rt = cc.find_library('rt')
205 dep_m = cc.find_library('m', required : false)
207 # The header is not required on Linux, and is in fact deprecated in glibc 2.30+
208 if ['linux'].contains(host_machine.system())
209 config.set10('HAVE_SYS_SYSCTL_H', false)
211 # From Niclas Zeising:
212 # FreeBSD requires sys/types.h for sys/sysctl.h, so add it as part of
213 # the includes when checking for headers.
214 config.set10('HAVE_SYS_SYSCTL_H',
215 cc.compiles('#include <sys/types.h>\n#include <sys/sysctl.h>', name : 'sys/sysctl.h works'))
218 foreach header : ['sys/select.h', 'alloca.h']
219 config.set10('HAVE_' + header.underscorify().to_upper(), cc.check_header(header))
222 if (cc.has_header_symbol('sys/sysmacros.h', 'major') and
223 cc.has_header_symbol('sys/sysmacros.h', 'minor') and
224 cc.has_header_symbol('sys/sysmacros.h', 'makedev'))
225 config.set10('MAJOR_IN_SYSMACROS', true)
227 if (cc.has_header_symbol('sys/mkdev.h', 'major') and
228 cc.has_header_symbol('sys/mkdev.h', 'minor') and
229 cc.has_header_symbol('sys/mkdev.h', 'makedev'))
230 config.set10('MAJOR_IN_MKDEV', true)
232 config.set10('HAVE_OPEN_MEMSTREAM', cc.has_function('open_memstream'))
234 libdrm_c_args = cc.get_supported_arguments([
235 '-Wsign-compare', '-Werror=undef', '-Werror=implicit-function-declaration',
236 '-Wpointer-arith', '-Wwrite-strings', '-Wstrict-prototypes',
237 '-Wmissing-prototypes', '-Wmissing-declarations', '-Wnested-externs',
238 '-Wpacked', '-Wswitch-enum', '-Wmissing-format-attribute',
239 '-Wstrict-aliasing=2', '-Winit-self', '-Winline', '-Wshadow',
240 '-Wdeclaration-after-statement', '-Wold-style-definition',
241 '-Wno-unused-parameter', '-Wno-attributes', '-Wno-long-long',
242 '-Wno-missing-field-initializers'])
244 dep_cunit = dependency('cunit', version : '>= 2.1', required : false)
245 dep_cairo = dependency('cairo', required : get_option('cairo-tests'))
246 with_cairo_tests = dep_cairo.found()
248 valgrind_version = []
250 valgrind_version = '>=3.10.0'
252 dep_valgrind = dependency('valgrind', required : get_option('valgrind'), version : valgrind_version)
253 with_valgrind = dep_valgrind.found()
255 prog_rst2man = find_program('rst2man', 'rst2man.py', required: get_option('man-pages'))
256 with_man_pages = prog_rst2man.found()
258 config.set10('HAVE_VISIBILITY', cc.has_function_attribute('visibility:hidden'))
261 [with_exynos, 'EXYNOS'],
262 [with_freedreno_kgsl, 'FREEDRENO_KGSL'],
263 [with_intel, 'INTEL'],
264 [with_nouveau, 'NOUVEAU'],
265 [with_radeon, 'RADEON'],
267 [with_vmwgfx, 'VMWGFX'],
268 [with_cairo_tests, 'CAIRO'],
269 [with_valgrind, 'VALGRIND'],
271 config.set10('HAVE_@0@'.format(t[1]), t[0])
273 if with_freedreno_kgsl and not with_freedreno
274 error('cannot enable freedreno-kgsl without freedreno support')
276 config.set10('_GNU_SOURCE', true)
277 config_file = configure_file(
278 configuration : config,
281 add_project_arguments('-include', '@0@'.format(config_file), language : 'c')
283 inc_root = include_directories('.')
284 inc_drm = include_directories('include/drm')
286 libdrm_files = [files(
287 'xf86drm.c', 'xf86drmHash.c', 'xf86drmRandom.c', 'xf86drmSL.c',
290 config_file, format_mod_static_table
293 # Build an unversioned so on android
297 libdrm_kw = {'version' : '2.4.0'}
303 c_args : libdrm_c_args,
304 dependencies : [dep_valgrind, dep_rt, dep_m],
305 include_directories : inc_drm,
308 gnu_symbol_visibility : 'hidden',
312 'core-symbols-check',
316 '--symbols-file', files('core-symbols.txt'),
317 '--nm', prog_nm.path(),
321 ext_libdrm = declare_dependency(
323 include_directories : [inc_root, inc_drm],
326 if meson.version().version_compare('>= 0.54.0')
327 meson.override_dependency('libdrm', ext_libdrm)
330 install_headers('libsync.h', 'xf86drm.h', 'xf86drmMode.h')
332 'include/drm/drm.h', 'include/drm/drm_fourcc.h', 'include/drm/drm_mode.h',
333 'include/drm/drm_sarea.h', 'include/drm/i915_drm.h',
334 'include/drm/mach64_drm.h', 'include/drm/mga_drm.h',
335 'include/drm/msm_drm.h', 'include/drm/nouveau_drm.h',
336 'include/drm/qxl_drm.h', 'include/drm/r128_drm.h',
337 'include/drm/radeon_drm.h', 'include/drm/amdgpu_drm.h',
338 'include/drm/savage_drm.h', 'include/drm/sis_drm.h',
339 'include/drm/tegra_drm.h', 'include/drm/vc4_drm.h',
340 'include/drm/via_drm.h', 'include/drm/virtgpu_drm.h',
344 install_headers('include/drm/vmwgfx_drm.h', subdir : 'libdrm')
350 subdirs : ['.', 'libdrm'],
351 description : 'Userspace interface to kernel DRM services',