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'
51 # The X locale directory for compose.
52 XLOCALEDIR = get_option('x-locale-root')
54 XLOCALEDIR = get_option('prefix')/get_option('datadir')/'X11'/'locale'
59 configh_data = configuration_data()
60 configh_data.set('EXIT_INVALID_USAGE', '2')
61 configh_data.set_quoted('LIBXKBCOMMON_VERSION', meson.project_version())
62 configh_data.set_quoted('LIBXKBCOMMON_TOOL_PATH', dir_libexec)
63 # Like AC_USE_SYSTEM_EXTENSIONS, what #define to use to get extensions
64 # beyond the base POSIX function set.
65 if host_machine.system() == 'sunos'
66 system_extensions = '__EXTENSIONS__'
68 system_extensions = '_GNU_SOURCE'
70 configh_data.set(system_extensions, 1)
71 system_ext_define = '#define ' + system_extensions
72 configh_data.set_quoted('DFLT_XKB_CONFIG_ROOT', XKBCONFIGROOT)
73 configh_data.set_quoted('XLOCALEDIR', XLOCALEDIR)
74 configh_data.set_quoted('DEFAULT_XKB_RULES', get_option('default-rules'))
75 configh_data.set_quoted('DEFAULT_XKB_MODEL', get_option('default-model'))
76 configh_data.set_quoted('DEFAULT_XKB_LAYOUT', get_option('default-layout'))
77 if get_option('default-variant') != ''
78 configh_data.set_quoted('DEFAULT_XKB_VARIANT', get_option('default-variant'))
80 configh_data.set('DEFAULT_XKB_VARIANT', 'NULL')
82 if get_option('default-options') != ''
83 configh_data.set_quoted('DEFAULT_XKB_OPTIONS', get_option('default-options'))
85 configh_data.set('DEFAULT_XKB_OPTIONS', 'NULL')
87 if cc.links('int main(){if(__builtin_expect(1<0,0)){}}', name: '__builtin_expect')
88 configh_data.set('HAVE___BUILTIN_EXPECT', 1)
90 if cc.has_header_symbol('unistd.h', 'eaccess', prefix: system_ext_define)
91 configh_data.set('HAVE_EACCESS', 1)
93 if cc.has_header_symbol('unistd.h', 'euidaccess', prefix: system_ext_define)
94 configh_data.set('HAVE_EUIDACCESS', 1)
96 if cc.has_header_symbol('sys/mman.h', 'mmap')
97 configh_data.set('HAVE_MMAP', 1)
99 if cc.has_header_symbol('stdlib.h', 'mkostemp', prefix: system_ext_define)
100 configh_data.set('HAVE_MKOSTEMP', 1)
102 if cc.has_header_symbol('fcntl.h', 'posix_fallocate', prefix: system_ext_define)
103 configh_data.set('HAVE_POSIX_FALLOCATE', 1)
105 if cc.has_header_symbol('string.h', 'strndup', prefix: system_ext_define)
106 configh_data.set('HAVE_STRNDUP', 1)
108 if cc.has_header_symbol('stdio.h', 'asprintf', prefix: system_ext_define)
109 configh_data.set('HAVE_ASPRINTF', 1)
110 elif cc.has_header_symbol('stdio.h', 'vasprintf', prefix: system_ext_define)
111 configh_data.set('HAVE_VASPRINTF', 1)
113 if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix: system_ext_define)
114 configh_data.set('HAVE_SECURE_GETENV', 1)
115 elif cc.has_header_symbol('stdlib.h', '__secure_getenv', prefix: system_ext_define)
116 configh_data.set('HAVE___SECURE_GETENV', 1)
118 message('C library does not support secure_getenv, using getenv instead')
120 have_getopt_long = cc.has_header_symbol('getopt.h', 'getopt_long',
121 prefix: '#define _GNU_SOURCE')
123 # Silence some security & deprecation warnings on MSVC
124 # for some unix/C functions we use.
125 # https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4996?view=vs-2019
126 configh_data.set('_CRT_SECURE_NO_WARNINGS', 1)
127 configh_data.set('_CRT_NONSTDC_NO_WARNINGS', 1)
128 configh_data.set('_CRT_NONSTDC_NO_DEPRECATE', 1)
129 # Reduce unnecessary includes on MSVC.
130 configh_data.set('WIN32_LEAN_AND_MEAN', 1)
132 # Supports -Wl,--version-script?
133 have_version_script = cc.links(
135 args: '-Wl,--version-script=' + meson.source_root()/'xkbcommon.map',
136 name: '-Wl,--version-script',
141 # Note: we use some yacc extensions, which work with either GNU bison
142 # (preferred) or byacc (with backtracking enabled).
143 bison = find_program('bison', 'win_bison', required: false)
145 yacc_gen = generator(
147 output: ['@BASENAME@.c', '@BASENAME@.h'],
148 arguments: ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@', '-p _xkbcommon_'],
151 byacc = find_program('byacc', required: false)
153 yacc_gen = generator(
155 output: ['@BASENAME@.c', '@BASENAME@.h'],
156 arguments: ['@INPUT@', '-H', '@OUTPUT1@', '-o', '@OUTPUT0@', '-p _xkbcommon_'],
159 error('Could not find a compatible YACC program (bison or byacc)')
162 libxkbcommon_sources = [
163 'src/compose/parser.c',
164 'src/compose/parser.h',
165 'src/compose/paths.c',
166 'src/compose/paths.h',
167 'src/compose/state.c',
168 'src/compose/table.c',
169 'src/compose/table.h',
170 'src/xkbcomp/action.c',
171 'src/xkbcomp/action.h',
173 'src/xkbcomp/ast-build.c',
174 'src/xkbcomp/ast-build.h',
175 'src/xkbcomp/compat.c',
176 'src/xkbcomp/expr.c',
177 'src/xkbcomp/expr.h',
178 'src/xkbcomp/include.c',
179 'src/xkbcomp/include.h',
180 'src/xkbcomp/keycodes.c',
181 'src/xkbcomp/keymap.c',
182 'src/xkbcomp/keymap-dump.c',
183 'src/xkbcomp/keywords.c',
184 yacc_gen.process('src/xkbcomp/parser.y'),
185 'src/xkbcomp/parser-priv.h',
186 'src/xkbcomp/rules.c',
187 'src/xkbcomp/rules.h',
188 'src/xkbcomp/scanner.c',
189 'src/xkbcomp/symbols.c',
190 'src/xkbcomp/types.c',
191 'src/xkbcomp/vmod.c',
192 'src/xkbcomp/vmod.h',
193 'src/xkbcomp/xkbcomp.c',
194 'src/xkbcomp/xkbcomp-priv.h',
199 'src/context-priv.c',
208 'src/scanner-utils.h',
217 libxkbcommon_link_args = []
218 if have_version_script
219 libxkbcommon_link_args += '-Wl,--version-script=' + meson.source_root()/'xkbcommon.map'
221 libxkbcommon = library(
223 'xkbcommon/xkbcommon.h',
224 libxkbcommon_sources,
225 link_args: libxkbcommon_link_args,
226 link_depends: 'xkbcommon.map',
227 gnu_symbol_visibility: 'hidden',
230 include_directories: include_directories('src'),
233 'xkbcommon/xkbcommon.h',
234 'xkbcommon/xkbcommon-compat.h',
235 'xkbcommon/xkbcommon-compose.h',
236 'xkbcommon/xkbcommon-keysyms.h',
237 'xkbcommon/xkbcommon-names.h',
240 libxkbcommon_dep = declare_dependency(
241 link_with: libxkbcommon,
246 filebase: 'xkbcommon',
247 version: meson.project_version(),
248 description: 'XKB API common to servers and clients',
253 if get_option('enable-x11')
254 xcb_dep = dependency('xcb', version: '>=1.10', required: false)
255 xcb_xkb_dep = dependency('xcb-xkb', version: '>=1.10', required: false)
256 if not xcb_dep.found() or not xcb_xkb_dep.found()
257 error('''X11 support requires xcb-xkb >= 1.10 which was not found.
258 You can disable X11 support with -Denable-x11=false.''')
261 libxkbcommon_x11_sources = [
265 'src/x11/x11-priv.h',
267 'src/context-priv.c',
273 libxkbcommon_x11_link_args = []
274 if have_version_script
275 libxkbcommon_x11_link_args += '-Wl,--version-script=' + meson.source_root()/'xkbcommon-x11.map'
277 libxkbcommon_x11 = library(
279 'xkbcommon/xkbcommon-x11.h',
280 libxkbcommon_x11_sources,
281 link_args: libxkbcommon_x11_link_args,
282 link_depends: 'xkbcommon-x11.map',
283 gnu_symbol_visibility: 'hidden',
286 include_directories: include_directories('src'),
287 link_with: libxkbcommon,
294 'xkbcommon/xkbcommon-x11.h',
297 libxkbcommon_x11_dep = declare_dependency(
298 link_with: libxkbcommon_x11,
302 name: 'xkbcommon-x11',
303 filebase: 'xkbcommon-x11',
304 version: meson.project_version(),
305 description: 'XKB API common to servers and clients - X11 support',
306 requires: ['xkbcommon'],
307 requires_private: ['xcb>=1.10', 'xcb-xkb>=1.10'],
312 if get_option('enable-xkbregistry')
313 dep_libxml = dependency('libxml-2.0')
314 deps_libxkbregistry = [dep_libxml]
315 libxkbregistry_sources = [
322 libxkbregistry_link_args = []
323 if have_version_script
324 libxkbregistry_link_args += '-Wl,--version-script=' + meson.source_root()/'xkbregistry.map'
326 libxkbregistry = library(
328 'xkbcommon/xkbregistry.h',
329 libxkbregistry_sources,
330 link_args: libxkbregistry_link_args,
331 link_depends: 'xkbregistry.map',
332 gnu_symbol_visibility: 'hidden',
333 dependencies: deps_libxkbregistry,
336 include_directories: include_directories('src'),
339 'xkbcommon/xkbregistry.h',
345 filebase: 'xkbregistry',
346 version: meson.project_version(),
347 description: 'XKB API to query available rules, models, layouts, variants and options',
350 dep_libxkbregistry = declare_dependency(
351 include_directories: include_directories('xkbcommon'),
352 link_with: 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', 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)
531 build_tools = have_getopt_long
533 libxkbcommon_tools_internal = static_library(
535 'tools/tools-common.h',
536 'tools/tools-common.c',
537 dependencies: libxkbcommon_dep,
539 tools_dep = declare_dependency(
540 include_directories: [include_directories('tools')],
541 link_with: libxkbcommon_tools_internal,
544 executable('xkbcli', 'tools/xkbcli.c',
545 dependencies: tools_dep, install: true)
546 install_man('tools/xkbcli.1')
548 executable('xkbcli-compile-keymap',
549 'tools/compile-keymap.c',
550 dependencies: tools_dep,
552 install_dir: dir_libexec)
553 install_man('tools/xkbcli-compile-keymap.1')
554 # The same tool again, but with access to some private APIs.
555 executable('compile-keymap',
556 'tools/compile-keymap.c',
557 libxkbcommon_sources,
558 dependencies: [tools_dep],
559 c_args: ['-DENABLE_PRIVATE_APIS'],
560 include_directories: [include_directories('src')],
562 configh_data.set10('HAVE_XKBCLI_COMPILE_KEYMAP', true)
563 executable('xkbcli-how-to-type',
564 'tools/how-to-type.c',
565 dependencies: tools_dep,
567 install_dir: dir_libexec)
568 install_man('tools/xkbcli-how-to-type.1')
569 configh_data.set10('HAVE_XKBCLI_HOW_TO_TYPE', true)
570 if cc.has_header('linux/input.h')
571 executable('xkbcli-interactive-evdev',
572 'tools/interactive-evdev.c',
573 dependencies: tools_dep,
575 install_dir: dir_libexec)
576 configh_data.set10('HAVE_XKBCLI_INTERACTIVE_EVDEV', true)
577 install_man('tools/xkbcli-interactive-evdev.1')
579 if get_option('enable-x11')
580 x11_tools_dep = declare_dependency(
581 link_with: libxkbcommon_x11,
588 executable('xkbcli-interactive-x11',
589 'tools/interactive-x11.c',
590 dependencies: x11_tools_dep,
592 install_dir: dir_libexec)
593 install_man('tools/xkbcli-interactive-x11.1')
594 configh_data.set10('HAVE_XKBCLI_INTERACTIVE_X11', true)
596 if get_option('enable-wayland')
597 wayland_client_dep = dependency('wayland-client', version: '>=1.2.0', required: false)
598 wayland_protocols_dep = dependency('wayland-protocols', version: '>=1.12', required: false)
599 wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)
600 if not wayland_client_dep.found() or not wayland_protocols_dep.found() or not wayland_scanner_dep.found()
601 error('''The Wayland xkbcli programs require wayland-client >= 1.2.0, wayland-protocols >= 1.7 which were not found.
602 You can disable the Wayland xkbcli programs with -Denable-wayland=false.''')
605 wayland_scanner = find_program(wayland_scanner_dep.get_pkgconfig_variable('wayland_scanner'))
606 wayland_scanner_code_gen = generator(
608 output: '@BASENAME@-protocol.c',
609 arguments: ['code', '@INPUT@', '@OUTPUT@'],
611 wayland_scanner_client_header_gen = generator(
613 output: '@BASENAME@-client-protocol.h',
614 arguments: ['client-header', '@INPUT@', '@OUTPUT@'],
616 wayland_protocols_datadir = wayland_protocols_dep.get_pkgconfig_variable('pkgdatadir')
617 xdg_shell_xml = wayland_protocols_datadir/'stable/xdg-shell/xdg-shell.xml'
618 xdg_shell_sources = [
619 wayland_scanner_code_gen.process(xdg_shell_xml),
620 wayland_scanner_client_header_gen.process(xdg_shell_xml),
622 executable('xkbcli-interactive-wayland',
623 'tools/interactive-wayland.c',
625 dependencies: [tools_dep, wayland_client_dep],
627 install_dir: dir_libexec)
628 install_man('tools/xkbcli-interactive-wayland.1')
629 configh_data.set10('HAVE_XKBCLI_INTERACTIVE_WAYLAND', true)
632 if get_option('enable-xkbregistry')
633 configh_data.set10('HAVE_XKBCLI_LIST', true)
634 executable('xkbcli-list',
635 'tools/registry-list.c',
636 dependencies: dep_libxkbregistry,
638 install_dir: dir_libexec)
639 install_man('tools/xkbcli-list.1')
642 test('tool-option-parsing',
643 find_program('test/tool-option-parsing.py'),
645 suite: ['python-tests'])
649 # xkeyboard-config "verifier"
650 xkct_config = configuration_data()
651 xkct_config.set('MESON_BUILD_ROOT', meson.build_root())
652 xkct_config.set('XKB_CONFIG_ROOT', XKBCONFIGROOT)
653 configure_file(input: 'test/xkeyboard-config-test.py.in',
654 output: 'xkeyboard-config-test',
655 configuration: xkct_config)
659 libxkbcommon_bench_internal = static_library(
660 'xkbcommon-bench-internal',
663 link_with: libxkbcommon_test_internal,
665 bench_dep = declare_dependency(
666 include_directories: include_directories('src'),
667 link_with: libxkbcommon_bench_internal,
669 bench_env = environment()
670 bench_env.set('top_srcdir', meson.source_root())
673 executable('bench-key-proc', 'bench/key-proc.c', dependencies: bench_dep),
678 executable('bench-rules', 'bench/rules.c', dependencies: bench_dep),
683 executable('bench-rulescomp', 'bench/rulescomp.c', dependencies: bench_dep),
688 executable('bench-compose', 'bench/compose.c', dependencies: bench_dep),
694 if get_option('enable-docs')
695 doxygen = find_program('doxygen', required: false)
696 if not doxygen.found()
697 error('''Documentation requires doxygen which was not found.
698 You can disable the documentation with -Denable-docs=false.''')
700 doxygen_wrapper = find_program('scripts/doxygen-wrapper')
704 'doc/doxygen-extra.css',
705 'doc/quick-guide.md',
707 'doc/user-configuration.md',
708 'doc/rules-format.md',
709 'xkbcommon/xkbcommon.h',
710 'xkbcommon/xkbcommon-names.h',
711 'xkbcommon/xkbcommon-x11.h',
712 'xkbcommon/xkbcommon-compose.h',
713 'xkbcommon/xkbregistry.h',
715 doxygen_data = configuration_data()
716 doxygen_data.set('PACKAGE_NAME', meson.project_name())
717 doxygen_data.set('PACKAGE_VERSION', meson.project_version())
718 doxygen_data.set('INPUT', ' '.join(doxygen_input))
719 doxygen_data.set('OUTPUT_DIRECTORY', meson.build_root())
720 doxyfile = configure_file(
721 input: 'doc/Doxyfile.in',
723 configuration: doxygen_data,
725 # TODO: Meson should provide this.
726 docdir = get_option('datadir')/'doc'/meson.project_name()
729 input: [doxyfile] + doxygen_input,
731 command: [doxygen_wrapper, doxygen.path(), meson.build_root()/'Doxyfile', meson.source_root()],
734 build_by_default: true,
738 configure_file(output: 'config.h', configuration: configh_data)