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