10 meson_version : '>= 0.49.0',
12 pkgconfig = import('pkgconfig')
13 cc = meson.get_compiler('c')
18 '-fvisibility=hidden',
19 '-fno-strict-aliasing',
20 '-fsanitize-undefined-trap-on-error',
22 '-Wno-unused-parameter',
23 '-Wno-missing-field-initializers',
25 '-Wmissing-declarations',
27 '-Wstrict-prototypes',
28 '-Wmissing-prototypes',
30 '-Wbad-function-cast',
35 '-Wno-documentation-deprecated-sync',
37 if cc.has_argument(cflag)
38 add_project_arguments(cflag, language: 'c')
43 # The XKB config root.
44 XKBCONFIGROOT = get_option('xkb-config-root')
45 if XKBCONFIGROOT == ''
46 xkeyboard_config_dep = dependency('xkeyboard-config', required: false)
47 if xkeyboard_config_dep.found()
48 XKBCONFIGROOT = xkeyboard_config_dep.get_pkgconfig_variable('xkb_base')
50 XKBCONFIGROOT = join_paths(get_option('prefix'), get_option('datadir'), 'X11', 'xkb')
55 # The X locale directory for compose.
56 XLOCALEDIR = get_option('x-locale-root')
58 XLOCALEDIR = join_paths(get_option('prefix'), get_option('datadir'), 'X11', 'locale')
63 configh_data = configuration_data()
64 # Like AC_USE_SYSTEM_EXTENSIONS, what #define to use to get extensions
65 # beyond the base POSIX function set.
66 if host_machine.system() == 'sunos'
67 system_extensions = '__EXTENSIONS__'
69 system_extensions = '_GNU_SOURCE'
71 configh_data.set(system_extensions, 1)
72 system_ext_define = '#define ' + system_extensions
73 configh_data.set_quoted('DFLT_XKB_CONFIG_ROOT', XKBCONFIGROOT)
74 configh_data.set_quoted('XLOCALEDIR', XLOCALEDIR)
75 configh_data.set_quoted('DEFAULT_XKB_RULES', get_option('default-rules'))
76 configh_data.set_quoted('DEFAULT_XKB_MODEL', get_option('default-model'))
77 configh_data.set_quoted('DEFAULT_XKB_LAYOUT', get_option('default-layout'))
78 if get_option('default-variant') != ''
79 configh_data.set_quoted('DEFAULT_XKB_VARIANT', get_option('default-variant'))
81 configh_data.set('DEFAULT_XKB_VARIANT', 'NULL')
83 if get_option('default-options') != ''
84 configh_data.set_quoted('DEFAULT_XKB_OPTIONS', get_option('default-options'))
86 configh_data.set('DEFAULT_XKB_OPTIONS', 'NULL')
88 if cc.links('int main(){if(__builtin_expect(1<0,0)){}}', name: '__builtin_expect')
89 configh_data.set('HAVE___BUILTIN_EXPECT', 1)
91 if cc.has_header_symbol('unistd.h', 'eaccess', prefix: system_ext_define)
92 configh_data.set('HAVE_EACCESS', 1)
94 if cc.has_header_symbol('unistd.h', 'euidaccess', prefix: system_ext_define)
95 configh_data.set('HAVE_EUIDACCESS', 1)
97 if cc.has_header_symbol('sys/mman.h', 'mmap')
98 configh_data.set('HAVE_MMAP', 1)
100 if cc.has_header_symbol('stdlib.h', 'mkostemp', prefix: system_ext_define)
101 configh_data.set('HAVE_MKOSTEMP', 1)
103 if cc.has_header_symbol('fcntl.h', 'posix_fallocate', prefix: system_ext_define)
104 configh_data.set('HAVE_POSIX_FALLOCATE', 1)
106 if cc.has_header_symbol('string.h', 'strndup', prefix: system_ext_define)
107 configh_data.set('HAVE_STRNDUP', 1)
109 if cc.has_header_symbol('stdio.h', 'asprintf', prefix: system_ext_define)
110 configh_data.set('HAVE_ASPRINTF', 1)
111 elif cc.has_header_symbol('stdio.h', 'vasprintf', prefix: system_ext_define)
112 configh_data.set('HAVE_VASPRINTF', 1)
114 if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix: system_ext_define)
115 configh_data.set('HAVE_SECURE_GETENV', 1)
116 elif cc.has_header_symbol('stdlib.h', '__secure_getenv', prefix: system_ext_define)
117 configh_data.set('HAVE___SECURE_GETENV', 1)
119 message('C library does not support secure_getenv, using getenv instead')
121 have_getopt_long = cc.has_header_symbol('getopt.h', 'getopt_long',
122 prefix: '#define _GNU_SOURCE')
124 # Silence some security & deprecation warnings on MSVC
125 # for some unix/C functions we use.
126 # https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4996?view=vs-2019
127 configh_data.set('_CRT_SECURE_NO_WARNINGS', 1)
128 configh_data.set('_CRT_NONSTDC_NO_WARNINGS', 1)
129 configh_data.set('_CRT_NONSTDC_NO_DEPRECATE', 1)
130 # Reduce unnecessary includes on MSVC.
131 configh_data.set('WIN32_LEAN_AND_MEAN', 1)
132 configure_file(output: 'config.h', configuration: configh_data)
135 # Supports -Wl,--version-script?
136 have_version_script = cc.links(
138 args: '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon.map'),
139 name: '-Wl,--version-script',
144 # Note: we use some yacc extensions, which work with either GNU bison
145 # (preferred) or byacc (with backtracking enabled).
146 bison = find_program('bison', 'win_bison', required: false)
148 yacc_gen = generator(
150 output: ['@BASENAME@.c', '@BASENAME@.h'],
151 arguments: ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@', '-p _xkbcommon_'],
154 byacc = find_program('byacc', required: false)
156 yacc_gen = generator(
158 output: ['@BASENAME@.c', '@BASENAME@.h'],
159 arguments: ['@INPUT@', '-H', '@OUTPUT1@', '-o', '@OUTPUT0@', '-p _xkbcommon_'],
162 error('Could not find a compatible YACC program (bison or byacc)')
165 libxkbcommon_sources = [
166 'src/compose/parser.c',
167 'src/compose/parser.h',
168 'src/compose/paths.c',
169 'src/compose/paths.h',
170 'src/compose/state.c',
171 'src/compose/table.c',
172 'src/compose/table.h',
173 'src/xkbcomp/action.c',
174 'src/xkbcomp/action.h',
176 'src/xkbcomp/ast-build.c',
177 'src/xkbcomp/ast-build.h',
178 'src/xkbcomp/compat.c',
179 'src/xkbcomp/expr.c',
180 'src/xkbcomp/expr.h',
181 'src/xkbcomp/include.c',
182 'src/xkbcomp/include.h',
183 'src/xkbcomp/keycodes.c',
184 'src/xkbcomp/keymap.c',
185 'src/xkbcomp/keymap-dump.c',
186 'src/xkbcomp/keywords.c',
187 yacc_gen.process('src/xkbcomp/parser.y'),
188 'src/xkbcomp/parser-priv.h',
189 'src/xkbcomp/rules.c',
190 'src/xkbcomp/rules.h',
191 'src/xkbcomp/scanner.c',
192 'src/xkbcomp/symbols.c',
193 'src/xkbcomp/types.c',
194 'src/xkbcomp/vmod.c',
195 'src/xkbcomp/vmod.h',
196 'src/xkbcomp/xkbcomp.c',
197 'src/xkbcomp/xkbcomp-priv.h',
202 'src/context-priv.c',
211 'src/scanner-utils.h',
220 libxkbcommon_link_args = []
221 if have_version_script
222 libxkbcommon_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon.map')
224 libxkbcommon = library(
226 'xkbcommon/xkbcommon.h',
227 libxkbcommon_sources,
228 link_args: libxkbcommon_link_args,
229 link_depends: 'xkbcommon.map',
232 include_directories: include_directories('src'),
235 'xkbcommon/xkbcommon.h',
236 'xkbcommon/xkbcommon-compat.h',
237 'xkbcommon/xkbcommon-compose.h',
238 'xkbcommon/xkbcommon-keysyms.h',
239 'xkbcommon/xkbcommon-names.h',
245 filebase: 'xkbcommon',
246 version: meson.project_version(),
247 description: 'XKB API common to servers and clients',
252 if get_option('enable-x11')
253 xcb_dep = dependency('xcb', version: '>=1.10', required: false)
254 xcb_xkb_dep = dependency('xcb-xkb', version: '>=1.10', required: false)
255 if not xcb_dep.found() or not xcb_xkb_dep.found()
256 error('''X11 support requires xcb-xkb >= 1.10 which was not found.
257 You can disable X11 support with -Denable-x11=false.''')
260 libxkbcommon_x11_sources = [
264 'src/x11/x11-priv.h',
266 'src/context-priv.c',
272 libxkbcommon_x11_link_args = []
273 if have_version_script
274 libxkbcommon_x11_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon-x11.map')
276 libxkbcommon_x11 = library(
278 'xkbcommon/xkbcommon-x11.h',
279 libxkbcommon_x11_sources,
280 link_args: libxkbcommon_x11_link_args,
281 link_depends: 'xkbcommon-x11.map',
284 include_directories: include_directories('src'),
285 link_with: libxkbcommon,
292 'xkbcommon/xkbcommon-x11.h',
297 name: 'xkbcommon-x11',
298 filebase: 'xkbcommon-x11',
299 version: meson.project_version(),
300 description: 'XKB API common to servers and clients - X11 support',
301 requires: ['xkbcommon'],
302 requires_private: ['xcb>=1.10', 'xcb-xkb>=1.10'],
307 if get_option('enable-xkbregistry')
308 dep_libxml = dependency('libxml-2.0')
309 deps_libxkbregistry = [dep_libxml]
310 libxkbregistry_sources = [
317 libxkbregistry_link_args = []
318 if have_version_script
319 libxkbregistry_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbregistry.map')
321 libxkbregistry = library(
323 'xkbcommon/xkbregistry.h',
324 libxkbregistry_sources,
325 link_args: libxkbregistry_link_args,
326 link_depends: 'xkbregistry.map',
327 dependencies: deps_libxkbregistry,
330 include_directories: include_directories('src'),
333 'xkbcommon/xkbregistry.h',
339 filebase: 'xkbregistry',
340 version: meson.project_version(),
341 description: 'XKB API to query available rules, models, layouts, variants and options',
344 dep_libxkbregistry = declare_dependency(
345 include_directories: include_directories('xkbcommon'),
346 link_with: libxkbregistry
349 executable('xkbcommon-registry-list',
350 'tools/registry-list.c',
351 dependencies: dep_libxkbregistry,
357 test_env = environment()
358 test_env.set('XKB_LOG_LEVEL', 'debug')
359 test_env.set('XKB_LOG_VERBOSITY', '10')
360 test_env.set('top_srcdir', meson.source_root())
361 test_env.set('top_builddir', meson.build_root())
363 test_configh_data = configuration_data()
364 test_configh_data.set_quoted('TEST_XKB_CONFIG_ROOT', join_paths(meson.source_root(), 'test', 'data'))
365 configure_file(output: 'test-config.h', configuration: test_configh_data)
367 # Some tests need to use unexported symbols, so we link them against
368 # an internal copy of libxkbcommon with all symbols exposed.
369 libxkbcommon_test_internal = static_library(
370 'xkbcommon-test-internal',
373 'test/evdev-scancodes.h',
374 libxkbcommon_sources,
375 include_directories: include_directories('src'),
377 test_dep = declare_dependency(
378 include_directories: include_directories('src'),
379 link_with: libxkbcommon_test_internal,
381 if get_option('enable-x11')
382 libxkbcommon_x11_internal = static_library(
383 'xkbcommon-x11-internal',
384 libxkbcommon_x11_sources,
385 include_directories: include_directories('src'),
386 link_with: libxkbcommon_test_internal,
392 x11_test_dep = declare_dependency(
393 link_with: libxkbcommon_x11_internal,
403 executable('test-keysym', 'test/keysym.c', dependencies: test_dep),
408 executable('test-keymap', 'test/keymap.c', dependencies: test_dep),
413 executable('test-filecomp', 'test/filecomp.c', dependencies: test_dep),
416 # TODO: This test currently uses some functions that don't exist on Windows.
417 if cc.get_id() != 'msvc'
420 executable('test-context', 'test/context.c', dependencies: test_dep),
426 executable('test-rules-file', 'test/rules-file.c', dependencies: test_dep),
430 'rules-file-includes',
431 executable('test-rules-file-includes', 'test/rules-file-includes.c', dependencies: test_dep),
436 executable('test-stringcomp', 'test/stringcomp.c', dependencies: test_dep),
441 executable('test-buffercomp', 'test/buffercomp.c', dependencies: test_dep),
446 executable('test-log', 'test/log.c', dependencies: test_dep),
451 executable('test-atom', 'test/atom.c', dependencies: test_dep),
456 executable('test-utf8', 'test/utf8.c', dependencies: test_dep),
461 executable('test-state', 'test/state.c', dependencies: test_dep),
466 executable('test-keyseq', 'test/keyseq.c', dependencies: test_dep),
471 executable('test-rulescomp', 'test/rulescomp.c', dependencies: test_dep),
476 executable('test-compose', 'test/compose.c', dependencies: test_dep),
481 executable('test-utils', 'test/utils.c', dependencies: test_dep),
486 find_program('test/symbols-leak-test.py'),
488 suite: ['python-tests'],
490 if get_option('enable-x11')
493 executable('test-x11', 'test/x11.c', dependencies: x11_test_dep),
496 # test/x11comp is meant to be run, but it is (temporarily?) disabled.
497 # See: https://github.com/xkbcommon/libxkbcommon/issues/30
498 executable('test-x11comp', 'test/x11comp.c', dependencies: x11_test_dep)
500 if get_option('enable-xkbregistry')
503 executable('test-registry', 'test/registry.c',
504 include_directories: include_directories('src'),
505 dependencies: dep_libxkbregistry),
510 valgrind = find_program('valgrind', required: false)
512 add_test_setup('valgrind',
513 exe_wrapper: [valgrind,
515 '--track-origins=yes',
516 '--gen-suppressions=all',
517 '--error-exitcode=99'],
518 timeout_multiplier : 10)
520 message('valgrind not found, disabling valgrind test setup')
524 # Fuzzing target programs.
525 executable('fuzz-keymap', 'fuzz/keymap/target.c', dependencies: test_dep)
526 executable('fuzz-compose', 'fuzz/compose/target.c', dependencies: test_dep)
530 libxkbcommon_tools_internal = static_library(
532 'tools/tools-common.h',
533 'tools/tools-common.c',
534 libxkbcommon_sources,
535 include_directories: include_directories('src'),
537 tools_dep = declare_dependency(
538 include_directories: [include_directories('src'), include_directories('tools')],
539 link_with: libxkbcommon_tools_internal,
543 executable('xkbcommon-rmlvo-to-keymap', 'tools/rmlvo-to-keymap.c', dependencies: tools_dep)
544 executable('xkbcommon-how-to-type', 'tools/how-to-type.c', dependencies: tools_dep)
546 if cc.has_header('linux/input.h')
547 executable('xkbcommon-interactive-evdev', 'tools/interactive-evdev.c', dependencies: tools_dep)
549 if get_option('enable-x11')
550 x11_tools_dep = declare_dependency(
551 link_with: libxkbcommon_x11_internal,
558 executable('xkbcommon-interactive-x11', 'tools/interactive-x11.c', dependencies: x11_tools_dep)
560 if get_option('enable-wayland')
561 wayland_client_dep = dependency('wayland-client', version: '>=1.2.0', required: false)
562 wayland_protocols_dep = dependency('wayland-protocols', version: '>=1.12', required: false)
563 wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)
564 if not wayland_client_dep.found() or not wayland_protocols_dep.found() or not wayland_scanner_dep.found()
565 error('''The Wayland demo programs require wayland-client >= 1.2.0, wayland-protocols >= 1.7 which were not found.
566 You can disable the Wayland demo programs with -Denable-wayland=false.''')
569 wayland_scanner = find_program(wayland_scanner_dep.get_pkgconfig_variable('wayland_scanner'))
570 wayland_scanner_code_gen = generator(
572 output: '@BASENAME@-protocol.c',
573 arguments: ['code', '@INPUT@', '@OUTPUT@'],
575 wayland_scanner_client_header_gen = generator(
577 output: '@BASENAME@-client-protocol.h',
578 arguments: ['client-header', '@INPUT@', '@OUTPUT@'],
580 wayland_protocols_datadir = wayland_protocols_dep.get_pkgconfig_variable('pkgdatadir')
581 xdg_shell_xml = join_paths(wayland_protocols_datadir, 'stable/xdg-shell/xdg-shell.xml')
582 xdg_shell_sources = [
583 wayland_scanner_code_gen.process(xdg_shell_xml),
584 wayland_scanner_client_header_gen.process(xdg_shell_xml),
586 executable('xkbcommon-interactive-wayland',
587 'tools/interactive-wayland.c',
589 dependencies: [tools_dep, wayland_client_dep])
592 # xkeyboard-config "verifier"
593 xkct_config = configuration_data()
594 xkct_config.set('MESON_BUILD_ROOT', meson.build_root())
595 xkct_config.set('XKB_CONFIG_ROOT', XKBCONFIGROOT)
596 configure_file(input: 'test/xkeyboard-config-test.py.in',
597 output: 'xkeyboard-config-test',
598 configuration: xkct_config)
602 libxkbcommon_bench_internal = static_library(
603 'xkbcommon-bench-internal',
606 link_with: libxkbcommon_test_internal,
608 bench_dep = declare_dependency(
609 include_directories: include_directories('src'),
610 link_with: libxkbcommon_bench_internal,
612 bench_env = environment()
613 bench_env.set('top_srcdir', meson.source_root())
616 executable('bench-key-proc', 'bench/key-proc.c', dependencies: bench_dep),
621 executable('bench-rules', 'bench/rules.c', dependencies: bench_dep),
626 executable('bench-rulescomp', 'bench/rulescomp.c', dependencies: bench_dep),
631 executable('bench-compose', 'bench/compose.c', dependencies: bench_dep),
637 if get_option('enable-docs')
638 doxygen = find_program('doxygen', required: false)
639 if not doxygen.found()
640 error('''Documentation requires doxygen which was not found.
641 You can disable the documentation with -Denable-docs=false.''')
643 doxygen_wrapper = find_program('scripts/doxygen-wrapper')
647 'doc/doxygen-extra.css',
648 'doc/quick-guide.md',
650 'doc/user-configuration.md',
651 'doc/rules-format.md',
652 'xkbcommon/xkbcommon.h',
653 'xkbcommon/xkbcommon-names.h',
654 'xkbcommon/xkbcommon-x11.h',
655 'xkbcommon/xkbcommon-compose.h',
656 'xkbcommon/xkbregistry.h',
658 doxygen_data = configuration_data()
659 doxygen_data.set('PACKAGE_NAME', meson.project_name())
660 doxygen_data.set('PACKAGE_VERSION', meson.project_version())
661 doxygen_data.set('INPUT', ' '.join(doxygen_input))
662 doxygen_data.set('OUTPUT_DIRECTORY', meson.build_root())
663 doxyfile = configure_file(
664 input: 'doc/Doxyfile.in',
666 configuration: doxygen_data,
668 # TODO: Meson should provide this.
669 docdir = join_paths(get_option('datadir'), 'doc', meson.project_name())
672 input: [doxyfile] + doxygen_input,
674 command: [doxygen_wrapper, doxygen.path(), join_paths(meson.build_root(), 'Doxyfile'), meson.source_root()],
677 build_by_default: true,