Fix xkb_keysym_from_name for numeric keysyms
[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.52.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, version: '>= 2.3a')
158 if bison.found()
159     yacc = bison
160     yacc_gen = generator(
161         bison,
162         output: ['@BASENAME@.c', '@BASENAME@.h'],
163         arguments: ['--defines=@OUTPUT1@', '-o', '@OUTPUT0@', '-p', '_xkbcommon_', '@INPUT@'],
164     )
165 else
166     byacc = find_program('byacc', required: false)
167     if byacc.found()
168         yacc = byacc
169         yacc_gen = generator(
170             byacc,
171             output: ['@BASENAME@.c', '@BASENAME@.h'],
172             arguments: ['-H', '@OUTPUT1@', '-o', '@OUTPUT0@', '-p', '_xkbcommon_', '@INPUT@'],
173         )
174     else
175         error('Could not find a compatible YACC program (bison or byacc)')
176     endif
177 endif
178 libxkbcommon_sources = [
179     'src/compose/parser.c',
180     'src/compose/parser.h',
181     'src/compose/paths.c',
182     'src/compose/paths.h',
183     'src/compose/state.c',
184     'src/compose/table.c',
185     'src/compose/table.h',
186     'src/xkbcomp/action.c',
187     'src/xkbcomp/action.h',
188     'src/xkbcomp/ast.h',
189     'src/xkbcomp/ast-build.c',
190     'src/xkbcomp/ast-build.h',
191     'src/xkbcomp/compat.c',
192     'src/xkbcomp/expr.c',
193     'src/xkbcomp/expr.h',
194     'src/xkbcomp/include.c',
195     'src/xkbcomp/include.h',
196     'src/xkbcomp/keycodes.c',
197     'src/xkbcomp/keymap.c',
198     'src/xkbcomp/keymap-dump.c',
199     'src/xkbcomp/keywords.c',
200     yacc_gen.process('src/xkbcomp/parser.y'),
201     'src/xkbcomp/parser-priv.h',
202     'src/xkbcomp/rules.c',
203     'src/xkbcomp/rules.h',
204     'src/xkbcomp/scanner.c',
205     'src/xkbcomp/symbols.c',
206     'src/xkbcomp/types.c',
207     'src/xkbcomp/vmod.c',
208     'src/xkbcomp/vmod.h',
209     'src/xkbcomp/xkbcomp.c',
210     'src/xkbcomp/xkbcomp-priv.h',
211     'src/atom.c',
212     'src/atom.h',
213     'src/context.c',
214     'src/context.h',
215     'src/context-priv.c',
216     'src/darray.h',
217     'src/keysym.c',
218     'src/keysym.h',
219     'src/keysym-utf.c',
220     'src/ks_tables.h',
221     'src/keymap.c',
222     'src/keymap.h',
223     'src/keymap-priv.c',
224     'src/scanner-utils.h',
225     'src/state.c',
226     'src/text.c',
227     'src/text.h',
228     'src/utf8.c',
229     'src/utf8.h',
230     'src/utils.c',
231     'src/utils.h',
232 ]
233 libxkbcommon_link_args = []
234 libxkbcommon_link_deps = []
235 if have_version_script
236     libxkbcommon_link_args += '-Wl,--version-script=' + meson.current_source_dir()/'xkbcommon.map'
237     libxkbcommon_link_deps += 'xkbcommon.map'
238 elif cc.get_argument_syntax() == 'msvc'
239     libxkbcommon_def = custom_target('xkbcommon.def',
240         command: [map_to_def, '@INPUT@', '@OUTPUT@'],
241         input: 'xkbcommon.map',
242         output: 'kxbcommon.def',
243     )
244     libxkbcommon_link_deps += libxkbcommon_def
245     libxkbcommon_link_args += '/DEF:' + libxkbcommon_def.full_path()
246 endif
247 libxkbcommon = library(
248     'xkbcommon',
249     'include/xkbcommon/xkbcommon.h',
250     libxkbcommon_sources,
251     link_args: libxkbcommon_link_args,
252     link_depends: libxkbcommon_link_deps,
253     gnu_symbol_visibility: 'hidden',
254     version: '0.0.0',
255     install: true,
256     include_directories: include_directories('src', 'include'),
257 )
258 install_headers(
259     'include/xkbcommon/xkbcommon.h',
260     'include/xkbcommon/xkbcommon-compat.h',
261     'include/xkbcommon/xkbcommon-compose.h',
262     'include/xkbcommon/xkbcommon-keysyms.h',
263     'include/xkbcommon/xkbcommon-names.h',
264     subdir: 'xkbcommon',
265 )
266
267 dep_libxkbcommon = declare_dependency(
268     link_with: libxkbcommon,
269     include_directories: include_directories('include'),
270 )
271 if meson.version().version_compare('>= 0.54.0')
272     meson.override_dependency('xkbcommon', dep_libxkbcommon)
273 endif
274 pkgconfig.generate(
275     libxkbcommon,
276     name: 'xkbcommon',
277     filebase: 'xkbcommon',
278     version: meson.project_version(),
279     description: 'XKB API common to servers and clients',
280 )
281
282
283 # libxkbcommon-x11.
284 if get_option('enable-x11')
285     xcb_dep = dependency('xcb', version: '>=1.10', required: false)
286     xcb_xkb_dep = dependency('xcb-xkb', version: '>=1.10', required: false)
287     if not xcb_dep.found() or not xcb_xkb_dep.found()
288         error('''X11 support requires xcb-xkb >= 1.10 which was not found.
289 You can disable X11 support with -Denable-x11=false.''')
290     endif
291
292     libxkbcommon_x11_sources = [
293         'src/x11/keymap.c',
294         'src/x11/state.c',
295         'src/x11/util.c',
296         'src/x11/x11-priv.h',
297         'src/context.h',
298         'src/context-priv.c',
299         'src/keymap.h',
300         'src/keymap-priv.c',
301         'src/atom.h',
302         'src/atom.c',
303     ]
304     libxkbcommon_x11_link_args = []
305     libxkbcommon_x11_link_deps = []
306     if have_version_script
307         libxkbcommon_x11_link_args += '-Wl,--version-script=' + meson.current_source_dir()/'xkbcommon-x11.map'
308         libxkbcommon_x11_link_deps += 'xkbcommon-x11.map'
309     elif cc.get_argument_syntax() == 'msvc'
310         libxkbcommon_x11_def = custom_target('xkbcommon-x11.def',
311             command: [map_to_def, '@INPUT@', '@OUTPUT@'],
312             input: 'xkbcommon-x11.map',
313             output: 'xkbcommon-x11.def',
314         )
315         libxkbcommon_x11_link_deps += libxkbcommon_x11_def
316         libxkbcommon_x11_link_args += '/DEF:' + libxkbcommon_x11_def.full_path()
317     endif
318     libxkbcommon_x11 = library(
319         'xkbcommon-x11',
320         'include/xkbcommon/xkbcommon-x11.h',
321         libxkbcommon_x11_sources,
322         link_args: libxkbcommon_x11_link_args,
323         link_depends: libxkbcommon_x11_link_deps,
324         gnu_symbol_visibility: 'hidden',
325         version: '0.0.0',
326         install: true,
327         include_directories: include_directories('src', 'include'),
328         link_with: libxkbcommon,
329         dependencies: [
330             xcb_dep,
331             xcb_xkb_dep,
332         ],
333     )
334     install_headers(
335         'include/xkbcommon/xkbcommon-x11.h',
336         subdir: 'xkbcommon',
337     )
338     dep_libxkbcommon_x11 = declare_dependency(
339         link_with: libxkbcommon_x11,
340         include_directories: include_directories('include'),
341     )
342     if meson.version().version_compare('>= 0.54.0')
343         meson.override_dependency('xkbcommon-x11', dep_libxkbcommon_x11)
344     endif
345     pkgconfig.generate(
346         libxkbcommon_x11,
347         name: 'xkbcommon-x11',
348         filebase: 'xkbcommon-x11',
349         version: meson.project_version(),
350         description: 'XKB API common to servers and clients - X11 support',
351         requires: ['xkbcommon'],
352         requires_private: ['xcb>=1.10', 'xcb-xkb>=1.10'],
353     )
354 endif
355
356 # libxkbregistry
357 if get_option('enable-xkbregistry')
358     dep_libxml = dependency('libxml-2.0')
359     deps_libxkbregistry = [dep_libxml]
360     libxkbregistry_sources = [
361         'src/registry.c',
362         'src/utils.h',
363         'src/utils.c',
364         'src/util-list.h',
365         'src/util-list.c',
366     ]
367     libxkbregistry_link_args = []
368     libxkbregistry_link_deps = []
369     if have_version_script
370         libxkbregistry_link_args += '-Wl,--version-script=' + meson.current_source_dir()/'xkbregistry.map'
371         libxkbregistry_link_deps += 'xkbregistry.map'
372     elif cc.get_argument_syntax() == 'msvc'
373         libxkbregistry_def = custom_target('xkbregistry.def',
374             command: [map_to_def, '@INPUT@', '@OUTPUT@'],
375             input: 'xkbregistry.map',
376             output: 'xkbregistry.def',
377         )
378         libxkbregistry_link_deps += libxkbregistry_def
379         libxkbregistry_link_args += '/DEF:' + libxkbregistry_def.full_path()
380     endif
381     libxkbregistry = library(
382         'xkbregistry',
383         'include/xkbcommon/xkbregistry.h',
384         libxkbregistry_sources,
385         link_args: libxkbregistry_link_args,
386         link_depends: libxkbregistry_link_deps,
387         gnu_symbol_visibility: 'hidden',
388         dependencies: deps_libxkbregistry,
389         version: '0.0.0',
390         install: true,
391         include_directories: include_directories('src', 'include'),
392     )
393     install_headers(
394         'include/xkbcommon/xkbregistry.h',
395         subdir: 'xkbcommon',
396     )
397     pkgconfig.generate(
398         libxkbregistry,
399         name: 'xkbregistry',
400         filebase: 'xkbregistry',
401         version: meson.project_version(),
402         description: 'XKB API to query available rules, models, layouts, variants and options',
403     )
404
405     dep_libxkbregistry = declare_dependency(
406         link_with: libxkbregistry,
407         include_directories: include_directories('include'),
408     )
409     if meson.version().version_compare('>= 0.54.0')
410         meson.override_dependency('xkbregistry', dep_libxkbregistry)
411     endif
412 endif
413
414 man_pages = []
415
416 # Tools
417 build_tools = get_option('enable-tools') and cc.has_header_symbol('getopt.h', 'getopt_long', prefix: '#define _GNU_SOURCE')
418 if build_tools
419     libxkbcommon_tools_internal = static_library(
420         'tools-internal',
421         'tools/tools-common.h',
422         'tools/tools-common.c',
423         dependencies: dep_libxkbcommon,
424     )
425     tools_dep = declare_dependency(
426         include_directories: [include_directories('tools', 'include')],
427         link_with: libxkbcommon_tools_internal,
428         dependencies: dep_libxkbcommon,
429     )
430
431     executable('xkbcli', 'tools/xkbcli.c',
432                dependencies: tools_dep, install: true)
433     install_man('tools/xkbcli.1')
434
435     xkbcli_compile_keymap = executable('xkbcli-compile-keymap',
436                                        'tools/compile-keymap.c',
437                                        dependencies: tools_dep,
438                                        install: true,
439                                        install_dir: dir_libexec)
440     install_man('tools/xkbcli-compile-keymap.1')
441     # The same tool again, but with access to some private APIs.
442     executable('compile-keymap',
443                'tools/compile-keymap.c',
444                libxkbcommon_sources,
445                dependencies: [tools_dep],
446                c_args: ['-DENABLE_PRIVATE_APIS'],
447                include_directories: [include_directories('src', 'include')],
448                install: false)
449     executable('compose',
450                'tools/compose.c',
451                dependencies: tools_dep,
452                include_directories: [include_directories('src', 'include')],
453                install: false)
454     configh_data.set10('HAVE_XKBCLI_COMPILE_KEYMAP', true)
455     executable('xkbcli-how-to-type',
456                'tools/how-to-type.c',
457                dependencies: tools_dep,
458                install: true,
459                install_dir: dir_libexec)
460     install_man('tools/xkbcli-how-to-type.1')
461     configh_data.set10('HAVE_XKBCLI_HOW_TO_TYPE', true)
462     if cc.has_header('linux/input.h')
463         executable('xkbcli-interactive-evdev',
464                    'tools/interactive-evdev.c',
465                    dependencies: tools_dep,
466                    install: true,
467                    install_dir: dir_libexec)
468         configh_data.set10('HAVE_XKBCLI_INTERACTIVE_EVDEV', true)
469         install_man('tools/xkbcli-interactive-evdev.1')
470     endif
471     if get_option('enable-x11')
472         x11_tools_dep = declare_dependency(
473             link_with: libxkbcommon_x11,
474             dependencies: [
475                 tools_dep,
476                 xcb_dep,
477                 xcb_xkb_dep,
478             ],
479         )
480         executable('xkbcli-interactive-x11',
481                    'tools/interactive-x11.c',
482                    dependencies: x11_tools_dep,
483                    install: true,
484                    install_dir: dir_libexec)
485         install_man('tools/xkbcli-interactive-x11.1')
486         configh_data.set10('HAVE_XKBCLI_INTERACTIVE_X11', true)
487     endif
488     if get_option('enable-wayland')
489         wayland_client_dep = dependency('wayland-client', version: '>=1.2.0', required: false)
490         wayland_protocols_dep = dependency('wayland-protocols', version: '>=1.12', required: false)
491         wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)
492         if not wayland_client_dep.found() or not wayland_protocols_dep.found() or not wayland_scanner_dep.found()
493             error('''The Wayland xkbcli programs require wayland-client >= 1.2.0, wayland-protocols >= 1.7 which were not found.
494 You can disable the Wayland xkbcli programs with -Denable-wayland=false.''')
495         endif
496
497         wayland_scanner = find_program(wayland_scanner_dep.get_variable(pkgconfig: 'wayland_scanner'))
498         wayland_scanner_code_gen = generator(
499             wayland_scanner,
500             output: '@BASENAME@-protocol.c',
501             arguments: ['private-code', '@INPUT@', '@OUTPUT@'],
502         )
503         wayland_scanner_client_header_gen = generator(
504             wayland_scanner,
505             output: '@BASENAME@-client-protocol.h',
506             arguments: ['client-header', '@INPUT@', '@OUTPUT@'],
507         )
508         wayland_protocols_datadir = wayland_protocols_dep.get_variable(pkgconfig: 'pkgdatadir')
509         xdg_shell_xml = wayland_protocols_datadir/'stable/xdg-shell/xdg-shell.xml'
510         xdg_shell_sources = [
511             wayland_scanner_code_gen.process(xdg_shell_xml),
512             wayland_scanner_client_header_gen.process(xdg_shell_xml),
513         ]
514         executable('xkbcli-interactive-wayland',
515                    'tools/interactive-wayland.c',
516                    xdg_shell_sources,
517                    dependencies: [tools_dep, wayland_client_dep],
518                    install: true,
519                    install_dir: dir_libexec)
520         install_man('tools/xkbcli-interactive-wayland.1')
521         configh_data.set10('HAVE_XKBCLI_INTERACTIVE_WAYLAND', true)
522     endif
523
524     if get_option('enable-xkbregistry')
525         configh_data.set10('HAVE_XKBCLI_LIST', true)
526         executable('xkbcli-list',
527                    'tools/registry-list.c',
528                    dependencies: dep_libxkbregistry,
529                    install: true,
530                    install_dir: dir_libexec)
531         install_man('tools/xkbcli-list.1')
532     endif
533 endif
534
535
536 # xkeyboard-config "verifier"
537 xkct_config = configuration_data()
538 xkct_config.set('MESON_BUILD_ROOT', meson.current_build_dir())
539 xkct_config.set('XKB_CONFIG_ROOT', XKBCONFIGROOT)
540 configure_file(input: 'test/xkeyboard-config-test.py.in',
541                output: 'xkeyboard-config-test',
542                configuration: xkct_config)
543
544 # Tests
545 test_env = environment()
546 test_env.set('XKB_LOG_LEVEL', 'debug')
547 test_env.set('XKB_LOG_VERBOSITY', '10')
548 test_env.set('top_srcdir', meson.current_source_dir())
549 test_env.set('top_builddir', meson.current_build_dir())
550 test_env.set('HAVE_XKBCLI_INTERACTIVE_EVDEV', configh_data.get('HAVE_XKBCLI_INTERACTIVE_EVDEV', 0).to_string())
551 test_env.set('HAVE_XKBCLI_INTERACTIVE_WAYLAND', configh_data.get('HAVE_XKBCLI_INTERACTIVE_WAYLAND', 0).to_string())
552 test_env.set('HAVE_XKBCLI_INTERACTIVE_X11', configh_data.get('HAVE_XKBCLI_INTERACTIVE_X11', 0).to_string())
553 test_env.set('HAVE_XKBCLI_LIST', configh_data.get('HAVE_XKBCLI_LIST', 0).to_string())
554
555 test_configh_data = configuration_data()
556 test_configh_data.set_quoted('TEST_XKB_CONFIG_ROOT', meson.current_source_dir()/'test'/'data')
557 configure_file(output: 'test-config.h', configuration: test_configh_data)
558
559 # Some tests need to use unexported symbols, so we link them against
560 # an internal copy of libxkbcommon with all symbols exposed.
561 libxkbcommon_test_internal = static_library(
562     'xkbcommon-test-internal',
563     'test/common.c',
564     'test/test.h',
565     'test/evdev-scancodes.h',
566     'bench/bench.c',
567     'bench/bench.h',
568     libxkbcommon_sources,
569     include_directories: include_directories('src', 'include'),
570 )
571 test_dep = declare_dependency(
572     include_directories: include_directories('src', 'include'),
573     link_with: libxkbcommon_test_internal,
574 )
575 if get_option('enable-x11')
576     libxkbcommon_x11_internal = static_library(
577         'xkbcommon-x11-internal',
578         libxkbcommon_x11_sources,
579         include_directories: include_directories('src', 'include'),
580         link_with: libxkbcommon_test_internal,
581         dependencies: [
582             xcb_dep,
583             xcb_xkb_dep,
584         ],
585     )
586     x11_test_dep = declare_dependency(
587         link_with: libxkbcommon_x11_internal,
588         dependencies: [
589             test_dep,
590             xcb_dep,
591             xcb_xkb_dep,
592         ],
593     )
594 endif
595 test(
596     'keysym',
597     executable('test-keysym', 'test/keysym.c', dependencies: test_dep),
598     env: test_env,
599 )
600 test(
601     'keymap',
602     executable('test-keymap', 'test/keymap.c', dependencies: test_dep),
603     env: test_env,
604 )
605 test(
606     'filecomp',
607     executable('test-filecomp', 'test/filecomp.c', dependencies: test_dep),
608     env: test_env,
609 )
610 test(
611     'context',
612     executable('test-context', 'test/context.c', dependencies: test_dep),
613     env: test_env,
614 )
615 test(
616     'rules-file',
617     executable('test-rules-file', 'test/rules-file.c', dependencies: test_dep),
618     env: test_env,
619 )
620 test(
621     'rules-file-includes',
622     executable('test-rules-file-includes', 'test/rules-file-includes.c', dependencies: test_dep),
623     env: test_env,
624 )
625 test(
626     'stringcomp',
627     executable('test-stringcomp', 'test/stringcomp.c', dependencies: test_dep),
628     env: test_env,
629 )
630 test(
631     'buffercomp',
632     executable('test-buffercomp', 'test/buffercomp.c', dependencies: test_dep),
633     env: test_env,
634 )
635 test(
636     'log',
637     executable('test-log', 'test/log.c', dependencies: test_dep),
638     env: test_env,
639 )
640 test(
641     'atom',
642     executable('test-atom', 'test/atom.c', dependencies: test_dep),
643     env: test_env,
644 )
645 test(
646     'utf8',
647     executable('test-utf8', 'test/utf8.c', dependencies: test_dep),
648     env: test_env,
649 )
650 test(
651     'state',
652     executable('test-state', 'test/state.c', dependencies: test_dep),
653     env: test_env,
654 )
655 test(
656     'keyseq',
657     executable('test-keyseq', 'test/keyseq.c', dependencies: test_dep),
658     env: test_env,
659 )
660 test(
661     'rulescomp',
662     executable('test-rulescomp', 'test/rulescomp.c', dependencies: test_dep),
663     env: test_env,
664 )
665 test(
666     'compose',
667     executable('test-compose', 'test/compose.c', dependencies: test_dep),
668     env: test_env,
669 )
670 test(
671     'utils',
672     executable('test-utils', 'test/utils.c', dependencies: test_dep),
673     env: test_env,
674 )
675 test(
676     'symbols-leak-test',
677     find_program('test/symbols-leak-test.py'),
678     env: test_env,
679     suite: ['python-tests'],
680 )
681 test(
682     'modifiers',
683     executable('test-modifiers', 'test/modifiers.c', dependencies: test_dep),
684     env: test_env,
685 )
686 if get_option('enable-x11')
687     test(
688         'x11',
689         executable('test-x11', 'test/x11.c', dependencies: x11_test_dep),
690         env: test_env,
691     )
692     # test/x11comp is meant to be run, but it is (temporarily?) disabled.
693     # See: https://github.com/xkbcommon/libxkbcommon/issues/30
694     executable('test-x11comp', 'test/x11comp.c', dependencies: x11_test_dep)
695 endif
696 if get_option('enable-xkbregistry')
697     test(
698         'registry',
699         executable('test-registry', 'test/registry.c',
700                    include_directories: include_directories('src'),
701                    dependencies: [dep_libxkbregistry, test_dep]),
702         env: test_env,
703     )
704 endif
705 if build_tools
706     test('tool-option-parsing',
707          find_program('test/tool-option-parsing.py'),
708          env: test_env,
709          suite: ['python-tests'])
710
711     # A set of keysyms to test for. Add one or two symbols to this array
712     # whenever the xorgproto gets updated to make sure we resolve them.
713     keysyms_to_test = [
714         'XF86Macro23',
715     ]
716
717     env = environment()
718     env.set('XKB_CONFIG_ROOT', meson.current_source_dir()/'test'/'data')
719     foreach keysym: keysyms_to_test
720         test('keysym-test-@0@'.format(keysym),
721              find_program('test/test-keysym.py'),
722              env: env,
723              args: [keysym, '--tool', xkbcli_compile_keymap],
724              suite: ['python-tests'])
725     endforeach
726 endif
727
728 valgrind = find_program('valgrind', required: false)
729 if valgrind.found()
730     add_test_setup('valgrind',
731         exe_wrapper: [valgrind,
732                        '--leak-check=full',
733                        '--track-origins=yes',
734                        '--gen-suppressions=all',
735                        '--error-exitcode=99'],
736         timeout_multiplier : 10)
737 else
738     message('valgrind not found, disabling valgrind test setup')
739 endif
740
741
742 # Fuzzing target programs.
743 executable('fuzz-keymap', 'fuzz/keymap/target.c', dependencies: test_dep)
744 executable('fuzz-compose', 'fuzz/compose/target.c', dependencies: test_dep)
745
746
747 # Benchmarks.
748 bench_env = environment()
749 bench_env.set('top_srcdir', meson.current_source_dir())
750 benchmark(
751     'key-proc',
752     executable('bench-key-proc', 'bench/key-proc.c', dependencies: test_dep),
753     env: bench_env,
754 )
755 benchmark(
756     'rules',
757     executable('bench-rules', 'bench/rules.c', dependencies: test_dep),
758     env: bench_env,
759 )
760 benchmark(
761     'rulescomp',
762     executable('bench-rulescomp', 'bench/rulescomp.c', dependencies: test_dep),
763     env: bench_env,
764 )
765 benchmark(
766     'compose',
767     executable('bench-compose', 'bench/compose.c', dependencies: test_dep),
768     env: bench_env,
769 )
770 benchmark(
771     'atom',
772     executable('bench-atom', 'bench/atom.c', dependencies: test_dep),
773     env: bench_env,
774 )
775 if get_option('enable-x11')
776   benchmark(
777       'x11',
778       executable('bench-x11', 'bench/x11.c', dependencies: x11_test_dep),
779       env: bench_env,
780   )
781 endif
782
783
784 # Documentation.
785 if get_option('enable-docs')
786     doxygen = find_program('doxygen', required: false)
787     if not doxygen.found()
788         error('''Documentation requires doxygen which was not found.
789 You can disable the documentation with -Denable-docs=false.''')
790     endif
791     doxygen_wrapper = find_program('scripts/doxygen-wrapper')
792
793     doxygen_input = [
794         'README.md',
795         'doc/diagrams/xkb-configuration.dot',
796         'doc/doxygen-extra.css',
797         'doc/introduction-to-xkb.md',
798         'doc/quick-guide.md',
799         'doc/compatibility.md',
800         'doc/user-configuration.md',
801         'doc/rules-format.md',
802         'doc/keymap-format-text-v1.md',
803         'include/xkbcommon/xkbcommon.h',
804         'include/xkbcommon/xkbcommon-compose.h',
805         'include/xkbcommon/xkbcommon-keysyms.h',
806         'include/xkbcommon/xkbcommon-names.h',
807         'include/xkbcommon/xkbcommon-x11.h',
808         'include/xkbcommon/xkbregistry.h',
809     ]
810     doxygen_data = configuration_data()
811     doxygen_data.set('PACKAGE_NAME', meson.project_name())
812     doxygen_data.set('PACKAGE_VERSION', meson.project_version())
813     doxygen_data.set('INPUT', ' '.join(doxygen_input))
814     doxygen_data.set('OUTPUT_DIRECTORY', meson.current_build_dir())
815     doxyfile = configure_file(
816         input: 'doc/Doxyfile.in',
817         output: 'Doxyfile',
818         configuration: doxygen_data,
819     )
820     # TODO: Meson should provide this.
821     docdir = get_option('datadir')/'doc'/meson.project_name()
822     doc_gen = custom_target(
823         'doc',
824         input: [doxyfile] + doxygen_input,
825         output: 'html',
826         command: [
827             doxygen_wrapper,
828             doxygen,
829             meson.current_build_dir()/'Doxyfile',
830             meson.current_source_dir(),
831         ],
832         install: true,
833         install_dir: docdir,
834         build_by_default: true,
835     )
836     if get_option('enable-cool-uris')
837         ensure_stable_urls = find_program('scripts'/'ensure-stable-doc-urls.py')
838         custom_target(
839             'doc-cool-uris',
840             input: [doc_gen, 'doc'/'cool-uris.yaml'],
841             output: 'html-xtra',
842             command: [
843                 ensure_stable_urls,
844                 'generate-redirections',
845                 meson.current_source_dir()/'doc'/'cool-uris.yaml',
846                 meson.current_build_dir()/'html'
847             ],
848             install: false,
849             build_by_default: true,
850         )
851     endif
852 endif
853
854 configure_file(output: 'config.h', configuration: configh_data)
855
856
857 # Stable variables for projects using xkbcommon as a subproject.
858 # These variables should not be renamed.
859 libxkbcommon_dep = dep_libxkbcommon
860 if get_option('enable-x11')
861   libxkbcommon_x11_dep = dep_libxkbcommon_x11
862 endif
863 if get_option('enable-xkbregistry')
864   libxkbregistry_dep = dep_libxkbregistry
865 endif
866
867 if meson.version().version_compare('>=0.62.0')
868     summary({
869       'backend': meson.backend(),
870       'buildtype': get_option('buildtype'),
871       'c_args': get_option('c_args'),
872       'c_link_args': get_option('c_link_args'),
873       'yacc': yacc.full_path() + ' ' + yacc.version(),
874     }, section: 'Compiler')
875     summary({
876       'prefix': get_option('prefix'),
877       'bindir': get_option('bindir'),
878       'libdir': get_option('libdir'),
879       'datadir': get_option('datadir'),
880       'xkb-config-root': XKBCONFIGROOT,
881       'xkb-config-extra-path': XKBCONFIGEXTRAPATH,
882       'xlocaledir': XLOCALEDIR,
883     }, section: 'Directories')
884     summary({
885       'docs': get_option('enable-docs'),
886       'tools': get_option('enable-tools'),
887       'wayland': get_option('enable-wayland'),
888       'x11': get_option('enable-x11'),
889     }, section: 'Features')
890     summary({
891       'layout': get_option('default-layout'),
892       'model': get_option('default-model'),
893       'options': get_option('default-options'),
894       'rules': get_option('default-rules'),
895       'variant': get_option('default-variant'),
896     }, section: 'Defaults')
897 endif