blob: 07d2e08695034c811d3b040d3bf48c9ff46541a9 [file] [log] [blame]
Dylan Baker5f7deb52017-09-13 11:46:13 -07001# 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'],
Simon Sera55042e2021-01-11 17:18:20 +010024 version : '2.4.104',
Dylan Baker5f7deb52017-09-13 11:46:13 -070025 license : 'MIT',
Dylan Baker5df93672018-01-12 11:53:39 -080026 meson_version : '>= 0.43',
Dylan Baker5f7deb52017-09-13 11:46:13 -070027 default_options : ['buildtype=debugoptimized', 'c_std=gnu99'],
28)
29
30pkg = import('pkgconfig')
31
Eric Engestromedaca472018-03-20 14:54:45 +000032config = configuration_data()
33
Eric Engestrom361d4bf2018-03-20 14:59:40 +000034config.set10('UDEV', get_option('udev'))
Dylan Baker5f7deb52017-09-13 11:46:13 -070035with_freedreno_kgsl = get_option('freedreno-kgsl')
36with_install_tests = get_option('install-test-programs')
Dylan Baker5f7deb52017-09-13 11:46:13 -070037
Jonathan Gray9eb6c8a2018-02-20 17:09:14 +110038if ['freebsd', 'dragonfly', 'netbsd'].contains(host_machine.system())
Dylan Baker5f7deb52017-09-13 11:46:13 -070039 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
Eric Engestrom303cf6b2019-10-23 22:57:51 +010047symbols_check = find_program('symbols-check.py')
48prog_nm = find_program('nm')
49
Dylan Baker5f7deb52017-09-13 11:46:13 -070050# Check for atomics
51intel_atomics = false
52lib_atomics = false
53
Eric Engestrom5236de62018-02-07 14:20:52 +000054dep_atomic_ops = dependency('atomic_ops', required : false)
Peter Seiderer8de26962018-07-16 23:01:40 +020055if cc.links('''
Dylan Baker5f7deb52017-09-13 11:46:13 -070056 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); }
Peter Seiderer8de26962018-07-16 23:01:40 +020058 int main() { }
Dylan Baker5f7deb52017-09-13 11:46:13 -070059 ''',
60 name : 'Intel Atomics')
61 intel_atomics = true
62 with_atomics = true
Eric Engestrom5236de62018-02-07 14:20:52 +000063 dep_atomic_ops = []
64elif dep_atomic_ops.found()
Dylan Baker5f7deb52017-09-13 11:46:13 -070065 lib_atomics = true
66 with_atomics = true
67elif cc.has_function('atomic_cas_uint')
68 with_atomics = true
69else
70 with_atomics = false
71endif
72
73config.set10('HAVE_LIBDRM_ATOMIC_PRIMITIVES', intel_atomics)
74config.set10('HAVE_LIB_ATOMIC_OPS', lib_atomics)
75
76with_intel = false
77_intel = get_option('intel')
78if _intel != 'false'
79 if _intel == 'true' and not with_atomics
80 error('libdrm_intel requires atomics.')
81 else
82 with_intel = _intel == 'true' or host_machine.cpu_family().startswith('x86')
83 endif
84endif
85
86with_radeon = false
87_radeon = get_option('radeon')
88if _radeon != 'false'
89 if _radeon == 'true' and not with_atomics
90 error('libdrm_radeon requires atomics.')
91 endif
92 with_radeon = true
93endif
94
95with_amdgpu = false
96_amdgpu = get_option('amdgpu')
97if _amdgpu != 'false'
98 if _amdgpu == 'true' and not with_atomics
99 error('libdrm_amdgpu requires atomics.')
100 endif
101 with_amdgpu = true
102endif
103
104with_nouveau = false
105_nouveau = get_option('nouveau')
106if _nouveau != 'false'
107 if _nouveau == 'true' and not with_atomics
108 error('libdrm_nouveau requires atomics.')
109 endif
110 with_nouveau = true
111endif
112
113with_vmwgfx = false
114_vmwgfx = get_option('vmwgfx')
115if _vmwgfx != 'false'
116 with_vmwgfx = true
117endif
118
119with_omap = false
120_omap = get_option('omap')
121if _omap == 'true'
122 if not with_atomics
123 error('libdrm_omap requires atomics.')
124 endif
125 with_omap = true
126endif
127
128with_freedreno = false
129_freedreno = get_option('freedreno')
130if _freedreno != 'false'
131 if _freedreno == 'true' and not with_atomics
132 error('libdrm_freedreno requires atomics.')
133 else
134 with_freedreno = _freedreno == 'true' or ['arm', 'aarch64'].contains(host_machine.cpu_family())
135 endif
136endif
137
138with_tegra = false
139_tegra = get_option('tegra')
140if _tegra == 'true'
141 if not with_atomics
142 error('libdrm_tegra requires atomics.')
143 endif
144 with_tegra = true
145endif
146
147with_etnaviv = false
148_etnaviv = get_option('etnaviv')
149if _etnaviv == 'true'
150 if not with_atomics
151 error('libdrm_etnaviv requires atomics.')
152 endif
153 with_etnaviv = true
154endif
155
156with_exynos = get_option('exynos') == 'true'
157
158with_vc4 = false
159_vc4 = get_option('vc4')
160if _vc4 != 'false'
161 with_vc4 = _vc4 == 'true' or ['arm', 'aarch64'].contains(host_machine.cpu_family())
162endif
163
Eric Engestrom360292c2018-12-19 14:55:45 +0000164# XXX: Apparently only freebsd and dragonfly bsd actually need this (and
Dylan Baker5f7deb52017-09-13 11:46:13 -0700165# gnu/kfreebsd), not openbsd and netbsd
166with_libkms = false
167_libkms = get_option('libkms')
168if _libkms != 'false'
169 with_libkms = _libkms == 'true' or ['linux', 'freebsd', 'dragonfly'].contains(host_machine.system())
170endif
171
Dylan Baker5f7deb52017-09-13 11:46:13 -0700172# Among others FreeBSD does not have a separate dl library.
173if not cc.has_function('dlsym')
174 dep_dl = cc.find_library('dl', required : with_nouveau)
175else
176 dep_dl = []
177endif
178# clock_gettime might require -rt, or it might not. find out
179if not cc.has_function('clock_gettime', prefix : '#define _GNU_SOURCE\n#include <time.h>')
180 # XXX: untested
181 dep_rt = cc.find_library('rt')
182else
183 dep_rt = []
184endif
185dep_m = cc.find_library('m', required : false)
Eric Engestrom1f8ada82020-03-29 22:45:52 +0200186
187# The header is not required on Linux, and is in fact deprecated in glibc 2.30+
188if ['linux'].contains(host_machine.system())
189 config.set10('HAVE_SYS_SYSCTL_H', false)
190else
191 # From Niclas Zeising:
192 # FreeBSD requires sys/types.h for sys/sysctl.h, so add it as part of
193 # the includes when checking for headers.
194 config.set10('HAVE_SYS_SYSCTL_H',
195 cc.compiles('#include <sys/types.h>\n#include <sys/sysctl.h>', name : 'sys/sysctl.h works'))
196endif
197
198foreach header : ['sys/select.h', 'alloca.h']
Eric Engestrom074947e2018-11-07 15:00:24 +0000199 config.set10('HAVE_' + header.underscorify().to_upper(),
Eric Engestrom1f8ada82020-03-29 22:45:52 +0200200 cc.compiles('#include <@0@>'.format(header), name : '@0@ works'.format(header)))
Eric Engestrom2bd461e2018-03-12 16:17:55 +0000201endforeach
Eric Engestrom1f8ada82020-03-29 22:45:52 +0200202
Eric Engestrom827a2a22019-09-14 22:22:03 +0100203if (cc.has_header_symbol('sys/sysmacros.h', 'major') and
204 cc.has_header_symbol('sys/sysmacros.h', 'minor') and
205 cc.has_header_symbol('sys/sysmacros.h', 'makedev'))
Dylan Baker5f7deb52017-09-13 11:46:13 -0700206 config.set10('MAJOR_IN_SYSMACROS', true)
Eric Engestrom827a2a22019-09-14 22:22:03 +0100207endif
208if (cc.has_header_symbol('sys/mkdev.h', 'major') and
209 cc.has_header_symbol('sys/mkdev.h', 'minor') and
210 cc.has_header_symbol('sys/mkdev.h', 'makedev'))
Dylan Baker5f7deb52017-09-13 11:46:13 -0700211 config.set10('MAJOR_IN_MKDEV', true)
212endif
Eric Engestrom1a44bba2018-01-26 17:04:28 +0000213config.set10('HAVE_OPEN_MEMSTREAM', cc.has_function('open_memstream'))
Dylan Baker5f7deb52017-09-13 11:46:13 -0700214
215warn_c_args = []
Eric Engestromba176732018-01-26 11:18:03 +0000216foreach a : ['-Wall', '-Wextra', '-Wsign-compare', '-Werror=undef',
Eric Engestrom8c1fddc2018-11-07 16:50:06 +0000217 '-Werror=implicit-function-declaration', '-Wpointer-arith',
Dylan Baker5f7deb52017-09-13 11:46:13 -0700218 '-Wwrite-strings', '-Wstrict-prototypes', '-Wmissing-prototypes',
219 '-Wmissing-declarations', '-Wnested-externs', '-Wpacked',
Eric Engestrom8177d732018-01-26 11:18:30 +0000220 '-Wswitch-enum', '-Wmissing-format-attribute',
221 '-Wstrict-aliasing=2', '-Winit-self', '-Winline', '-Wshadow',
Dylan Baker5f7deb52017-09-13 11:46:13 -0700222 '-Wdeclaration-after-statement', '-Wold-style-definition']
223 if cc.has_argument(a)
224 warn_c_args += a
225 endif
226endforeach
227# GCC will never error for -Wno-*, so check for -W* then add -Wno-* to the list
228# of options
Eric Engestrom8177d732018-01-26 11:18:30 +0000229foreach a : ['unused-parameter', 'attributes', 'long-long',
Dylan Baker5f7deb52017-09-13 11:46:13 -0700230 'missing-field-initializers']
231 if cc.has_argument('-W@0@'.format(a))
232 warn_c_args += '-Wno-@0@'.format(a)
233 endif
234endforeach
235
Lucas De Marchiba808252018-09-12 13:24:12 -0700236# all c args:
237libdrm_c_args = warn_c_args + ['-fvisibility=hidden']
238
Dylan Baker5f7deb52017-09-13 11:46:13 -0700239
240dep_pciaccess = dependency('pciaccess', version : '>= 0.10', required : with_intel)
241dep_cunit = dependency('cunit', version : '>= 2.1', required : false)
Igor Gnatenko9411f8e2018-02-19 13:55:27 +0100242_cairo_tests = get_option('cairo-tests')
243if _cairo_tests != 'false'
244 dep_cairo = dependency('cairo', required : _cairo_tests == 'true')
245 with_cairo_tests = dep_cairo.found()
246else
247 dep_cairo = []
248 with_cairo_tests = false
249endif
250_valgrind = get_option('valgrind')
251if _valgrind != 'false'
Jose Maria Casanova Crespoc997baf2020-05-05 21:50:33 +0200252 if with_freedreno
253 dep_valgrind = dependency('valgrind', required : _valgrind == 'true', version : '>=3.10.0')
254 else
255 dep_valgrind = dependency('valgrind', required : _valgrind == 'true')
256 endif
Igor Gnatenko9411f8e2018-02-19 13:55:27 +0100257 with_valgrind = dep_valgrind.found()
258else
259 dep_valgrind = []
260 with_valgrind = false
261endif
Dylan Baker5f7deb52017-09-13 11:46:13 -0700262
263with_man_pages = get_option('man-pages')
Heiko Becker62b9a3e2021-01-15 21:11:41 +0100264prog_rst2man = find_program('rst2man', 'rst2man.py', required: with_man_pages == 'true')
Simon Ser05b0a952020-06-03 11:58:07 +0200265with_man_pages = with_man_pages != 'false' and prog_rst2man.found()
Dylan Baker5f7deb52017-09-13 11:46:13 -0700266
Eric Engestrome8d3d882018-03-16 17:07:08 +0000267config.set10('HAVE_VISIBILITY',
268 cc.compiles('''int foo_hidden(void) __attribute__((visibility(("hidden"))));''',
269 name : 'compiler supports __attribute__(("hidden"))'))
Dylan Baker5f7deb52017-09-13 11:46:13 -0700270
Eric Engestrom5457e002018-01-26 16:23:01 +0000271foreach t : [
Eric Engestrom2cd91052018-01-26 16:17:53 +0000272 [with_exynos, 'EXYNOS'],
Eric Engestromec53f482018-01-26 15:19:03 +0000273 [with_freedreno_kgsl, 'FREEDRENO_KGSL'],
Eric Engestrom5457e002018-01-26 16:23:01 +0000274 [with_intel, 'INTEL'],
275 [with_nouveau, 'NOUVEAU'],
276 [with_radeon, 'RADEON'],
277 [with_vc4, 'VC4'],
278 [with_vmwgfx, 'VMWGFX'],
Igor Gnatenko9411f8e2018-02-19 13:55:27 +0100279 [with_cairo_tests, 'CAIRO'],
280 [with_valgrind, 'VALGRIND'],
Eric Engestrom5457e002018-01-26 16:23:01 +0000281 ]
Eric Engestromee473292018-01-26 16:21:30 +0000282 config.set10('HAVE_@0@'.format(t[1]), t[0])
Dylan Baker5f7deb52017-09-13 11:46:13 -0700283endforeach
Eric Engestromec53f482018-01-26 15:19:03 +0000284if with_freedreno_kgsl and not with_freedreno
285 error('cannot enable freedreno-kgsl without freedreno support')
Dylan Baker5f7deb52017-09-13 11:46:13 -0700286endif
Dylan Baker5f7deb52017-09-13 11:46:13 -0700287config.set10('_GNU_SOURCE', true)
288config_file = configure_file(
289 configuration : config,
290 output : 'config.h',
291)
Scott Andersonc70bd7b2019-12-17 22:08:02 +1300292add_project_arguments('-include', '@0@'.format(config_file), language : 'c')
Dylan Baker5f7deb52017-09-13 11:46:13 -0700293
294inc_root = include_directories('.')
295inc_drm = include_directories('include/drm')
296
297libdrm = shared_library(
298 'drm',
299 [files(
300 'xf86drm.c', 'xf86drmHash.c', 'xf86drmRandom.c', 'xf86drmSL.c',
301 'xf86drmMode.c'
302 ),
303 config_file,
304 ],
Lucas De Marchiba808252018-09-12 13:24:12 -0700305 c_args : libdrm_c_args,
Eric Engestrom56f6d3d2018-03-20 14:55:50 +0000306 dependencies : [dep_valgrind, dep_rt, dep_m],
Dylan Baker5f7deb52017-09-13 11:46:13 -0700307 include_directories : inc_drm,
308 version : '2.4.0',
309 install : true,
310)
311
Eric Engestrom077e6422019-11-11 23:51:04 +0000312test(
313 'core-symbols-check',
314 symbols_check,
315 args : [
316 '--lib', libdrm,
317 '--symbols-file', files('core-symbols.txt'),
318 '--nm', prog_nm.path(),
319 ],
320)
321
Dylan Baker5f7deb52017-09-13 11:46:13 -0700322ext_libdrm = declare_dependency(
323 link_with : libdrm,
Dylan Bakerdeb59782018-02-07 15:35:24 -0800324 include_directories : [inc_root, inc_drm],
Dylan Baker5f7deb52017-09-13 11:46:13 -0700325)
326
327install_headers('libsync.h', 'xf86drm.h', 'xf86drmMode.h')
328install_headers(
329 'include/drm/drm.h', 'include/drm/drm_fourcc.h', 'include/drm/drm_mode.h',
330 'include/drm/drm_sarea.h', 'include/drm/i915_drm.h',
331 'include/drm/mach64_drm.h', 'include/drm/mga_drm.h',
Tanmay Shahf0c642e2018-08-13 17:29:21 -0700332 'include/drm/msm_drm.h', 'include/drm/nouveau_drm.h',
333 'include/drm/qxl_drm.h', 'include/drm/r128_drm.h',
334 'include/drm/radeon_drm.h', 'include/drm/amdgpu_drm.h',
335 'include/drm/savage_drm.h', 'include/drm/sis_drm.h',
336 'include/drm/tegra_drm.h', 'include/drm/vc4_drm.h',
Dylan Baker5f7deb52017-09-13 11:46:13 -0700337 'include/drm/via_drm.h', 'include/drm/virtgpu_drm.h',
338 subdir : 'libdrm',
339)
340if with_vmwgfx
341 install_headers('include/drm/vmwgfx_drm.h', subdir : 'libdrm')
342endif
343
344pkg.generate(
345 name : 'libdrm',
346 libraries : libdrm,
347 subdirs : ['.', 'libdrm'],
348 version : meson.project_version(),
349 description : 'Userspace interface to kernel DRM services',
350)
Eric Engestrom8177d732018-01-26 11:18:30 +0000351
Dylan Baker5f7deb52017-09-13 11:46:13 -0700352if with_libkms
353 subdir('libkms')
354endif
355if with_intel
356 subdir('intel')
357endif
358if with_nouveau
359 subdir('nouveau')
360endif
361if with_radeon
362 subdir('radeon')
363endif
364if with_amdgpu
365 subdir('amdgpu')
366endif
367if with_omap
368 subdir('omap')
369endif
370if with_exynos
371 subdir('exynos')
372endif
373if with_freedreno
374 subdir('freedreno')
375endif
376if with_tegra
377 subdir('tegra')
378endif
379if with_vc4
380 subdir('vc4')
381endif
382if with_etnaviv
383 subdir('etnaviv')
384endif
385if with_man_pages
386 subdir('man')
387endif
388subdir('data')
389subdir('tests')
Eric Engestrom7a58c212018-02-26 15:42:18 +0000390
391message('')
392message('@0@ will be compiled with:'.format(meson.project_name()))
393message('')
394message(' libkms @0@'.format(with_libkms))
395message(' Intel API @0@'.format(with_intel))
396message(' vmwgfx API @0@'.format(with_vmwgfx))
397message(' Radeon API @0@'.format(with_radeon))
398message(' AMDGPU API @0@'.format(with_amdgpu))
399message(' Nouveau API @0@'.format(with_nouveau))
400message(' OMAP API @0@'.format(with_omap))
401message(' EXYNOS API @0@'.format(with_exynos))
402message(' Freedreno API @0@ (kgsl: @1@)'.format(with_freedreno, with_freedreno_kgsl))
403message(' Tegra API @0@'.format(with_tegra))
404message(' VC4 API @0@'.format(with_vc4))
405message(' Etnaviv API @0@'.format(with_etnaviv))
406message('')