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)
133 # Supports -Wl,--version-script?
134 have_version_script = cc.links(
136 args: '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon.map'),
137 name: '-Wl,--version-script',
142 # Note: we use some yacc extensions, which work with either GNU bison
143 # (preferred) or byacc (with backtracking enabled).
144 bison = find_program('bison', 'win_bison', required: false)
146 yacc_gen = generator(
148 output: ['@BASENAME@.c', '@BASENAME@.h'],
149 arguments: ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@', '-p _xkbcommon_'],
152 byacc = find_program('byacc', required: false)
154 yacc_gen = generator(
156 output: ['@BASENAME@.c', '@BASENAME@.h'],
157 arguments: ['@INPUT@', '-H', '@OUTPUT1@', '-o', '@OUTPUT0@', '-p _xkbcommon_'],
160 error('Could not find a compatible YACC program (bison or byacc)')
163 libxkbcommon_sources = [
164 'src/compose/parser.c',
165 'src/compose/parser.h',
166 'src/compose/paths.c',
167 'src/compose/paths.h',
168 'src/compose/state.c',
169 'src/compose/table.c',
170 'src/compose/table.h',
171 'src/xkbcomp/action.c',
172 'src/xkbcomp/action.h',
174 'src/xkbcomp/ast-build.c',
175 'src/xkbcomp/ast-build.h',
176 'src/xkbcomp/compat.c',
177 'src/xkbcomp/expr.c',
178 'src/xkbcomp/expr.h',
179 'src/xkbcomp/include.c',
180 'src/xkbcomp/include.h',
181 'src/xkbcomp/keycodes.c',
182 'src/xkbcomp/keymap.c',
183 'src/xkbcomp/keymap-dump.c',
184 'src/xkbcomp/keywords.c',
185 yacc_gen.process('src/xkbcomp/parser.y'),
186 'src/xkbcomp/parser-priv.h',
187 'src/xkbcomp/rules.c',
188 'src/xkbcomp/rules.h',
189 'src/xkbcomp/scanner.c',
190 'src/xkbcomp/symbols.c',
191 'src/xkbcomp/types.c',
192 'src/xkbcomp/vmod.c',
193 'src/xkbcomp/vmod.h',
194 'src/xkbcomp/xkbcomp.c',
195 'src/xkbcomp/xkbcomp-priv.h',
200 'src/context-priv.c',
209 'src/scanner-utils.h',
218 libxkbcommon_link_args = []
219 if have_version_script
220 libxkbcommon_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon.map')
222 libxkbcommon = library(
224 'xkbcommon/xkbcommon.h',
225 libxkbcommon_sources,
226 link_args: libxkbcommon_link_args,
227 link_depends: 'xkbcommon.map',
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',
243 filebase: 'xkbcommon',
244 version: meson.project_version(),
245 description: 'XKB API common to servers and clients',
250 if get_option('enable-x11')
251 xcb_dep = dependency('xcb', version: '>=1.10', required: false)
252 xcb_xkb_dep = dependency('xcb-xkb', version: '>=1.10', required: false)
253 if not xcb_dep.found() or not xcb_xkb_dep.found()
254 error('''X11 support requires xcb-xkb >= 1.10 which was not found.
255 You can disable X11 support with -Denable-x11=false.''')
258 libxkbcommon_x11_sources = [
262 'src/x11/x11-priv.h',
264 'src/context-priv.c',
270 libxkbcommon_x11_link_args = []
271 if have_version_script
272 libxkbcommon_x11_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon-x11.map')
274 libxkbcommon_x11 = library(
276 'xkbcommon/xkbcommon-x11.h',
277 libxkbcommon_x11_sources,
278 link_args: libxkbcommon_x11_link_args,
279 link_depends: 'xkbcommon-x11.map',
282 include_directories: include_directories('src'),
283 link_with: libxkbcommon,
290 'xkbcommon/xkbcommon-x11.h',
295 name: 'xkbcommon-x11',
296 filebase: 'xkbcommon-x11',
297 version: meson.project_version(),
298 description: 'XKB API common to servers and clients - X11 support',
299 requires: ['xkbcommon'],
300 requires_private: ['xcb>=1.10', 'xcb-xkb>=1.10'],
305 if get_option('enable-xkbregistry')
306 dep_libxml = dependency('libxml-2.0')
307 deps_libxkbregistry = [dep_libxml]
308 libxkbregistry_sources = [
315 libxkbregistry_link_args = []
316 if have_version_script
317 libxkbregistry_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbregistry.map')
319 libxkbregistry = library(
321 'xkbcommon/xkbregistry.h',
322 libxkbregistry_sources,
323 link_args: libxkbregistry_link_args,
324 link_depends: 'xkbregistry.map',
325 dependencies: deps_libxkbregistry,
328 include_directories: include_directories('src'),
331 'xkbcommon/xkbregistry.h',
337 filebase: 'xkbregistry',
338 version: meson.project_version(),
339 description: 'XKB API to query available rules, models, layouts, variants and options',
342 dep_libxkbregistry = declare_dependency(
343 include_directories: include_directories('xkbcommon'),
344 link_with: libxkbregistry
347 executable('xkbcommon-registry-list',
348 'tools/registry-list.c',
349 dependencies: dep_libxkbregistry,
355 test_env = environment()
356 test_env.set('XKB_LOG_LEVEL', 'debug')
357 test_env.set('XKB_LOG_VERBOSITY', '10')
358 test_env.set('top_srcdir', meson.source_root())
359 test_env.set('top_builddir', meson.build_root())
361 test_configh_data = configuration_data()
362 test_configh_data.set_quoted('TEST_XKB_CONFIG_ROOT', join_paths(meson.source_root(), 'test', 'data'))
363 configure_file(output: 'test-config.h', configuration: test_configh_data)
365 # Some tests need to use unexported symbols, so we link them against
366 # an internal copy of libxkbcommon with all symbols exposed.
367 libxkbcommon_test_internal = static_library(
368 'xkbcommon-test-internal',
371 'test/evdev-scancodes.h',
372 libxkbcommon_sources,
373 include_directories: include_directories('src'),
375 test_dep = declare_dependency(
376 include_directories: include_directories('src'),
377 link_with: libxkbcommon_test_internal,
379 if get_option('enable-x11')
380 libxkbcommon_x11_internal = static_library(
381 'xkbcommon-x11-internal',
382 libxkbcommon_x11_sources,
383 include_directories: include_directories('src'),
384 link_with: libxkbcommon_test_internal,
390 x11_test_dep = declare_dependency(
391 link_with: libxkbcommon_x11_internal,
401 executable('test-keysym', 'test/keysym.c', dependencies: test_dep),
406 executable('test-keymap', 'test/keymap.c', dependencies: test_dep),
411 executable('test-filecomp', 'test/filecomp.c', dependencies: test_dep),
414 # TODO: This test currently uses some functions that don't exist on Windows.
415 if cc.get_id() != 'msvc'
418 executable('test-context', 'test/context.c', dependencies: test_dep),
424 executable('test-rules-file', 'test/rules-file.c', dependencies: test_dep),
428 'rules-file-includes',
429 executable('test-rules-file-includes', 'test/rules-file-includes.c', dependencies: test_dep),
434 executable('test-stringcomp', 'test/stringcomp.c', dependencies: test_dep),
439 executable('test-buffercomp', 'test/buffercomp.c', dependencies: test_dep),
444 executable('test-log', 'test/log.c', dependencies: test_dep),
449 executable('test-atom', 'test/atom.c', dependencies: test_dep),
454 executable('test-utf8', 'test/utf8.c', dependencies: test_dep),
459 executable('test-state', 'test/state.c', dependencies: test_dep),
464 executable('test-keyseq', 'test/keyseq.c', dependencies: test_dep),
469 executable('test-rulescomp', 'test/rulescomp.c', dependencies: test_dep),
474 executable('test-compose', 'test/compose.c', dependencies: test_dep),
479 executable('test-utils', 'test/utils.c', dependencies: test_dep),
484 find_program('test/symbols-leak-test.py'),
486 suite: ['python-tests'],
488 if get_option('enable-x11')
491 executable('test-x11', 'test/x11.c', dependencies: x11_test_dep),
494 # test/x11comp is meant to be run, but it is (temporarily?) disabled.
495 # See: https://github.com/xkbcommon/libxkbcommon/issues/30
496 executable('test-x11comp', 'test/x11comp.c', dependencies: x11_test_dep)
498 if get_option('enable-xkbregistry')
501 executable('test-registry', 'test/registry.c',
502 include_directories: include_directories('src'),
503 dependencies: dep_libxkbregistry),
508 valgrind = find_program('valgrind', required: false)
510 add_test_setup('valgrind',
511 exe_wrapper: [valgrind,
513 '--track-origins=yes',
514 '--gen-suppressions=all',
515 '--error-exitcode=99'],
516 timeout_multiplier : 10)
518 message('valgrind not found, disabling valgrind test setup')
522 # Fuzzing target programs.
523 executable('fuzz-keymap', 'fuzz/keymap/target.c', dependencies: test_dep)
524 executable('fuzz-compose', 'fuzz/compose/target.c', dependencies: test_dep)
528 libxkbcommon_tools_internal = static_library(
530 'tools/tools-common.h',
531 'tools/tools-common.c',
532 libxkbcommon_sources,
533 include_directories: include_directories('src'),
535 tools_dep = declare_dependency(
536 include_directories: [include_directories('src'), include_directories('tools')],
537 link_with: libxkbcommon_tools_internal,
541 executable('xkbcommon-rmlvo-to-keymap', 'tools/rmlvo-to-keymap.c', dependencies: tools_dep)
542 executable('xkbcommon-how-to-type', 'tools/how-to-type.c', dependencies: tools_dep)
544 if cc.has_header('linux/input.h')
545 executable('xkbcommon-interactive-evdev', 'tools/interactive-evdev.c', dependencies: tools_dep)
547 if get_option('enable-x11')
548 x11_tools_dep = declare_dependency(
549 link_with: libxkbcommon_x11_internal,
556 executable('xkbcommon-interactive-x11', 'tools/interactive-x11.c', dependencies: x11_tools_dep)
558 if get_option('enable-wayland')
559 wayland_client_dep = dependency('wayland-client', version: '>=1.2.0', required: false)
560 wayland_protocols_dep = dependency('wayland-protocols', version: '>=1.12', required: false)
561 wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)
562 if not wayland_client_dep.found() or not wayland_protocols_dep.found() or not wayland_scanner_dep.found()
563 error('''The Wayland demo programs require wayland-client >= 1.2.0, wayland-protocols >= 1.7 which were not found.
564 You can disable the Wayland demo programs with -Denable-wayland=false.''')
567 wayland_scanner = find_program(wayland_scanner_dep.get_pkgconfig_variable('wayland_scanner'))
568 wayland_scanner_code_gen = generator(
570 output: '@BASENAME@-protocol.c',
571 arguments: ['code', '@INPUT@', '@OUTPUT@'],
573 wayland_scanner_client_header_gen = generator(
575 output: '@BASENAME@-client-protocol.h',
576 arguments: ['client-header', '@INPUT@', '@OUTPUT@'],
578 wayland_protocols_datadir = wayland_protocols_dep.get_pkgconfig_variable('pkgdatadir')
579 xdg_shell_xml = join_paths(wayland_protocols_datadir, 'stable/xdg-shell/xdg-shell.xml')
580 xdg_shell_sources = [
581 wayland_scanner_code_gen.process(xdg_shell_xml),
582 wayland_scanner_client_header_gen.process(xdg_shell_xml),
584 executable('xkbcommon-interactive-wayland',
585 'tools/interactive-wayland.c',
587 dependencies: [tools_dep, wayland_client_dep])
590 # xkeyboard-config "verifier"
591 xkct_config = configuration_data()
592 xkct_config.set('MESON_BUILD_ROOT', meson.build_root())
593 xkct_config.set('XKB_CONFIG_ROOT', XKBCONFIGROOT)
594 configure_file(input: 'test/xkeyboard-config-test.py.in',
595 output: 'xkeyboard-config-test',
596 configuration: xkct_config)
600 libxkbcommon_bench_internal = static_library(
601 'xkbcommon-bench-internal',
604 link_with: libxkbcommon_test_internal,
606 bench_dep = declare_dependency(
607 include_directories: include_directories('src'),
608 link_with: libxkbcommon_bench_internal,
610 bench_env = environment()
611 bench_env.set('top_srcdir', meson.source_root())
614 executable('bench-key-proc', 'bench/key-proc.c', dependencies: bench_dep),
619 executable('bench-rules', 'bench/rules.c', dependencies: bench_dep),
624 executable('bench-rulescomp', 'bench/rulescomp.c', dependencies: bench_dep),
629 executable('bench-compose', 'bench/compose.c', dependencies: bench_dep),
635 if get_option('enable-docs')
636 doxygen = find_program('doxygen', required: false)
637 if not doxygen.found()
638 error('''Documentation requires doxygen which was not found.
639 You can disable the documentation with -Denable-docs=false.''')
641 doxygen_wrapper = find_program('scripts/doxygen-wrapper')
645 'doc/doxygen-extra.css',
646 'doc/quick-guide.md',
648 'doc/user-configuration.md',
649 'doc/rules-format.md',
650 'xkbcommon/xkbcommon.h',
651 'xkbcommon/xkbcommon-names.h',
652 'xkbcommon/xkbcommon-x11.h',
653 'xkbcommon/xkbcommon-compose.h',
654 'xkbcommon/xkbregistry.h',
656 doxygen_data = configuration_data()
657 doxygen_data.set('PACKAGE_NAME', meson.project_name())
658 doxygen_data.set('PACKAGE_VERSION', meson.project_version())
659 doxygen_data.set('INPUT', ' '.join(doxygen_input))
660 doxygen_data.set('OUTPUT_DIRECTORY', meson.build_root())
661 doxyfile = configure_file(
662 input: 'doc/Doxyfile.in',
664 configuration: doxygen_data,
666 # TODO: Meson should provide this.
667 docdir = join_paths(get_option('datadir'), 'doc', meson.project_name())
670 input: [doxyfile] + doxygen_input,
672 command: [doxygen_wrapper, doxygen.path(), join_paths(meson.build_root(), 'Doxyfile'), meson.source_root()],
675 build_by_default: true,
679 configure_file(output: 'config.h', configuration: configh_data)