blob: ddcd25ff0e428ce4a59193bebe305805f6125be2 [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'],
Rob Clark85ae22a2018-03-05 15:55:51 -050024 version : '2.4.91',
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
Dylan Baker5f7deb52017-09-13 11:46:13 -070034with_udev = get_option('udev')
35with_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
47# Check for atomics
48intel_atomics = false
49lib_atomics = false
50
Eric Engestrom5236de62018-02-07 14:20:52 +000051dep_atomic_ops = dependency('atomic_ops', required : false)
Dylan Baker5f7deb52017-09-13 11:46:13 -070052if cc.compiles('''
53 int atomic_add(int *i) { return __sync_add_and_fetch (i, 1); }
54 int atomic_cmpxchg(int *i, int j, int k) { return __sync_val_compare_and_swap (i, j, k); }
55 ''',
56 name : 'Intel Atomics')
57 intel_atomics = true
58 with_atomics = true
Eric Engestrom5236de62018-02-07 14:20:52 +000059 dep_atomic_ops = []
60elif dep_atomic_ops.found()
Dylan Baker5f7deb52017-09-13 11:46:13 -070061 lib_atomics = true
62 with_atomics = true
63elif cc.has_function('atomic_cas_uint')
64 with_atomics = true
65else
66 with_atomics = false
67endif
68
69config.set10('HAVE_LIBDRM_ATOMIC_PRIMITIVES', intel_atomics)
70config.set10('HAVE_LIB_ATOMIC_OPS', lib_atomics)
71
72with_intel = false
73_intel = get_option('intel')
74if _intel != 'false'
75 if _intel == 'true' and not with_atomics
76 error('libdrm_intel requires atomics.')
77 else
78 with_intel = _intel == 'true' or host_machine.cpu_family().startswith('x86')
79 endif
80endif
81
82with_radeon = false
83_radeon = get_option('radeon')
84if _radeon != 'false'
85 if _radeon == 'true' and not with_atomics
86 error('libdrm_radeon requires atomics.')
87 endif
88 with_radeon = true
89endif
90
91with_amdgpu = false
92_amdgpu = get_option('amdgpu')
93if _amdgpu != 'false'
94 if _amdgpu == 'true' and not with_atomics
95 error('libdrm_amdgpu requires atomics.')
96 endif
97 with_amdgpu = true
98endif
99
100with_nouveau = false
101_nouveau = get_option('nouveau')
102if _nouveau != 'false'
103 if _nouveau == 'true' and not with_atomics
104 error('libdrm_nouveau requires atomics.')
105 endif
106 with_nouveau = true
107endif
108
109with_vmwgfx = false
110_vmwgfx = get_option('vmwgfx')
111if _vmwgfx != 'false'
112 with_vmwgfx = true
113endif
114
115with_omap = false
116_omap = get_option('omap')
117if _omap == 'true'
118 if not with_atomics
119 error('libdrm_omap requires atomics.')
120 endif
121 with_omap = true
122endif
123
124with_freedreno = false
125_freedreno = get_option('freedreno')
126if _freedreno != 'false'
127 if _freedreno == 'true' and not with_atomics
128 error('libdrm_freedreno requires atomics.')
129 else
130 with_freedreno = _freedreno == 'true' or ['arm', 'aarch64'].contains(host_machine.cpu_family())
131 endif
132endif
133
134with_tegra = false
135_tegra = get_option('tegra')
136if _tegra == 'true'
137 if not with_atomics
138 error('libdrm_tegra requires atomics.')
139 endif
140 with_tegra = true
141endif
142
143with_etnaviv = false
144_etnaviv = get_option('etnaviv')
145if _etnaviv == 'true'
146 if not with_atomics
147 error('libdrm_etnaviv requires atomics.')
148 endif
149 with_etnaviv = true
150endif
151
152with_exynos = get_option('exynos') == 'true'
153
154with_vc4 = false
155_vc4 = get_option('vc4')
156if _vc4 != 'false'
157 with_vc4 = _vc4 == 'true' or ['arm', 'aarch64'].contains(host_machine.cpu_family())
158endif
159
160# XXX: Aparently only freebsd and dragonfly bsd actually need this (and
161# gnu/kfreebsd), not openbsd and netbsd
162with_libkms = false
163_libkms = get_option('libkms')
164if _libkms != 'false'
165 with_libkms = _libkms == 'true' or ['linux', 'freebsd', 'dragonfly'].contains(host_machine.system())
166endif
167
Eric Engestrom07585202018-03-16 17:04:50 +0000168config.set10('UDEV', with_udev)
Dylan Baker5f7deb52017-09-13 11:46:13 -0700169# Among others FreeBSD does not have a separate dl library.
170if not cc.has_function('dlsym')
171 dep_dl = cc.find_library('dl', required : with_nouveau)
172else
173 dep_dl = []
174endif
175# clock_gettime might require -rt, or it might not. find out
176if not cc.has_function('clock_gettime', prefix : '#define _GNU_SOURCE\n#include <time.h>')
177 # XXX: untested
178 dep_rt = cc.find_library('rt')
179else
180 dep_rt = []
181endif
182dep_m = cc.find_library('m', required : false)
Eric Engestroma58490d2018-03-13 14:31:29 +0000183foreach header : ['sys/sysctl.h', 'sys/select.h', 'alloca.h']
Eric Engestrom431f1a12018-03-16 17:10:26 +0000184 config.set('HAVE_' + header.underscorify().to_upper(),
185 cc.compiles('#include <@0@>'.format(header), name : '@0@ works'.format(header)))
Eric Engestrom2bd461e2018-03-12 16:17:55 +0000186endforeach
Dylan Baker5f7deb52017-09-13 11:46:13 -0700187if cc.has_header_symbol('sys/sysmacros.h', 'major')
188 config.set10('MAJOR_IN_SYSMACROS', true)
189elif cc.has_header_symbol('sys/mkdev.h', 'major')
190 config.set10('MAJOR_IN_MKDEV', true)
191endif
Eric Engestrom1a44bba2018-01-26 17:04:28 +0000192config.set10('HAVE_OPEN_MEMSTREAM', cc.has_function('open_memstream'))
Dylan Baker5f7deb52017-09-13 11:46:13 -0700193
194warn_c_args = []
Eric Engestromba176732018-01-26 11:18:03 +0000195foreach a : ['-Wall', '-Wextra', '-Wsign-compare', '-Werror=undef',
Dylan Baker5f7deb52017-09-13 11:46:13 -0700196 '-Werror-implicit-function-declaration', '-Wpointer-arith',
197 '-Wwrite-strings', '-Wstrict-prototypes', '-Wmissing-prototypes',
198 '-Wmissing-declarations', '-Wnested-externs', '-Wpacked',
Eric Engestrom8177d732018-01-26 11:18:30 +0000199 '-Wswitch-enum', '-Wmissing-format-attribute',
200 '-Wstrict-aliasing=2', '-Winit-self', '-Winline', '-Wshadow',
Dylan Baker5f7deb52017-09-13 11:46:13 -0700201 '-Wdeclaration-after-statement', '-Wold-style-definition']
202 if cc.has_argument(a)
203 warn_c_args += a
204 endif
205endforeach
206# GCC will never error for -Wno-*, so check for -W* then add -Wno-* to the list
207# of options
Eric Engestrom8177d732018-01-26 11:18:30 +0000208foreach a : ['unused-parameter', 'attributes', 'long-long',
Dylan Baker5f7deb52017-09-13 11:46:13 -0700209 'missing-field-initializers']
210 if cc.has_argument('-W@0@'.format(a))
211 warn_c_args += '-Wno-@0@'.format(a)
212 endif
213endforeach
214
215
216dep_pciaccess = dependency('pciaccess', version : '>= 0.10', required : with_intel)
217dep_cunit = dependency('cunit', version : '>= 2.1', required : false)
Igor Gnatenko9411f8e2018-02-19 13:55:27 +0100218_cairo_tests = get_option('cairo-tests')
219if _cairo_tests != 'false'
220 dep_cairo = dependency('cairo', required : _cairo_tests == 'true')
221 with_cairo_tests = dep_cairo.found()
222else
223 dep_cairo = []
224 with_cairo_tests = false
225endif
226_valgrind = get_option('valgrind')
227if _valgrind != 'false'
228 dep_valgrind = dependency('valgrind', required : _valgrind == 'true')
229 with_valgrind = dep_valgrind.found()
230else
231 dep_valgrind = []
232 with_valgrind = false
233endif
Dylan Baker5f7deb52017-09-13 11:46:13 -0700234
235with_man_pages = get_option('man-pages')
236prog_xslt = find_program('xsltproc', required : with_man_pages == 'true')
237prog_sed = find_program('sed', required : with_man_pages == 'true')
238manpage_style = 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
239if prog_xslt.found()
240 if run_command(prog_xslt, '--nonet', manpage_style).returncode() != 0
241 if with_man_pages == 'true'
242 error('Manpage style sheet cannot be found')
243 endif
244 with_man_pages = 'false'
245 endif
246endif
247with_man_pages = with_man_pages != 'false' and prog_xslt.found() and prog_sed.found()
248
249# Used for tets
250prog_bash = find_program('bash')
251
Eric Engestrome8d3d882018-03-16 17:07:08 +0000252config.set10('HAVE_VISIBILITY',
253 cc.compiles('''int foo_hidden(void) __attribute__((visibility(("hidden"))));''',
254 name : 'compiler supports __attribute__(("hidden"))'))
Dylan Baker5f7deb52017-09-13 11:46:13 -0700255
Eric Engestrom5457e002018-01-26 16:23:01 +0000256foreach t : [
Eric Engestrom2cd91052018-01-26 16:17:53 +0000257 [with_exynos, 'EXYNOS'],
Eric Engestromec53f482018-01-26 15:19:03 +0000258 [with_freedreno_kgsl, 'FREEDRENO_KGSL'],
Eric Engestrom5457e002018-01-26 16:23:01 +0000259 [with_intel, 'INTEL'],
260 [with_nouveau, 'NOUVEAU'],
261 [with_radeon, 'RADEON'],
262 [with_vc4, 'VC4'],
263 [with_vmwgfx, 'VMWGFX'],
Igor Gnatenko9411f8e2018-02-19 13:55:27 +0100264 [with_cairo_tests, 'CAIRO'],
265 [with_valgrind, 'VALGRIND'],
Eric Engestrom5457e002018-01-26 16:23:01 +0000266 ]
Eric Engestromee473292018-01-26 16:21:30 +0000267 config.set10('HAVE_@0@'.format(t[1]), t[0])
Dylan Baker5f7deb52017-09-13 11:46:13 -0700268endforeach
Eric Engestromec53f482018-01-26 15:19:03 +0000269if with_freedreno_kgsl and not with_freedreno
270 error('cannot enable freedreno-kgsl without freedreno support')
Dylan Baker5f7deb52017-09-13 11:46:13 -0700271endif
Dylan Baker5f7deb52017-09-13 11:46:13 -0700272config.set10('_GNU_SOURCE', true)
273config_file = configure_file(
274 configuration : config,
275 output : 'config.h',
276)
Eric Engestrom0926f0a2018-02-01 11:12:05 +0000277add_project_arguments('-include', 'config.h', language : 'c')
Dylan Baker5f7deb52017-09-13 11:46:13 -0700278
279inc_root = include_directories('.')
280inc_drm = include_directories('include/drm')
281
282libdrm = shared_library(
283 'drm',
284 [files(
285 'xf86drm.c', 'xf86drmHash.c', 'xf86drmRandom.c', 'xf86drmSL.c',
286 'xf86drmMode.c'
287 ),
288 config_file,
289 ],
290 c_args : warn_c_args,
Eric Engestrom56f6d3d2018-03-20 14:55:50 +0000291 dependencies : [dep_valgrind, dep_rt, dep_m],
Dylan Baker5f7deb52017-09-13 11:46:13 -0700292 include_directories : inc_drm,
293 version : '2.4.0',
294 install : true,
295)
296
297ext_libdrm = declare_dependency(
298 link_with : libdrm,
Dylan Bakerdeb59782018-02-07 15:35:24 -0800299 include_directories : [inc_root, inc_drm],
Dylan Baker5f7deb52017-09-13 11:46:13 -0700300)
301
302install_headers('libsync.h', 'xf86drm.h', 'xf86drmMode.h')
303install_headers(
304 'include/drm/drm.h', 'include/drm/drm_fourcc.h', 'include/drm/drm_mode.h',
305 'include/drm/drm_sarea.h', 'include/drm/i915_drm.h',
306 'include/drm/mach64_drm.h', 'include/drm/mga_drm.h',
307 'include/drm/nouveau_drm.h', 'include/drm/qxl_drm.h',
308 'include/drm/r128_drm.h', 'include/drm/radeon_drm.h',
309 'include/drm/amdgpu_drm.h', 'include/drm/savage_drm.h',
310 'include/drm/sis_drm.h', 'include/drm/tegra_drm.h', 'include/drm/vc4_drm.h',
311 'include/drm/via_drm.h', 'include/drm/virtgpu_drm.h',
312 subdir : 'libdrm',
313)
314if with_vmwgfx
315 install_headers('include/drm/vmwgfx_drm.h', subdir : 'libdrm')
316endif
317
318pkg.generate(
319 name : 'libdrm',
320 libraries : libdrm,
321 subdirs : ['.', 'libdrm'],
322 version : meson.project_version(),
323 description : 'Userspace interface to kernel DRM services',
324)
Eric Engestrom8177d732018-01-26 11:18:30 +0000325
Heiko Becker4f08bfe2018-02-19 15:13:15 +0000326env_test = environment()
327env_test.set('NM', find_program('nm').path())
328
Dylan Baker5f7deb52017-09-13 11:46:13 -0700329if with_libkms
330 subdir('libkms')
331endif
332if with_intel
333 subdir('intel')
334endif
335if with_nouveau
336 subdir('nouveau')
337endif
338if with_radeon
339 subdir('radeon')
340endif
341if with_amdgpu
342 subdir('amdgpu')
343endif
344if with_omap
345 subdir('omap')
346endif
347if with_exynos
348 subdir('exynos')
349endif
350if with_freedreno
351 subdir('freedreno')
352endif
353if with_tegra
354 subdir('tegra')
355endif
356if with_vc4
357 subdir('vc4')
358endif
359if with_etnaviv
360 subdir('etnaviv')
361endif
362if with_man_pages
363 subdir('man')
364endif
365subdir('data')
366subdir('tests')
Eric Engestrom7a58c212018-02-26 15:42:18 +0000367
368message('')
369message('@0@ will be compiled with:'.format(meson.project_name()))
370message('')
371message(' libkms @0@'.format(with_libkms))
372message(' Intel API @0@'.format(with_intel))
373message(' vmwgfx API @0@'.format(with_vmwgfx))
374message(' Radeon API @0@'.format(with_radeon))
375message(' AMDGPU API @0@'.format(with_amdgpu))
376message(' Nouveau API @0@'.format(with_nouveau))
377message(' OMAP API @0@'.format(with_omap))
378message(' EXYNOS API @0@'.format(with_exynos))
379message(' Freedreno API @0@ (kgsl: @1@)'.format(with_freedreno, with_freedreno_kgsl))
380message(' Tegra API @0@'.format(with_tegra))
381message(' VC4 API @0@'.format(with_vc4))
382message(' Etnaviv API @0@'.format(with_etnaviv))
383message('')