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