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