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