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