• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1project('libevdev', 'c',
2	version: '1.12.1', # change autotools version too
3	license: 'MIT/Expat',
4	default_options: [ 'c_std=gnu99', 'warning_level=2' ],
5	meson_version: '>= 0.47.0')
6
7libevdev_version = meson.project_version().split('.')
8
9dir_src         = join_paths(meson.source_root(), 'libevdev')
10dir_src_test    = join_paths(meson.source_root(), 'test')
11
12# Include directories
13includes_include = include_directories('include')
14
15# DO NOT MODIFY THIS
16# Use symbol versioning instead.
17libevdev_lt_c=5
18libevdev_lt_r=0
19libevdev_lt_a=3
20
21# convert to soname
22libevdev_so_version = '@0@.@1@.@2@'.format((libevdev_lt_c - libevdev_lt_a),
23					   libevdev_lt_a, libevdev_lt_r)
24
25
26# Compiler setup
27cc = meson.get_compiler('c')
28cppflags = ['-Wno-unused-parameter', '-fvisibility=hidden']
29cflags = cppflags + ['-Wmissing-prototypes', '-Wstrict-prototypes']
30add_project_arguments(cflags, language: 'c')
31add_project_arguments(cppflags, language: 'cpp')
32
33# config.h
34config_h = configuration_data()
35config_h.set('_GNU_SOURCE', '1')
36
37# Dependencies
38pkgconfig = import('pkgconfig')
39dep_lm = cc.find_library('m')
40dep_rt = cc.find_library('rt')
41
42input_h = join_paths(meson.source_root(), 'include', 'linux', host_machine.system(), 'input.h')
43uinput_h = join_paths(meson.source_root(), 'include', 'linux', host_machine.system(), 'uinput.h')
44input_event_codes_h = join_paths(meson.source_root(), 'include', 'linux', host_machine.system(), 'input-event-codes.h')
45
46# event-names.h
47make_event_names = find_program('libevdev/make-event-names.py')
48event_names_h = configure_file(input: 'libevdev/libevdev.h',
49			       output: 'event-names.h',
50			       command: [make_event_names, input_h, input_event_codes_h],
51			       capture: true)
52
53
54# libevdev.so
55install_headers('libevdev/libevdev.h',
56		'libevdev/libevdev-uinput.h',
57		subdir: 'libevdev-1.0/libevdev')
58src_libevdev = [
59	event_names_h,
60	'libevdev/libevdev.h',
61	'libevdev/libevdev-int.h',
62	'libevdev/libevdev-util.h',
63	'libevdev/libevdev-uinput.c',
64	'libevdev/libevdev-uinput.h',
65	'libevdev/libevdev-uinput-int.h',
66	'libevdev/libevdev.c',
67	'libevdev/libevdev-names.c',
68	'include/linux/input.h',
69	'include/linux/uinput.h',
70	input_event_codes_h,
71	input_h,
72	uinput_h
73]
74
75mapfile = join_paths(dir_src, 'libevdev.sym')
76version_flag = '-Wl,--version-script,@0@'.format(mapfile)
77lib_libevdev = library('evdev',
78	src_libevdev,
79	include_directories: [includes_include],
80	dependencies: [dep_rt],
81	version: libevdev_so_version,
82	link_args: version_flag,
83	link_depends: mapfile,
84	install: true
85)
86
87dep_libevdev = declare_dependency(link_with: lib_libevdev)
88
89pkgconfig.generate(
90	filebase: 'libevdev',
91	name: 'libevdev',
92	description: 'Handler library for evdev events',
93	version: meson.project_version(),
94	libraries: lib_libevdev,
95	subdirs: 'libevdev-1.0',
96)
97
98man_config = configuration_data()
99man_config.set('PACKAGE_VERSION', meson.project_version())
100manpage = configure_file(input: 'doc/libevdev.man.in',
101                         output: 'libevdev.3',
102                         configuration: man_config)
103install_man(manpage)
104
105
106# tools
107executable('libevdev-events',
108	   sources: ['tools/libevdev-events.c'],
109	   include_directories: [includes_include],
110	   dependencies: dep_libevdev,
111	   install: false)
112executable('libevdev-list-codes',
113	   sources: ['tools/libevdev-list-codes.c'],
114	   include_directories: [includes_include],
115	   dependencies: dep_libevdev,
116	   install: false)
117executable('touchpad-edge-detector',
118	   sources: ['tools/touchpad-edge-detector.c'],
119	   include_directories: [includes_include],
120	   dependencies: [dep_libevdev, dep_lm],
121           install: true)
122executable('mouse-dpi-tool',
123	   sources: ['tools/mouse-dpi-tool.c'],
124	   include_directories: [includes_include],
125	   dependencies: dep_libevdev,
126           install: true)
127executable('libevdev-tweak-device',
128	   sources: ['tools/libevdev-tweak-device.c'],
129	   include_directories: [includes_include],
130	   dependencies: dep_libevdev,
131	   install: true)
132install_man('tools/libevdev-tweak-device.1',
133            'tools/touchpad-edge-detector.1')
134
135# tests
136dep_check = dependency('check', version: '>= 0.9.9',
137		       required: get_option('tests'))
138if dep_check.found()
139	executable('test-link',
140		   sources: ['test/test-link.c'],
141		   include_directories: [includes_include],
142		   dependencies: dep_libevdev,
143		   install: false)
144	executable('test-compile-pedantic',
145		   sources: ['test/test-compile-pedantic.c'],
146		   c_args: ['-pedantic', '-Werror', '-std=c89'],
147		   include_directories: [includes_include],
148		   dependencies: dep_libevdev,
149		   install: false)
150
151	src_common = [
152		'test/test-common-uinput.c',
153		'test/test-common-uinput.h',
154		'test/test-common.c',
155		'test/test-common.h',
156		'test/test-main.c',
157	]
158	test_event_codes = executable('test-event-codes',
159				      sources: src_common + [
160					'test/test-event-codes.c',
161					'test/test-event-names.c',
162					'test/test-context.c',
163				      ],
164				      include_directories: [includes_include],
165				      dependencies: [dep_libevdev, dep_check],
166				      install: false)
167	test('test-event-codes', test_event_codes, suite: 'library')
168
169	test_internals = executable('test-internals',
170				    sources: src_common + [
171					'test/test-int-queue.c',
172				    ],
173				    include_directories: [includes_include],
174				    dependencies: [dep_libevdev, dep_check],
175				    install: false)
176	test('test-internals', test_internals, suite: 'library')
177
178	test_uinput = executable('test-uinput',
179				 sources: src_common + [
180					'test/test-uinput.c',
181				 ],
182				 include_directories: [includes_include],
183				 dependencies: [dep_libevdev, dep_check],
184				 install: false)
185	test('test-uinput', test_uinput, suite: 'library')
186
187	test_libevdev = executable('test-libevdev',
188				   sources: src_common + [
189					'test/test-libevdev-init.c',
190					'test/test-libevdev-has-event.c',
191					'test/test-libevdev-events.c',
192				   ],
193				   include_directories: [includes_include],
194				   dependencies: [dep_libevdev, dep_check],
195				   install: false)
196	test('test-libevdev', test_libevdev, suite: 'library')
197
198	test_kernel = executable('test-kernel',
199				 sources: src_common + [
200					'test/test-kernel.c',
201				 ],
202				 include_directories: [includes_include],
203				 dependencies: [dep_libevdev, dep_check],
204				 install: false)
205	test('test-kernel', test_kernel, suite: 'kernel')
206
207
208	valgrind = find_program('valgrind', required: false)
209	if valgrind.found()
210		valgrind_env = environment()
211		valgrind_env.set('CK_TIMEOUT_MULTIPLIER', '10')
212		valgrind_env.set('CK_FORK', 'no')
213		valgrind_env.set('RUNNING_ON_VALGRIND', '1')
214		valgrind_suppressions_file = join_paths(dir_src_test, 'valgrind.suppressions')
215		add_test_setup('valgrind',
216				exe_wrapper: [ valgrind,
217						'--leak-check=full',
218						'--gen-suppressions=all',
219						'--error-exitcode=3',
220						'--suppressions=' + valgrind_suppressions_file ],
221				env:  valgrind_env,
222				timeout_multiplier: 100)
223	else
224		message('valgrind not found, disabling valgrind test suite')
225	endif
226
227	test_static_link = find_program('test/test-static-symbols-leak.sh')
228	test('static-symbols-leak', test_static_link,
229	     args: [meson.current_build_dir()],
230	     suite: 'static')
231endif
232
233doxygen = find_program('doxygen', required: get_option('documentation'))
234if doxygen.found()
235	doxygen = find_program('doxygen')
236
237	src_doxygen = files(
238		# source files
239		join_paths(dir_src, 'libevdev.h'),
240		join_paths(dir_src, 'libevdev-uinput.h'),
241		# style files
242		'doc/style/bootstrap.css',
243		'doc/style/customdoxygen.css',
244		'doc/style/doxy-boot.js',
245		'doc/style/dynsections.js',
246		'doc/style/footer.html',
247		'doc/style/header.html',
248		'doc/style/layout.xml',
249		'doc/style/libevdevdoxygen.css',
250		'doc/style/LICENSE',
251		'doc/style/README.md',
252		'doc/style/style.css',
253	)
254	doxyfiles = []
255	foreach f: src_doxygen
256		df = configure_file(input: f,
257				    output: '@PLAINNAME@',
258				    copy: true)
259		doxyfiles += [df]
260	endforeach
261
262	doc_config = configuration_data()
263	doc_config.set('PACKAGE_NAME', meson.project_name())
264	doc_config.set('PACKAGE_VERSION', meson.project_version())
265	doc_config.set('builddir', meson.current_build_dir())
266	doc_config.set('top_srcdir', meson.source_root())
267	doc_config.set('srcdir', join_paths(meson.source_root(), 'doc'))
268
269	doxyfile = configure_file(input: 'doc/libevdev.doxygen.in',
270				  output: 'libevdev.doxygen',
271				  configuration: doc_config)
272	custom_target('doxygen',
273		      input: [doxyfiles, doxyfile] + src_doxygen,
274		      output: ['.'],
275		      command: [doxygen, doxyfile],
276		      install: false,
277		      build_by_default: true)
278endif
279
280# Coverity breaks because it doesn't define _Float128 correctly, you'll end
281# up with a bunch of messages in the form:
282# "/usr/include/stdlib.h", line 133: error #20: identifier "_Float128" is
283#           undefined
284#   extern _Float128 strtof128 (const char *__restrict __nptr,
285#          ^
286# We don't use float128 ourselves, it gets pulled in from math.h or
287# something, so let's just define it as uint128 and move on.
288# Unfortunately we can't detect the coverity build at meson configure
289# time, we only know it fails at runtime. So make this an option instead, to
290# be removed when coverity fixes this again.
291if get_option('coverity')
292        config_h.set('_Float128', '__uint128_t')
293        config_h.set('_Float32', 'int')
294        config_h.set('_Float32x', 'int')
295        config_h.set('_Float64', 'long')
296        config_h.set('_Float64x', 'long')
297endif
298
299############ output files ############
300configure_file(output: 'config.h', configuration: config_h)
301