10 meson_version : '>= 0.49.0',
12 pkgconfig = import('pkgconfig')
13 cc = meson.get_compiler('c')
15 dir_libexec = get_option('prefix')/get_option('libexecdir')/'xkbcommon'
19 '-fno-strict-aliasing',
20 '-fsanitize-undefined-trap-on-error',
21 '-Wno-unused-parameter',
22 '-Wno-missing-field-initializers',
24 '-Wmissing-declarations',
26 '-Wstrict-prototypes',
27 '-Wmissing-prototypes',
29 '-Wbad-function-cast',
34 '-Wno-documentation-deprecated-sync',
36 add_project_arguments(cc.get_supported_arguments(cflags), language: 'c')
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')
46 XKBCONFIGROOT = get_option('prefix')/get_option('datadir')/'X11'/'xkb'
50 XKBCONFIGEXTRAPATH = get_option('xkb-config-extra-path')
51 if XKBCONFIGEXTRAPATH == ''
52 XKBCONFIGEXTRAPATH = get_option('prefix')/get_option('sysconfdir')/'xkb'
55 # The X locale directory for compose.
56 XLOCALEDIR = get_option('x-locale-root')
58 XLOCALEDIR = get_option('prefix')/get_option('datadir')/'X11'/'locale'
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__'
72 system_extensions = '_GNU_SOURCE'
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'))
85 configh_data.set('DEFAULT_XKB_VARIANT', 'NULL')
87 if get_option('default-options') != ''
88 configh_data.set_quoted('DEFAULT_XKB_OPTIONS', get_option('default-options'))
90 configh_data.set('DEFAULT_XKB_OPTIONS', 'NULL')
92 if cc.has_header('unistd.h')
93 configh_data.set('HAVE_UNISTD_H', 1)
95 if cc.links('int main(){if(__builtin_expect(1<0,0)){}}', name: '__builtin_expect')
96 configh_data.set('HAVE___BUILTIN_EXPECT', 1)
98 if cc.has_header_symbol('unistd.h', 'eaccess', prefix: system_ext_define)
99 configh_data.set('HAVE_EACCESS', 1)
101 if cc.has_header_symbol('unistd.h', 'euidaccess', prefix: system_ext_define)
102 configh_data.set('HAVE_EUIDACCESS', 1)
104 if cc.has_header_symbol('sys/mman.h', 'mmap')
105 configh_data.set('HAVE_MMAP', 1)
107 if cc.has_header_symbol('stdlib.h', 'mkostemp', prefix: system_ext_define)
108 configh_data.set('HAVE_MKOSTEMP', 1)
110 if cc.has_header_symbol('fcntl.h', 'posix_fallocate', prefix: system_ext_define)
111 configh_data.set('HAVE_POSIX_FALLOCATE', 1)
113 if cc.has_header_symbol('string.h', 'strndup', prefix: system_ext_define)
114 configh_data.set('HAVE_STRNDUP', 1)
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)
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)
126 message('C library does not support secure_getenv, using getenv instead')
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)
135 configh_data.set('PATH_MAX', 4096)
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)
148 # Supports -Wl,--version-script?
149 have_version_script = cc.links(
151 args: '-Wl,--version-script=' + meson.source_root()/'xkbcommon.map',
152 name: '-Wl,--version-script',
157 # Note: we use some yacc extensions, which work with either GNU bison
158 # (preferred) or byacc (with backtracking enabled).
159 bison = find_program('bison', 'win_bison', required: false)
161 yacc_gen = generator(
163 output: ['@BASENAME@.c', '@BASENAME@.h'],
164 arguments: ['--defines=@OUTPUT1@', '-o', '@OUTPUT0@', '-p', '_xkbcommon_', '@INPUT@'],
167 byacc = find_program('byacc', required: false)
169 yacc_gen = generator(
171 output: ['@BASENAME@.c', '@BASENAME@.h'],
172 arguments: ['-H', '@OUTPUT1@', '-o', '@OUTPUT0@', '-p', '_xkbcommon_', '@INPUT@'],
175 error('Could not find a compatible YACC program (bison or byacc)')
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',
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',
215 'src/context-priv.c',
224 'src/scanner-utils.h',
233 libxkbcommon_link_args = []
234 if have_version_script
235 libxkbcommon_link_args += '-Wl,--version-script=' + meson.source_root()/'xkbcommon.map'
237 libxkbcommon = library(
239 'xkbcommon/xkbcommon.h',
240 libxkbcommon_sources,
241 link_args: libxkbcommon_link_args,
242 link_depends: 'xkbcommon.map',
243 gnu_symbol_visibility: 'hidden',
246 include_directories: include_directories('src'),
249 'xkbcommon/xkbcommon.h',
250 'xkbcommon/xkbcommon-compat.h',
251 'xkbcommon/xkbcommon-compose.h',
252 'xkbcommon/xkbcommon-keysyms.h',
253 'xkbcommon/xkbcommon-names.h',
256 libxkbcommon_dep = declare_dependency(
257 link_with: libxkbcommon,
262 filebase: 'xkbcommon',
263 version: meson.project_version(),
264 description: 'XKB API common to servers and clients',
269 if get_option('enable-x11')
270 xcb_dep = dependency('xcb', version: '>=1.10', required: false)
271 xcb_xkb_dep = dependency('xcb-xkb', version: '>=1.10', required: false)
272 if not xcb_dep.found() or not xcb_xkb_dep.found()
273 error('''X11 support requires xcb-xkb >= 1.10 which was not found.
274 You can disable X11 support with -Denable-x11=false.''')
277 libxkbcommon_x11_sources = [
281 'src/x11/x11-priv.h',
283 'src/context-priv.c',
289 libxkbcommon_x11_link_args = []
290 if have_version_script
291 libxkbcommon_x11_link_args += '-Wl,--version-script=' + meson.source_root()/'xkbcommon-x11.map'
293 libxkbcommon_x11 = library(
295 'xkbcommon/xkbcommon-x11.h',
296 libxkbcommon_x11_sources,
297 link_args: libxkbcommon_x11_link_args,
298 link_depends: 'xkbcommon-x11.map',
299 gnu_symbol_visibility: 'hidden',
302 include_directories: include_directories('src'),
303 link_with: libxkbcommon,
310 'xkbcommon/xkbcommon-x11.h',
313 libxkbcommon_x11_dep = declare_dependency(
314 link_with: libxkbcommon_x11,
318 name: 'xkbcommon-x11',
319 filebase: 'xkbcommon-x11',
320 version: meson.project_version(),
321 description: 'XKB API common to servers and clients - X11 support',
322 requires: ['xkbcommon'],
323 requires_private: ['xcb>=1.10', 'xcb-xkb>=1.10'],
328 if get_option('enable-xkbregistry')
329 dep_libxml = dependency('libxml-2.0')
330 deps_libxkbregistry = [dep_libxml]
331 libxkbregistry_sources = [
338 libxkbregistry_link_args = []
339 if have_version_script
340 libxkbregistry_link_args += '-Wl,--version-script=' + meson.source_root()/'xkbregistry.map'
342 libxkbregistry = library(
344 'xkbcommon/xkbregistry.h',
345 libxkbregistry_sources,
346 link_args: libxkbregistry_link_args,
347 link_depends: 'xkbregistry.map',
348 gnu_symbol_visibility: 'hidden',
349 dependencies: deps_libxkbregistry,
352 include_directories: include_directories('src'),
355 'xkbcommon/xkbregistry.h',
361 filebase: 'xkbregistry',
362 version: meson.project_version(),
363 description: 'XKB API to query available rules, models, layouts, variants and options',
366 dep_libxkbregistry = declare_dependency(
367 include_directories: include_directories('xkbcommon'),
368 link_with: libxkbregistry
375 build_tools = have_getopt_long
377 libxkbcommon_tools_internal = static_library(
379 'tools/tools-common.h',
380 'tools/tools-common.c',
381 dependencies: libxkbcommon_dep,
383 tools_dep = declare_dependency(
384 include_directories: [include_directories('tools')],
385 link_with: libxkbcommon_tools_internal,
388 executable('xkbcli', 'tools/xkbcli.c',
389 dependencies: tools_dep, install: true)
390 install_man('tools/xkbcli.1')
392 xkbcli_compile_keymap = executable('xkbcli-compile-keymap',
393 'tools/compile-keymap.c',
394 dependencies: tools_dep,
396 install_dir: dir_libexec)
397 install_man('tools/xkbcli-compile-keymap.1')
398 # The same tool again, but with access to some private APIs.
399 executable('compile-keymap',
400 'tools/compile-keymap.c',
401 libxkbcommon_sources,
402 dependencies: [tools_dep],
403 c_args: ['-DENABLE_PRIVATE_APIS'],
404 include_directories: [include_directories('src')],
406 configh_data.set10('HAVE_XKBCLI_COMPILE_KEYMAP', true)
407 executable('xkbcli-how-to-type',
408 'tools/how-to-type.c',
409 dependencies: tools_dep,
411 install_dir: dir_libexec)
412 install_man('tools/xkbcli-how-to-type.1')
413 configh_data.set10('HAVE_XKBCLI_HOW_TO_TYPE', true)
414 if cc.has_header('linux/input.h')
415 executable('xkbcli-interactive-evdev',
416 'tools/interactive-evdev.c',
417 dependencies: tools_dep,
419 install_dir: dir_libexec)
420 configh_data.set10('HAVE_XKBCLI_INTERACTIVE_EVDEV', true)
421 install_man('tools/xkbcli-interactive-evdev.1')
423 if get_option('enable-x11')
424 x11_tools_dep = declare_dependency(
425 link_with: libxkbcommon_x11,
432 executable('xkbcli-interactive-x11',
433 'tools/interactive-x11.c',
434 dependencies: x11_tools_dep,
436 install_dir: dir_libexec)
437 install_man('tools/xkbcli-interactive-x11.1')
438 configh_data.set10('HAVE_XKBCLI_INTERACTIVE_X11', true)
440 if get_option('enable-wayland')
441 wayland_client_dep = dependency('wayland-client', version: '>=1.2.0', required: false)
442 wayland_protocols_dep = dependency('wayland-protocols', version: '>=1.12', required: false)
443 wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)
444 if not wayland_client_dep.found() or not wayland_protocols_dep.found() or not wayland_scanner_dep.found()
445 error('''The Wayland xkbcli programs require wayland-client >= 1.2.0, wayland-protocols >= 1.7 which were not found.
446 You can disable the Wayland xkbcli programs with -Denable-wayland=false.''')
449 wayland_scanner = find_program(wayland_scanner_dep.get_pkgconfig_variable('wayland_scanner'))
450 wayland_scanner_code_gen = generator(
452 output: '@BASENAME@-protocol.c',
453 arguments: ['code', '@INPUT@', '@OUTPUT@'],
455 wayland_scanner_client_header_gen = generator(
457 output: '@BASENAME@-client-protocol.h',
458 arguments: ['client-header', '@INPUT@', '@OUTPUT@'],
460 wayland_protocols_datadir = wayland_protocols_dep.get_pkgconfig_variable('pkgdatadir')
461 xdg_shell_xml = wayland_protocols_datadir/'stable/xdg-shell/xdg-shell.xml'
462 xdg_shell_sources = [
463 wayland_scanner_code_gen.process(xdg_shell_xml),
464 wayland_scanner_client_header_gen.process(xdg_shell_xml),
466 executable('xkbcli-interactive-wayland',
467 'tools/interactive-wayland.c',
469 dependencies: [tools_dep, wayland_client_dep],
471 install_dir: dir_libexec)
472 install_man('tools/xkbcli-interactive-wayland.1')
473 configh_data.set10('HAVE_XKBCLI_INTERACTIVE_WAYLAND', true)
476 if get_option('enable-xkbregistry')
477 configh_data.set10('HAVE_XKBCLI_LIST', true)
478 executable('xkbcli-list',
479 'tools/registry-list.c',
480 dependencies: dep_libxkbregistry,
482 install_dir: dir_libexec)
483 install_man('tools/xkbcli-list.1')
488 # xkeyboard-config "verifier"
489 xkct_config = configuration_data()
490 xkct_config.set('MESON_BUILD_ROOT', meson.build_root())
491 xkct_config.set('XKB_CONFIG_ROOT', XKBCONFIGROOT)
492 configure_file(input: 'test/xkeyboard-config-test.py.in',
493 output: 'xkeyboard-config-test',
494 configuration: xkct_config)
497 test_env = environment()
498 test_env.set('XKB_LOG_LEVEL', 'debug')
499 test_env.set('XKB_LOG_VERBOSITY', '10')
500 test_env.set('top_srcdir', meson.source_root())
501 test_env.set('top_builddir', meson.build_root())
502 test_env.set('HAVE_XKBCLI_INTERACTIVE_EVDEV', configh_data.get('HAVE_XKBCLI_INTERACTIVE_EVDEV', 0).to_string())
503 test_env.set('HAVE_XKBCLI_INTERACTIVE_WAYLAND', configh_data.get('HAVE_XKBCLI_INTERACTIVE_WAYLAND', 0).to_string())
504 test_env.set('HAVE_XKBCLI_INTERACTIVE_X11', configh_data.get('HAVE_XKBCLI_INTERACTIVE_X11', 0).to_string())
505 test_env.set('HAVE_XKBCLI_LIST', configh_data.get('HAVE_XKBCLI_LIST', 0).to_string())
507 test_configh_data = configuration_data()
508 test_configh_data.set_quoted('TEST_XKB_CONFIG_ROOT', meson.source_root()/'test'/'data')
509 configure_file(output: 'test-config.h', configuration: test_configh_data)
511 # Some tests need to use unexported symbols, so we link them against
512 # an internal copy of libxkbcommon with all symbols exposed.
513 libxkbcommon_test_internal = static_library(
514 'xkbcommon-test-internal',
517 'test/evdev-scancodes.h',
520 libxkbcommon_sources,
521 include_directories: include_directories('src'),
523 test_dep = declare_dependency(
524 include_directories: include_directories('src'),
525 link_with: libxkbcommon_test_internal,
527 if get_option('enable-x11')
528 libxkbcommon_x11_internal = static_library(
529 'xkbcommon-x11-internal',
530 libxkbcommon_x11_sources,
531 include_directories: include_directories('src'),
532 link_with: libxkbcommon_test_internal,
538 x11_test_dep = declare_dependency(
539 link_with: libxkbcommon_x11_internal,
549 executable('test-keysym', 'test/keysym.c', dependencies: test_dep),
554 executable('test-keymap', 'test/keymap.c', dependencies: test_dep),
559 executable('test-filecomp', 'test/filecomp.c', dependencies: test_dep),
562 # TODO: This test currently uses some functions that don't exist on Windows.
563 if cc.get_id() != 'msvc'
566 executable('test-context', 'test/context.c', dependencies: test_dep),
572 executable('test-rules-file', 'test/rules-file.c', dependencies: test_dep),
576 'rules-file-includes',
577 executable('test-rules-file-includes', 'test/rules-file-includes.c', dependencies: test_dep),
582 executable('test-stringcomp', 'test/stringcomp.c', dependencies: test_dep),
587 executable('test-buffercomp', 'test/buffercomp.c', dependencies: test_dep),
592 executable('test-log', 'test/log.c', dependencies: test_dep),
597 executable('test-atom', 'test/atom.c', dependencies: test_dep),
602 executable('test-utf8', 'test/utf8.c', dependencies: test_dep),
607 executable('test-state', 'test/state.c', dependencies: test_dep),
612 executable('test-keyseq', 'test/keyseq.c', dependencies: test_dep),
617 executable('test-rulescomp', 'test/rulescomp.c', dependencies: test_dep),
622 executable('test-compose', 'test/compose.c', dependencies: test_dep),
627 executable('test-utils', 'test/utils.c', dependencies: test_dep),
632 find_program('test/symbols-leak-test.py'),
634 suite: ['python-tests'],
636 if get_option('enable-x11')
639 executable('test-x11', 'test/x11.c', dependencies: x11_test_dep),
642 # test/x11comp is meant to be run, but it is (temporarily?) disabled.
643 # See: https://github.com/xkbcommon/libxkbcommon/issues/30
644 executable('test-x11comp', 'test/x11comp.c', dependencies: x11_test_dep)
646 if get_option('enable-xkbregistry')
649 executable('test-registry', 'test/registry.c',
650 include_directories: include_directories('src'),
651 dependencies: dep_libxkbregistry),
656 test('tool-option-parsing',
657 find_program('test/tool-option-parsing.py'),
659 suite: ['python-tests'])
661 # A set of keysyms to test for. Add one or two symbols to this array
662 # whenever the xorgproto gets updated to make sure we resolve them.
668 env.set('XKB_CONFIG_ROOT', meson.source_root()/'test'/'data')
669 foreach keysym: keysyms_to_test
670 test('keysym-test-@0@'.format(keysym),
671 find_program('test/test-keysym.py'),
673 args: [keysym, '--tool', xkbcli_compile_keymap],
674 suite: ['python-tests'])
678 valgrind = find_program('valgrind', required: false)
680 add_test_setup('valgrind',
681 exe_wrapper: [valgrind,
683 '--track-origins=yes',
684 '--gen-suppressions=all',
685 '--error-exitcode=99'],
686 timeout_multiplier : 10)
688 message('valgrind not found, disabling valgrind test setup')
692 # Fuzzing target programs.
693 executable('fuzz-keymap', 'fuzz/keymap/target.c', dependencies: test_dep)
694 executable('fuzz-compose', 'fuzz/compose/target.c', dependencies: test_dep)
698 bench_env = environment()
699 bench_env.set('top_srcdir', meson.source_root())
702 executable('bench-key-proc', 'bench/key-proc.c', dependencies: test_dep),
707 executable('bench-rules', 'bench/rules.c', dependencies: test_dep),
712 executable('bench-rulescomp', 'bench/rulescomp.c', dependencies: test_dep),
717 executable('bench-compose', 'bench/compose.c', dependencies: test_dep),
720 if get_option('enable-x11')
723 executable('bench-x11', 'bench/x11.c', dependencies: x11_test_dep),
730 if get_option('enable-docs')
731 doxygen = find_program('doxygen', required: false)
732 if not doxygen.found()
733 error('''Documentation requires doxygen which was not found.
734 You can disable the documentation with -Denable-docs=false.''')
736 doxygen_wrapper = find_program('scripts/doxygen-wrapper')
740 'doc/doxygen-extra.css',
741 'doc/quick-guide.md',
743 'doc/user-configuration.md',
744 'doc/rules-format.md',
745 'doc/keymap-format-text-v1.md',
746 'xkbcommon/xkbcommon.h',
747 'xkbcommon/xkbcommon-names.h',
748 'xkbcommon/xkbcommon-x11.h',
749 'xkbcommon/xkbcommon-compose.h',
750 'xkbcommon/xkbregistry.h',
752 doxygen_data = configuration_data()
753 doxygen_data.set('PACKAGE_NAME', meson.project_name())
754 doxygen_data.set('PACKAGE_VERSION', meson.project_version())
755 doxygen_data.set('INPUT', ' '.join(doxygen_input))
756 doxygen_data.set('OUTPUT_DIRECTORY', meson.build_root())
757 doxyfile = configure_file(
758 input: 'doc/Doxyfile.in',
760 configuration: doxygen_data,
762 # TODO: Meson should provide this.
763 docdir = get_option('datadir')/'doc'/meson.project_name()
766 input: [doxyfile] + doxygen_input,
768 command: [doxygen_wrapper, doxygen.path(), meson.build_root()/'Doxyfile', meson.source_root()],
771 build_by_default: true,
775 configure_file(output: 'config.h', configuration: configh_data)