blob: 478869eb671fd5d0b1c343ac499f7c2f58434135 [file] [log] [blame]
Arkadiusz Hilereccae132018-05-15 14:07:50 +03001project('igt-gpu-tools', 'c',
Petri Latvala22850c12019-06-20 14:52:12 +03002 version : '1.24',
Daniel Vetter9a7d8502017-09-05 14:36:14 +02003 default_options: [
4 'warning_level=2',
Lucas De Marchi523bc592018-06-06 15:27:39 -07005 'c_std=gnu11',
Arkadiusz Hilerefec5d22019-05-07 14:52:09 +03006 'b_ndebug=false',
7 'buildtype=debugoptimized',
Daniel Vetter9a7d8502017-09-05 14:36:14 +02008 ],
Daniel Vetter866970a2017-09-05 14:36:24 +02009 license : 'MIT',
Arkadiusz Hiler736b0992019-05-21 12:36:01 +030010 meson_version : '>=0.47.0')
Daniel Vetter9a7d8502017-09-05 14:36:14 +020011
Lyude Paul3f26aa32019-04-24 14:48:35 -040012if get_option('b_ndebug') != 'false'
13 error('Building without -Db_ndebug=false is not supported')
14endif
15
Daniel Vetter9a7d8502017-09-05 14:36:14 +020016cc = meson.get_compiler('c')
17
Lyude Paul3f26aa32019-04-24 14:48:35 -040018# Also make sure that the user doesn't have -DNDEBUG defined in their config
19if not cc.compiles(files('lib/check-ndebug.h'), args: get_option('c_args'))
20 error('Building with NDEBUG defined is not supported')
21endif
22
Daniel Vetterc4614fe2017-09-05 14:36:20 +020023cc_args = [
Petri Latvala7fd5da22018-10-29 16:30:54 +020024 '-Wbad-function-cast',
25 '-Wdeclaration-after-statement',
26 '-Wformat=2',
Eric Anholtcae05d92017-09-05 14:36:17 +020027# igt_assert(0) in switch statements triggers a bunch of this.
Daniel Vetterc4614fe2017-09-05 14:36:20 +020028 '-Wimplicit-fallthrough=0',
Petri Latvala7fd5da22018-10-29 16:30:54 +020029 '-Wlogical-op',
30 '-Wmissing-declarations',
31 '-Wmissing-format-attribute',
32 '-Wmissing-noreturn',
33 '-Wmissing-prototypes',
34 '-Wnested-externs',
35 '-Wold-style-definition',
36 '-Wpointer-arith',
37 '-Wredundant-decls',
38 '-Wshadow',
39 '-Wstrict-prototypes',
40 '-Wuninitialized',
41 '-Wunused',
42
43 '-Wno-clobbered',
44 '-Wno-maybe-uninitialized',
45 '-Wno-missing-field-initializers',
46 '-Wno-pointer-arith',
47 '-Wno-sign-compare',
48# Macros asserting on the range of their arguments triggers this.
49 '-Wno-type-limits',
50 '-Wno-unused-parameter',
51 '-Wno-unused-result',
52
53 '-Werror=address',
54 '-Werror=array-bounds',
55 '-Werror=implicit',
56 '-Werror=init-self',
57 '-Werror=int-to-pointer-cast',
58 '-Werror=main',
59 '-Werror=missing-braces',
60 '-Werror=nonnull',
61 '-Werror=pointer-to-int-cast',
62 '-Werror=return-type',
63 '-Werror=sequence-point',
64 '-Werror=trigraphs',
65 '-Werror=write-strings',
Arkadiusz Hiler615c7562019-05-08 11:09:42 +030066# Disable the memory allocating builtins as they may cause unexpected behavior
67# with our framework. They *may* get optimized out in favor of a register or
68# stack variable, making them effectively local. Local variables do not play
69# well with longjmp which is heavily used by IGT framework.
70 '-fno-builtin-malloc',
71 '-fno-builtin-calloc',
Daniel Vetterc4614fe2017-09-05 14:36:20 +020072]
73
74foreach cc_arg : cc_args
75 if cc.has_argument(cc_arg)
76 add_global_arguments(cc_arg, language : 'c')
77 endif
78endforeach
Eric Anholtcae05d92017-09-05 14:36:17 +020079
Simon Ser0ea68a12019-07-05 16:42:23 +030080build_chamelium = get_option('chamelium')
81build_docs = get_option('docs')
82build_tests = not get_option('tests').disabled()
83with_libdrm = get_option('libdrm_drivers')
Petri Latvala0e98bf62018-06-21 14:06:25 +030084
Arkadiusz Hilerefec5d22019-05-07 14:52:09 +030085build_info = ['Build type: ' + get_option('buildtype')]
Petri Latvala0e98bf62018-06-21 14:06:25 +030086
Lucas De Marchi31ea7dd2018-07-24 15:20:23 -070087inc = include_directories('include/drm-uapi', 'lib', 'lib/stubs/syscalls', '.')
Daniel Vetter9a7d8502017-09-05 14:36:14 +020088
Daniel Vetter491e8c12017-12-05 11:16:49 +010089inc_for_gtkdoc = include_directories('lib')
90
Daniel Vetter6e262252017-09-08 17:14:48 +020091config = configuration_data()
Daniel Vetter9a7d8502017-09-05 14:36:14 +020092
Petri Latvala0e98bf62018-06-21 14:06:25 +030093null_dep = dependency('', required : false)
94
95libdrm_info = []
96libdrm_intel = null_dep
97libdrm_nouveau = null_dep
98libdrm_amdgpu = null_dep
99
Arkadiusz Hiler43d7c052018-03-08 13:25:44 +0200100libdrm_version = '>=2.4.82'
101libdrm = dependency('libdrm', version : libdrm_version)
Petri Latvala0e98bf62018-06-21 14:06:25 +0300102if with_libdrm.contains('auto') or with_libdrm.contains('intel')
103 libdrm_intel = dependency('libdrm_intel', version : libdrm_version, required : with_libdrm.contains('intel'))
104 libdrm_info += 'intel'
105endif
106if with_libdrm.contains('auto') or with_libdrm.contains('nouveau')
107 libdrm_nouveau = dependency('libdrm_nouveau', version : libdrm_version, required : with_libdrm.contains('nouveau'))
108 libdrm_info += 'nouveau'
109endif
110if with_libdrm.contains('auto') or with_libdrm.contains('amdgpu')
111 libdrm_amdgpu = dependency('libdrm_amdgpu', version : libdrm_version, required : with_libdrm.contains('amdgpu'))
112 libdrm_info += 'amdgpu'
113endif
114
115build_info += 'With libdrm: ' + ','.join(libdrm_info)
Daniel Vetter9a7d8502017-09-05 14:36:14 +0200116
117pciaccess = dependency('pciaccess', version : '>=0.10')
118libkmod = dependency('libkmod')
Arkadiusz Hiler643dc092017-11-24 17:17:48 +0200119libprocps = dependency('libprocps', required : true)
Daniel Vetter2908e4c2018-10-30 13:22:12 +0100120
Simon Ser0ea68a12019-07-05 16:42:23 +0300121libunwind = dependency('libunwind', required : get_option('libunwind'))
Arkadiusz Hiler736b0992019-05-21 12:36:01 +0300122build_info += 'With libunwind: @0@'.format(libunwind.found())
Daniel Vetter2908e4c2018-10-30 13:22:12 +0100123
Maarten Lankhorste39e0992018-08-28 14:04:25 +0200124libdw = dependency('libdw', required : true)
Maxime Ripardddb38282018-10-04 14:39:01 +0200125pixman = dependency('pixman-1', required : true)
Daniel Vetter9a7d8502017-09-05 14:36:14 +0200126
Simon Ser0ea68a12019-07-05 16:42:23 +0300127valgrind = dependency('valgrind', required : get_option('valgrind'))
Arkadiusz Hiler736b0992019-05-21 12:36:01 +0300128if valgrind.found()
129 config.set('HAVE_VALGRIND', 1)
Daniel Vetter9a7d8502017-09-05 14:36:14 +0200130endif
Arkadiusz Hiler736b0992019-05-21 12:36:01 +0300131build_info += 'Valgrind annotations: @0@'.format(valgrind.found())
Daniel Vetter9a7d8502017-09-05 14:36:14 +0200132
Arkadiusz Hilerf9b6fd62018-02-20 11:00:22 +0200133cairo = dependency('cairo', version : '>1.12.0', required : true)
Antonio Argenzianod75e6762018-02-23 15:14:40 -0800134libudev = dependency('libudev', required : true)
Petri Latvala9bbfbb12018-06-21 14:06:24 +0300135glib = dependency('glib-2.0', required : true)
Daniel Vetter9a7d8502017-09-05 14:36:14 +0200136
Daniel Vetter9a7d8502017-09-05 14:36:14 +0200137xmlrpc = dependency('xmlrpc', required : false)
138xmlrpc_util = dependency('xmlrpc_util', required : false)
139xmlrpc_client = dependency('xmlrpc_client', required : false)
140
Jani Nikula1ae18b02017-10-24 11:14:14 +0300141xmlrpc_cmd = find_program('xmlrpc-c-config', required : false)
142if not xmlrpc.found() and xmlrpc_cmd.found()
143 libs_cmd = run_command(xmlrpc_cmd, 'client', '--libs')
144 cflags_cmd = run_command(xmlrpc_cmd, 'client', '--cflags')
Arkadiusz Hiler892abc62017-10-17 15:05:41 +0300145
146 if libs_cmd.returncode() == 0 and cflags_cmd.returncode() == 0
147 xmlrpc = declare_dependency(compile_args: cflags_cmd.stdout().strip().split(),
Simon Ser311baff2019-04-23 16:04:52 +0300148 link_args : libs_cmd.stdout().strip().split())
Arkadiusz Hiler892abc62017-10-17 15:05:41 +0300149 xmlrpc_util = declare_dependency()
150 xmlrpc_client = declare_dependency()
151 endif
152endif
153
Arkadiusz Hiler736b0992019-05-21 12:36:01 +0300154if build_chamelium.enabled() and not (xmlrpc.found() and xmlrpc_util.found() and xmlrpc_client.found())
155 error('Chamelium build forced and required dependency xmlrpc not found')
156endif
157
158gsl = dependency('gsl', required : build_chamelium)
159alsa = dependency('alsa', required : build_chamelium)
160libcurl = dependency('libcurl', required : build_chamelium)
161
162if xmlrpc.found() and xmlrpc_util.found() and xmlrpc_client.found() and gsl.found() and alsa.found() and libcurl.found()
163 config.set('HAVE_CHAMELIUM', 1)
Simon Ser311baff2019-04-23 16:04:52 +0300164 chamelium = declare_dependency(dependencies : [
165 xmlrpc,
166 xmlrpc_util,
167 xmlrpc_client,
168 gsl,
169 alsa,
Petri Latvalaeff5d0d2019-05-20 12:39:24 +0300170 ])
Arkadiusz Hiler736b0992019-05-21 12:36:01 +0300171else
172 chamelium = disabler()
Daniel Vetter9a7d8502017-09-05 14:36:14 +0200173endif
Arkadiusz Hiler736b0992019-05-21 12:36:01 +0300174
175build_info += 'Build Chamelium test: @0@'.format(chamelium.found())
Daniel Vetter9a7d8502017-09-05 14:36:14 +0200176
177pthreads = dependency('threads')
178math = cc.find_library('m')
179realtime = cc.find_library('rt')
180dlsym = cc.find_library('dl')
181zlib = cc.find_library('z')
182
Guillaume Tucker70303d22019-06-24 17:22:33 +0100183if cc.links('''
184#include <stdint.h>
185int main(void) {
186 uint32_t x32 = 0;
187 uint64_t x64 = 0;
188 __atomic_load_n(&x32, __ATOMIC_SEQ_CST);
189 __atomic_load_n(&x64, __ATOMIC_SEQ_CST);
190 return 0;
191}''', name : 'built-in atomics')
192 libatomic = null_dep
193else
194 libatomic = cc.find_library('atomic')
195endif
196
Daniel Vetter9a7d8502017-09-05 14:36:14 +0200197if cc.has_header('linux/kd.h')
Daniel Vetter6e262252017-09-08 17:14:48 +0200198 config.set('HAVE_LINUX_KD_H', 1)
Daniel Vetter9a7d8502017-09-05 14:36:14 +0200199endif
200if cc.has_header('sys/kd.h')
Daniel Vetter6e262252017-09-08 17:14:48 +0200201 config.set('HAVE_SYS_KD_H', 1)
Daniel Vetter9a7d8502017-09-05 14:36:14 +0200202endif
203if cc.has_header('libgen.h')
Daniel Vetter6e262252017-09-08 17:14:48 +0200204 config.set('HAVE_LIBGEN_H', 1)
Daniel Vetter9a7d8502017-09-05 14:36:14 +0200205endif
206if cc.has_header('sys/io.h')
Daniel Vetter6e262252017-09-08 17:14:48 +0200207 config.set('HAVE_SYS_IO_H', 1)
Daniel Vetter9a7d8502017-09-05 14:36:14 +0200208endif
209if cc.has_header('cpuid.h')
210 # FIXME: Do we need the example link test from configure.ac?
Daniel Vetter6e262252017-09-08 17:14:48 +0200211 config.set('HAVE_CPUID_H', 1)
Daniel Vetter9a7d8502017-09-05 14:36:14 +0200212endif
Lyude Paulef7c18b2019-04-24 16:11:31 -0400213if cc.has_header_symbol('unistd.h', 'gettid', args : '-D_GNU_SOURCE')
214 config.set('HAVE_GETTID', 1)
215endif
Daniel Vetter9a7d8502017-09-05 14:36:14 +0200216
217if cc.has_member('struct sysinfo', 'totalram',
218 prefix : '#include <sys/sysinfo.h>')
Daniel Vetter6e262252017-09-08 17:14:48 +0200219 config.set('HAVE_STRUCT_SYSINFO_TOTALRAM', 1)
Daniel Vetter9a7d8502017-09-05 14:36:14 +0200220endif
221
Lucas De Marchibcb37a92018-07-24 15:20:24 -0700222have = cc.has_function('memfd_create', prefix : '''#include <sys/mman.h>''', args : '-D_GNU_SOURCE')
223config.set10('HAVE_MEMFD_CREATE', have)
224
Daniel Vetter9a7d8502017-09-05 14:36:14 +0200225add_project_arguments('-D_GNU_SOURCE', language : 'c')
226add_project_arguments('-include', 'config.h', language : 'c')
227
Arkadiusz Hiler5b51f9e2019-05-07 14:54:35 +0300228# FEATURE_TEST_MACROS(7)
229# performs lightweight overflow checks on quite a few libc functions
230# requires -O optimizations
231if ['debugoptimized', 'release', 'minsize'].contains(get_option('buildtype'))
232 add_project_arguments('-D_FORTIFY_SOURCE=2', language : 'c')
233endif
234
Daniel Vetter6e262252017-09-08 17:14:48 +0200235config.set('PACKAGE_NAME', meson.project_name())
236config.set_quoted('PACKAGE_VERSION', meson.project_version())
237config.set_quoted('PACKAGE', meson.project_name())
238config.set('PACKAGE_STRING', meson.project_name() + ' ' + meson.project_version())
239config.set_quoted('TARGET_CPU_PLATFORM', host_machine.cpu_family())
Daniel Vetter9a7d8502017-09-05 14:36:14 +0200240
Daniel Vetter6e262252017-09-08 17:14:48 +0200241configure_file(output: 'config.h', install: false, configuration: config)
Daniel Vetter9a7d8502017-09-05 14:36:14 +0200242
Petri Latvala4ebf6872018-01-15 13:14:56 +0200243prefix = get_option('prefix')
244bindir = get_option('bindir')
Arkadiusz Hilereccae132018-05-15 14:07:50 +0300245datadir = join_paths(get_option('datadir'), 'igt-gpu-tools')
Petri Latvala4ebf6872018-01-15 13:14:56 +0200246includedir = get_option('includedir')
247libdir = get_option('libdir')
Arkadiusz Hilereccae132018-05-15 14:07:50 +0300248libexecdir = join_paths(get_option('libexecdir'), 'igt-gpu-tools')
Arkadiusz Hiler6cc5ebf2018-08-13 13:16:22 +0300249amdgpudir = join_paths(libexecdir, 'amdgpu')
Petri Latvala4ebf6872018-01-15 13:14:56 +0200250mandir = get_option('mandir')
251pkgconfigdir = join_paths(libdir, 'pkgconfig')
252
Arkadiusz Hiler6cc5ebf2018-08-13 13:16:22 +0300253if get_option('use_rpath')
254 # Set up runpath for the test executables towards libigt.so.
255 # The path should be relative to $ORIGIN so the library is
256 # still found properly even if installed to a path other than
257 # prefix.
258
259 # libdir and bindir are pathnames relative to prefix. meson
260 # enforces this.
261
262 # 1. Start from the executable.
263 # 2. Executables are installed in certain dir. Add a .. for each
264 # directory name in it.
265 # 3. Add relative path to libdir.
266
267 bindir_rpathdir = '$ORIGIN'
268 foreach p : bindir.split('/')
269 bindir_rpathdir = join_paths(bindir_rpathdir, '..')
270 endforeach
271 bindir_rpathdir = join_paths(bindir_rpathdir, libdir)
272
273 libexecdir_rpathdir = '$ORIGIN'
274 foreach p : libexecdir.split('/')
275 libexecdir_rpathdir = join_paths(libexecdir_rpathdir, '..')
276 endforeach
277 libexecdir_rpathdir = join_paths(libexecdir_rpathdir, libdir)
278
279 amdgpudir_rpathdir = '$ORIGIN'
280 foreach p : amdgpudir.split('/')
281 amdgpudir_rpathdir = join_paths(amdgpudir_rpathdir, '..')
282 endforeach
283 amdgpudir_rpathdir = join_paths(amdgpudir_rpathdir, libdir)
284else
285 bindir_rpathdir = ''
286 libexecdir_rpathdir = ''
287 amdgpudir_rpathdir = ''
288endif
289
Daniel Vetter9a7d8502017-09-05 14:36:14 +0200290subdir('lib')
Arkadiusz Hiler736b0992019-05-21 12:36:01 +0300291if build_tests
Petri Latvala0e98bf62018-06-21 14:06:25 +0300292 subdir('tests')
Petri Latvala0e98bf62018-06-21 14:06:25 +0300293endif
Arkadiusz Hiler736b0992019-05-21 12:36:01 +0300294build_info += 'Build tests: @0@'.format(build_tests)
295
Daniel Vetter9a7d8502017-09-05 14:36:14 +0200296subdir('benchmarks')
297subdir('tools')
Petri Latvala18c1e752018-08-08 14:07:00 +0300298subdir('runner')
Daniel Vetter9a7d8502017-09-05 14:36:14 +0200299if libdrm_intel.found()
300 subdir('assembler')
Petri Latvala0e98bf62018-06-21 14:06:25 +0300301endif
302subdir('overlay')
303subdir('man')
304
Arkadiusz Hiler736b0992019-05-21 12:36:01 +0300305gtk_doc = dependency('gtk-doc', required : build_docs)
Arkadiusz Hilerd2a10fb2019-07-01 15:21:53 +0300306python3 = find_program('python3', required : build_docs)
307if build_tests and gtk_doc.found() and python3.found()
Arkadiusz Hiler736b0992019-05-21 12:36:01 +0300308 subdir('docs')
309elif build_docs.enabled()
310 error('Documentation requires building tests')
Daniel Vetter9a7d8502017-09-05 14:36:14 +0200311endif
Arkadiusz Hiler736b0992019-05-21 12:36:01 +0300312build_info += 'Build documentation: @0@'.format(build_tests and gtk_doc.found())
Petri Latvala0e98bf62018-06-21 14:06:25 +0300313
314message('Build options')
315message('=============')
316foreach str : build_info
317 message(str)
318endforeach
Maarten Lankhorstcb8e45a2019-02-01 11:13:59 +0100319
320if cairo.version().version_compare('<1.17.2')
321 if pixman.version().version_compare('<0.36.0')
322 warning('Pixman < 0.36.0 found, cannot test HDR formats')
323 endif
324 warning('Cairo < 1.17.2 found, cannot test HDR formats')
325elif pixman.version().version_compare('<0.36.0')
326 # Cairo 1.17.2 requires 0.36.0 to compile, but somehow it went missing?
327 error('Cairo with floating point support found, but pixman version too old')
328endif