Ignore joystick devices if LIBINPUT_IGNORE_JOYSTICK env is 1
[platform/upstream/libinput.git] / meson.build
1 project('libinput', 'c',
2         version : '1.22.0',
3         license : 'MIT/Expat',
4         default_options : [ 'c_std=gnu99', 'warning_level=2' ],
5         meson_version : '>= 0.49.0')
6
7 libinput_version = meson.project_version().split('.')
8
9 dir_data        = get_option('prefix') / get_option('datadir') / 'libinput'
10 dir_etc         = get_option('prefix') / get_option('sysconfdir')
11 dir_overrides   = get_option('prefix') / get_option('sysconfdir') / 'libinput'
12 dir_libexec     = get_option('prefix') / get_option('libexecdir') / 'libinput'
13 dir_lib         = get_option('prefix') / get_option('libdir')
14 dir_man1        = get_option('prefix') / get_option('mandir') / 'man1'
15 dir_system_udev = get_option('prefix') / 'lib' / 'udev'
16 dir_src_quirks  = meson.current_source_dir() / 'quirks'
17 dir_src_test    = meson.current_source_dir() / 'test'
18 dir_src         = meson.current_source_dir() / 'src'
19 dir_gitlab_ci   = meson.current_source_dir() / '.gitlab-ci'
20
21 dir_udev = get_option('udev-dir')
22 if dir_udev == ''
23         dir_udev = dir_system_udev
24 endif
25 dir_udev_callouts = dir_udev
26 dir_udev_rules    = dir_udev / 'rules.d'
27
28 # Collection of man pages, we'll append to that
29 src_man = files()
30
31 # We use libtool-version numbers because it's easier to understand.
32 # Before making a release, the libinput_so_*
33 # numbers should be modified. The components are of the form C:R:A.
34 # a) If binary compatibility has been broken (eg removed or changed interfaces)
35 #    change to C+1:0:0.
36 # b) If interfaces have been changed or added, but binary compatibility has
37 #    been preserved, change to C+1:0:A+1
38 # c) If the interface is the same as the previous version, change to C:R+1:A
39 libinput_lt_c=23
40 libinput_lt_r=0
41 libinput_lt_a=13
42
43 # convert to soname
44 libinput_so_version = '@0@.@1@.@2@'.format((libinput_lt_c - libinput_lt_a),
45                                             libinput_lt_a, libinput_lt_r)
46
47 # Compiler setup
48 cc = meson.get_compiler('c')
49 cflags = [
50         '-Wno-unused-parameter',
51         '-Wmissing-prototypes',
52         '-Wstrict-prototypes',
53         '-Wundef',
54         '-Wlogical-op',
55         '-Wpointer-arith',
56         '-Wuninitialized',
57         '-Winit-self',
58         '-Wstrict-prototypes',
59         '-Wimplicit-fallthrough',
60         '-Wredundant-decls',
61         '-Wincompatible-pointer-types',
62         '-Wformat=2',
63         '-Wno-missing-field-initializers',
64         '-Wmissing-declarations',
65
66         '-fvisibility=hidden',
67 ]
68 add_project_arguments(cc.get_supported_arguments(cflags), language : 'c')
69
70 # config.h
71 config_h = configuration_data()
72
73 doc_url_base = 'https://wayland.freedesktop.org/libinput/doc'
74 if libinput_version[2].to_int() >= 90
75         doc_url = '@0@/latest'.format(doc_url_base)
76 else
77         doc_url = '@0@/@1@'.format(doc_url_base, meson.project_version())
78 endif
79 config_h.set_quoted('HTTP_DOC_LINK', doc_url)
80
81 config_h.set('_GNU_SOURCE', '1')
82 if get_option('buildtype') == 'debug' or get_option('buildtype') == 'debugoptimized'
83         config_h.set_quoted('MESON_BUILD_ROOT', meson.current_build_dir())
84 else
85         config_h.set_quoted('MESON_BUILD_ROOT', '')
86 endif
87
88 prefix = '''#define _GNU_SOURCE 1
89 #include <assert.h>
90 '''
91 if cc.get_define('static_assert', prefix : prefix) == ''
92         config_h.set('static_assert(...)', '/* */')
93 endif
94
95 # Coverity breaks because it doesn't define _Float128 correctly, you'll end
96 # up with a bunch of messages in the form:
97 # "/usr/include/stdlib.h", line 133: error #20: identifier "_Float128" is
98 #           undefined
99 #   extern _Float128 strtof128 (const char *__restrict __nptr,
100 #          ^
101 # We don't use float128 ourselves, it gets pulled in from math.h or
102 # something, so let's just define it as uint128 and move on.
103 # Unfortunately we can't detect the coverity build at meson configure
104 # time, we only know it fails at runtime. So make this an option instead, to
105 # be removed when coverity fixes this again.
106 if get_option('coverity')
107         config_h.set('_Float128', '__uint128_t')
108         config_h.set('_Float32', 'int')
109         config_h.set('_Float32x', 'int')
110         config_h.set('_Float64', 'long')
111         config_h.set('_Float64x', 'long')
112 endif
113
114 if cc.has_header_symbol('dirent.h', 'versionsort', prefix : prefix)
115         config_h.set('HAVE_VERSIONSORT', '1')
116 endif
117
118 if not cc.has_header_symbol('errno.h', 'program_invocation_short_name', prefix : prefix)
119         if cc.has_header_symbol('stdlib.h', 'getprogname')
120                 config_h.set('program_invocation_short_name', 'getprogname()')
121         endif
122 endif
123
124 if cc.has_header('xlocale.h')
125         config_h.set('HAVE_XLOCALE_H', '1')
126 endif
127
128 code = '''
129 #include <locale.h>
130 void main(void) { newlocale(LC_NUMERIC_MASK, "C", (locale_t)0); }
131 '''
132 if cc.links(code, name : 'locale.h')
133         config_h.set('HAVE_LOCALE_H', '1')
134 endif
135
136 if not cc.has_header_symbol('sys/ptrace.h', 'PTRACE_ATTACH', prefix : prefix)
137         config_h.set('PTRACE_ATTACH', 'PT_ATTACH')
138         config_h.set('PTRACE_CONT', 'PT_CONTINUE')
139         config_h.set('PTRACE_DETACH', 'PT_DETACH')
140 endif
141
142 config_h.set10('HAVE_INSTALLED_TESTS', get_option('install-tests'))
143
144 # Dependencies
145 pkgconfig = import('pkgconfig')
146 dep_udev = dependency('libudev')
147 dep_mtdev = dependency('mtdev', version : '>= 1.1.0')
148 dep_libevdev = dependency('libevdev')
149 config_h.set10('HAVE_LIBEVDEV_DISABLE_PROPERTY',
150                 dep_libevdev.version().version_compare('>= 1.9.902'))
151
152 dep_lm = cc.find_library('m', required : false)
153 dep_rt = cc.find_library('rt', required : false)
154
155 # Include directories
156 includes_include = include_directories('include')
157 includes_src = include_directories('src')
158
159 ############ libwacom configuration ############
160
161 have_libwacom = get_option('libwacom')
162 config_h.set10('HAVE_LIBWACOM', have_libwacom)
163 if have_libwacom
164         dep_libwacom = dependency('libwacom', version : '>= 0.27')
165 else
166         dep_libwacom = declare_dependency()
167 endif
168
169 ############ ttrace configuration ############
170
171 dep_ttrace = dependency('ttrace', required : false)
172 if dep_ttrace.found()
173         config_h.set10('ENABLE_TTRACE', 1)
174 endif
175
176 ############ check udev function  ############
177
178 if cc.has_function('input_set_default_property', dependencies : dep_udev)
179         config_h.set10('HAVE_INPUT_SET_DEFAULT_PROPERTY', 1)
180 endif
181
182 ############ udev bits ############
183
184 executable('libinput-device-group',
185            'udev/libinput-device-group.c',
186            dependencies : [dep_udev, dep_libwacom],
187            include_directories : [includes_src, includes_include],
188            install : true,
189            install_dir : dir_udev_callouts)
190 executable('libinput-fuzz-extract',
191            'udev/libinput-fuzz-extract.c',
192            'src/util-strings.c',
193            'src/util-prop-parsers.c',
194            dependencies : [dep_udev, dep_libevdev, dep_lm],
195            include_directories : [includes_src, includes_include],
196            install : true,
197            install_dir : dir_udev_callouts)
198 executable('libinput-fuzz-to-zero',
199            'udev/libinput-fuzz-to-zero.c',
200            dependencies : [dep_udev, dep_libevdev],
201            include_directories : [includes_src, includes_include],
202            install : true,
203            install_dir : dir_udev_callouts)
204
205 udev_rules_config = configuration_data()
206 udev_rules_config.set('UDEV_TEST_PATH', '')
207 configure_file(input : 'udev/80-libinput-device-groups.rules.in',
208                output : '80-libinput-device-groups.rules',
209                install_dir : dir_udev_rules,
210                configuration : udev_rules_config)
211 configure_file(input : 'udev/90-libinput-fuzz-override.rules.in',
212                output : '90-libinput-fuzz-override.rules',
213                install_dir : dir_udev_rules,
214                configuration : udev_rules_config)
215
216 litest_udev_rules_config = configuration_data()
217 litest_udev_rules_config.set('UDEV_TEST_PATH', meson.current_build_dir() + '/')
218 litest_groups_rules_file = configure_file(input : 'udev/80-libinput-device-groups.rules.in',
219                output : '80-libinput-device-groups-litest.rules',
220                configuration : litest_udev_rules_config)
221 litest_fuzz_override_file = configure_file(input : 'udev/90-libinput-fuzz-override.rules.in',
222                                            output : '90-libinput-fuzz-override-litest.rules',
223                                            configuration : litest_udev_rules_config)
224
225 ############ Check for leftover udev rules ########
226
227 # This test should be defined first so we don't waste time testing anything
228 # else if we're about to fail anyway. ninja test will execute tests in the
229 # order of them defined in meson.build
230
231 if get_option('tests')
232         test('leftover-rules',
233              find_program('test/check-leftover-udev-rules.sh'),
234              is_parallel : false,
235              suite : ['all'])
236 endif
237
238 ############ libepoll-shim (BSD) ############
239
240 if cc.has_header_symbol('sys/epoll.h', 'epoll_create1', prefix : prefix)
241         # epoll is built-in (Linux, illumos)
242         dep_libepoll = declare_dependency()
243 else
244         # epoll is implemented in userspace by libepoll-shim (FreeBSD)
245         dir_libepoll = get_option('epoll-dir')
246         if dir_libepoll == ''
247                 dir_libepoll = get_option('prefix')
248         endif
249         includes_epoll = include_directories(dir_libepoll / 'include' / 'libepoll-shim')
250         dep_libepoll = cc.find_library('epoll-shim', dirs : dir_libepoll / 'lib')
251         code = '''
252         #include <sys/epoll.h>
253         int main(void) { epoll_create1(0); }
254         '''
255         if not cc.links(code,
256                 name : 'libepoll-shim check',
257                 dependencies : [dep_libepoll, dep_rt],
258                 include_directories : includes_epoll) # note: wants an include_directories object
259                 error('No built-in epoll or libepoll-shim found.')
260         endif
261         dep_libepoll = declare_dependency(
262                 include_directories : includes_epoll,
263                 dependencies : [dep_libepoll, dep_rt])
264 endif
265
266 ############ libinput-util.a ############
267
268 # Basic compilation test to make sure the headers include and define all the
269 # necessary bits.
270 util_headers = [
271                 'util-bits.h',
272                 'util-input-event.h',
273                 'util-list.h',
274                 'util-macros.h',
275                 'util-matrix.h',
276                 'util-prop-parsers.h',
277                 'util-ratelimit.h',
278                 'util-strings.h',
279                 'util-time.h',
280 ]
281 foreach h: util_headers
282         c = configuration_data()
283         c.set_quoted('FILE', h)
284         testfile = configure_file(input : 'test/test-util-includes.c',
285                                   output : 'test-util-includes-@0@.c'.format(h),
286                                   configuration : c)
287         executable('test-build-@0@'.format(h),
288                    testfile,
289                    include_directories : [includes_src, includes_include],
290                    install : false)
291 endforeach
292
293 src_libinput_util = [
294         'src/util-list.c',
295         'src/util-ratelimit.c',
296         'src/util-strings.c',
297         'src/util-prop-parsers.c',
298 ]
299 libinput_util = static_library('libinput-util',
300                                src_libinput_util,
301                                dependencies : [dep_udev, dep_libevdev, dep_libwacom],
302                                include_directories : includes_include)
303 dep_libinput_util = declare_dependency(link_with : libinput_util)
304
305 ############ libfilter.a ############
306 src_libfilter = [
307                 'src/filter.c',
308                 'src/filter-flat.c',
309                 'src/filter-low-dpi.c',
310                 'src/filter-mouse.c',
311                 'src/filter-touchpad.c',
312                 'src/filter-touchpad-flat.c',
313                 'src/filter-touchpad-x230.c',
314                 'src/filter-tablet.c',
315                 'src/filter-trackpoint.c',
316                 'src/filter-trackpoint-flat.c',
317 ]
318 libfilter = static_library('filter', src_libfilter,
319                            dependencies : [dep_udev, dep_libwacom],
320                            include_directories : includes_include)
321 dep_libfilter = declare_dependency(link_with : libfilter)
322
323 ############ libquirks.a #############
324 libinput_data_path = dir_data
325 libinput_data_override_path = dir_overrides / 'local-overrides.quirks'
326 config_h.set_quoted('LIBINPUT_QUIRKS_DIR', dir_data)
327 config_h.set_quoted('LIBINPUT_QUIRKS_OVERRIDE_FILE', libinput_data_override_path)
328
329 config_h.set_quoted('LIBINPUT_QUIRKS_SRCDIR', dir_src_quirks)
330 install_subdir('quirks',
331                exclude_files: ['README.md'],
332                install_dir : dir_data,
333                strip_directory : true)
334
335 src_libquirks = [
336         'src/quirks.c',
337 ]
338
339 deps_libquirks = [dep_udev, dep_libwacom, dep_libinput_util]
340 libquirks = static_library('quirks', src_libquirks,
341                            dependencies : deps_libquirks,
342                            include_directories : includes_include)
343 dep_libquirks = declare_dependency(link_with : libquirks)
344
345 # Create /etc/libinput
346 if meson.version().version_compare('>= 0.60')
347         install_emptydir(dir_etc / 'libinput')
348 else
349         install_subdir('libinput', install_dir : dir_etc)
350 endif
351
352 ############ libinput.so ############
353 install_headers('src/libinput.h')
354 src_libinput = src_libfilter + [
355         'src/libinput.c',
356         'src/libinput-private-config.c',
357         'src/evdev.c',
358         'src/evdev-debounce.c',
359         'src/evdev-fallback.c',
360         'src/evdev-totem.c',
361         'src/evdev-middle-button.c',
362         'src/evdev-mt-touchpad.c',
363         'src/evdev-mt-touchpad-tap.c',
364         'src/evdev-mt-touchpad-thumb.c',
365         'src/evdev-mt-touchpad-buttons.c',
366         'src/evdev-mt-touchpad-edge-scroll.c',
367         'src/evdev-mt-touchpad-gestures.c',
368         'src/evdev-tablet.c',
369         'src/evdev-tablet-pad.c',
370         'src/evdev-tablet-pad-leds.c',
371         'src/evdev-wheel.c',
372         'src/path-seat.c',
373         'src/udev-seat.c',
374         'src/timer.c',
375 ]
376
377 deps_libinput = [
378         dep_mtdev,
379         dep_udev,
380         dep_libevdev,
381         dep_libepoll,
382         dep_lm,
383         dep_rt,
384         dep_libwacom,
385         dep_libinput_util,
386         dep_libquirks,
387         dep_ttrace
388 ]
389
390 libinput_version_h_config = configuration_data()
391 libinput_version_h_config.set('LIBINPUT_VERSION_MAJOR', libinput_version[0])
392 libinput_version_h_config.set('LIBINPUT_VERSION_MINOR', libinput_version[1])
393 libinput_version_h_config.set('LIBINPUT_VERSION_MICRO', libinput_version[2])
394 libinput_version_h_config.set('LIBINPUT_VERSION', meson.project_version())
395
396 libinput_version_h = configure_file(
397                 input : 'src/libinput-version.h.in',
398                 output : 'libinput-version.h',
399                 configuration : libinput_version_h_config,
400 )
401
402 mapfile = dir_src / 'libinput.sym'
403 version_flag = '-Wl,--version-script,@0@'.format(mapfile)
404 lib_libinput = shared_library('input',
405                 src_libinput,
406                 include_directories : [include_directories('.'), includes_include],
407                 dependencies : deps_libinput,
408                 version : libinput_so_version,
409                 link_args : version_flag,
410                 link_depends : mapfile,
411                 install : true
412                 )
413
414 dep_libinput = declare_dependency(
415                 link_with : lib_libinput,
416                 dependencies : deps_libinput)
417
418 pkgconfig.generate(
419         filebase : 'libinput',
420         name : 'Libinput',
421         description : 'Input device library',
422         version : meson.project_version(),
423         libraries : lib_libinput
424 )
425
426 git_version_h = vcs_tag(command : ['git', 'describe'],
427                         fallback : 'unknown',
428                         input : 'src/libinput-git-version.h.in',
429                         output :'libinput-git-version.h')
430
431 ############ documentation ############
432
433 if get_option('documentation')
434         subdir('doc/api')
435         subdir('doc/user')
436 endif
437
438 ############ shell completion #########
439
440 subdir('completion/zsh')
441
442 ############ tools ############
443 libinput_tool_path = dir_libexec
444 config_h.set_quoted('LIBINPUT_TOOL_PATH', libinput_tool_path)
445 tools_shared_sources = [ 'tools/shared.c' ]
446 deps_tools_shared = [ dep_libinput, dep_libevdev ]
447 lib_tools_shared = static_library('tools_shared',
448                                   tools_shared_sources,
449                                   include_directories : [includes_src, includes_include],
450                                   dependencies : deps_tools_shared)
451 dep_tools_shared = declare_dependency(link_with : lib_tools_shared,
452                                       dependencies : deps_tools_shared)
453
454 deps_tools = [ dep_tools_shared, dep_libinput ]
455 libinput_debug_events_sources = [
456         'tools/libinput-debug-events.c',
457         libinput_version_h,
458 ]
459 executable('libinput-debug-events',
460            libinput_debug_events_sources,
461            dependencies : deps_tools,
462            include_directories : [includes_src, includes_include],
463            install_dir : libinput_tool_path,
464            install : true
465            )
466
467 libinput_debug_tablet_sources = [ 'tools/libinput-debug-tablet.c' ]
468 executable('libinput-debug-tablet',
469            libinput_debug_tablet_sources,
470            dependencies : deps_tools,
471            include_directories : [includes_src, includes_include],
472            install_dir : libinput_tool_path,
473            install : true)
474
475
476 libinput_quirks_sources = [ 'tools/libinput-quirks.c' ]
477 libinput_quirks = executable('libinput-quirks',
478                              libinput_quirks_sources,
479                              dependencies : [dep_libquirks, dep_tools_shared, dep_libinput],
480                              include_directories : [includes_src, includes_include],
481                              install_dir : libinput_tool_path,
482                              install : true
483                             )
484 test('validate-quirks',
485      libinput_quirks,
486      args: ['validate', '--data-dir=@0@'.format(dir_src_quirks)],
487      suite : ['all']
488      )
489
490 libinput_list_devices_sources = [ 'tools/libinput-list-devices.c' ]
491 libinput_list_devices = executable('libinput-list-devices',
492                                    libinput_list_devices_sources,
493                                    dependencies : deps_tools,
494                                    include_directories : [includes_src, includes_include],
495                                    install_dir : libinput_tool_path,
496                                    install : true,
497                                   )
498 test('list-devices',
499      libinput_list_devices,
500      suite : ['all', 'root', 'hardware'])
501
502 libinput_measure_sources = [ 'tools/libinput-measure.c' ]
503 executable('libinput-measure',
504            libinput_measure_sources,
505            dependencies : deps_tools,
506            include_directories : [includes_src, includes_include],
507            install_dir : libinput_tool_path,
508            install : true,
509            )
510
511 libinput_analyze_sources = [ 'tools/libinput-analyze.c' ]
512 executable('libinput-analyze',
513            libinput_analyze_sources,
514            dependencies : deps_tools,
515            include_directories : [includes_src, includes_include],
516            install_dir : libinput_tool_path,
517            install : true,
518            )
519
520 src_python_tools = files(
521               'tools/libinput-analyze-per-slot-delta.py',
522               'tools/libinput-analyze-recording.py',
523               'tools/libinput-analyze-touch-down-state.py',
524               'tools/libinput-measure-fuzz.py',
525               'tools/libinput-measure-touchpad-size.py',
526               'tools/libinput-measure-touchpad-tap.py',
527               'tools/libinput-measure-touchpad-pressure.py',
528               'tools/libinput-measure-touch-size.py',
529               'tools/libinput-replay.py'
530 )
531
532 foreach t : src_python_tools
533         configure_file(input: t,
534                        output: '@BASENAME@',
535                        copy: true,
536                        install_dir : libinput_tool_path
537                       )
538 endforeach
539
540 libinput_record_sources = [ 'tools/libinput-record.c', git_version_h ]
541 executable('libinput-record',
542            libinput_record_sources,
543            dependencies : deps_tools + [dep_udev],
544            include_directories : [includes_src, includes_include],
545            install_dir : libinput_tool_path,
546            install : true,
547            )
548
549 config_h.set10('HAVE_DEBUG_GUI', get_option('debug-gui'))
550 if get_option('debug-gui')
551         dep_gtk = dependency('gtk4', version : '>= 4.0', required : false)
552         config_h.set10('HAVE_GTK4', dep_gtk.found())
553         if not dep_gtk.found()
554                 dep_gtk = dependency('gtk+-3.0', version : '>= 3.20')
555                 config_h.set10('HAVE_GTK3', dep_gtk.found())
556         endif
557
558         gtk_targets = dep_gtk.get_pkgconfig_variable('targets')
559         have_gtk_wayland = gtk_targets.contains('wayland')
560         have_gtk_x11 = gtk_targets.contains('x11')
561
562         dep_cairo = dependency('cairo')
563         dep_glib = dependency('glib-2.0')
564         dep_x11 = dependency('x11', required : false)
565         dep_wayland_client = dependency('wayland-client', required : false)
566         dep_wayland_protocols = dependency('wayland-protocols', required : false)
567
568         config_h.set10('HAVE_GTK_X11', have_gtk_x11 and dep_x11.found())
569         config_h.set10('HAVE_GTK_WAYLAND', false)
570
571         debug_gui_sources = [ 'tools/libinput-debug-gui.c' ]
572
573         if have_gtk_wayland and dep_wayland_client.found() and dep_wayland_protocols.found()
574                 wayland_scanner = find_program('wayland-scanner')
575                 wlproto_dir = dep_wayland_protocols.get_pkgconfig_variable('pkgdatadir')
576
577                 proto_name = 'pointer-constraints-unstable-v1'
578                 input = files(wlproto_dir / 'unstable' / 'pointer-constraints' / '@0@.xml'.format(proto_name))
579
580                 wayland_headers = custom_target('@0@ client header'.format(proto_name),
581                         input: input,
582                         output: '@0@-client-protocol.h'.format(proto_name),
583                         command: [wayland_scanner, 'client-header', '@INPUT@', '@OUTPUT@'],
584                 )
585
586                 wayland_sources = custom_target('@0@ source'.format(proto_name),
587                         input: input,
588                         output: '@0@-protocol.c'.format(proto_name),
589                         command: [wayland_scanner, 'private-code', '@INPUT@', '@OUTPUT@'],
590                 )
591
592                 debug_gui_sources += [ wayland_headers, wayland_sources ]
593                 config_h.set10('HAVE_GTK_WAYLAND', true)
594         endif
595
596         deps_debug_gui = [
597                         dep_gtk,
598                         dep_cairo,
599                         dep_glib,
600                         dep_wayland_client,
601                         dep_wayland_protocols,
602                         dep_x11,
603                         ] + deps_tools
604         executable('libinput-debug-gui',
605                    debug_gui_sources,
606                    dependencies : deps_debug_gui,
607                    include_directories : [includes_src, includes_include],
608                    install_dir : libinput_tool_path,
609                    install : true
610                    )
611         src_man += files('tools/libinput-debug-gui.man')
612 endif
613
614 libinput_sources = [ 'tools/libinput-tool.c' ]
615
616 libinput_tool = executable('libinput',
617                            libinput_sources,
618                            dependencies : deps_tools,
619                            include_directories : [includes_src, includes_include],
620                            install : true
621                           )
622
623 ptraccel_debug_sources = [ 'tools/ptraccel-debug.c' ]
624 executable('ptraccel-debug',
625            ptraccel_debug_sources,
626            dependencies : [ dep_libfilter, dep_libinput ],
627            include_directories : [includes_src, includes_include],
628            install : false
629            )
630
631 # Don't run the test during a release build because we rely on the magic
632 # subtool lookup
633 if get_option('buildtype') == 'debug' or get_option('buildtype') == 'debugoptimized'
634         config_tool_option_test = configuration_data()
635         config_tool_option_test.set('DISABLE_WARNING', 'yes')
636         config_tool_option_test.set('MESON_ENABLED_DEBUG_GUI', get_option('debug-gui'))
637         config_tool_option_test.set('MESON_BUILD_ROOT', meson.current_build_dir())
638         config_tool_option_test.set('TOOL_PATH', libinput_tool.full_path())
639         tool_option_test = configure_file(input: 'tools/test_tool_option_parsing.py',
640                                           output: '@PLAINNAME@',
641                                           configuration : config_tool_option_test)
642         test('tool-option-parsing',
643              tool_option_test,
644              args : [tool_option_test, '-n', 'auto'],
645              suite : ['all', 'root'],
646              timeout : 240)
647 endif
648
649 # the libinput tools check whether we execute from the builddir, this is
650 # the test to verify that lookup. We test twice, once as normal test
651 # run from the builddir, once after copying to /tmp
652 test_builddir_lookup = executable('test-builddir-lookup',
653                                   'test/test-builddir-lookup.c',
654                                   dependencies : [ dep_tools_shared],
655                                   include_directories : [includes_src, includes_include],
656                                   install : false)
657 test('tools-builddir-lookup',
658      test_builddir_lookup,
659      args : ['--builddir-is-set'],
660      suite : ['all'])
661 test('tools-builddir-lookup-installed',
662      find_program('test/helper-copy-and-exec-from-tmp.sh'),
663      args : [test_builddir_lookup.full_path(), '--builddir-is-null'],
664      env : ['LD_LIBRARY_PATH=@0@'.format(meson.current_build_dir())],
665      suite : ['all'],
666      workdir : '/tmp')
667
668 ############ tests ############
669
670 test('symbols-leak-test',
671      find_program('test/symbols-leak-test'),
672      args : [ dir_src / 'libinput.sym', dir_src],
673      suite : ['all'])
674
675 # build-test only
676 executable('test-build-pedantic',
677            'test/build-pedantic.c',
678            dependencies : [dep_udev],
679            include_directories : [includes_src, includes_include],
680            c_args : ['-std=c99', '-pedantic', '-Werror'],
681            install : false)
682 # build-test only
683 executable('test-build-std-gnuc90',
684            'test/build-pedantic.c',
685            dependencies : [dep_udev],
686            include_directories : [includes_src, includes_include],
687            c_args : ['-std=gnu89', '-Werror'],
688            install : false)
689 # test for linking with the minimal linker flags
690 executable('test-build-linker',
691            'test/build-pedantic.c',
692            include_directories : [includes_src, includes_include],
693            dependencies : [ dep_libinput, dep_libinput_util ],
694            install : false)
695 # test including from C++ (in case CPP compiler is available)
696 if add_languages('cpp', required: false)
697         executable('test-build-cxx',
698                    'test/build-cxx.cc',
699                    dependencies : [dep_udev],
700                    include_directories : [includes_src, includes_include],
701                    install : false)
702 endif
703
704 libinput_test_sources = [ 'tools/libinput-test.c' ]
705 executable('libinput-test',
706            libinput_test_sources,
707            dependencies : deps_tools,
708            include_directories : [includes_src, includes_include],
709            install_dir : libinput_tool_path,
710            install : true,
711            )
712
713 # This is the test suite runner, we allow disabling that one because of
714 # dependencies
715 if get_option('tests')
716         dep_check = dependency('check', version : '>= 0.9.10')
717
718         gstack = find_program('gstack', required : false)
719         config_h.set10('HAVE_GSTACK', gstack.found())
720
721         # for inhibit support during test run
722         dep_libsystemd = dependency('libsystemd', version : '>= 221', required : false)
723         config_h.set10('HAVE_LIBSYSTEMD', dep_libsystemd.found())
724
725         litest_sources = [
726                 'src/libinput-private-config.c',
727                 'test/litest-device-absinfo-override.c',
728                 'test/litest-device-acer-hawaii-keyboard.c',
729                 'test/litest-device-acer-hawaii-touchpad.c',
730                 'test/litest-device-aiptek-tablet.c',
731                 'test/litest-device-alps-3fg.c',
732                 'test/litest-device-alps-semi-mt.c',
733                 'test/litest-device-alps-dualpoint.c',
734                 'test/litest-device-anker-mouse-kbd.c',
735                 'test/litest-device-apple-appletouch.c',
736                 'test/litest-device-apple-internal-keyboard.c',
737                 'test/litest-device-apple-magicmouse.c',
738                 'test/litest-device-asus-rog-gladius.c',
739                 'test/litest-device-atmel-hover.c',
740                 'test/litest-device-bcm5974.c',
741                 'test/litest-device-calibrated-touchscreen.c',
742                 'test/litest-device-cyborg-rat-5.c',
743                 'test/litest-device-dell-canvas-totem.c',
744                 'test/litest-device-dell-canvas-totem-touch.c',
745                 'test/litest-device-elantech-touchpad.c',
746                 'test/litest-device-elan-tablet.c',
747                 'test/litest-device-format-string.c',
748                 'test/litest-device-generic-pressurepad.c',
749                 'test/litest-device-generic-singletouch.c',
750                 'test/litest-device-gpio-keys.c',
751                 'test/litest-device-huion-pentablet.c',
752                 'test/litest-device-hp-wmi-hotkeys.c',
753                 'test/litest-device-ignored-mouse.c',
754                 'test/litest-device-keyboard.c',
755                 'test/litest-device-keyboard-all-codes.c',
756                 'test/litest-device-keyboard-quirked.c',
757                 'test/litest-device-keyboard-razer-blackwidow.c',
758                 'test/litest-device-keyboard-razer-blade-stealth.c',
759                 'test/litest-device-keyboard-razer-blade-stealth-videoswitch.c',
760                 'test/litest-device-lenovo-scrollpoint.c',
761                 'test/litest-device-lid-switch.c',
762                 'test/litest-device-lid-switch-surface3.c',
763                 'test/litest-device-logitech-media-keyboard-elite.c',
764                 'test/litest-device-logitech-trackball.c',
765                 'test/litest-device-nexus4-touch-screen.c',
766                 'test/litest-device-magic-trackpad.c',
767                 'test/litest-device-mouse.c',
768                 'test/litest-device-mouse-wheel-tilt.c',
769                 'test/litest-device-mouse-roccat.c',
770                 'test/litest-device-mouse-low-dpi.c',
771                 'test/litest-device-mouse-wheel-click-angle.c',
772                 'test/litest-device-mouse-wheel-click-count.c',
773                 'test/litest-device-ms-nano-transceiver-mouse.c',
774                 'test/litest-device-ms-surface-cover.c',
775                 'test/litest-device-protocol-a-touch-screen.c',
776                 'test/litest-device-qemu-usb-tablet.c',
777                 'test/litest-device-sony-vaio-keys.c',
778                 'test/litest-device-synaptics-x220.c',
779                 'test/litest-device-synaptics-hover.c',
780                 'test/litest-device-synaptics-i2c.c',
781                 'test/litest-device-synaptics-pressurepad.c',
782                 'test/litest-device-synaptics-rmi4.c',
783                 'test/litest-device-synaptics-st.c',
784                 'test/litest-device-synaptics-t440.c',
785                 'test/litest-device-synaptics-x1-carbon-3rd.c',
786                 'test/litest-device-tablet-mode-switch.c',
787                 'test/litest-device-thinkpad-extrabuttons.c',
788                 'test/litest-device-trackpoint.c',
789                 'test/litest-device-touch-screen.c',
790                 'test/litest-device-touchscreen-invalid-range.c',
791                 'test/litest-device-touchscreen-fuzz.c',
792                 'test/litest-device-touchscreen-mt-tool.c',
793                 'test/litest-device-uclogic-tablet.c',
794                 'test/litest-device-wacom-bamboo-2fg-finger.c',
795                 'test/litest-device-wacom-bamboo-2fg-pad.c',
796                 'test/litest-device-wacom-bamboo-2fg-pen.c',
797                 'test/litest-device-wacom-bamboo-16fg-pen.c',
798                 'test/litest-device-wacom-cintiq-12wx-pen.c',
799                 'test/litest-device-wacom-cintiq-13hdt-finger.c',
800                 'test/litest-device-wacom-cintiq-13hdt-pad.c',
801                 'test/litest-device-wacom-cintiq-13hdt-pen.c',
802                 'test/litest-device-wacom-cintiq-24hd-pen.c',
803                 'test/litest-device-wacom-cintiq-24hdt-pad.c',
804                 'test/litest-device-wacom-cintiq-pro-16-finger.c',
805                 'test/litest-device-wacom-cintiq-pro-16-pad.c',
806                 'test/litest-device-wacom-cintiq-pro-16-pen.c',
807                 'test/litest-device-wacom-ekr.c',
808                 'test/litest-device-wacom-hid4800-pen.c',
809                 'test/litest-device-wacom-intuos3-pad.c',
810                 'test/litest-device-wacom-intuos5-finger.c',
811                 'test/litest-device-wacom-intuos5-pad.c',
812                 'test/litest-device-wacom-intuos5-pen.c',
813                 'test/litest-device-wacom-isdv4-4200-pen.c',
814                 'test/litest-device-wacom-isdv4-524c-pen.c',
815                 'test/litest-device-wacom-isdv4-e6-pen.c',
816                 'test/litest-device-wacom-isdv4-e6-finger.c',
817                 'test/litest-device-wacom-mobilestudio-pro-pad.c',
818                 'test/litest-device-waltop-tablet.c',
819                 'test/litest-device-wheel-only.c',
820                 'test/litest-device-xen-virtual-pointer.c',
821                 'test/litest-device-vmware-virtual-usb-mouse.c',
822                 'test/litest-device-yubikey.c',
823                 'test/litest.c',
824         ]
825
826         dep_dl = cc.find_library('dl')
827         deps_litest = [
828                 dep_libinput,
829                 dep_check,
830                 dep_udev,
831                 dep_libevdev,
832                 dep_dl,
833                 dep_lm,
834                 dep_libsystemd,
835                 dep_libquirks,
836         ]
837
838         litest_config_h = configuration_data()
839         litest_config_h.set_quoted('LIBINPUT_DEVICE_GROUPS_RULES_FILE',
840                                    meson.current_build_dir() /
841                                    '80-libinput-device-groups-litest.rules')
842         litest_config_h.set_quoted('LIBINPUT_FUZZ_OVERRIDE_UDEV_RULES_FILE',
843                                    meson.current_build_dir() /
844                                    '90-libinput-fuzz-override-litest.rules')
845
846         def_no_main = '-DLITEST_NO_MAIN'
847         def_disable_backtrace = '-DLITEST_DISABLE_BACKTRACE_LOGGING'
848         defs_litest_selftest = [
849                 def_no_main,
850                 def_disable_backtrace,
851                 '-Wno-unused',
852         ]
853         test_litest_selftest_sources = [
854                 'test/litest-selftest.c',
855                 'test/litest.c',
856         ]
857         test_litest_selftest = executable('test-litest-selftest',
858                                           test_litest_selftest_sources,
859                                           include_directories : [includes_src, includes_include],
860                                           dependencies : deps_litest,
861                                           c_args : defs_litest_selftest,
862                                           install : false)
863         test('test-litest-selftest',
864              test_litest_selftest,
865              suite : ['all'],
866              timeout : 100)
867
868         def_LT_VERSION = '-DLIBINPUT_LT_VERSION="@0@:@1@:@2@"'.format(libinput_lt_c, libinput_lt_r, libinput_lt_a)
869         test_library_version = executable('test-library-version',
870                                           ['test/test-library-version.c'],
871                                           c_args : [ def_LT_VERSION ],
872                                           install : false)
873         test('test-library-version',
874              test_library_version,
875              suite : ['all'])
876
877         test_utils_sources = [
878                 'test/test-utils.c',
879         ]
880         test_utils = executable('libinput-test-utils',
881                                 test_utils_sources,
882                                 include_directories : [includes_src, includes_include],
883                                 dependencies : deps_litest,
884                                 install_dir : libinput_tool_path,
885                                 install : get_option('install-tests'))
886         test('test-utils',
887              test_utils,
888              suite : ['all'])
889
890         # When adding new files to this list, update the CI
891         tests_sources = [
892                 'test/test-udev.c',
893                 'test/test-path.c',
894                 'test/test-pointer.c',
895                 'test/test-touch.c',
896                 'test/test-log.c',
897                 'test/test-tablet.c',
898                 'test/test-totem.c',
899                 'test/test-pad.c',
900                 'test/test-touchpad.c',
901                 'test/test-touchpad-tap.c',
902                 'test/test-touchpad-buttons.c',
903                 'test/test-trackpoint.c',
904                 'test/test-trackball.c',
905                 'test/test-misc.c',
906                 'test/test-keyboard.c',
907                 'test/test-device.c',
908                 'test/test-gestures.c',
909                 'test/test-switch.c',
910                 'test/test-quirks.c',
911         ]
912         libinput_test_runner_sources = litest_sources + tests_sources
913         libinput_test_runner = executable('libinput-test-suite',
914                                           libinput_test_runner_sources,
915                                           include_directories : [includes_src, includes_include],
916                                           dependencies : deps_litest,
917                                           install_dir : libinput_tool_path,
918                                           install : get_option('install-tests'))
919
920         src_man += 'test/libinput-test-suite.man'
921
922         foreach testfile : tests_sources
923                 tfile = testfile.split('test/test-')[1]
924                 group = tfile.split('.c')[0]
925                 test('libinput-test-suite-@0@'.format(group),
926                      libinput_test_runner,
927                      suite : ['all', 'valgrind', 'root', 'hardware'],
928                      args : ['--filter-group=@0@'.format(group),
929                              '--xml-output=junit-@0@-XXXXXX.xml'.format(group)],
930                      is_parallel : false,
931                      timeout : 1200)
932         endforeach
933
934         test('libinput-test-deviceless',
935              libinput_test_runner,
936              suite : ['all', 'valgrind'],
937              args: ['--filter-deviceless',
938                     '--xml-output=junit-deviceless-XXXXXX.xml'])
939
940         valgrind = find_program('valgrind', required : false)
941         if valgrind.found()
942                 valgrind_env = environment()
943                 valgrind_suppressions_file = dir_src_test / 'valgrind.suppressions'
944                 add_test_setup('valgrind',
945                                 exe_wrapper : [ valgrind,
946                                                 '--leak-check=full',
947                                                 '--gen-suppressions=all',
948                                                 '--error-exitcode=3',
949                                                 '--suppressions=' + valgrind_suppressions_file ],
950                                 env :  valgrind_env,
951                                 timeout_multiplier : 100)
952         else
953                 message('valgrind not found, disabling valgrind test suite')
954         endif
955         configure_file(output : 'litest-config.h',
956                        configuration : litest_config_h)
957 endif
958
959
960 ############ man pages ############
961 man_config = configuration_data()
962 man_config.set('LIBINPUT_VERSION', meson.project_version())
963 man_config.set('LIBINPUT_DATA_DIR', dir_data)
964 if get_option('install-tests')
965         man_config.set('HAVE_INSTALLED_TESTS', '.\"')
966 else
967         man_config.set('HAVE_INSTALLED_TESTS', '')
968 endif
969 src_man += files(
970         'tools/libinput.man',
971         'tools/libinput-analyze.man',
972         'tools/libinput-analyze-per-slot-delta.man',
973         'tools/libinput-analyze-recording.man',
974         'tools/libinput-analyze-touch-down-state.man',
975         'tools/libinput-debug-events.man',
976         'tools/libinput-debug-tablet.man',
977         'tools/libinput-list-devices.man',
978         'tools/libinput-measure.man',
979         'tools/libinput-measure-fuzz.man',
980         'tools/libinput-measure-touchpad-size.man',
981         'tools/libinput-measure-touchpad-tap.man',
982         'tools/libinput-measure-touchpad-pressure.man',
983         'tools/libinput-measure-touch-size.man',
984         'tools/libinput-quirks.man',
985         'tools/libinput-record.man',
986         'tools/libinput-replay.man',
987         'tools/libinput-test.man',
988 )
989
990 foreach m : src_man
991         configure_file(input : m,
992                        output : '@BASENAME@.1',
993                        configuration : man_config,
994                        install_dir : dir_man1)
995 endforeach
996
997 # Same man page for the subtools to stay consistent with the other tools
998 configure_file(input : 'tools/libinput-quirks.man',
999                output : 'libinput-quirks-list.1',
1000                configuration : man_config,
1001                install_dir : dir_man1,
1002                )
1003 configure_file(input : 'tools/libinput-quirks.man',
1004                output : 'libinput-quirks-validate.1',
1005                configuration : man_config,
1006                install_dir : dir_man1,
1007                )
1008
1009 ############ output files ############
1010 configure_file(output : 'config.h', configuration : config_h)