blob: 5824da8aee8d5fa446af16439d5e0f0dc11e6f4e [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 Serfebfe0a2021-11-25 21:33:02 +010024 version : '2.4.109',
Dylan Baker5f7deb52017-09-13 11:46:13 -070025 license : 'MIT',
Marius Vlad67e91192021-02-01 13:23:20 +020026 meson_version : '>= 0.46',
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 Anholta819b9a2021-04-22 16:03:38 -070047android = cc.compiles('''int func() { return __ANDROID__; }''')
48
Eric Engestrom303cf6b2019-10-23 22:57:51 +010049symbols_check = find_program('symbols-check.py')
50prog_nm = find_program('nm')
51
Dylan Baker5f7deb52017-09-13 11:46:13 -070052# Check for atomics
53intel_atomics = false
54lib_atomics = false
55
Marius Vlad67e91192021-02-01 13:23:20 +020056python3 = 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
Eric Engestrom5236de62018-02-07 14:20:52 +000061dep_atomic_ops = dependency('atomic_ops', required : false)
Peter Seiderer8de26962018-07-16 23:01:40 +020062if cc.links('''
Dylan Baker5f7deb52017-09-13 11:46:13 -070063 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); }
Peter Seiderer8de26962018-07-16 23:01:40 +020065 int main() { }
Dylan Baker5f7deb52017-09-13 11:46:13 -070066 ''',
67 name : 'Intel Atomics')
68 intel_atomics = true
69 with_atomics = true
Eric Engestrom5236de62018-02-07 14:20:52 +000070 dep_atomic_ops = []
71elif dep_atomic_ops.found()
Dylan Baker5f7deb52017-09-13 11:46:13 -070072 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
Eric Engestrom360292c2018-12-19 14:55:45 +0000171# XXX: Apparently only freebsd and dragonfly bsd actually need this (and
Dylan Baker5f7deb52017-09-13 11:46:13 -0700172# gnu/kfreebsd), not openbsd and netbsd
173with_libkms = false
174_libkms = get_option('libkms')
175if _libkms != 'false'
Eric Anholte6fb9cc2021-04-22 16:25:07 -0700176 with_libkms = _libkms == 'true' or (['linux', 'freebsd', 'dragonfly'].contains(host_machine.system()) and not android)
Dylan Baker5f7deb52017-09-13 11:46:13 -0700177endif
178
Dylan Baker5f7deb52017-09-13 11:46:13 -0700179# 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)
Eric Engestrom1f8ada82020-03-29 22:45:52 +0200193
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']
Eric Engestrom074947e2018-11-07 15:00:24 +0000206 config.set10('HAVE_' + header.underscorify().to_upper(),
Eric Engestrom1f8ada82020-03-29 22:45:52 +0200207 cc.compiles('#include <@0@>'.format(header), name : '@0@ works'.format(header)))
Eric Engestrom2bd461e2018-03-12 16:17:55 +0000208endforeach
Eric Engestrom1f8ada82020-03-29 22:45:52 +0200209
Eric Engestrom827a2a22019-09-14 22:22:03 +0100210if (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'))
Dylan Baker5f7deb52017-09-13 11:46:13 -0700213 config.set10('MAJOR_IN_SYSMACROS', true)
Eric Engestrom827a2a22019-09-14 22:22:03 +0100214endif
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'))
Dylan Baker5f7deb52017-09-13 11:46:13 -0700218 config.set10('MAJOR_IN_MKDEV', true)
219endif
Eric Engestrom1a44bba2018-01-26 17:04:28 +0000220config.set10('HAVE_OPEN_MEMSTREAM', cc.has_function('open_memstream'))
Dylan Baker5f7deb52017-09-13 11:46:13 -0700221
222warn_c_args = []
Eric Engestromba176732018-01-26 11:18:03 +0000223foreach a : ['-Wall', '-Wextra', '-Wsign-compare', '-Werror=undef',
Eric Engestrom8c1fddc2018-11-07 16:50:06 +0000224 '-Werror=implicit-function-declaration', '-Wpointer-arith',
Dylan Baker5f7deb52017-09-13 11:46:13 -0700225 '-Wwrite-strings', '-Wstrict-prototypes', '-Wmissing-prototypes',
226 '-Wmissing-declarations', '-Wnested-externs', '-Wpacked',
Eric Engestrom8177d732018-01-26 11:18:30 +0000227 '-Wswitch-enum', '-Wmissing-format-attribute',
228 '-Wstrict-aliasing=2', '-Winit-self', '-Winline', '-Wshadow',
Dylan Baker5f7deb52017-09-13 11:46:13 -0700229 '-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
Eric Engestrom8177d732018-01-26 11:18:30 +0000236foreach a : ['unused-parameter', 'attributes', 'long-long',
Dylan Baker5f7deb52017-09-13 11:46:13 -0700237 'missing-field-initializers']
238 if cc.has_argument('-W@0@'.format(a))
239 warn_c_args += '-Wno-@0@'.format(a)
240 endif
241endforeach
242
Lucas De Marchiba808252018-09-12 13:24:12 -0700243# all c args:
244libdrm_c_args = warn_c_args + ['-fvisibility=hidden']
245
Dylan Baker5f7deb52017-09-13 11:46:13 -0700246
247dep_pciaccess = dependency('pciaccess', version : '>= 0.10', required : with_intel)
248dep_cunit = dependency('cunit', version : '>= 2.1', required : false)
Igor Gnatenko9411f8e2018-02-19 13:55:27 +0100249_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'
Jose Maria Casanova Crespoc997baf2020-05-05 21:50:33 +0200259 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
Igor Gnatenko9411f8e2018-02-19 13:55:27 +0100264 with_valgrind = dep_valgrind.found()
265else
266 dep_valgrind = []
267 with_valgrind = false
268endif
Dylan Baker5f7deb52017-09-13 11:46:13 -0700269
270with_man_pages = get_option('man-pages')
Heiko Becker62b9a3e2021-01-15 21:11:41 +0100271prog_rst2man = find_program('rst2man', 'rst2man.py', required: with_man_pages == 'true')
Simon Ser05b0a952020-06-03 11:58:07 +0200272with_man_pages = with_man_pages != 'false' and prog_rst2man.found()
Dylan Baker5f7deb52017-09-13 11:46:13 -0700273
Eric Engestrome8d3d882018-03-16 17:07:08 +0000274config.set10('HAVE_VISIBILITY',
275 cc.compiles('''int foo_hidden(void) __attribute__((visibility(("hidden"))));''',
276 name : 'compiler supports __attribute__(("hidden"))'))
Dylan Baker5f7deb52017-09-13 11:46:13 -0700277
Eric Engestrom5457e002018-01-26 16:23:01 +0000278foreach t : [
Eric Engestrom2cd91052018-01-26 16:17:53 +0000279 [with_exynos, 'EXYNOS'],
Eric Engestromec53f482018-01-26 15:19:03 +0000280 [with_freedreno_kgsl, 'FREEDRENO_KGSL'],
Eric Engestrom5457e002018-01-26 16:23:01 +0000281 [with_intel, 'INTEL'],
282 [with_nouveau, 'NOUVEAU'],
283 [with_radeon, 'RADEON'],
284 [with_vc4, 'VC4'],
285 [with_vmwgfx, 'VMWGFX'],
Igor Gnatenko9411f8e2018-02-19 13:55:27 +0100286 [with_cairo_tests, 'CAIRO'],
287 [with_valgrind, 'VALGRIND'],
Eric Engestrom5457e002018-01-26 16:23:01 +0000288 ]
Eric Engestromee473292018-01-26 16:21:30 +0000289 config.set10('HAVE_@0@'.format(t[1]), t[0])
Dylan Baker5f7deb52017-09-13 11:46:13 -0700290endforeach
Eric Engestromec53f482018-01-26 15:19:03 +0000291if with_freedreno_kgsl and not with_freedreno
292 error('cannot enable freedreno-kgsl without freedreno support')
Dylan Baker5f7deb52017-09-13 11:46:13 -0700293endif
Dylan Baker5f7deb52017-09-13 11:46:13 -0700294config.set10('_GNU_SOURCE', true)
295config_file = configure_file(
296 configuration : config,
297 output : 'config.h',
298)
Scott Andersonc70bd7b2019-12-17 22:08:02 +1300299add_project_arguments('-include', '@0@'.format(config_file), language : 'c')
Dylan Baker5f7deb52017-09-13 11:46:13 -0700300
301inc_root = include_directories('.')
302inc_drm = include_directories('include/drm')
303
Eric Anholta819b9a2021-04-22 16:03:38 -0700304libdrm_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
Dylan Baker5f7deb52017-09-13 11:46:13 -0700327
Eric Engestrom077e6422019-11-11 23:51:04 +0000328test(
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
Dylan Baker5f7deb52017-09-13 11:46:13 -0700338ext_libdrm = declare_dependency(
339 link_with : libdrm,
Dylan Bakerdeb59782018-02-07 15:35:24 -0800340 include_directories : [inc_root, inc_drm],
Dylan Baker5f7deb52017-09-13 11:46:13 -0700341)
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',
Tanmay Shahf0c642e2018-08-13 17:29:21 -0700348 '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',
Dylan Baker5f7deb52017-09-13 11:46:13 -0700353 '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)
Eric Engestrom8177d732018-01-26 11:18:30 +0000367
Dylan Baker5f7deb52017-09-13 11:46:13 -0700368if 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')
Eric Engestrom7a58c212018-02-26 15:42:18 +0000406
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('')