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