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