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'],
314 if get_option('enable-xkbregistry')
315 dep_libxml = dependency('libxml-2.0')
316 deps_libxkbregistry = [dep_libxml]
317 libxkbregistry_sources = [
324 libxkbregistry_link_args = []
325 if have_version_script
326 libxkbregistry_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbregistry.map')
328 libxkbregistry = library(
330 'xkbcommon/xkbregistry.h',
331 libxkbregistry_sources,
332 link_args: libxkbregistry_link_args,
333 link_depends: 'xkbregistry.map',
334 dependencies: deps_libxkbregistry,
337 include_directories: include_directories('src'),
340 'xkbcommon/xkbregistry.h',
346 filebase: 'xkbregistry',
347 version: meson.project_version(),
348 description: 'XKB API to query available rules, models, layouts, variants and options',
351 dep_libxkbregistry = declare_dependency(
352 include_directories: include_directories('xkbcommon'),
353 link_with: libxkbregistry
358 test_env = environment()
359 test_env.set('XKB_LOG_LEVEL', 'debug')
360 test_env.set('XKB_LOG_VERBOSITY', '10')
361 test_env.set('top_srcdir', meson.source_root())
362 test_env.set('top_builddir', meson.build_root())
364 test_configh_data = configuration_data()
365 test_configh_data.set_quoted('TEST_XKB_CONFIG_ROOT', join_paths(meson.source_root(), 'test', 'data'))
366 configure_file(output: 'test-config.h', configuration: test_configh_data)
368 # Some tests need to use unexported symbols, so we link them against
369 # an internal copy of libxkbcommon with all symbols exposed.
370 libxkbcommon_test_internal = static_library(
371 'xkbcommon-test-internal',
374 'test/evdev-scancodes.h',
375 libxkbcommon_sources,
376 include_directories: include_directories('src'),
378 test_dep = declare_dependency(
379 include_directories: include_directories('src'),
380 link_with: libxkbcommon_test_internal,
382 if get_option('enable-x11')
383 libxkbcommon_x11_internal = static_library(
384 'xkbcommon-x11-internal',
385 libxkbcommon_x11_sources,
386 include_directories: include_directories('src'),
387 link_with: libxkbcommon_test_internal,
393 x11_test_dep = declare_dependency(
394 link_with: libxkbcommon_x11_internal,
404 executable('test-keysym', 'test/keysym.c', dependencies: test_dep),
409 executable('test-keymap', 'test/keymap.c', dependencies: test_dep),
414 executable('test-filecomp', 'test/filecomp.c', dependencies: test_dep),
417 # TODO: This test currently uses some functions that don't exist on Windows.
418 if cc.get_id() != 'msvc'
421 executable('test-context', 'test/context.c', dependencies: test_dep),
427 executable('test-rules-file', 'test/rules-file.c', dependencies: test_dep),
431 'rules-file-includes',
432 executable('test-rules-file-includes', 'test/rules-file-includes.c', dependencies: test_dep),
437 executable('test-stringcomp', 'test/stringcomp.c', dependencies: test_dep),
442 executable('test-buffercomp', 'test/buffercomp.c', dependencies: test_dep),
447 executable('test-log', 'test/log.c', dependencies: test_dep),
452 executable('test-atom', 'test/atom.c', dependencies: test_dep),
457 executable('test-utf8', 'test/utf8.c', dependencies: test_dep),
462 executable('test-state', 'test/state.c', dependencies: test_dep),
467 executable('test-keyseq', 'test/keyseq.c', dependencies: test_dep),
472 executable('test-rulescomp', 'test/rulescomp.c', dependencies: test_dep),
477 executable('test-compose', 'test/compose.c', dependencies: test_dep),
482 executable('test-utils', 'test/utils.c', dependencies: test_dep),
487 find_program('test/symbols-leak-test.py'),
489 suite: ['python-tests'],
491 if get_option('enable-x11')
494 executable('test-x11', 'test/x11.c', dependencies: x11_test_dep),
497 # test/x11comp is meant to be run, but it is (temporarily?) disabled.
498 # See: https://github.com/xkbcommon/libxkbcommon/issues/30
499 executable('test-x11comp', 'test/x11comp.c', dependencies: x11_test_dep)
501 if get_option('enable-xkbregistry')
504 executable('test-registry', 'test/registry.c',
505 include_directories: include_directories('src'),
506 dependencies: dep_libxkbregistry),
511 valgrind = find_program('valgrind', required: false)
513 add_test_setup('valgrind',
514 exe_wrapper: [valgrind,
516 '--track-origins=yes',
517 '--gen-suppressions=all',
518 '--error-exitcode=99'],
519 timeout_multiplier : 10)
521 message('valgrind not found, disabling valgrind test setup')
525 # Fuzzing target programs.
526 executable('fuzz-keymap', 'fuzz/keymap/target.c', dependencies: test_dep)
527 executable('fuzz-compose', 'fuzz/compose/target.c', dependencies: test_dep)
532 build_tools = have_getopt
534 libxkbcommon_tools_internal = static_library(
536 'tools/tools-common.h',
537 'tools/tools-common.c',
538 libxkbcommon_sources,
539 include_directories: include_directories('src'),
541 tools_dep = declare_dependency(
542 include_directories: [include_directories('src'), include_directories('tools')],
543 link_with: libxkbcommon_tools_internal,
546 executable('xkbcli', 'tools/xkbcli.c',
547 dependencies: tools_dep, install: true)
548 man_pages += 'tools/xkbcli.1.ronn'
551 executable('xkbcommon-rmlvo-to-keymap', 'tools/rmlvo-to-keymap.c', dependencies: tools_dep)
552 executable('xkbcommon-how-to-type', 'tools/how-to-type.c', dependencies: tools_dep)
554 if cc.has_header('linux/input.h')
555 executable('xkbcommon-interactive-evdev', 'tools/interactive-evdev.c', dependencies: tools_dep)
557 if get_option('enable-x11')
558 x11_tools_dep = declare_dependency(
559 link_with: libxkbcommon_x11_internal,
566 executable('xkbcommon-interactive-x11', 'tools/interactive-x11.c', dependencies: x11_tools_dep)
568 if get_option('enable-wayland')
569 wayland_client_dep = dependency('wayland-client', version: '>=1.2.0', required: false)
570 wayland_protocols_dep = dependency('wayland-protocols', version: '>=1.12', required: false)
571 wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)
572 if not wayland_client_dep.found() or not wayland_protocols_dep.found() or not wayland_scanner_dep.found()
573 error('''The Wayland demo programs require wayland-client >= 1.2.0, wayland-protocols >= 1.7 which were not found.
574 You can disable the Wayland demo programs with -Denable-wayland=false.''')
577 wayland_scanner = find_program(wayland_scanner_dep.get_pkgconfig_variable('wayland_scanner'))
578 wayland_scanner_code_gen = generator(
580 output: '@BASENAME@-protocol.c',
581 arguments: ['code', '@INPUT@', '@OUTPUT@'],
583 wayland_scanner_client_header_gen = generator(
585 output: '@BASENAME@-client-protocol.h',
586 arguments: ['client-header', '@INPUT@', '@OUTPUT@'],
588 wayland_protocols_datadir = wayland_protocols_dep.get_pkgconfig_variable('pkgdatadir')
589 xdg_shell_xml = join_paths(wayland_protocols_datadir, 'stable/xdg-shell/xdg-shell.xml')
590 xdg_shell_sources = [
591 wayland_scanner_code_gen.process(xdg_shell_xml),
592 wayland_scanner_client_header_gen.process(xdg_shell_xml),
594 executable('xkbcommon-interactive-wayland',
595 'tools/interactive-wayland.c',
597 dependencies: [tools_dep, wayland_client_dep])
600 if have_getopt_long and get_option('enable-xkbregistry')
601 executable('xkbcommon-registry-list',
602 'tools/registry-list.c',
603 dependencies: dep_libxkbregistry,
608 if get_option('enable-manpages')
609 prog_ronn = find_program('ronn', required: true)
610 foreach manpage : man_pages
611 # man page filenames adhere to directory/topic.section.ronn
612 topic = manpage.split('/')[-1].split('.')[-3]
613 section = manpage.split('.')[-2]
614 output = '@0@.@1@'.format(topic, section)
615 custom_target(output,
618 command: [prog_ronn, '--manual=libxkbcommon manual', '--pipe', '--roff', files(manpage)],
621 install_dir: join_paths(dir_man, section))
625 # xkeyboard-config "verifier"
626 xkct_config = configuration_data()
627 xkct_config.set('MESON_BUILD_ROOT', meson.build_root())
628 xkct_config.set('XKB_CONFIG_ROOT', XKBCONFIGROOT)
629 configure_file(input: 'test/xkeyboard-config-test.py.in',
630 output: 'xkeyboard-config-test',
631 configuration: xkct_config)
635 libxkbcommon_bench_internal = static_library(
636 'xkbcommon-bench-internal',
639 link_with: libxkbcommon_test_internal,
641 bench_dep = declare_dependency(
642 include_directories: include_directories('src'),
643 link_with: libxkbcommon_bench_internal,
645 bench_env = environment()
646 bench_env.set('top_srcdir', meson.source_root())
649 executable('bench-key-proc', 'bench/key-proc.c', dependencies: bench_dep),
654 executable('bench-rules', 'bench/rules.c', dependencies: bench_dep),
659 executable('bench-rulescomp', 'bench/rulescomp.c', dependencies: bench_dep),
664 executable('bench-compose', 'bench/compose.c', dependencies: bench_dep),
670 if get_option('enable-docs')
671 doxygen = find_program('doxygen', required: false)
672 if not doxygen.found()
673 error('''Documentation requires doxygen which was not found.
674 You can disable the documentation with -Denable-docs=false.''')
676 doxygen_wrapper = find_program('scripts/doxygen-wrapper')
680 'doc/doxygen-extra.css',
681 'doc/quick-guide.md',
683 'doc/user-configuration.md',
684 'doc/rules-format.md',
685 'xkbcommon/xkbcommon.h',
686 'xkbcommon/xkbcommon-names.h',
687 'xkbcommon/xkbcommon-x11.h',
688 'xkbcommon/xkbcommon-compose.h',
689 'xkbcommon/xkbregistry.h',
691 doxygen_data = configuration_data()
692 doxygen_data.set('PACKAGE_NAME', meson.project_name())
693 doxygen_data.set('PACKAGE_VERSION', meson.project_version())
694 doxygen_data.set('INPUT', ' '.join(doxygen_input))
695 doxygen_data.set('OUTPUT_DIRECTORY', meson.build_root())
696 doxyfile = configure_file(
697 input: 'doc/Doxyfile.in',
699 configuration: doxygen_data,
701 # TODO: Meson should provide this.
702 docdir = join_paths(get_option('datadir'), 'doc', meson.project_name())
705 input: [doxyfile] + doxygen_input,
707 command: [doxygen_wrapper, doxygen.path(), join_paths(meson.build_root(), 'Doxyfile'), meson.source_root()],
710 build_by_default: true,
714 configure_file(output: 'config.h', configuration: configh_data)