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