615bb55d13ba7392dcef49f56722a0a07427c301
[platform/upstream/libdrm.git] / meson.build
1 # 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
21 project(
22   'libdrm',
23   ['c'],
24   version : '2.4.109',
25   license : 'MIT',
26   meson_version : '>= 0.52',
27   default_options : ['buildtype=debugoptimized', 'c_std=c99'],
28 )
29
30 pkg = import('pkgconfig')
31
32 config = configuration_data()
33
34 config.set10('UDEV', get_option('udev'))
35 with_freedreno_kgsl = get_option('freedreno-kgsl')
36 with_install_tests = get_option('install-test-programs')
37
38 if ['freebsd', 'dragonfly', 'netbsd'].contains(host_machine.system())
39   dep_pthread_stubs = dependency('pthread-stubs', version : '>= 0.4')
40 else
41   dep_pthread_stubs = []
42 endif
43 dep_threads = dependency('threads')
44
45 cc = meson.get_compiler('c')
46
47 android = cc.compiles('''int func() { return __ANDROID__; }''')
48
49 symbols_check = find_program('symbols-check.py')
50 prog_nm = find_program('nm')
51
52 # Check for atomics
53 intel_atomics = false
54 lib_atomics = false
55
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@'])
62
63 dep_atomic_ops = dependency('atomic_ops', required : false)
64 if cc.links('''
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); }
67     int main() { }
68     ''',
69     name : 'Intel Atomics')
70   intel_atomics = true
71   with_atomics = true
72   dep_atomic_ops = []
73 elif dep_atomic_ops.found()
74   lib_atomics = true
75   with_atomics = true
76 elif cc.has_function('atomic_cas_uint')
77   with_atomics = true
78 else
79   with_atomics = false
80 endif
81
82 config.set10('HAVE_LIBDRM_ATOMIC_PRIMITIVES', intel_atomics)
83 config.set10('HAVE_LIB_ATOMIC_OPS', lib_atomics)
84
85 with_intel = false
86 _intel = get_option('intel')
87 if _intel != 'false'
88   if _intel == 'true' and not with_atomics
89     error('libdrm_intel requires atomics.')
90   else
91     with_intel = _intel == 'true' or host_machine.cpu_family().startswith('x86')
92   endif
93 endif
94
95 with_radeon = false
96 _radeon = get_option('radeon')
97 if _radeon != 'false'
98   if _radeon == 'true' and not with_atomics
99     error('libdrm_radeon requires atomics.')
100   endif
101   with_radeon = true
102 endif
103
104 with_amdgpu = false
105 _amdgpu = get_option('amdgpu')
106 if _amdgpu != 'false'
107   if _amdgpu == 'true' and not with_atomics
108     error('libdrm_amdgpu requires atomics.')
109   endif
110   with_amdgpu = true
111 endif
112
113 with_nouveau = false
114 _nouveau = get_option('nouveau')
115 if _nouveau != 'false'
116   if _nouveau == 'true' and not with_atomics
117     error('libdrm_nouveau requires atomics.')
118   endif
119   with_nouveau = true
120 endif
121
122 with_vmwgfx = false
123 _vmwgfx = get_option('vmwgfx')
124 if _vmwgfx != 'false'
125   with_vmwgfx = true
126 endif
127
128 with_omap = false
129 _omap = get_option('omap')
130 if _omap == 'true'
131   if not with_atomics
132     error('libdrm_omap requires atomics.')
133   endif
134   with_omap = true
135 endif
136
137 with_freedreno = false
138 _freedreno = get_option('freedreno')
139 if _freedreno != 'false'
140   if _freedreno == 'true' and not with_atomics
141     error('libdrm_freedreno requires atomics.')
142   else
143     with_freedreno = _freedreno == 'true' or ['arm', 'aarch64'].contains(host_machine.cpu_family())
144   endif
145 endif
146
147 with_tegra = false
148 _tegra = get_option('tegra')
149 if _tegra == 'true'
150   if not with_atomics
151     error('libdrm_tegra requires atomics.')
152   endif
153   with_tegra = true
154 endif
155
156 with_etnaviv = false
157 _etnaviv = get_option('etnaviv')
158 if _etnaviv == 'true'
159   if not with_atomics
160     error('libdrm_etnaviv requires atomics.')
161   endif
162   with_etnaviv = true
163 endif
164
165 with_exynos = get_option('exynos') == 'true'
166
167 with_vc4 = false
168 _vc4 = get_option('vc4')
169 if _vc4 != 'false'
170   with_vc4 = _vc4 == 'true' or ['arm', 'aarch64'].contains(host_machine.cpu_family())
171 endif
172
173 # XXX: Apparently only freebsd and dragonfly bsd actually need this (and
174 # gnu/kfreebsd), not openbsd and netbsd
175 with_libkms = false
176 _libkms = get_option('libkms')
177 if _libkms != 'false'
178   with_libkms = _libkms == 'true' or (['linux', 'freebsd', 'dragonfly'].contains(host_machine.system()) and not android)
179 endif
180
181 # Among others FreeBSD does not have a separate dl library.
182 if not cc.has_function('dlsym')
183   dep_dl = cc.find_library('dl', required : with_nouveau)
184 else
185   dep_dl = []
186 endif
187 # clock_gettime might require -rt, or it might not. find out
188 if not cc.has_function('clock_gettime', prefix : '#define _GNU_SOURCE\n#include <time.h>')
189   # XXX: untested
190   dep_rt = cc.find_library('rt')
191 else
192   dep_rt = []
193 endif
194 dep_m = cc.find_library('m', required : false)
195
196 # The header is not required on Linux, and is in fact deprecated in glibc 2.30+
197 if ['linux'].contains(host_machine.system())
198   config.set10('HAVE_SYS_SYSCTL_H', false)
199 else
200   # From Niclas Zeising:
201   # FreeBSD requires sys/types.h for sys/sysctl.h, so add it as part of
202   # the includes when checking for headers.
203   config.set10('HAVE_SYS_SYSCTL_H',
204     cc.compiles('#include <sys/types.h>\n#include <sys/sysctl.h>', name : 'sys/sysctl.h works'))
205 endif
206
207 foreach header : ['sys/select.h', 'alloca.h']
208   config.set10('HAVE_' + header.underscorify().to_upper(), cc.check_header(header))
209 endforeach
210
211 if (cc.has_header_symbol('sys/sysmacros.h', 'major') and
212   cc.has_header_symbol('sys/sysmacros.h', 'minor') and
213   cc.has_header_symbol('sys/sysmacros.h', 'makedev'))
214   config.set10('MAJOR_IN_SYSMACROS', true)
215 endif
216 if (cc.has_header_symbol('sys/mkdev.h', 'major') and
217   cc.has_header_symbol('sys/mkdev.h', 'minor') and
218   cc.has_header_symbol('sys/mkdev.h', 'makedev'))
219   config.set10('MAJOR_IN_MKDEV', true)
220 endif
221 config.set10('HAVE_OPEN_MEMSTREAM', cc.has_function('open_memstream'))
222
223 libdrm_c_args = cc.get_supported_arguments([
224   '-Wsign-compare', '-Werror=undef', '-Werror=implicit-function-declaration',
225   '-Wpointer-arith', '-Wwrite-strings', '-Wstrict-prototypes',
226   '-Wmissing-prototypes', '-Wmissing-declarations', '-Wnested-externs',
227   '-Wpacked', '-Wswitch-enum', '-Wmissing-format-attribute',
228   '-Wstrict-aliasing=2', '-Winit-self', '-Winline', '-Wshadow',
229   '-Wdeclaration-after-statement', '-Wold-style-definition',
230   '-Wno-unused-parameter', '-Wno-attributes', '-Wno-long-long',
231   '-Wno-missing-field-initializers'])
232
233 dep_pciaccess = dependency('pciaccess', version : '>= 0.10', required : with_intel)
234 dep_cunit = dependency('cunit', version : '>= 2.1', required : false)
235 _cairo_tests = get_option('cairo-tests')
236 if _cairo_tests != 'false'
237   dep_cairo = dependency('cairo', required : _cairo_tests == 'true')
238   with_cairo_tests = dep_cairo.found()
239 else
240   dep_cairo = []
241   with_cairo_tests = false
242 endif
243 _valgrind = get_option('valgrind')
244 if _valgrind != 'false'
245   if with_freedreno
246     dep_valgrind = dependency('valgrind', required : _valgrind == 'true', version : '>=3.10.0')
247   else
248     dep_valgrind = dependency('valgrind', required : _valgrind == 'true')
249   endif
250   with_valgrind = dep_valgrind.found()
251 else
252   dep_valgrind = []
253   with_valgrind = false
254 endif
255
256 with_man_pages = get_option('man-pages')
257 prog_rst2man = find_program('rst2man', 'rst2man.py', required: with_man_pages == 'true')
258 with_man_pages = with_man_pages != 'false' and prog_rst2man.found()
259
260 config.set10('HAVE_VISIBILITY', cc.has_function_attribute('visibility:hidden'))
261
262 foreach t : [
263              [with_exynos, 'EXYNOS'],
264              [with_freedreno_kgsl, 'FREEDRENO_KGSL'],
265              [with_intel, 'INTEL'],
266              [with_nouveau, 'NOUVEAU'],
267              [with_radeon, 'RADEON'],
268              [with_vc4, 'VC4'],
269              [with_vmwgfx, 'VMWGFX'],
270              [with_cairo_tests, 'CAIRO'],
271              [with_valgrind, 'VALGRIND'],
272             ]
273   config.set10('HAVE_@0@'.format(t[1]), t[0])
274 endforeach
275 if with_freedreno_kgsl and not with_freedreno
276   error('cannot enable freedreno-kgsl without freedreno support')
277 endif
278 config.set10('_GNU_SOURCE', true)
279 config_file = configure_file(
280   configuration : config,
281   output : 'config.h',
282 )
283 add_project_arguments('-include', '@0@'.format(config_file), language : 'c')
284
285 inc_root = include_directories('.')
286 inc_drm = include_directories('include/drm')
287
288 libdrm_files = [files(
289    'xf86drm.c', 'xf86drmHash.c', 'xf86drmRandom.c', 'xf86drmSL.c',
290    'xf86drmMode.c'
291   ),
292   config_file, format_mod_static_table
293 ]
294
295 # Build an unversioned so on android
296 if android
297   libdrm_kw = {}
298 else
299   libdrm_kw = {'version' : '2.4.0'}
300 endif
301
302 libdrm = library(
303   'drm',
304   libdrm_files,
305   c_args : libdrm_c_args,
306   dependencies : [dep_valgrind, dep_rt, dep_m],
307   include_directories : inc_drm,
308   install : true,
309   kwargs : libdrm_kw,
310   gnu_symbol_visibility : 'hidden',
311 )
312
313 test(
314   'core-symbols-check',
315   symbols_check,
316   args : [
317     '--lib', libdrm,
318     '--symbols-file', files('core-symbols.txt'),
319     '--nm', prog_nm.path(),
320   ],
321 )
322
323 ext_libdrm = declare_dependency(
324   link_with : libdrm,
325   include_directories : [inc_root, inc_drm],
326 )
327
328 if meson.version().version_compare('>= 0.54.0')
329   meson.override_dependency('libdrm', ext_libdrm)
330 endif
331
332 install_headers('libsync.h', 'xf86drm.h', 'xf86drmMode.h')
333 install_headers(
334   'include/drm/drm.h', 'include/drm/drm_fourcc.h', 'include/drm/drm_mode.h',
335   'include/drm/drm_sarea.h', 'include/drm/i915_drm.h',
336   'include/drm/mach64_drm.h', 'include/drm/mga_drm.h',
337   'include/drm/msm_drm.h', 'include/drm/nouveau_drm.h',
338   'include/drm/qxl_drm.h', 'include/drm/r128_drm.h',
339   'include/drm/radeon_drm.h', 'include/drm/amdgpu_drm.h',
340   'include/drm/savage_drm.h', 'include/drm/sis_drm.h',
341   'include/drm/tegra_drm.h', 'include/drm/vc4_drm.h',
342   'include/drm/via_drm.h', 'include/drm/virtgpu_drm.h',
343   subdir : 'libdrm',
344 )
345 if with_vmwgfx
346   install_headers('include/drm/vmwgfx_drm.h', subdir : 'libdrm')
347 endif
348
349 pkg.generate(
350   libdrm,
351   name : 'libdrm',
352   subdirs : ['.', 'libdrm'],
353   description : 'Userspace interface to kernel DRM services',
354 )
355
356 if with_libkms
357   subdir('libkms')
358 endif
359 if with_intel
360   subdir('intel')
361 endif
362 if with_nouveau
363   subdir('nouveau')
364 endif
365 if with_radeon
366   subdir('radeon')
367 endif
368 if with_amdgpu
369   subdir('amdgpu')
370 endif
371 if with_omap
372   subdir('omap')
373 endif
374 if with_exynos
375   subdir('exynos')
376 endif
377 if with_freedreno
378   subdir('freedreno')
379 endif
380 if with_tegra
381   subdir('tegra')
382 endif
383 if with_vc4
384   subdir('vc4')
385 endif
386 if with_etnaviv
387   subdir('etnaviv')
388 endif
389 if with_man_pages
390   subdir('man')
391 endif
392 subdir('data')
393 subdir('tests')
394
395 message('')
396 message('@0@ will be compiled with:'.format(meson.project_name()))
397 message('')
398 message('  libkms         @0@'.format(with_libkms))
399 message('  Intel API      @0@'.format(with_intel))
400 message('  vmwgfx API     @0@'.format(with_vmwgfx))
401 message('  Radeon API     @0@'.format(with_radeon))
402 message('  AMDGPU API     @0@'.format(with_amdgpu))
403 message('  Nouveau API    @0@'.format(with_nouveau))
404 message('  OMAP API       @0@'.format(with_omap))
405 message('  EXYNOS API     @0@'.format(with_exynos))
406 message('  Freedreno API  @0@ (kgsl: @1@)'.format(with_freedreno, with_freedreno_kgsl))
407 message('  Tegra API      @0@'.format(with_tegra))
408 message('  VC4 API        @0@'.format(with_vc4))
409 message('  Etnaviv API    @0@'.format(with_etnaviv))
410 message('')