build: remove explicit -Wextra
[platform/upstream/libxkbcommon.git] / meson.build
1 project(
2     'libxkbcommon',
3     'c',
4     version: '0.10.0',
5     default_options: [
6         'c_std=c99',
7         'warning_level=2',
8         'b_lundef=true',
9     ],
10     meson_version : '>= 0.49.0',
11 )
12 pkgconfig = import('pkgconfig')
13 cc = meson.get_compiler('c')
14
15 dir_libexec = join_paths(get_option('prefix'), get_option('libexecdir'), 'xkbcommon')
16
17 # Compiler flags.
18 foreach cflag: [
19     '-fvisibility=hidden',
20     '-fno-strict-aliasing',
21     '-fsanitize-undefined-trap-on-error',
22     '-Wno-unused-parameter',
23     '-Wno-missing-field-initializers',
24     '-Wpointer-arith',
25     '-Wmissing-declarations',
26     '-Wformat=2',
27     '-Wstrict-prototypes',
28     '-Wmissing-prototypes',
29     '-Wnested-externs',
30     '-Wbad-function-cast',
31     '-Wshadow',
32     '-Wlogical-op',
33     '-Wdate-time',
34     '-Wwrite-strings',
35     '-Wno-documentation-deprecated-sync',
36 ]
37     if cc.has_argument(cflag)
38         add_project_arguments(cflag, language: 'c')
39     endif
40 endforeach
41
42
43 # The XKB config root.
44 XKBCONFIGROOT = get_option('xkb-config-root')
45 if XKBCONFIGROOT == ''
46     xkeyboard_config_dep = dependency('xkeyboard-config', required: false)
47     if xkeyboard_config_dep.found()
48         XKBCONFIGROOT = xkeyboard_config_dep.get_pkgconfig_variable('xkb_base')
49     else
50         XKBCONFIGROOT = join_paths(get_option('prefix'), get_option('datadir'), 'X11', 'xkb')
51   endif
52 endif
53
54
55 # The X locale directory for compose.
56 XLOCALEDIR = get_option('x-locale-root')
57 if XLOCALEDIR == ''
58     XLOCALEDIR = join_paths(get_option('prefix'), get_option('datadir'), 'X11', 'locale')
59 endif
60
61
62 # config.h.
63 configh_data = configuration_data()
64 configh_data.set('EXIT_INVALID_USAGE', '2')
65 configh_data.set_quoted('LIBXKBCOMMON_VERSION', meson.project_version())
66 configh_data.set_quoted('LIBXKBCOMMON_TOOL_PATH', dir_libexec)
67 # Like AC_USE_SYSTEM_EXTENSIONS, what #define to use to get extensions
68 # beyond the base POSIX function set.
69 if host_machine.system() == 'sunos'
70   system_extensions = '__EXTENSIONS__'
71 else
72   system_extensions = '_GNU_SOURCE'
73 endif
74 configh_data.set(system_extensions, 1)
75 system_ext_define = '#define ' + system_extensions
76 configh_data.set_quoted('DFLT_XKB_CONFIG_ROOT', XKBCONFIGROOT)
77 configh_data.set_quoted('XLOCALEDIR', XLOCALEDIR)
78 configh_data.set_quoted('DEFAULT_XKB_RULES', get_option('default-rules'))
79 configh_data.set_quoted('DEFAULT_XKB_MODEL', get_option('default-model'))
80 configh_data.set_quoted('DEFAULT_XKB_LAYOUT', get_option('default-layout'))
81 if get_option('default-variant') != ''
82     configh_data.set_quoted('DEFAULT_XKB_VARIANT', get_option('default-variant'))
83 else
84     configh_data.set('DEFAULT_XKB_VARIANT', 'NULL')
85 endif
86 if get_option('default-options') != ''
87     configh_data.set_quoted('DEFAULT_XKB_OPTIONS', get_option('default-options'))
88 else
89     configh_data.set('DEFAULT_XKB_OPTIONS', 'NULL')
90 endif
91 if cc.links('int main(){if(__builtin_expect(1<0,0)){}}', name: '__builtin_expect')
92     configh_data.set('HAVE___BUILTIN_EXPECT', 1)
93 endif
94 if cc.has_header_symbol('unistd.h', 'eaccess', prefix: system_ext_define)
95     configh_data.set('HAVE_EACCESS', 1)
96 endif
97 if cc.has_header_symbol('unistd.h', 'euidaccess', prefix: system_ext_define)
98     configh_data.set('HAVE_EUIDACCESS', 1)
99 endif
100 if cc.has_header_symbol('sys/mman.h', 'mmap')
101     configh_data.set('HAVE_MMAP', 1)
102 endif
103 if cc.has_header_symbol('stdlib.h', 'mkostemp', prefix: system_ext_define)
104     configh_data.set('HAVE_MKOSTEMP', 1)
105 endif
106 if cc.has_header_symbol('fcntl.h', 'posix_fallocate', prefix: system_ext_define)
107     configh_data.set('HAVE_POSIX_FALLOCATE', 1)
108 endif
109 if cc.has_header_symbol('string.h', 'strndup', prefix: system_ext_define)
110     configh_data.set('HAVE_STRNDUP', 1)
111 endif
112 if cc.has_header_symbol('stdio.h', 'asprintf', prefix: system_ext_define)
113     configh_data.set('HAVE_ASPRINTF', 1)
114 elif cc.has_header_symbol('stdio.h', 'vasprintf', prefix: system_ext_define)
115     configh_data.set('HAVE_VASPRINTF', 1)
116 endif
117 if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix: system_ext_define)
118     configh_data.set('HAVE_SECURE_GETENV', 1)
119 elif cc.has_header_symbol('stdlib.h', '__secure_getenv', prefix: system_ext_define)
120     configh_data.set('HAVE___SECURE_GETENV', 1)
121 else
122     message('C library does not support secure_getenv, using getenv instead')
123 endif
124 have_getopt_long = cc.has_header_symbol('getopt.h', 'getopt_long',
125                                         prefix: '#define _GNU_SOURCE')
126
127 # Silence some security & deprecation warnings on MSVC
128 # for some unix/C functions we use.
129 # https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4996?view=vs-2019
130 configh_data.set('_CRT_SECURE_NO_WARNINGS', 1)
131 configh_data.set('_CRT_NONSTDC_NO_WARNINGS', 1)
132 configh_data.set('_CRT_NONSTDC_NO_DEPRECATE', 1)
133 # Reduce unnecessary includes on MSVC.
134 configh_data.set('WIN32_LEAN_AND_MEAN', 1)
135
136 # Supports -Wl,--version-script?
137 have_version_script = cc.links(
138     'int main(){}',
139     args: '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon.map'),
140     name: '-Wl,--version-script',
141 )
142
143
144 # libxkbcommon.
145 # Note: we use some yacc extensions, which work with either GNU bison
146 # (preferred) or byacc (with backtracking enabled).
147 bison = find_program('bison', 'win_bison', required: false)
148 if bison.found()
149     yacc_gen = generator(
150         bison,
151         output: ['@BASENAME@.c', '@BASENAME@.h'],
152         arguments: ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@', '-p _xkbcommon_'],
153     )
154 else
155     byacc = find_program('byacc', required: false)
156     if byacc.found()
157         yacc_gen = generator(
158             byacc,
159             output: ['@BASENAME@.c', '@BASENAME@.h'],
160             arguments: ['@INPUT@', '-H', '@OUTPUT1@', '-o', '@OUTPUT0@', '-p _xkbcommon_'],
161         )
162     else
163         error('Could not find a compatible YACC program (bison or byacc)')
164     endif
165 endif
166 libxkbcommon_sources = [
167     'src/compose/parser.c',
168     'src/compose/parser.h',
169     'src/compose/paths.c',
170     'src/compose/paths.h',
171     'src/compose/state.c',
172     'src/compose/table.c',
173     'src/compose/table.h',
174     'src/xkbcomp/action.c',
175     'src/xkbcomp/action.h',
176     'src/xkbcomp/ast.h',
177     'src/xkbcomp/ast-build.c',
178     'src/xkbcomp/ast-build.h',
179     'src/xkbcomp/compat.c',
180     'src/xkbcomp/expr.c',
181     'src/xkbcomp/expr.h',
182     'src/xkbcomp/include.c',
183     'src/xkbcomp/include.h',
184     'src/xkbcomp/keycodes.c',
185     'src/xkbcomp/keymap.c',
186     'src/xkbcomp/keymap-dump.c',
187     'src/xkbcomp/keywords.c',
188     yacc_gen.process('src/xkbcomp/parser.y'),
189     'src/xkbcomp/parser-priv.h',
190     'src/xkbcomp/rules.c',
191     'src/xkbcomp/rules.h',
192     'src/xkbcomp/scanner.c',
193     'src/xkbcomp/symbols.c',
194     'src/xkbcomp/types.c',
195     'src/xkbcomp/vmod.c',
196     'src/xkbcomp/vmod.h',
197     'src/xkbcomp/xkbcomp.c',
198     'src/xkbcomp/xkbcomp-priv.h',
199     'src/atom.c',
200     'src/atom.h',
201     'src/context.c',
202     'src/context.h',
203     'src/context-priv.c',
204     'src/darray.h',
205     'src/keysym.c',
206     'src/keysym.h',
207     'src/keysym-utf.c',
208     'src/ks_tables.h',
209     'src/keymap.c',
210     'src/keymap.h',
211     'src/keymap-priv.c',
212     'src/scanner-utils.h',
213     'src/state.c',
214     'src/text.c',
215     'src/text.h',
216     'src/utf8.c',
217     'src/utf8.h',
218     'src/utils.c',
219     'src/utils.h',
220 ]
221 libxkbcommon_link_args = []
222 if have_version_script
223     libxkbcommon_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon.map')
224 endif
225 libxkbcommon = library(
226     'xkbcommon',
227     'xkbcommon/xkbcommon.h',
228     libxkbcommon_sources,
229     link_args: libxkbcommon_link_args,
230     link_depends: 'xkbcommon.map',
231     version: '0.0.0',
232     install: true,
233     include_directories: include_directories('src'),
234 )
235 install_headers(
236     'xkbcommon/xkbcommon.h',
237     'xkbcommon/xkbcommon-compat.h',
238     'xkbcommon/xkbcommon-compose.h',
239     'xkbcommon/xkbcommon-keysyms.h',
240     'xkbcommon/xkbcommon-names.h',
241     subdir: 'xkbcommon',
242 )
243 libxkbcommon_dep = declare_dependency(
244     link_with: libxkbcommon,
245 )
246 pkgconfig.generate(
247     libxkbcommon,
248     name: 'xkbcommon',
249     filebase: 'xkbcommon',
250     version: meson.project_version(),
251     description: 'XKB API common to servers and clients',
252 )
253
254
255 # libxkbcommon-x11.
256 if get_option('enable-x11')
257     xcb_dep = dependency('xcb', version: '>=1.10', required: false)
258     xcb_xkb_dep = dependency('xcb-xkb', version: '>=1.10', required: false)
259     if not xcb_dep.found() or not xcb_xkb_dep.found()
260         error('''X11 support requires xcb-xkb >= 1.10 which was not found.
261 You can disable X11 support with -Denable-x11=false.''')
262     endif
263
264     libxkbcommon_x11_sources = [
265         'src/x11/keymap.c',
266         'src/x11/state.c',
267         'src/x11/util.c',
268         'src/x11/x11-priv.h',
269         'src/context.h',
270         'src/context-priv.c',
271         'src/keymap.h',
272         'src/keymap-priv.c',
273         'src/atom.h',
274         'src/atom.c',
275     ]
276     libxkbcommon_x11_link_args = []
277     if have_version_script
278         libxkbcommon_x11_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon-x11.map')
279     endif
280     libxkbcommon_x11 = library(
281         'xkbcommon-x11',
282         'xkbcommon/xkbcommon-x11.h',
283         libxkbcommon_x11_sources,
284         link_args: libxkbcommon_x11_link_args,
285         link_depends: 'xkbcommon-x11.map',
286         version: '0.0.0',
287         install: true,
288         include_directories: include_directories('src'),
289         link_with: libxkbcommon,
290         dependencies: [
291             xcb_dep,
292             xcb_xkb_dep,
293         ],
294     )
295     install_headers(
296         'xkbcommon/xkbcommon-x11.h',
297         subdir: 'xkbcommon',
298     )
299     libxkbcommon_x11_dep = declare_dependency(
300         link_with: libxkbcommon_x11,
301     )
302     pkgconfig.generate(
303         libxkbcommon_x11,
304         name: 'xkbcommon-x11',
305         filebase: 'xkbcommon-x11',
306         version: meson.project_version(),
307         description: 'XKB API common to servers and clients - X11 support',
308         requires: ['xkbcommon'],
309         requires_private: ['xcb>=1.10', 'xcb-xkb>=1.10'],
310     )
311 endif
312
313 # libxkbregistry
314 if get_option('enable-xkbregistry')
315     dep_libxml = dependency('libxml-2.0')
316     deps_libxkbregistry = [dep_libxml]
317     libxkbregistry_sources = [
318         'src/registry.c',
319         'src/utils.h',
320         'src/utils.c',
321         'src/util-list.h',
322         'src/util-list.c',
323     ]
324     libxkbregistry_link_args = []
325     if have_version_script
326         libxkbregistry_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbregistry.map')
327     endif
328     libxkbregistry = library(
329         'xkbregistry',
330         'xkbcommon/xkbregistry.h',
331         libxkbregistry_sources,
332         link_args: libxkbregistry_link_args,
333         link_depends: 'xkbregistry.map',
334         dependencies: deps_libxkbregistry,
335         version: '0.0.0',
336         install: true,
337         include_directories: include_directories('src'),
338     )
339     install_headers(
340         'xkbcommon/xkbregistry.h',
341         subdir: 'xkbcommon',
342     )
343     pkgconfig.generate(
344         libxkbregistry,
345         name: 'xkbregistry',
346         filebase: 'xkbregistry',
347         version: meson.project_version(),
348         description: 'XKB API to query available rules, models, layouts, variants and options',
349     )
350
351     dep_libxkbregistry = declare_dependency(
352                                 include_directories: include_directories('xkbcommon'),
353                                 link_with: libxkbregistry
354                                 )
355 endif
356
357 # Tests
358 test_env = environment()
359 test_env.set('XKB_LOG_LEVEL', 'debug')
360 test_env.set('XKB_LOG_VERBOSITY', '10')
361 test_env.set('top_srcdir', meson.source_root())
362 test_env.set('top_builddir', meson.build_root())
363
364 test_configh_data = configuration_data()
365 test_configh_data.set_quoted('TEST_XKB_CONFIG_ROOT', join_paths(meson.source_root(), 'test', 'data'))
366 configure_file(output: 'test-config.h', configuration: test_configh_data)
367
368 # Some tests need to use unexported symbols, so we link them against
369 # an internal copy of libxkbcommon with all symbols exposed.
370 libxkbcommon_test_internal = static_library(
371     'xkbcommon-test-internal',
372     'test/common.c',
373     'test/test.h',
374     'test/evdev-scancodes.h',
375     libxkbcommon_sources,
376     include_directories: include_directories('src'),
377 )
378 test_dep = declare_dependency(
379     include_directories: include_directories('src'),
380     link_with: libxkbcommon_test_internal,
381 )
382 if get_option('enable-x11')
383     libxkbcommon_x11_internal = static_library(
384         'xkbcommon-x11-internal',
385         libxkbcommon_x11_sources,
386         include_directories: include_directories('src'),
387         link_with: libxkbcommon_test_internal,
388         dependencies: [
389             xcb_dep,
390             xcb_xkb_dep,
391         ],
392     )
393     x11_test_dep = declare_dependency(
394         link_with: libxkbcommon_x11_internal,
395         dependencies: [
396             test_dep,
397             xcb_dep,
398             xcb_xkb_dep,
399         ],
400     )
401 endif
402 test(
403     'keysym',
404     executable('test-keysym', 'test/keysym.c', dependencies: test_dep),
405     env: test_env,
406 )
407 test(
408     'keymap',
409     executable('test-keymap', 'test/keymap.c', dependencies: test_dep),
410     env: test_env,
411 )
412 test(
413     'filecomp',
414     executable('test-filecomp', 'test/filecomp.c', dependencies: test_dep),
415     env: test_env,
416 )
417 # TODO: This test currently uses some functions that don't exist on Windows.
418 if cc.get_id() != 'msvc'
419   test(
420       'context',
421       executable('test-context', 'test/context.c', dependencies: test_dep),
422       env: test_env,
423   )
424 endif
425 test(
426     'rules-file',
427     executable('test-rules-file', 'test/rules-file.c', dependencies: test_dep),
428     env: test_env,
429 )
430 test(
431     'rules-file-includes',
432     executable('test-rules-file-includes', 'test/rules-file-includes.c', dependencies: test_dep),
433     env: test_env,
434 )
435 test(
436     'stringcomp',
437     executable('test-stringcomp', 'test/stringcomp.c', dependencies: test_dep),
438     env: test_env,
439 )
440 test(
441     'buffercomp',
442     executable('test-buffercomp', 'test/buffercomp.c', dependencies: test_dep),
443     env: test_env,
444 )
445 test(
446     'log',
447     executable('test-log', 'test/log.c', dependencies: test_dep),
448     env: test_env,
449 )
450 test(
451     'atom',
452     executable('test-atom', 'test/atom.c', dependencies: test_dep),
453     env: test_env,
454 )
455 test(
456     'utf8',
457     executable('test-utf8', 'test/utf8.c', dependencies: test_dep),
458     env: test_env,
459 )
460 test(
461     'state',
462     executable('test-state', 'test/state.c', dependencies: test_dep),
463     env: test_env,
464 )
465 test(
466     'keyseq',
467     executable('test-keyseq', 'test/keyseq.c', dependencies: test_dep),
468     env: test_env,
469 )
470 test(
471     'rulescomp',
472     executable('test-rulescomp', 'test/rulescomp.c', dependencies: test_dep),
473     env: test_env,
474 )
475 test(
476     'compose',
477     executable('test-compose', 'test/compose.c', dependencies: test_dep),
478     env: test_env,
479 )
480 test(
481     'utils',
482     executable('test-utils', 'test/utils.c', dependencies: test_dep),
483     env: test_env,
484 )
485 test(
486     'symbols-leak-test',
487     find_program('test/symbols-leak-test.py'),
488     env: test_env,
489     suite: ['python-tests'],
490 )
491 if get_option('enable-x11')
492     test(
493         'x11',
494         executable('test-x11', 'test/x11.c', dependencies: x11_test_dep),
495         env: test_env,
496     )
497     # test/x11comp is meant to be run, but it is (temporarily?) disabled.
498     # See: https://github.com/xkbcommon/libxkbcommon/issues/30
499     executable('test-x11comp', 'test/x11comp.c', dependencies: x11_test_dep)
500 endif
501 if get_option('enable-xkbregistry')
502     test(
503         'registry',
504         executable('test-registry', 'test/registry.c',
505                    include_directories: include_directories('src'),
506                    dependencies: dep_libxkbregistry),
507         env: test_env,
508     )
509 endif
510
511 valgrind = find_program('valgrind', required: false)
512 if valgrind.found()
513     add_test_setup('valgrind',
514         exe_wrapper: [valgrind,
515                        '--leak-check=full',
516                        '--track-origins=yes',
517                        '--gen-suppressions=all',
518                        '--error-exitcode=99'],
519         timeout_multiplier : 10)
520 else
521     message('valgrind not found, disabling valgrind test setup')
522 endif
523
524
525 # Fuzzing target programs.
526 executable('fuzz-keymap', 'fuzz/keymap/target.c', dependencies: test_dep)
527 executable('fuzz-compose', 'fuzz/compose/target.c', dependencies: test_dep)
528
529 man_pages = []
530
531 # Tools
532 build_tools = have_getopt_long
533 if build_tools
534     libxkbcommon_tools_internal = static_library(
535         'tools-internal',
536         'tools/tools-common.h',
537         'tools/tools-common.c',
538         include_directories: include_directories('src'),
539         dependencies: libxkbcommon_dep,
540     )
541     tools_dep = declare_dependency(
542         include_directories: [include_directories('src'), include_directories('tools')],
543         link_with: libxkbcommon_tools_internal,
544     )
545
546     executable('xkbcli', 'tools/xkbcli.c',
547                dependencies: tools_dep, install: true)
548     install_man('tools/xkbcli.1')
549
550     executable('xkbcli-compile-keymap',
551                'tools/compile-keymap.c',
552                dependencies: tools_dep,
553                install: true,
554                install_dir: dir_libexec)
555     install_man('tools/xkbcli-compile-keymap.1')
556     # The same tool again, but with access to some private APIs.
557     executable('compile-keymap',
558                'tools/compile-keymap.c',
559                libxkbcommon_sources,
560                dependencies: [tools_dep],
561                c_args: ['-DENABLE_PRIVATE_APIS'],
562                install: false)
563     configh_data.set10('HAVE_XKBCLI_COMPILE_KEYMAP', true)
564     executable('xkbcli-how-to-type',
565                'tools/how-to-type.c',
566                dependencies: tools_dep,
567                install: true,
568                install_dir: dir_libexec)
569     install_man('tools/xkbcli-how-to-type.1')
570     configh_data.set10('HAVE_XKBCLI_HOW_TO_TYPE', true)
571     if cc.has_header('linux/input.h')
572         executable('xkbcli-interactive-evdev',
573                    'tools/interactive-evdev.c',
574                    dependencies: tools_dep,
575                    install: true,
576                    install_dir: dir_libexec)
577         configh_data.set10('HAVE_XKBCLI_INTERACTIVE_EVDEV', true)
578         install_man('tools/xkbcli-interactive-evdev.1')
579     endif
580     if get_option('enable-x11')
581         x11_tools_dep = declare_dependency(
582             link_with: libxkbcommon_x11,
583             dependencies: [
584                 tools_dep,
585                 xcb_dep,
586                 xcb_xkb_dep,
587             ],
588         )
589         executable('xkbcli-interactive-x11',
590                    'tools/interactive-x11.c',
591                    dependencies: x11_tools_dep,
592                    install: true,
593                    install_dir: dir_libexec)
594         install_man('tools/xkbcli-interactive-x11.1')
595         configh_data.set10('HAVE_XKBCLI_INTERACTIVE_X11', true)
596     endif
597     if get_option('enable-wayland')
598         wayland_client_dep = dependency('wayland-client', version: '>=1.2.0', required: false)
599         wayland_protocols_dep = dependency('wayland-protocols', version: '>=1.12', required: false)
600         wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)
601         if not wayland_client_dep.found() or not wayland_protocols_dep.found() or not wayland_scanner_dep.found()
602             error('''The Wayland xkbcli programs require wayland-client >= 1.2.0, wayland-protocols >= 1.7 which were not found.
603 You can disable the Wayland xkbcli programs with -Denable-wayland=false.''')
604         endif
605
606         wayland_scanner = find_program(wayland_scanner_dep.get_pkgconfig_variable('wayland_scanner'))
607         wayland_scanner_code_gen = generator(
608             wayland_scanner,
609             output: '@BASENAME@-protocol.c',
610             arguments: ['code', '@INPUT@', '@OUTPUT@'],
611         )
612         wayland_scanner_client_header_gen = generator(
613             wayland_scanner,
614             output: '@BASENAME@-client-protocol.h',
615             arguments: ['client-header', '@INPUT@', '@OUTPUT@'],
616         )
617         wayland_protocols_datadir = wayland_protocols_dep.get_pkgconfig_variable('pkgdatadir')
618         xdg_shell_xml = join_paths(wayland_protocols_datadir, 'stable/xdg-shell/xdg-shell.xml')
619         xdg_shell_sources = [
620             wayland_scanner_code_gen.process(xdg_shell_xml),
621             wayland_scanner_client_header_gen.process(xdg_shell_xml),
622         ]
623         executable('xkbcli-interactive-wayland',
624                    'tools/interactive-wayland.c',
625                    xdg_shell_sources,
626                    dependencies: [tools_dep, wayland_client_dep],
627                    install: true,
628                    install_dir: dir_libexec)
629         install_man('tools/xkbcli-interactive-wayland.1')
630         configh_data.set10('HAVE_XKBCLI_INTERACTIVE_WAYLAND', true)
631     endif
632
633     if get_option('enable-xkbregistry')
634         configh_data.set10('HAVE_XKBCLI_LIST', true)
635         executable('xkbcli-list',
636                    'tools/registry-list.c',
637                    dependencies: dep_libxkbregistry,
638                    install: true,
639                    install_dir: dir_libexec)
640         install_man('tools/xkbcli-list.1')
641     endif
642
643     # pytest finds files named test_foo_bar.py but not
644     # test-foo-bar.py, let's rename the source file so it only ever finds the
645     # built one.
646     config_tool_option_test = configuration_data()
647     config_tool_option_test.set('MESON_BUILD_ROOT', meson.current_build_dir())
648     tool_option_test = configure_file(input: 'tools/test-tool-option-parsing.py',
649                                       output: 'test_tool_option_parsing.py',
650                                       configuration : config_tool_option_test)
651     test('tool-option-parsing',
652          tool_option_test,
653          args: [tool_option_test, '-n', 'auto'])
654 endif
655
656
657 # xkeyboard-config "verifier"
658 xkct_config = configuration_data()
659 xkct_config.set('MESON_BUILD_ROOT', meson.build_root())
660 xkct_config.set('XKB_CONFIG_ROOT', XKBCONFIGROOT)
661 configure_file(input: 'test/xkeyboard-config-test.py.in',
662                output: 'xkeyboard-config-test',
663                configuration: xkct_config)
664
665
666 # Benchmarks.
667 libxkbcommon_bench_internal = static_library(
668     'xkbcommon-bench-internal',
669     'bench/bench.c',
670     'bench/bench.h',
671     link_with: libxkbcommon_test_internal,
672 )
673 bench_dep = declare_dependency(
674     include_directories: include_directories('src'),
675     link_with: libxkbcommon_bench_internal,
676 )
677 bench_env = environment()
678 bench_env.set('top_srcdir', meson.source_root())
679 benchmark(
680     'key-proc',
681     executable('bench-key-proc', 'bench/key-proc.c', dependencies: bench_dep),
682     env: bench_env,
683 )
684 benchmark(
685     'rules',
686     executable('bench-rules', 'bench/rules.c', dependencies: bench_dep),
687     env: bench_env,
688 )
689 benchmark(
690     'rulescomp',
691     executable('bench-rulescomp', 'bench/rulescomp.c', dependencies: bench_dep),
692     env: bench_env,
693 )
694 benchmark(
695     'compose',
696     executable('bench-compose', 'bench/compose.c', dependencies: bench_dep),
697     env: bench_env,
698 )
699
700
701 # Documentation.
702 if get_option('enable-docs')
703     doxygen = find_program('doxygen', required: false)
704     if not doxygen.found()
705         error('''Documentation requires doxygen which was not found.
706 You can disable the documentation with -Denable-docs=false.''')
707     endif
708     doxygen_wrapper = find_program('scripts/doxygen-wrapper')
709
710     doxygen_input = [
711         'README.md',
712         'doc/doxygen-extra.css',
713         'doc/quick-guide.md',
714         'doc/compat.md',
715         'doc/user-configuration.md',
716         'doc/rules-format.md',
717         'xkbcommon/xkbcommon.h',
718         'xkbcommon/xkbcommon-names.h',
719         'xkbcommon/xkbcommon-x11.h',
720         'xkbcommon/xkbcommon-compose.h',
721         'xkbcommon/xkbregistry.h',
722     ]
723     doxygen_data = configuration_data()
724     doxygen_data.set('PACKAGE_NAME', meson.project_name())
725     doxygen_data.set('PACKAGE_VERSION', meson.project_version())
726     doxygen_data.set('INPUT', ' '.join(doxygen_input))
727     doxygen_data.set('OUTPUT_DIRECTORY', meson.build_root())
728     doxyfile = configure_file(
729         input: 'doc/Doxyfile.in',
730         output: 'Doxyfile',
731         configuration: doxygen_data,
732     )
733     # TODO: Meson should provide this.
734     docdir = join_paths(get_option('datadir'), 'doc', meson.project_name())
735     custom_target(
736         'doc',
737         input: [doxyfile] + doxygen_input,
738         output: 'html',
739         command: [doxygen_wrapper, doxygen.path(), join_paths(meson.build_root(), 'Doxyfile'), meson.source_root()],
740         install: true,
741         install_dir: docdir,
742         build_by_default: true,
743     )
744 endif
745
746 configure_file(output: 'config.h', configuration: configh_data)