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