Modify a ttrace macro name TRACE_BEGIN to TRACE_INPUT_BEGIN
[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
177 ############ udev bits ############
178
179 executable('libinput-device-group',
180            'udev/libinput-device-group.c',
181            dependencies : [dep_udev, dep_libwacom],
182            include_directories : [includes_src, includes_include],
183            install : true,
184            install_dir : dir_udev_callouts)
185 executable('libinput-fuzz-extract',
186            'udev/libinput-fuzz-extract.c',
187            'src/util-strings.c',
188            'src/util-prop-parsers.c',
189            dependencies : [dep_udev, dep_libevdev, dep_lm],
190            include_directories : [includes_src, includes_include],
191            install : true,
192            install_dir : dir_udev_callouts)
193 executable('libinput-fuzz-to-zero',
194            'udev/libinput-fuzz-to-zero.c',
195            dependencies : [dep_udev, dep_libevdev],
196            include_directories : [includes_src, includes_include],
197            install : true,
198            install_dir : dir_udev_callouts)
199
200 udev_rules_config = configuration_data()
201 udev_rules_config.set('UDEV_TEST_PATH', '')
202 configure_file(input : 'udev/80-libinput-device-groups.rules.in',
203                output : '80-libinput-device-groups.rules',
204                install_dir : dir_udev_rules,
205                configuration : udev_rules_config)
206 configure_file(input : 'udev/90-libinput-fuzz-override.rules.in',
207                output : '90-libinput-fuzz-override.rules',
208                install_dir : dir_udev_rules,
209                configuration : udev_rules_config)
210
211 litest_udev_rules_config = configuration_data()
212 litest_udev_rules_config.set('UDEV_TEST_PATH', meson.current_build_dir() + '/')
213 litest_groups_rules_file = configure_file(input : 'udev/80-libinput-device-groups.rules.in',
214                output : '80-libinput-device-groups-litest.rules',
215                configuration : litest_udev_rules_config)
216 litest_fuzz_override_file = configure_file(input : 'udev/90-libinput-fuzz-override.rules.in',
217                                            output : '90-libinput-fuzz-override-litest.rules',
218                                            configuration : litest_udev_rules_config)
219
220 ############ Check for leftover udev rules ########
221
222 # This test should be defined first so we don't waste time testing anything
223 # else if we're about to fail anyway. ninja test will execute tests in the
224 # order of them defined in meson.build
225
226 if get_option('tests')
227         test('leftover-rules',
228              find_program('test/check-leftover-udev-rules.sh'),
229              is_parallel : false,
230              suite : ['all'])
231 endif
232
233 ############ libepoll-shim (BSD) ############
234
235 if cc.has_header_symbol('sys/epoll.h', 'epoll_create1', prefix : prefix)
236         # epoll is built-in (Linux, illumos)
237         dep_libepoll = declare_dependency()
238 else
239         # epoll is implemented in userspace by libepoll-shim (FreeBSD)
240         dir_libepoll = get_option('epoll-dir')
241         if dir_libepoll == ''
242                 dir_libepoll = get_option('prefix')
243         endif
244         includes_epoll = include_directories(dir_libepoll / 'include' / 'libepoll-shim')
245         dep_libepoll = cc.find_library('epoll-shim', dirs : dir_libepoll / 'lib')
246         code = '''
247         #include <sys/epoll.h>
248         int main(void) { epoll_create1(0); }
249         '''
250         if not cc.links(code,
251                 name : 'libepoll-shim check',
252                 dependencies : [dep_libepoll, dep_rt],
253                 include_directories : includes_epoll) # note: wants an include_directories object
254                 error('No built-in epoll or libepoll-shim found.')
255         endif
256         dep_libepoll = declare_dependency(
257                 include_directories : includes_epoll,
258                 dependencies : [dep_libepoll, dep_rt])
259 endif
260
261 ############ libinput-util.a ############
262
263 # Basic compilation test to make sure the headers include and define all the
264 # necessary bits.
265 util_headers = [
266                 'util-bits.h',
267                 'util-input-event.h',
268                 'util-list.h',
269                 'util-macros.h',
270                 'util-matrix.h',
271                 'util-prop-parsers.h',
272                 'util-ratelimit.h',
273                 'util-strings.h',
274                 'util-time.h',
275 ]
276 foreach h: util_headers
277         c = configuration_data()
278         c.set_quoted('FILE', h)
279         testfile = configure_file(input : 'test/test-util-includes.c',
280                                   output : 'test-util-includes-@0@.c'.format(h),
281                                   configuration : c)
282         executable('test-build-@0@'.format(h),
283                    testfile,
284                    include_directories : [includes_src, includes_include],
285                    install : false)
286 endforeach
287
288 src_libinput_util = [
289         'src/util-list.c',
290         'src/util-ratelimit.c',
291         'src/util-strings.c',
292         'src/util-prop-parsers.c',
293 ]
294 libinput_util = static_library('libinput-util',
295                                src_libinput_util,
296                                dependencies : [dep_udev, dep_libevdev, dep_libwacom],
297                                include_directories : includes_include)
298 dep_libinput_util = declare_dependency(link_with : libinput_util)
299
300 ############ libfilter.a ############
301 src_libfilter = [
302                 'src/filter.c',
303                 'src/filter-flat.c',
304                 'src/filter-low-dpi.c',
305                 'src/filter-mouse.c',
306                 'src/filter-touchpad.c',
307                 'src/filter-touchpad-flat.c',
308                 'src/filter-touchpad-x230.c',
309                 'src/filter-tablet.c',
310                 'src/filter-trackpoint.c',
311                 'src/filter-trackpoint-flat.c',
312 ]
313 libfilter = static_library('filter', src_libfilter,
314                            dependencies : [dep_udev, dep_libwacom],
315                            include_directories : includes_include)
316 dep_libfilter = declare_dependency(link_with : libfilter)
317
318 ############ libquirks.a #############
319 libinput_data_path = dir_data
320 libinput_data_override_path = dir_overrides / 'local-overrides.quirks'
321 config_h.set_quoted('LIBINPUT_QUIRKS_DIR', dir_data)
322 config_h.set_quoted('LIBINPUT_QUIRKS_OVERRIDE_FILE', libinput_data_override_path)
323
324 config_h.set_quoted('LIBINPUT_QUIRKS_SRCDIR', dir_src_quirks)
325 install_subdir('quirks',
326                exclude_files: ['README.md'],
327                install_dir : dir_data,
328                strip_directory : true)
329
330 src_libquirks = [
331         'src/quirks.c',
332 ]
333
334 deps_libquirks = [dep_udev, dep_libwacom, dep_libinput_util]
335 libquirks = static_library('quirks', src_libquirks,
336                            dependencies : deps_libquirks,
337                            include_directories : includes_include)
338 dep_libquirks = declare_dependency(link_with : libquirks)
339
340 # Create /etc/libinput
341 if meson.version().version_compare('>= 0.60')
342         install_emptydir(dir_etc / 'libinput')
343 else
344         install_subdir('libinput', install_dir : dir_etc)
345 endif
346
347 ############ libinput.so ############
348 install_headers('src/libinput.h')
349 src_libinput = src_libfilter + [
350         'src/libinput.c',
351         'src/libinput-private-config.c',
352         'src/evdev.c',
353         'src/evdev-debounce.c',
354         'src/evdev-fallback.c',
355         'src/evdev-totem.c',
356         'src/evdev-middle-button.c',
357         'src/evdev-mt-touchpad.c',
358         'src/evdev-mt-touchpad-tap.c',
359         'src/evdev-mt-touchpad-thumb.c',
360         'src/evdev-mt-touchpad-buttons.c',
361         'src/evdev-mt-touchpad-edge-scroll.c',
362         'src/evdev-mt-touchpad-gestures.c',
363         'src/evdev-tablet.c',
364         'src/evdev-tablet-pad.c',
365         'src/evdev-tablet-pad-leds.c',
366         'src/evdev-wheel.c',
367         'src/path-seat.c',
368         'src/udev-seat.c',
369         'src/timer.c',
370 ]
371
372 deps_libinput = [
373         dep_mtdev,
374         dep_udev,
375         dep_libevdev,
376         dep_libepoll,
377         dep_lm,
378         dep_rt,
379         dep_libwacom,
380         dep_libinput_util,
381         dep_libquirks,
382         dep_ttrace
383 ]
384
385 libinput_version_h_config = configuration_data()
386 libinput_version_h_config.set('LIBINPUT_VERSION_MAJOR', libinput_version[0])
387 libinput_version_h_config.set('LIBINPUT_VERSION_MINOR', libinput_version[1])
388 libinput_version_h_config.set('LIBINPUT_VERSION_MICRO', libinput_version[2])
389 libinput_version_h_config.set('LIBINPUT_VERSION', meson.project_version())
390
391 libinput_version_h = configure_file(
392                 input : 'src/libinput-version.h.in',
393                 output : 'libinput-version.h',
394                 configuration : libinput_version_h_config,
395 )
396
397 mapfile = dir_src / 'libinput.sym'
398 version_flag = '-Wl,--version-script,@0@'.format(mapfile)
399 lib_libinput = shared_library('input',
400                 src_libinput,
401                 include_directories : [include_directories('.'), includes_include],
402                 dependencies : deps_libinput,
403                 version : libinput_so_version,
404                 link_args : version_flag,
405                 link_depends : mapfile,
406                 install : true
407                 )
408
409 dep_libinput = declare_dependency(
410                 link_with : lib_libinput,
411                 dependencies : deps_libinput)
412
413 pkgconfig.generate(
414         filebase : 'libinput',
415         name : 'Libinput',
416         description : 'Input device library',
417         version : meson.project_version(),
418         libraries : lib_libinput
419 )
420
421 git_version_h = vcs_tag(command : ['git', 'describe'],
422                         fallback : 'unknown',
423                         input : 'src/libinput-git-version.h.in',
424                         output :'libinput-git-version.h')
425
426 ############ documentation ############
427
428 if get_option('documentation')
429         subdir('doc/api')
430         subdir('doc/user')
431 endif
432
433 ############ shell completion #########
434
435 subdir('completion/zsh')
436
437 ############ tools ############
438 libinput_tool_path = dir_libexec
439 config_h.set_quoted('LIBINPUT_TOOL_PATH', libinput_tool_path)
440 tools_shared_sources = [ 'tools/shared.c' ]
441 deps_tools_shared = [ dep_libinput, dep_libevdev ]
442 lib_tools_shared = static_library('tools_shared',
443                                   tools_shared_sources,
444                                   include_directories : [includes_src, includes_include],
445                                   dependencies : deps_tools_shared)
446 dep_tools_shared = declare_dependency(link_with : lib_tools_shared,
447                                       dependencies : deps_tools_shared)
448
449 deps_tools = [ dep_tools_shared, dep_libinput ]
450 libinput_debug_events_sources = [
451         'tools/libinput-debug-events.c',
452         libinput_version_h,
453 ]
454 executable('libinput-debug-events',
455            libinput_debug_events_sources,
456            dependencies : deps_tools,
457            include_directories : [includes_src, includes_include],
458            install_dir : libinput_tool_path,
459            install : true
460            )
461
462 libinput_debug_tablet_sources = [ 'tools/libinput-debug-tablet.c' ]
463 executable('libinput-debug-tablet',
464            libinput_debug_tablet_sources,
465            dependencies : deps_tools,
466            include_directories : [includes_src, includes_include],
467            install_dir : libinput_tool_path,
468            install : true)
469
470
471 libinput_quirks_sources = [ 'tools/libinput-quirks.c' ]
472 libinput_quirks = executable('libinput-quirks',
473                              libinput_quirks_sources,
474                              dependencies : [dep_libquirks, dep_tools_shared, dep_libinput],
475                              include_directories : [includes_src, includes_include],
476                              install_dir : libinput_tool_path,
477                              install : true
478                             )
479 test('validate-quirks',
480      libinput_quirks,
481      args: ['validate', '--data-dir=@0@'.format(dir_src_quirks)],
482      suite : ['all']
483      )
484
485 libinput_list_devices_sources = [ 'tools/libinput-list-devices.c' ]
486 libinput_list_devices = executable('libinput-list-devices',
487                                    libinput_list_devices_sources,
488                                    dependencies : deps_tools,
489                                    include_directories : [includes_src, includes_include],
490                                    install_dir : libinput_tool_path,
491                                    install : true,
492                                   )
493 test('list-devices',
494      libinput_list_devices,
495      suite : ['all', 'root', 'hardware'])
496
497 libinput_measure_sources = [ 'tools/libinput-measure.c' ]
498 executable('libinput-measure',
499            libinput_measure_sources,
500            dependencies : deps_tools,
501            include_directories : [includes_src, includes_include],
502            install_dir : libinput_tool_path,
503            install : true,
504            )
505
506 libinput_analyze_sources = [ 'tools/libinput-analyze.c' ]
507 executable('libinput-analyze',
508            libinput_analyze_sources,
509            dependencies : deps_tools,
510            include_directories : [includes_src, includes_include],
511            install_dir : libinput_tool_path,
512            install : true,
513            )
514
515 src_python_tools = files(
516               'tools/libinput-analyze-per-slot-delta.py',
517               'tools/libinput-analyze-recording.py',
518               'tools/libinput-analyze-touch-down-state.py',
519               'tools/libinput-measure-fuzz.py',
520               'tools/libinput-measure-touchpad-size.py',
521               'tools/libinput-measure-touchpad-tap.py',
522               'tools/libinput-measure-touchpad-pressure.py',
523               'tools/libinput-measure-touch-size.py',
524               'tools/libinput-replay.py'
525 )
526
527 foreach t : src_python_tools
528         configure_file(input: t,
529                        output: '@BASENAME@',
530                        copy: true,
531                        install_dir : libinput_tool_path
532                       )
533 endforeach
534
535 libinput_record_sources = [ 'tools/libinput-record.c', git_version_h ]
536 executable('libinput-record',
537            libinput_record_sources,
538            dependencies : deps_tools + [dep_udev],
539            include_directories : [includes_src, includes_include],
540            install_dir : libinput_tool_path,
541            install : true,
542            )
543
544 config_h.set10('HAVE_DEBUG_GUI', get_option('debug-gui'))
545 if get_option('debug-gui')
546         dep_gtk = dependency('gtk4', version : '>= 4.0', required : false)
547         config_h.set10('HAVE_GTK4', dep_gtk.found())
548         if not dep_gtk.found()
549                 dep_gtk = dependency('gtk+-3.0', version : '>= 3.20')
550                 config_h.set10('HAVE_GTK3', dep_gtk.found())
551         endif
552
553         gtk_targets = dep_gtk.get_pkgconfig_variable('targets')
554         have_gtk_wayland = gtk_targets.contains('wayland')
555         have_gtk_x11 = gtk_targets.contains('x11')
556
557         dep_cairo = dependency('cairo')
558         dep_glib = dependency('glib-2.0')
559         dep_x11 = dependency('x11', required : false)
560         dep_wayland_client = dependency('wayland-client', required : false)
561         dep_wayland_protocols = dependency('wayland-protocols', required : false)
562
563         config_h.set10('HAVE_GTK_X11', have_gtk_x11 and dep_x11.found())
564         config_h.set10('HAVE_GTK_WAYLAND', false)
565
566         debug_gui_sources = [ 'tools/libinput-debug-gui.c' ]
567
568         if have_gtk_wayland and dep_wayland_client.found() and dep_wayland_protocols.found()
569                 wayland_scanner = find_program('wayland-scanner')
570                 wlproto_dir = dep_wayland_protocols.get_pkgconfig_variable('pkgdatadir')
571
572                 proto_name = 'pointer-constraints-unstable-v1'
573                 input = files(wlproto_dir / 'unstable' / 'pointer-constraints' / '@0@.xml'.format(proto_name))
574
575                 wayland_headers = custom_target('@0@ client header'.format(proto_name),
576                         input: input,
577                         output: '@0@-client-protocol.h'.format(proto_name),
578                         command: [wayland_scanner, 'client-header', '@INPUT@', '@OUTPUT@'],
579                 )
580
581                 wayland_sources = custom_target('@0@ source'.format(proto_name),
582                         input: input,
583                         output: '@0@-protocol.c'.format(proto_name),
584                         command: [wayland_scanner, 'private-code', '@INPUT@', '@OUTPUT@'],
585                 )
586
587                 debug_gui_sources += [ wayland_headers, wayland_sources ]
588                 config_h.set10('HAVE_GTK_WAYLAND', true)
589         endif
590
591         deps_debug_gui = [
592                         dep_gtk,
593                         dep_cairo,
594                         dep_glib,
595                         dep_wayland_client,
596                         dep_wayland_protocols,
597                         dep_x11,
598                         ] + deps_tools
599         executable('libinput-debug-gui',
600                    debug_gui_sources,
601                    dependencies : deps_debug_gui,
602                    include_directories : [includes_src, includes_include],
603                    install_dir : libinput_tool_path,
604                    install : true
605                    )
606         src_man += files('tools/libinput-debug-gui.man')
607 endif
608
609 libinput_sources = [ 'tools/libinput-tool.c' ]
610
611 libinput_tool = executable('libinput',
612                            libinput_sources,
613                            dependencies : deps_tools,
614                            include_directories : [includes_src, includes_include],
615                            install : true
616                           )
617
618 ptraccel_debug_sources = [ 'tools/ptraccel-debug.c' ]
619 executable('ptraccel-debug',
620            ptraccel_debug_sources,
621            dependencies : [ dep_libfilter, dep_libinput ],
622            include_directories : [includes_src, includes_include],
623            install : false
624            )
625
626 # Don't run the test during a release build because we rely on the magic
627 # subtool lookup
628 if get_option('buildtype') == 'debug' or get_option('buildtype') == 'debugoptimized'
629         config_tool_option_test = configuration_data()
630         config_tool_option_test.set('DISABLE_WARNING', 'yes')
631         config_tool_option_test.set('MESON_ENABLED_DEBUG_GUI', get_option('debug-gui'))
632         config_tool_option_test.set('MESON_BUILD_ROOT', meson.current_build_dir())
633         config_tool_option_test.set('TOOL_PATH', libinput_tool.full_path())
634         tool_option_test = configure_file(input: 'tools/test_tool_option_parsing.py',
635                                           output: '@PLAINNAME@',
636                                           configuration : config_tool_option_test)
637         test('tool-option-parsing',
638              tool_option_test,
639              args : [tool_option_test, '-n', 'auto'],
640              suite : ['all', 'root'],
641              timeout : 240)
642 endif
643
644 # the libinput tools check whether we execute from the builddir, this is
645 # the test to verify that lookup. We test twice, once as normal test
646 # run from the builddir, once after copying to /tmp
647 test_builddir_lookup = executable('test-builddir-lookup',
648                                   'test/test-builddir-lookup.c',
649                                   dependencies : [ dep_tools_shared],
650                                   include_directories : [includes_src, includes_include],
651                                   install : false)
652 test('tools-builddir-lookup',
653      test_builddir_lookup,
654      args : ['--builddir-is-set'],
655      suite : ['all'])
656 test('tools-builddir-lookup-installed',
657      find_program('test/helper-copy-and-exec-from-tmp.sh'),
658      args : [test_builddir_lookup.full_path(), '--builddir-is-null'],
659      env : ['LD_LIBRARY_PATH=@0@'.format(meson.current_build_dir())],
660      suite : ['all'],
661      workdir : '/tmp')
662
663 ############ tests ############
664
665 test('symbols-leak-test',
666      find_program('test/symbols-leak-test'),
667      args : [ dir_src / 'libinput.sym', dir_src],
668      suite : ['all'])
669
670 # build-test only
671 executable('test-build-pedantic',
672            'test/build-pedantic.c',
673            dependencies : [dep_udev],
674            include_directories : [includes_src, includes_include],
675            c_args : ['-std=c99', '-pedantic', '-Werror'],
676            install : false)
677 # build-test only
678 executable('test-build-std-gnuc90',
679            'test/build-pedantic.c',
680            dependencies : [dep_udev],
681            include_directories : [includes_src, includes_include],
682            c_args : ['-std=gnu89', '-Werror'],
683            install : false)
684 # test for linking with the minimal linker flags
685 executable('test-build-linker',
686            'test/build-pedantic.c',
687            include_directories : [includes_src, includes_include],
688            dependencies : [ dep_libinput, dep_libinput_util ],
689            install : false)
690 # test including from C++ (in case CPP compiler is available)
691 if add_languages('cpp', required: false)
692         executable('test-build-cxx',
693                    'test/build-cxx.cc',
694                    dependencies : [dep_udev],
695                    include_directories : [includes_src, includes_include],
696                    install : false)
697 endif
698
699 libinput_test_sources = [ 'tools/libinput-test.c' ]
700 executable('libinput-test',
701            libinput_test_sources,
702            dependencies : deps_tools,
703            include_directories : [includes_src, includes_include],
704            install_dir : libinput_tool_path,
705            install : true,
706            )
707
708 # This is the test suite runner, we allow disabling that one because of
709 # dependencies
710 if get_option('tests')
711         dep_check = dependency('check', version : '>= 0.9.10')
712
713         gstack = find_program('gstack', required : false)
714         config_h.set10('HAVE_GSTACK', gstack.found())
715
716         # for inhibit support during test run
717         dep_libsystemd = dependency('libsystemd', version : '>= 221', required : false)
718         config_h.set10('HAVE_LIBSYSTEMD', dep_libsystemd.found())
719
720         litest_sources = [
721                 'src/libinput-private-config.c',
722                 'test/litest-device-absinfo-override.c',
723                 'test/litest-device-acer-hawaii-keyboard.c',
724                 'test/litest-device-acer-hawaii-touchpad.c',
725                 'test/litest-device-aiptek-tablet.c',
726                 'test/litest-device-alps-3fg.c',
727                 'test/litest-device-alps-semi-mt.c',
728                 'test/litest-device-alps-dualpoint.c',
729                 'test/litest-device-anker-mouse-kbd.c',
730                 'test/litest-device-apple-appletouch.c',
731                 'test/litest-device-apple-internal-keyboard.c',
732                 'test/litest-device-apple-magicmouse.c',
733                 'test/litest-device-asus-rog-gladius.c',
734                 'test/litest-device-atmel-hover.c',
735                 'test/litest-device-bcm5974.c',
736                 'test/litest-device-calibrated-touchscreen.c',
737                 'test/litest-device-cyborg-rat-5.c',
738                 'test/litest-device-dell-canvas-totem.c',
739                 'test/litest-device-dell-canvas-totem-touch.c',
740                 'test/litest-device-elantech-touchpad.c',
741                 'test/litest-device-elan-tablet.c',
742                 'test/litest-device-format-string.c',
743                 'test/litest-device-generic-pressurepad.c',
744                 'test/litest-device-generic-singletouch.c',
745                 'test/litest-device-gpio-keys.c',
746                 'test/litest-device-huion-pentablet.c',
747                 'test/litest-device-hp-wmi-hotkeys.c',
748                 'test/litest-device-ignored-mouse.c',
749                 'test/litest-device-keyboard.c',
750                 'test/litest-device-keyboard-all-codes.c',
751                 'test/litest-device-keyboard-quirked.c',
752                 'test/litest-device-keyboard-razer-blackwidow.c',
753                 'test/litest-device-keyboard-razer-blade-stealth.c',
754                 'test/litest-device-keyboard-razer-blade-stealth-videoswitch.c',
755                 'test/litest-device-lenovo-scrollpoint.c',
756                 'test/litest-device-lid-switch.c',
757                 'test/litest-device-lid-switch-surface3.c',
758                 'test/litest-device-logitech-media-keyboard-elite.c',
759                 'test/litest-device-logitech-trackball.c',
760                 'test/litest-device-nexus4-touch-screen.c',
761                 'test/litest-device-magic-trackpad.c',
762                 'test/litest-device-mouse.c',
763                 'test/litest-device-mouse-wheel-tilt.c',
764                 'test/litest-device-mouse-roccat.c',
765                 'test/litest-device-mouse-low-dpi.c',
766                 'test/litest-device-mouse-wheel-click-angle.c',
767                 'test/litest-device-mouse-wheel-click-count.c',
768                 'test/litest-device-ms-nano-transceiver-mouse.c',
769                 'test/litest-device-ms-surface-cover.c',
770                 'test/litest-device-protocol-a-touch-screen.c',
771                 'test/litest-device-qemu-usb-tablet.c',
772                 'test/litest-device-sony-vaio-keys.c',
773                 'test/litest-device-synaptics-x220.c',
774                 'test/litest-device-synaptics-hover.c',
775                 'test/litest-device-synaptics-i2c.c',
776                 'test/litest-device-synaptics-pressurepad.c',
777                 'test/litest-device-synaptics-rmi4.c',
778                 'test/litest-device-synaptics-st.c',
779                 'test/litest-device-synaptics-t440.c',
780                 'test/litest-device-synaptics-x1-carbon-3rd.c',
781                 'test/litest-device-tablet-mode-switch.c',
782                 'test/litest-device-thinkpad-extrabuttons.c',
783                 'test/litest-device-trackpoint.c',
784                 'test/litest-device-touch-screen.c',
785                 'test/litest-device-touchscreen-invalid-range.c',
786                 'test/litest-device-touchscreen-fuzz.c',
787                 'test/litest-device-touchscreen-mt-tool.c',
788                 'test/litest-device-uclogic-tablet.c',
789                 'test/litest-device-wacom-bamboo-2fg-finger.c',
790                 'test/litest-device-wacom-bamboo-2fg-pad.c',
791                 'test/litest-device-wacom-bamboo-2fg-pen.c',
792                 'test/litest-device-wacom-bamboo-16fg-pen.c',
793                 'test/litest-device-wacom-cintiq-12wx-pen.c',
794                 'test/litest-device-wacom-cintiq-13hdt-finger.c',
795                 'test/litest-device-wacom-cintiq-13hdt-pad.c',
796                 'test/litest-device-wacom-cintiq-13hdt-pen.c',
797                 'test/litest-device-wacom-cintiq-24hd-pen.c',
798                 'test/litest-device-wacom-cintiq-24hdt-pad.c',
799                 'test/litest-device-wacom-cintiq-pro-16-finger.c',
800                 'test/litest-device-wacom-cintiq-pro-16-pad.c',
801                 'test/litest-device-wacom-cintiq-pro-16-pen.c',
802                 'test/litest-device-wacom-ekr.c',
803                 'test/litest-device-wacom-hid4800-pen.c',
804                 'test/litest-device-wacom-intuos3-pad.c',
805                 'test/litest-device-wacom-intuos5-finger.c',
806                 'test/litest-device-wacom-intuos5-pad.c',
807                 'test/litest-device-wacom-intuos5-pen.c',
808                 'test/litest-device-wacom-isdv4-4200-pen.c',
809                 'test/litest-device-wacom-isdv4-524c-pen.c',
810                 'test/litest-device-wacom-isdv4-e6-pen.c',
811                 'test/litest-device-wacom-isdv4-e6-finger.c',
812                 'test/litest-device-wacom-mobilestudio-pro-pad.c',
813                 'test/litest-device-waltop-tablet.c',
814                 'test/litest-device-wheel-only.c',
815                 'test/litest-device-xen-virtual-pointer.c',
816                 'test/litest-device-vmware-virtual-usb-mouse.c',
817                 'test/litest-device-yubikey.c',
818                 'test/litest.c',
819         ]
820
821         dep_dl = cc.find_library('dl')
822         deps_litest = [
823                 dep_libinput,
824                 dep_check,
825                 dep_udev,
826                 dep_libevdev,
827                 dep_dl,
828                 dep_lm,
829                 dep_libsystemd,
830                 dep_libquirks,
831         ]
832
833         litest_config_h = configuration_data()
834         litest_config_h.set_quoted('LIBINPUT_DEVICE_GROUPS_RULES_FILE',
835                                    meson.current_build_dir() /
836                                    '80-libinput-device-groups-litest.rules')
837         litest_config_h.set_quoted('LIBINPUT_FUZZ_OVERRIDE_UDEV_RULES_FILE',
838                                    meson.current_build_dir() /
839                                    '90-libinput-fuzz-override-litest.rules')
840
841         def_no_main = '-DLITEST_NO_MAIN'
842         def_disable_backtrace = '-DLITEST_DISABLE_BACKTRACE_LOGGING'
843         defs_litest_selftest = [
844                 def_no_main,
845                 def_disable_backtrace,
846                 '-Wno-unused',
847         ]
848         test_litest_selftest_sources = [
849                 'test/litest-selftest.c',
850                 'test/litest.c',
851         ]
852         test_litest_selftest = executable('test-litest-selftest',
853                                           test_litest_selftest_sources,
854                                           include_directories : [includes_src, includes_include],
855                                           dependencies : deps_litest,
856                                           c_args : defs_litest_selftest,
857                                           install : false)
858         test('test-litest-selftest',
859              test_litest_selftest,
860              suite : ['all'],
861              timeout : 100)
862
863         def_LT_VERSION = '-DLIBINPUT_LT_VERSION="@0@:@1@:@2@"'.format(libinput_lt_c, libinput_lt_r, libinput_lt_a)
864         test_library_version = executable('test-library-version',
865                                           ['test/test-library-version.c'],
866                                           c_args : [ def_LT_VERSION ],
867                                           install : false)
868         test('test-library-version',
869              test_library_version,
870              suite : ['all'])
871
872         test_utils_sources = [
873                 'test/test-utils.c',
874         ]
875         test_utils = executable('libinput-test-utils',
876                                 test_utils_sources,
877                                 include_directories : [includes_src, includes_include],
878                                 dependencies : deps_litest,
879                                 install_dir : libinput_tool_path,
880                                 install : get_option('install-tests'))
881         test('test-utils',
882              test_utils,
883              suite : ['all'])
884
885         # When adding new files to this list, update the CI
886         tests_sources = [
887                 'test/test-udev.c',
888                 'test/test-path.c',
889                 'test/test-pointer.c',
890                 'test/test-touch.c',
891                 'test/test-log.c',
892                 'test/test-tablet.c',
893                 'test/test-totem.c',
894                 'test/test-pad.c',
895                 'test/test-touchpad.c',
896                 'test/test-touchpad-tap.c',
897                 'test/test-touchpad-buttons.c',
898                 'test/test-trackpoint.c',
899                 'test/test-trackball.c',
900                 'test/test-misc.c',
901                 'test/test-keyboard.c',
902                 'test/test-device.c',
903                 'test/test-gestures.c',
904                 'test/test-switch.c',
905                 'test/test-quirks.c',
906         ]
907         libinput_test_runner_sources = litest_sources + tests_sources
908         libinput_test_runner = executable('libinput-test-suite',
909                                           libinput_test_runner_sources,
910                                           include_directories : [includes_src, includes_include],
911                                           dependencies : deps_litest,
912                                           install_dir : libinput_tool_path,
913                                           install : get_option('install-tests'))
914
915         src_man += 'test/libinput-test-suite.man'
916
917         foreach testfile : tests_sources
918                 tfile = testfile.split('test/test-')[1]
919                 group = tfile.split('.c')[0]
920                 test('libinput-test-suite-@0@'.format(group),
921                      libinput_test_runner,
922                      suite : ['all', 'valgrind', 'root', 'hardware'],
923                      args : ['--filter-group=@0@'.format(group),
924                              '--xml-output=junit-@0@-XXXXXX.xml'.format(group)],
925                      is_parallel : false,
926                      timeout : 1200)
927         endforeach
928
929         test('libinput-test-deviceless',
930              libinput_test_runner,
931              suite : ['all', 'valgrind'],
932              args: ['--filter-deviceless',
933                     '--xml-output=junit-deviceless-XXXXXX.xml'])
934
935         valgrind = find_program('valgrind', required : false)
936         if valgrind.found()
937                 valgrind_env = environment()
938                 valgrind_suppressions_file = dir_src_test / 'valgrind.suppressions'
939                 add_test_setup('valgrind',
940                                 exe_wrapper : [ valgrind,
941                                                 '--leak-check=full',
942                                                 '--gen-suppressions=all',
943                                                 '--error-exitcode=3',
944                                                 '--suppressions=' + valgrind_suppressions_file ],
945                                 env :  valgrind_env,
946                                 timeout_multiplier : 100)
947         else
948                 message('valgrind not found, disabling valgrind test suite')
949         endif
950         configure_file(output : 'litest-config.h',
951                        configuration : litest_config_h)
952 endif
953
954
955 ############ man pages ############
956 man_config = configuration_data()
957 man_config.set('LIBINPUT_VERSION', meson.project_version())
958 man_config.set('LIBINPUT_DATA_DIR', dir_data)
959 if get_option('install-tests')
960         man_config.set('HAVE_INSTALLED_TESTS', '.\"')
961 else
962         man_config.set('HAVE_INSTALLED_TESTS', '')
963 endif
964 src_man += files(
965         'tools/libinput.man',
966         'tools/libinput-analyze.man',
967         'tools/libinput-analyze-per-slot-delta.man',
968         'tools/libinput-analyze-recording.man',
969         'tools/libinput-analyze-touch-down-state.man',
970         'tools/libinput-debug-events.man',
971         'tools/libinput-debug-tablet.man',
972         'tools/libinput-list-devices.man',
973         'tools/libinput-measure.man',
974         'tools/libinput-measure-fuzz.man',
975         'tools/libinput-measure-touchpad-size.man',
976         'tools/libinput-measure-touchpad-tap.man',
977         'tools/libinput-measure-touchpad-pressure.man',
978         'tools/libinput-measure-touch-size.man',
979         'tools/libinput-quirks.man',
980         'tools/libinput-record.man',
981         'tools/libinput-replay.man',
982         'tools/libinput-test.man',
983 )
984
985 foreach m : src_man
986         configure_file(input : m,
987                        output : '@BASENAME@.1',
988                        configuration : man_config,
989                        install_dir : dir_man1)
990 endforeach
991
992 # Same man page for the subtools to stay consistent with the other tools
993 configure_file(input : 'tools/libinput-quirks.man',
994                output : 'libinput-quirks-list.1',
995                configuration : man_config,
996                install_dir : dir_man1,
997                )
998 configure_file(input : 'tools/libinput-quirks.man',
999                output : 'libinput-quirks-validate.1',
1000                configuration : man_config,
1001                install_dir : dir_man1,
1002                )
1003
1004 ############ output files ############
1005 configure_file(output : 'config.h', configuration : config_h)