10 meson_version : '>= 0.49.0',
12 pkgconfig = import('pkgconfig')
13 cc = meson.get_compiler('c')
15 dir_libexec = join_paths(get_option('prefix'), get_option('libexecdir'), 'xkbcommon')
16 dir_man = join_paths(get_option('prefix'), get_option('mandir'))
20 '-fvisibility=hidden',
21 '-fno-strict-aliasing',
22 '-fsanitize-undefined-trap-on-error',
24 '-Wno-unused-parameter',
25 '-Wno-missing-field-initializers',
27 '-Wmissing-declarations',
29 '-Wstrict-prototypes',
30 '-Wmissing-prototypes',
32 '-Wbad-function-cast',
37 '-Wno-documentation-deprecated-sync',
39 if cc.has_argument(cflag)
40 add_project_arguments(cflag, language: 'c')
45 # The XKB config root.
46 XKBCONFIGROOT = get_option('xkb-config-root')
47 if XKBCONFIGROOT == ''
48 xkeyboard_config_dep = dependency('xkeyboard-config', required: false)
49 if xkeyboard_config_dep.found()
50 XKBCONFIGROOT = xkeyboard_config_dep.get_pkgconfig_variable('xkb_base')
52 XKBCONFIGROOT = join_paths(get_option('prefix'), get_option('datadir'), 'X11', 'xkb')
57 # The X locale directory for compose.
58 XLOCALEDIR = get_option('x-locale-root')
60 XLOCALEDIR = join_paths(get_option('prefix'), get_option('datadir'), 'X11', 'locale')
65 configh_data = configuration_data()
66 configh_data.set('EXIT_INVALID_USAGE', '2')
67 configh_data.set_quoted('LIBXKBCOMMON_VERSION', meson.project_version())
68 configh_data.set_quoted('LIBXKBCOMMON_TOOL_PATH', dir_libexec)
69 # Like AC_USE_SYSTEM_EXTENSIONS, what #define to use to get extensions
70 # beyond the base POSIX function set.
71 if host_machine.system() == 'sunos'
72 system_extensions = '__EXTENSIONS__'
74 system_extensions = '_GNU_SOURCE'
76 configh_data.set(system_extensions, 1)
77 system_ext_define = '#define ' + system_extensions
78 configh_data.set_quoted('DFLT_XKB_CONFIG_ROOT', XKBCONFIGROOT)
79 configh_data.set_quoted('XLOCALEDIR', XLOCALEDIR)
80 configh_data.set_quoted('DEFAULT_XKB_RULES', get_option('default-rules'))
81 configh_data.set_quoted('DEFAULT_XKB_MODEL', get_option('default-model'))
82 configh_data.set_quoted('DEFAULT_XKB_LAYOUT', get_option('default-layout'))
83 if get_option('default-variant') != ''
84 configh_data.set_quoted('DEFAULT_XKB_VARIANT', get_option('default-variant'))
86 configh_data.set('DEFAULT_XKB_VARIANT', 'NULL')
88 if get_option('default-options') != ''
89 configh_data.set_quoted('DEFAULT_XKB_OPTIONS', get_option('default-options'))
91 configh_data.set('DEFAULT_XKB_OPTIONS', 'NULL')
93 if cc.links('int main(){if(__builtin_expect(1<0,0)){}}', name: '__builtin_expect')
94 configh_data.set('HAVE___BUILTIN_EXPECT', 1)
96 if cc.has_header_symbol('unistd.h', 'eaccess', prefix: system_ext_define)
97 configh_data.set('HAVE_EACCESS', 1)
99 if cc.has_header_symbol('unistd.h', 'euidaccess', prefix: system_ext_define)
100 configh_data.set('HAVE_EUIDACCESS', 1)
102 if cc.has_header_symbol('sys/mman.h', 'mmap')
103 configh_data.set('HAVE_MMAP', 1)
105 if cc.has_header_symbol('stdlib.h', 'mkostemp', prefix: system_ext_define)
106 configh_data.set('HAVE_MKOSTEMP', 1)
108 if cc.has_header_symbol('fcntl.h', 'posix_fallocate', prefix: system_ext_define)
109 configh_data.set('HAVE_POSIX_FALLOCATE', 1)
111 if cc.has_header_symbol('string.h', 'strndup', prefix: system_ext_define)
112 configh_data.set('HAVE_STRNDUP', 1)
114 if cc.has_header_symbol('stdio.h', 'asprintf', prefix: system_ext_define)
115 configh_data.set('HAVE_ASPRINTF', 1)
116 elif cc.has_header_symbol('stdio.h', 'vasprintf', prefix: system_ext_define)
117 configh_data.set('HAVE_VASPRINTF', 1)
119 if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix: system_ext_define)
120 configh_data.set('HAVE_SECURE_GETENV', 1)
121 elif cc.has_header_symbol('stdlib.h', '__secure_getenv', prefix: system_ext_define)
122 configh_data.set('HAVE___SECURE_GETENV', 1)
124 message('C library does not support secure_getenv, using getenv instead')
126 have_getopt = cc.has_header_symbol('getopt.h', 'getopt')
127 have_getopt_long = cc.has_header_symbol('getopt.h', 'getopt_long',
128 prefix: '#define _GNU_SOURCE')
130 configh_data.set10('HAVE_GETOPT_LONG', true)
133 # Silence some security & deprecation warnings on MSVC
134 # for some unix/C functions we use.
135 # https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4996?view=vs-2019
136 configh_data.set('_CRT_SECURE_NO_WARNINGS', 1)
137 configh_data.set('_CRT_NONSTDC_NO_WARNINGS', 1)
138 configh_data.set('_CRT_NONSTDC_NO_DEPRECATE', 1)
139 # Reduce unnecessary includes on MSVC.
140 configh_data.set('WIN32_LEAN_AND_MEAN', 1)
142 # Supports -Wl,--version-script?
143 have_version_script = cc.links(
145 args: '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon.map'),
146 name: '-Wl,--version-script',
151 # Note: we use some yacc extensions, which work with either GNU bison
152 # (preferred) or byacc (with backtracking enabled).
153 bison = find_program('bison', 'win_bison', required: false)
155 yacc_gen = generator(
157 output: ['@BASENAME@.c', '@BASENAME@.h'],
158 arguments: ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@', '-p _xkbcommon_'],
161 byacc = find_program('byacc', required: false)
163 yacc_gen = generator(
165 output: ['@BASENAME@.c', '@BASENAME@.h'],
166 arguments: ['@INPUT@', '-H', '@OUTPUT1@', '-o', '@OUTPUT0@', '-p _xkbcommon_'],
169 error('Could not find a compatible YACC program (bison or byacc)')
172 libxkbcommon_sources = [
173 'src/compose/parser.c',
174 'src/compose/parser.h',
175 'src/compose/paths.c',
176 'src/compose/paths.h',
177 'src/compose/state.c',
178 'src/compose/table.c',
179 'src/compose/table.h',
180 'src/xkbcomp/action.c',
181 'src/xkbcomp/action.h',
183 'src/xkbcomp/ast-build.c',
184 'src/xkbcomp/ast-build.h',
185 'src/xkbcomp/compat.c',
186 'src/xkbcomp/expr.c',
187 'src/xkbcomp/expr.h',
188 'src/xkbcomp/include.c',
189 'src/xkbcomp/include.h',
190 'src/xkbcomp/keycodes.c',
191 'src/xkbcomp/keymap.c',
192 'src/xkbcomp/keymap-dump.c',
193 'src/xkbcomp/keywords.c',
194 yacc_gen.process('src/xkbcomp/parser.y'),
195 'src/xkbcomp/parser-priv.h',
196 'src/xkbcomp/rules.c',
197 'src/xkbcomp/rules.h',
198 'src/xkbcomp/scanner.c',
199 'src/xkbcomp/symbols.c',
200 'src/xkbcomp/types.c',
201 'src/xkbcomp/vmod.c',
202 'src/xkbcomp/vmod.h',
203 'src/xkbcomp/xkbcomp.c',
204 'src/xkbcomp/xkbcomp-priv.h',
209 'src/context-priv.c',
218 'src/scanner-utils.h',
227 libxkbcommon_link_args = []
228 if have_version_script
229 libxkbcommon_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon.map')
231 libxkbcommon = library(
233 'xkbcommon/xkbcommon.h',
234 libxkbcommon_sources,
235 link_args: libxkbcommon_link_args,
236 link_depends: 'xkbcommon.map',
239 include_directories: include_directories('src'),
242 'xkbcommon/xkbcommon.h',
243 'xkbcommon/xkbcommon-compat.h',
244 'xkbcommon/xkbcommon-compose.h',
245 'xkbcommon/xkbcommon-keysyms.h',
246 'xkbcommon/xkbcommon-names.h',
252 filebase: 'xkbcommon',
253 version: meson.project_version(),
254 description: 'XKB API common to servers and clients',
259 if get_option('enable-x11')
260 xcb_dep = dependency('xcb', version: '>=1.10', required: false)
261 xcb_xkb_dep = dependency('xcb-xkb', version: '>=1.10', required: false)
262 if not xcb_dep.found() or not xcb_xkb_dep.found()
263 error('''X11 support requires xcb-xkb >= 1.10 which was not found.
264 You can disable X11 support with -Denable-x11=false.''')
267 libxkbcommon_x11_sources = [
271 'src/x11/x11-priv.h',
273 'src/context-priv.c',
279 libxkbcommon_x11_link_args = []
280 if have_version_script
281 libxkbcommon_x11_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon-x11.map')
283 libxkbcommon_x11 = library(
285 'xkbcommon/xkbcommon-x11.h',
286 libxkbcommon_x11_sources,
287 link_args: libxkbcommon_x11_link_args,
288 link_depends: 'xkbcommon-x11.map',
291 include_directories: include_directories('src'),
292 link_with: libxkbcommon,
299 'xkbcommon/xkbcommon-x11.h',
304 name: 'xkbcommon-x11',
305 filebase: 'xkbcommon-x11',
306 version: meson.project_version(),
307 description: 'XKB API common to servers and clients - X11 support',
308 requires: ['xkbcommon'],
309 requires_private: ['xcb>=1.10', 'xcb-xkb>=1.10'],
316 if get_option('enable-xkbregistry')
317 dep_libxml = dependency('libxml-2.0')
318 deps_libxkbregistry = [dep_libxml]
319 libxkbregistry_sources = [
326 libxkbregistry_link_args = []
327 if have_version_script
328 libxkbregistry_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbregistry.map')
330 libxkbregistry = library(
332 'xkbcommon/xkbregistry.h',
333 libxkbregistry_sources,
334 link_args: libxkbregistry_link_args,
335 link_depends: 'xkbregistry.map',
336 dependencies: deps_libxkbregistry,
339 include_directories: include_directories('src'),
342 'xkbcommon/xkbregistry.h',
348 filebase: 'xkbregistry',
349 version: meson.project_version(),
350 description: 'XKB API to query available rules, models, layouts, variants and options',
353 dep_libxkbregistry = declare_dependency(
354 include_directories: include_directories('xkbcommon'),
355 link_with: libxkbregistry
360 test_env = environment()
361 test_env.set('XKB_LOG_LEVEL', 'debug')
362 test_env.set('XKB_LOG_VERBOSITY', '10')
363 test_env.set('top_srcdir', meson.source_root())
364 test_env.set('top_builddir', meson.build_root())
366 test_configh_data = configuration_data()
367 test_configh_data.set_quoted('TEST_XKB_CONFIG_ROOT', join_paths(meson.source_root(), 'test', 'data'))
368 configure_file(output: 'test-config.h', configuration: test_configh_data)
370 # Some tests need to use unexported symbols, so we link them against
371 # an internal copy of libxkbcommon with all symbols exposed.
372 libxkbcommon_test_internal = static_library(
373 'xkbcommon-test-internal',
376 'test/evdev-scancodes.h',
377 libxkbcommon_sources,
378 include_directories: include_directories('src'),
380 test_dep = declare_dependency(
381 include_directories: include_directories('src'),
382 link_with: libxkbcommon_test_internal,
384 if get_option('enable-x11')
385 libxkbcommon_x11_internal = static_library(
386 'xkbcommon-x11-internal',
387 libxkbcommon_x11_sources,
388 include_directories: include_directories('src'),
389 link_with: libxkbcommon_test_internal,
395 x11_test_dep = declare_dependency(
396 link_with: libxkbcommon_x11_internal,
406 executable('test-keysym', 'test/keysym.c', dependencies: test_dep),
411 executable('test-keymap', 'test/keymap.c', dependencies: test_dep),
416 executable('test-filecomp', 'test/filecomp.c', dependencies: test_dep),
419 # TODO: This test currently uses some functions that don't exist on Windows.
420 if cc.get_id() != 'msvc'
423 executable('test-context', 'test/context.c', dependencies: test_dep),
429 executable('test-rules-file', 'test/rules-file.c', dependencies: test_dep),
433 'rules-file-includes',
434 executable('test-rules-file-includes', 'test/rules-file-includes.c', dependencies: test_dep),
439 executable('test-stringcomp', 'test/stringcomp.c', dependencies: test_dep),
444 executable('test-buffercomp', 'test/buffercomp.c', dependencies: test_dep),
449 executable('test-log', 'test/log.c', dependencies: test_dep),
454 executable('test-atom', 'test/atom.c', dependencies: test_dep),
459 executable('test-utf8', 'test/utf8.c', dependencies: test_dep),
464 executable('test-state', 'test/state.c', dependencies: test_dep),
469 executable('test-keyseq', 'test/keyseq.c', dependencies: test_dep),
474 executable('test-rulescomp', 'test/rulescomp.c', dependencies: test_dep),
479 executable('test-compose', 'test/compose.c', dependencies: test_dep),
484 executable('test-utils', 'test/utils.c', dependencies: test_dep),
489 find_program('test/symbols-leak-test.py'),
491 suite: ['python-tests'],
493 if get_option('enable-x11')
496 executable('test-x11', 'test/x11.c', dependencies: x11_test_dep),
499 # test/x11comp is meant to be run, but it is (temporarily?) disabled.
500 # See: https://github.com/xkbcommon/libxkbcommon/issues/30
501 executable('test-x11comp', 'test/x11comp.c', dependencies: x11_test_dep)
503 if get_option('enable-xkbregistry')
506 executable('test-registry', 'test/registry.c',
507 include_directories: include_directories('src'),
508 dependencies: dep_libxkbregistry),
513 valgrind = find_program('valgrind', required: false)
515 add_test_setup('valgrind',
516 exe_wrapper: [valgrind,
518 '--track-origins=yes',
519 '--gen-suppressions=all',
520 '--error-exitcode=99'],
521 timeout_multiplier : 10)
523 message('valgrind not found, disabling valgrind test setup')
527 # Fuzzing target programs.
528 executable('fuzz-keymap', 'fuzz/keymap/target.c', dependencies: test_dep)
529 executable('fuzz-compose', 'fuzz/compose/target.c', dependencies: test_dep)
534 build_tools = have_getopt
536 libxkbcommon_tools_internal = static_library(
538 'tools/tools-common.h',
539 'tools/tools-common.c',
540 libxkbcommon_sources,
541 include_directories: include_directories('src'),
543 tools_dep = declare_dependency(
544 include_directories: [include_directories('src'), include_directories('tools')],
545 link_with: libxkbcommon_tools_internal,
548 executable('xkbcli', 'tools/xkbcli.c',
549 dependencies: tools_dep, install: true)
550 man_pages += 'tools/xkbcli.1.ronn'
553 executable('xkbcli-compile-keymap',
554 'tools/compile-keymap.c',
555 dependencies: tools_dep,
557 install_dir: dir_libexec)
558 man_pages += 'tools/xkbcli-compile-keymap.1.ronn'
559 configh_data.set10('HAVE_XKBCLI_COMPILE_KEYMAP', true)
560 executable('xkbcli-how-to-type',
561 'tools/how-to-type.c',
562 dependencies: tools_dep,
564 install_dir: dir_libexec)
565 man_pages += 'tools/xkbcli-how-to-type.1.ronn'
566 configh_data.set10('HAVE_XKBCLI_HOW_TO_TYPE', true)
568 if cc.has_header('linux/input.h')
569 executable('xkbcli-interactive-evdev',
570 'tools/interactive-evdev.c',
571 dependencies: tools_dep,
573 install_dir: dir_libexec)
574 configh_data.set10('HAVE_XKBCLI_INTERACTIVE_EVDEV', true)
575 man_pages += 'tools/xkbcli-interactive-evdev.1.ronn'
577 if get_option('enable-x11')
578 x11_tools_dep = declare_dependency(
579 link_with: libxkbcommon_x11_internal,
586 executable('xkbcli-interactive-x11',
587 'tools/interactive-x11.c',
588 dependencies: x11_tools_dep,
590 install_dir: dir_libexec)
591 man_pages += 'tools/xkbcli-interactive-x11.1.ronn'
592 configh_data.set10('HAVE_XKBCLI_INTERACTIVE_X11', true)
594 if get_option('enable-wayland')
595 wayland_client_dep = dependency('wayland-client', version: '>=1.2.0', required: false)
596 wayland_protocols_dep = dependency('wayland-protocols', version: '>=1.12', required: false)
597 wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)
598 if not wayland_client_dep.found() or not wayland_protocols_dep.found() or not wayland_scanner_dep.found()
599 error('''The Wayland demo programs require wayland-client >= 1.2.0, wayland-protocols >= 1.7 which were not found.
600 You can disable the Wayland demo programs with -Denable-wayland=false.''')
603 wayland_scanner = find_program(wayland_scanner_dep.get_pkgconfig_variable('wayland_scanner'))
604 wayland_scanner_code_gen = generator(
606 output: '@BASENAME@-protocol.c',
607 arguments: ['code', '@INPUT@', '@OUTPUT@'],
609 wayland_scanner_client_header_gen = generator(
611 output: '@BASENAME@-client-protocol.h',
612 arguments: ['client-header', '@INPUT@', '@OUTPUT@'],
614 wayland_protocols_datadir = wayland_protocols_dep.get_pkgconfig_variable('pkgdatadir')
615 xdg_shell_xml = join_paths(wayland_protocols_datadir, 'stable/xdg-shell/xdg-shell.xml')
616 xdg_shell_sources = [
617 wayland_scanner_code_gen.process(xdg_shell_xml),
618 wayland_scanner_client_header_gen.process(xdg_shell_xml),
620 executable('xkbcli-interactive-wayland',
621 'tools/interactive-wayland.c',
623 dependencies: [tools_dep, wayland_client_dep],
625 install_dir: dir_libexec)
626 man_pages += 'tools/xkbcli-interactive-wayland.1.ronn'
627 configh_data.set10('HAVE_XKBCLI_INTERACTIVE_WAYLAND', true)
630 if have_getopt_long and get_option('enable-xkbregistry')
631 configh_data.set10('HAVE_XKBCLI_LIST', true)
632 executable('xkbcli-list',
633 'tools/registry-list.c',
634 dependencies: dep_libxkbregistry,
636 install_dir: dir_libexec)
637 man_pages += 'tools/xkbcli-list.1.ronn'
641 if get_option('enable-manpages')
642 prog_ronn = find_program('ronn', required: true)
643 foreach manpage : man_pages
644 # man page filenames adhere to directory/topic.section.ronn
645 topic = manpage.split('/')[-1].split('.')[-3]
646 section = manpage.split('.')[-2]
647 output = '@0@.@1@'.format(topic, section)
648 custom_target(output,
651 command: [prog_ronn, '--manual=libxkbcommon manual', '--pipe', '--roff', files(manpage)],
654 install_dir: join_paths(dir_man, section))
658 # xkeyboard-config "verifier"
659 xkct_config = configuration_data()
660 xkct_config.set('MESON_BUILD_ROOT', meson.build_root())
661 xkct_config.set('XKB_CONFIG_ROOT', XKBCONFIGROOT)
662 configure_file(input: 'test/xkeyboard-config-test.py.in',
663 output: 'xkeyboard-config-test',
664 configuration: xkct_config)
668 libxkbcommon_bench_internal = static_library(
669 'xkbcommon-bench-internal',
672 link_with: libxkbcommon_test_internal,
674 bench_dep = declare_dependency(
675 include_directories: include_directories('src'),
676 link_with: libxkbcommon_bench_internal,
678 bench_env = environment()
679 bench_env.set('top_srcdir', meson.source_root())
682 executable('bench-key-proc', 'bench/key-proc.c', dependencies: bench_dep),
687 executable('bench-rules', 'bench/rules.c', dependencies: bench_dep),
692 executable('bench-rulescomp', 'bench/rulescomp.c', dependencies: bench_dep),
697 executable('bench-compose', 'bench/compose.c', dependencies: bench_dep),
703 if get_option('enable-docs')
704 doxygen = find_program('doxygen', required: false)
705 if not doxygen.found()
706 error('''Documentation requires doxygen which was not found.
707 You can disable the documentation with -Denable-docs=false.''')
709 doxygen_wrapper = find_program('scripts/doxygen-wrapper')
713 'doc/doxygen-extra.css',
714 'doc/quick-guide.md',
716 'doc/user-configuration.md',
717 'doc/rules-format.md',
718 'xkbcommon/xkbcommon.h',
719 'xkbcommon/xkbcommon-names.h',
720 'xkbcommon/xkbcommon-x11.h',
721 'xkbcommon/xkbcommon-compose.h',
722 'xkbcommon/xkbregistry.h',
724 doxygen_data = configuration_data()
725 doxygen_data.set('PACKAGE_NAME', meson.project_name())
726 doxygen_data.set('PACKAGE_VERSION', meson.project_version())
727 doxygen_data.set('INPUT', ' '.join(doxygen_input))
728 doxygen_data.set('OUTPUT_DIRECTORY', meson.build_root())
729 doxyfile = configure_file(
730 input: 'doc/Doxyfile.in',
732 configuration: doxygen_data,
734 # TODO: Meson should provide this.
735 docdir = join_paths(get_option('datadir'), 'doc', meson.project_name())
738 input: [doxyfile] + doxygen_input,
740 command: [doxygen_wrapper, doxygen.path(), join_paths(meson.build_root(), 'Doxyfile'), meson.source_root()],
743 build_by_default: true,
747 configure_file(output: 'config.h', configuration: configh_data)