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 = join_paths(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.links('int main(){if(__builtin_expect(1<0,0)){}}', name: '__builtin_expect')
93 configh_data.set('HAVE___BUILTIN_EXPECT', 1)
95 if cc.has_header_symbol('unistd.h', 'eaccess', prefix: system_ext_define)
96 configh_data.set('HAVE_EACCESS', 1)
98 if cc.has_header_symbol('unistd.h', 'euidaccess', prefix: system_ext_define)
99 configh_data.set('HAVE_EUIDACCESS', 1)
101 if cc.has_header_symbol('sys/mman.h', 'mmap')
102 configh_data.set('HAVE_MMAP', 1)
104 if cc.has_header_symbol('stdlib.h', 'mkostemp', prefix: system_ext_define)
105 configh_data.set('HAVE_MKOSTEMP', 1)
107 if cc.has_header_symbol('fcntl.h', 'posix_fallocate', prefix: system_ext_define)
108 configh_data.set('HAVE_POSIX_FALLOCATE', 1)
110 if cc.has_header_symbol('string.h', 'strndup', prefix: system_ext_define)
111 configh_data.set('HAVE_STRNDUP', 1)
113 if cc.has_header_symbol('stdio.h', 'asprintf', prefix: system_ext_define)
114 configh_data.set('HAVE_ASPRINTF', 1)
115 elif cc.has_header_symbol('stdio.h', 'vasprintf', prefix: system_ext_define)
116 configh_data.set('HAVE_VASPRINTF', 1)
118 if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix: system_ext_define)
119 configh_data.set('HAVE_SECURE_GETENV', 1)
120 elif cc.has_header_symbol('stdlib.h', '__secure_getenv', prefix: system_ext_define)
121 configh_data.set('HAVE___SECURE_GETENV', 1)
123 message('C library does not support secure_getenv, using getenv instead')
125 have_getopt_long = cc.has_header_symbol('getopt.h', 'getopt_long',
126 prefix: '#define _GNU_SOURCE')
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)
132 configh_data.set('PATH_MAX', 4096)
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)
145 # Supports -Wl,--version-script?
146 have_version_script = cc.links(
148 args: '-Wl,--version-script=' + meson.source_root()/'xkbcommon.map',
149 name: '-Wl,--version-script',
154 # Note: we use some yacc extensions, which work with either GNU bison
155 # (preferred) or byacc (with backtracking enabled).
156 bison = find_program('bison', 'win_bison', required: false)
158 yacc_gen = generator(
160 output: ['@BASENAME@.c', '@BASENAME@.h'],
161 arguments: ['--defines=@OUTPUT1@', '-o', '@OUTPUT0@', '-p', '_xkbcommon_', '@INPUT@'],
164 byacc = find_program('byacc', required: false)
166 yacc_gen = generator(
168 output: ['@BASENAME@.c', '@BASENAME@.h'],
169 arguments: ['-H', '@OUTPUT1@', '-o', '@OUTPUT0@', '-p', '_xkbcommon_', '@INPUT@'],
172 error('Could not find a compatible YACC program (bison or byacc)')
175 libxkbcommon_sources = [
176 'src/compose/parser.c',
177 'src/compose/parser.h',
178 'src/compose/paths.c',
179 'src/compose/paths.h',
180 'src/compose/state.c',
181 'src/compose/table.c',
182 'src/compose/table.h',
183 'src/xkbcomp/action.c',
184 'src/xkbcomp/action.h',
186 'src/xkbcomp/ast-build.c',
187 'src/xkbcomp/ast-build.h',
188 'src/xkbcomp/compat.c',
189 'src/xkbcomp/expr.c',
190 'src/xkbcomp/expr.h',
191 'src/xkbcomp/include.c',
192 'src/xkbcomp/include.h',
193 'src/xkbcomp/keycodes.c',
194 'src/xkbcomp/keymap.c',
195 'src/xkbcomp/keymap-dump.c',
196 'src/xkbcomp/keywords.c',
197 yacc_gen.process('src/xkbcomp/parser.y'),
198 'src/xkbcomp/parser-priv.h',
199 'src/xkbcomp/rules.c',
200 'src/xkbcomp/rules.h',
201 'src/xkbcomp/scanner.c',
202 'src/xkbcomp/symbols.c',
203 'src/xkbcomp/types.c',
204 'src/xkbcomp/vmod.c',
205 'src/xkbcomp/vmod.h',
206 'src/xkbcomp/xkbcomp.c',
207 'src/xkbcomp/xkbcomp-priv.h',
212 'src/context-priv.c',
221 'src/scanner-utils.h',
230 libxkbcommon_link_args = []
231 if have_version_script
232 libxkbcommon_link_args += '-Wl,--version-script=' + meson.source_root()/'xkbcommon.map'
234 libxkbcommon = library(
236 'xkbcommon/xkbcommon.h',
237 libxkbcommon_sources,
238 link_args: libxkbcommon_link_args,
239 link_depends: 'xkbcommon.map',
240 gnu_symbol_visibility: 'hidden',
243 include_directories: include_directories('src'),
246 'xkbcommon/xkbcommon.h',
247 'xkbcommon/xkbcommon-compat.h',
248 'xkbcommon/xkbcommon-compose.h',
249 'xkbcommon/xkbcommon-keysyms.h',
250 'xkbcommon/xkbcommon-names.h',
253 libxkbcommon_dep = declare_dependency(
254 link_with: libxkbcommon,
259 filebase: 'xkbcommon',
260 version: meson.project_version(),
261 description: 'XKB API common to servers and clients',
266 if get_option('enable-x11')
267 xcb_dep = dependency('xcb', version: '>=1.10', required: false)
268 xcb_xkb_dep = dependency('xcb-xkb', version: '>=1.10', required: false)
269 if not xcb_dep.found() or not xcb_xkb_dep.found()
270 error('''X11 support requires xcb-xkb >= 1.10 which was not found.
271 You can disable X11 support with -Denable-x11=false.''')
274 libxkbcommon_x11_sources = [
278 'src/x11/x11-priv.h',
280 'src/context-priv.c',
286 libxkbcommon_x11_link_args = []
287 if have_version_script
288 libxkbcommon_x11_link_args += '-Wl,--version-script=' + meson.source_root()/'xkbcommon-x11.map'
290 libxkbcommon_x11 = library(
292 'xkbcommon/xkbcommon-x11.h',
293 libxkbcommon_x11_sources,
294 link_args: libxkbcommon_x11_link_args,
295 link_depends: 'xkbcommon-x11.map',
296 gnu_symbol_visibility: 'hidden',
299 include_directories: include_directories('src'),
300 link_with: libxkbcommon,
307 'xkbcommon/xkbcommon-x11.h',
310 libxkbcommon_x11_dep = declare_dependency(
311 link_with: libxkbcommon_x11,
315 name: 'xkbcommon-x11',
316 filebase: 'xkbcommon-x11',
317 version: meson.project_version(),
318 description: 'XKB API common to servers and clients - X11 support',
319 requires: ['xkbcommon'],
320 requires_private: ['xcb>=1.10', 'xcb-xkb>=1.10'],
325 if get_option('enable-xkbregistry')
326 dep_libxml = dependency('libxml-2.0')
327 deps_libxkbregistry = [dep_libxml]
328 libxkbregistry_sources = [
335 libxkbregistry_link_args = []
336 if have_version_script
337 libxkbregistry_link_args += '-Wl,--version-script=' + meson.source_root()/'xkbregistry.map'
339 libxkbregistry = library(
341 'xkbcommon/xkbregistry.h',
342 libxkbregistry_sources,
343 link_args: libxkbregistry_link_args,
344 link_depends: 'xkbregistry.map',
345 gnu_symbol_visibility: 'hidden',
346 dependencies: deps_libxkbregistry,
349 include_directories: include_directories('src'),
352 'xkbcommon/xkbregistry.h',
358 filebase: 'xkbregistry',
359 version: meson.project_version(),
360 description: 'XKB API to query available rules, models, layouts, variants and options',
363 dep_libxkbregistry = declare_dependency(
364 include_directories: include_directories('xkbcommon'),
365 link_with: libxkbregistry
370 test_env = environment()
371 test_env.set('XKB_LOG_LEVEL', 'debug')
372 test_env.set('XKB_LOG_VERBOSITY', '10')
373 test_env.set('top_srcdir', meson.source_root())
374 test_env.set('top_builddir', meson.build_root())
376 test_configh_data = configuration_data()
377 test_configh_data.set_quoted('TEST_XKB_CONFIG_ROOT', meson.source_root()/'test'/'data')
378 configure_file(output: 'test-config.h', configuration: test_configh_data)
380 # Some tests need to use unexported symbols, so we link them against
381 # an internal copy of libxkbcommon with all symbols exposed.
382 libxkbcommon_test_internal = static_library(
383 'xkbcommon-test-internal',
386 'test/evdev-scancodes.h',
387 libxkbcommon_sources,
388 include_directories: include_directories('src'),
390 test_dep = declare_dependency(
391 include_directories: include_directories('src'),
392 link_with: libxkbcommon_test_internal,
394 if get_option('enable-x11')
395 libxkbcommon_x11_internal = static_library(
396 'xkbcommon-x11-internal',
397 libxkbcommon_x11_sources,
398 include_directories: include_directories('src'),
399 link_with: libxkbcommon_test_internal,
405 x11_test_dep = declare_dependency(
406 link_with: libxkbcommon_x11_internal,
416 executable('test-keysym', 'test/keysym.c', dependencies: test_dep),
421 executable('test-keymap', 'test/keymap.c', dependencies: test_dep),
426 executable('test-filecomp', 'test/filecomp.c', dependencies: test_dep),
429 # TODO: This test currently uses some functions that don't exist on Windows.
430 if cc.get_id() != 'msvc'
433 executable('test-context', 'test/context.c', dependencies: test_dep),
439 executable('test-rules-file', 'test/rules-file.c', dependencies: test_dep),
443 'rules-file-includes',
444 executable('test-rules-file-includes', 'test/rules-file-includes.c', dependencies: test_dep),
449 executable('test-stringcomp', 'test/stringcomp.c', dependencies: test_dep),
454 executable('test-buffercomp', 'test/buffercomp.c', dependencies: test_dep),
459 executable('test-log', 'test/log.c', dependencies: test_dep),
464 executable('test-atom', 'test/atom.c', dependencies: test_dep),
469 executable('test-utf8', 'test/utf8.c', dependencies: test_dep),
474 executable('test-state', 'test/state.c', dependencies: test_dep),
479 executable('test-keyseq', 'test/keyseq.c', dependencies: test_dep),
484 executable('test-rulescomp', 'test/rulescomp.c', dependencies: test_dep),
489 executable('test-compose', 'test/compose.c', dependencies: test_dep),
494 executable('test-utils', 'test/utils.c', dependencies: test_dep),
499 find_program('test/symbols-leak-test.py'),
501 suite: ['python-tests'],
503 if get_option('enable-x11')
506 executable('test-x11', 'test/x11.c', dependencies: x11_test_dep),
509 # test/x11comp is meant to be run, but it is (temporarily?) disabled.
510 # See: https://github.com/xkbcommon/libxkbcommon/issues/30
511 executable('test-x11comp', 'test/x11comp.c', dependencies: x11_test_dep)
513 if get_option('enable-xkbregistry')
516 executable('test-registry', 'test/registry.c',
517 include_directories: include_directories('src'),
518 dependencies: dep_libxkbregistry),
523 valgrind = find_program('valgrind', required: false)
525 add_test_setup('valgrind',
526 exe_wrapper: [valgrind,
528 '--track-origins=yes',
529 '--gen-suppressions=all',
530 '--error-exitcode=99'],
531 timeout_multiplier : 10)
533 message('valgrind not found, disabling valgrind test setup')
537 # Fuzzing target programs.
538 executable('fuzz-keymap', 'fuzz/keymap/target.c', dependencies: test_dep)
539 executable('fuzz-compose', 'fuzz/compose/target.c', dependencies: test_dep)
544 build_tools = have_getopt_long
546 libxkbcommon_tools_internal = static_library(
548 'tools/tools-common.h',
549 'tools/tools-common.c',
550 dependencies: libxkbcommon_dep,
552 tools_dep = declare_dependency(
553 include_directories: [include_directories('tools')],
554 link_with: libxkbcommon_tools_internal,
557 executable('xkbcli', 'tools/xkbcli.c',
558 dependencies: tools_dep, install: true)
559 install_man('tools/xkbcli.1')
561 executable('xkbcli-compile-keymap',
562 'tools/compile-keymap.c',
563 dependencies: tools_dep,
565 install_dir: dir_libexec)
566 install_man('tools/xkbcli-compile-keymap.1')
567 # The same tool again, but with access to some private APIs.
568 executable('compile-keymap',
569 'tools/compile-keymap.c',
570 libxkbcommon_sources,
571 dependencies: [tools_dep],
572 c_args: ['-DENABLE_PRIVATE_APIS'],
573 include_directories: [include_directories('src')],
575 configh_data.set10('HAVE_XKBCLI_COMPILE_KEYMAP', true)
576 executable('xkbcli-how-to-type',
577 'tools/how-to-type.c',
578 dependencies: tools_dep,
580 install_dir: dir_libexec)
581 install_man('tools/xkbcli-how-to-type.1')
582 configh_data.set10('HAVE_XKBCLI_HOW_TO_TYPE', true)
583 if cc.has_header('linux/input.h')
584 executable('xkbcli-interactive-evdev',
585 'tools/interactive-evdev.c',
586 dependencies: tools_dep,
588 install_dir: dir_libexec)
589 configh_data.set10('HAVE_XKBCLI_INTERACTIVE_EVDEV', true)
590 install_man('tools/xkbcli-interactive-evdev.1')
592 if get_option('enable-x11')
593 x11_tools_dep = declare_dependency(
594 link_with: libxkbcommon_x11,
601 executable('xkbcli-interactive-x11',
602 'tools/interactive-x11.c',
603 dependencies: x11_tools_dep,
605 install_dir: dir_libexec)
606 install_man('tools/xkbcli-interactive-x11.1')
607 configh_data.set10('HAVE_XKBCLI_INTERACTIVE_X11', true)
609 if get_option('enable-wayland')
610 wayland_client_dep = dependency('wayland-client', version: '>=1.2.0', required: false)
611 wayland_protocols_dep = dependency('wayland-protocols', version: '>=1.12', required: false)
612 wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)
613 if not wayland_client_dep.found() or not wayland_protocols_dep.found() or not wayland_scanner_dep.found()
614 error('''The Wayland xkbcli programs require wayland-client >= 1.2.0, wayland-protocols >= 1.7 which were not found.
615 You can disable the Wayland xkbcli programs with -Denable-wayland=false.''')
618 wayland_scanner = find_program(wayland_scanner_dep.get_pkgconfig_variable('wayland_scanner'))
619 wayland_scanner_code_gen = generator(
621 output: '@BASENAME@-protocol.c',
622 arguments: ['code', '@INPUT@', '@OUTPUT@'],
624 wayland_scanner_client_header_gen = generator(
626 output: '@BASENAME@-client-protocol.h',
627 arguments: ['client-header', '@INPUT@', '@OUTPUT@'],
629 wayland_protocols_datadir = wayland_protocols_dep.get_pkgconfig_variable('pkgdatadir')
630 xdg_shell_xml = wayland_protocols_datadir/'stable/xdg-shell/xdg-shell.xml'
631 xdg_shell_sources = [
632 wayland_scanner_code_gen.process(xdg_shell_xml),
633 wayland_scanner_client_header_gen.process(xdg_shell_xml),
635 executable('xkbcli-interactive-wayland',
636 'tools/interactive-wayland.c',
638 dependencies: [tools_dep, wayland_client_dep],
640 install_dir: dir_libexec)
641 install_man('tools/xkbcli-interactive-wayland.1')
642 configh_data.set10('HAVE_XKBCLI_INTERACTIVE_WAYLAND', true)
645 if get_option('enable-xkbregistry')
646 configh_data.set10('HAVE_XKBCLI_LIST', true)
647 executable('xkbcli-list',
648 'tools/registry-list.c',
649 dependencies: dep_libxkbregistry,
651 install_dir: dir_libexec)
652 install_man('tools/xkbcli-list.1')
655 config_scaffold = configuration_data()
656 config_scaffold.set('XKBEXTRAPATH', XKBCONFIGEXTRAPATH)
657 config_scaffold.set('DEFAULT_XKB_RULES', get_option('default-rules'))
658 configure_file(input: 'tools/xkbcli-scaffold-new-layout.py',
659 output: 'xkbcli-scaffold-new-layout',
660 configuration: config_scaffold)
662 test('tool-option-parsing',
663 find_program('test/tool-option-parsing.py'),
665 suite: ['python-tests'])
669 # xkeyboard-config "verifier"
670 xkct_config = configuration_data()
671 xkct_config.set('MESON_BUILD_ROOT', meson.build_root())
672 xkct_config.set('XKB_CONFIG_ROOT', XKBCONFIGROOT)
673 configure_file(input: 'test/xkeyboard-config-test.py.in',
674 output: 'xkeyboard-config-test',
675 configuration: xkct_config)
679 libxkbcommon_bench_internal = static_library(
680 'xkbcommon-bench-internal',
683 link_with: libxkbcommon_test_internal,
685 bench_dep = declare_dependency(
686 include_directories: include_directories('src'),
687 link_with: libxkbcommon_bench_internal,
689 bench_env = environment()
690 bench_env.set('top_srcdir', meson.source_root())
693 executable('bench-key-proc', 'bench/key-proc.c', dependencies: bench_dep),
698 executable('bench-rules', 'bench/rules.c', dependencies: bench_dep),
703 executable('bench-rulescomp', 'bench/rulescomp.c', dependencies: bench_dep),
708 executable('bench-compose', 'bench/compose.c', dependencies: bench_dep),
714 if get_option('enable-docs')
715 doxygen = find_program('doxygen', required: false)
716 if not doxygen.found()
717 error('''Documentation requires doxygen which was not found.
718 You can disable the documentation with -Denable-docs=false.''')
720 doxygen_wrapper = find_program('scripts/doxygen-wrapper')
724 'doc/doxygen-extra.css',
725 'doc/quick-guide.md',
727 'doc/user-configuration.md',
728 'doc/rules-format.md',
729 'xkbcommon/xkbcommon.h',
730 'xkbcommon/xkbcommon-names.h',
731 'xkbcommon/xkbcommon-x11.h',
732 'xkbcommon/xkbcommon-compose.h',
733 'xkbcommon/xkbregistry.h',
735 doxygen_data = configuration_data()
736 doxygen_data.set('PACKAGE_NAME', meson.project_name())
737 doxygen_data.set('PACKAGE_VERSION', meson.project_version())
738 doxygen_data.set('INPUT', ' '.join(doxygen_input))
739 doxygen_data.set('OUTPUT_DIRECTORY', meson.build_root())
740 doxyfile = configure_file(
741 input: 'doc/Doxyfile.in',
743 configuration: doxygen_data,
745 # TODO: Meson should provide this.
746 docdir = get_option('datadir')/'doc'/meson.project_name()
749 input: [doxyfile] + doxygen_input,
751 command: [doxygen_wrapper, doxygen.path(), meson.build_root()/'Doxyfile', meson.source_root()],
754 build_by_default: true,
758 configure_file(output: 'config.h', configuration: configh_data)