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