10 meson_version : '>= 0.41.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 if get_option('default-options') != ''
82 configh_data.set_quoted('DEFAULT_XKB_OPTIONS', get_option('default-options'))
84 if cc.links('int main(){if(__builtin_expect(1<0,0)){}}', name: '__builtin_expect')
85 configh_data.set('HAVE___BUILTIN_EXPECT', 1)
87 if cc.has_header_symbol('unistd.h', 'eaccess', prefix: system_ext_define)
88 configh_data.set('HAVE_EACCESS', 1)
90 if cc.has_header_symbol('unistd.h', 'euidaccess', prefix: system_ext_define)
91 configh_data.set('HAVE_EUIDACCESS', 1)
93 if cc.has_header_symbol('sys/mman.h', 'mmap')
94 configh_data.set('HAVE_MMAP', 1)
96 if cc.has_header_symbol('stdlib.h', 'mkostemp', prefix: system_ext_define)
97 configh_data.set('HAVE_MKOSTEMP', 1)
99 if cc.has_header_symbol('fcntl.h', 'posix_fallocate', prefix: system_ext_define)
100 configh_data.set('HAVE_POSIX_FALLOCATE', 1)
102 if cc.has_header_symbol('string.h', 'strndup', prefix: system_ext_define)
103 configh_data.set('HAVE_STRNDUP', 1)
105 if cc.has_header_symbol('stdio.h', 'asprintf', prefix: system_ext_define)
106 configh_data.set('HAVE_ASPRINTF', 1)
107 elif cc.has_header_symbol('stdio.h', 'vasprintf', prefix: system_ext_define)
108 configh_data.set('HAVE_VASPRINTF', 1)
110 if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix: system_ext_define)
111 configh_data.set('HAVE_SECURE_GETENV', 1)
112 elif cc.has_header_symbol('stdlib.h', '__secure_getenv', prefix: system_ext_define)
113 configh_data.set('HAVE___SECURE_GETENV', 1)
115 message('C library does not support secure_getenv, using getenv instead')
117 # Silence some security & deprecation warnings on MSVC
118 # for some unix/C functions we use.
119 # https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4996?view=vs-2019
120 configh_data.set('_CRT_SECURE_NO_WARNINGS', 1)
121 configh_data.set('_CRT_NONSTDC_NO_WARNINGS', 1)
122 configh_data.set('_CRT_NONSTDC_NO_DEPRECATE', 1)
123 # Reduce unnecessary includes on MSVC.
124 configh_data.set('WIN32_LEAN_AND_MEAN', 1)
125 configure_file(output: 'config.h', configuration: configh_data)
128 # Supports -Wl,--version-script?
129 have_version_script = cc.links(
131 args: '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon.map'),
132 name: '-Wl,--version-script',
137 # Note: we use some yacc extensions, which work with either GNU bison
138 # (preferred) or byacc (with backtracking enabled).
139 bison = find_program('bison', 'win_bison', required: false)
141 yacc_gen = generator(
143 output: ['@BASENAME@.c', '@BASENAME@.h'],
144 arguments: ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@', '-p _xkbcommon_'],
147 byacc = find_program('byacc', required: false)
149 yacc_gen = generator(
151 output: ['@BASENAME@.c', '@BASENAME@.h'],
152 arguments: ['@INPUT@', '-H', '@OUTPUT1@', '-o', '@OUTPUT0@', '-p _xkbcommon_'],
155 error('Could not find a compatible YACC program (bison or byacc)')
158 libxkbcommon_sources = [
159 'src/compose/parser.c',
160 'src/compose/parser.h',
161 'src/compose/paths.c',
162 'src/compose/paths.h',
163 'src/compose/state.c',
164 'src/compose/table.c',
165 'src/compose/table.h',
166 'src/xkbcomp/action.c',
167 'src/xkbcomp/action.h',
169 'src/xkbcomp/ast-build.c',
170 'src/xkbcomp/ast-build.h',
171 'src/xkbcomp/compat.c',
172 'src/xkbcomp/expr.c',
173 'src/xkbcomp/expr.h',
174 'src/xkbcomp/include.c',
175 'src/xkbcomp/include.h',
176 'src/xkbcomp/keycodes.c',
177 'src/xkbcomp/keymap.c',
178 'src/xkbcomp/keymap-dump.c',
179 'src/xkbcomp/keywords.c',
180 yacc_gen.process('src/xkbcomp/parser.y'),
181 'src/xkbcomp/parser-priv.h',
182 'src/xkbcomp/rules.c',
183 'src/xkbcomp/rules.h',
184 'src/xkbcomp/scanner.c',
185 'src/xkbcomp/symbols.c',
186 'src/xkbcomp/types.c',
187 'src/xkbcomp/vmod.c',
188 'src/xkbcomp/vmod.h',
189 'src/xkbcomp/xkbcomp.c',
190 'src/xkbcomp/xkbcomp-priv.h',
195 'src/context-priv.c',
204 'src/scanner-utils.h',
213 libxkbcommon_link_args = []
214 if have_version_script
215 libxkbcommon_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon.map')
217 libxkbcommon = library(
219 'xkbcommon/xkbcommon.h',
220 libxkbcommon_sources,
221 link_args: libxkbcommon_link_args,
222 link_depends: 'xkbcommon.map',
225 include_directories: include_directories('src'),
228 'xkbcommon/xkbcommon.h',
229 'xkbcommon/xkbcommon-compat.h',
230 'xkbcommon/xkbcommon-compose.h',
231 'xkbcommon/xkbcommon-keysyms.h',
232 'xkbcommon/xkbcommon-names.h',
237 filebase: 'xkbcommon',
238 libraries: libxkbcommon,
239 version: meson.project_version(),
240 description: 'XKB API common to servers and clients',
245 if get_option('enable-x11')
246 xcb_dep = dependency('xcb', version: '>=1.10', required: false)
247 xcb_xkb_dep = dependency('xcb-xkb', version: '>=1.10', required: false)
248 if not xcb_dep.found() or not xcb_xkb_dep.found()
249 error('''X11 support requires xcb-xkb >= 1.10 which was not found.
250 You can disable X11 support with -Denable-x11=false.''')
253 libxkbcommon_x11_sources = [
257 'src/x11/x11-priv.h',
259 'src/context-priv.c',
265 libxkbcommon_x11_link_args = []
266 if have_version_script
267 libxkbcommon_x11_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon-x11.map')
269 libxkbcommon_x11 = library(
271 'xkbcommon/xkbcommon-x11.h',
272 libxkbcommon_x11_sources,
273 link_args: libxkbcommon_x11_link_args,
274 link_depends: 'xkbcommon-x11.map',
277 include_directories: include_directories('src'),
278 link_with: libxkbcommon,
285 'xkbcommon/xkbcommon-x11.h',
289 name: 'xkbcommon-x11',
290 filebase: 'xkbcommon-x11',
291 libraries: libxkbcommon_x11,
292 version: meson.project_version(),
293 description: 'XKB API common to servers and clients - X11 support',
294 requires: ['xkbcommon'],
295 requires_private: ['xcb>=1.10', 'xcb-xkb>=1.10'],
301 test_env = environment()
302 test_env.set('XKB_LOG_LEVEL', 'debug')
303 test_env.set('XKB_LOG_VERBOSITY', '10')
304 test_env.set('top_srcdir', meson.source_root())
305 test_env.set('top_builddir', meson.build_root())
307 test_configh_data = configuration_data()
308 test_configh_data.set_quoted('TEST_XKB_CONFIG_ROOT', join_paths(meson.source_root(), 'test', 'data'))
309 configure_file(output: 'test-config.h', configuration: test_configh_data)
311 # Some tests need to use unexported symbols, so we link them against
312 # an internal copy of libxkbcommon with all symbols exposed.
313 libxkbcommon_test_internal = static_library(
314 'xkbcommon-test-internal',
317 'test/evdev-scancodes.h',
318 libxkbcommon_sources,
319 include_directories: include_directories('src'),
321 test_dep = declare_dependency(
322 include_directories: include_directories('src'),
323 link_with: libxkbcommon_test_internal,
325 if get_option('enable-x11')
326 libxkbcommon_x11_internal = static_library(
327 'xkbcommon-x11-internal',
328 libxkbcommon_x11_sources,
329 include_directories: include_directories('src'),
330 link_with: libxkbcommon_test_internal,
336 x11_test_dep = declare_dependency(
337 link_with: libxkbcommon_x11_internal,
347 executable('test-keysym', 'test/keysym.c', dependencies: test_dep),
352 executable('test-keymap', 'test/keymap.c', dependencies: test_dep),
357 executable('test-filecomp', 'test/filecomp.c', dependencies: test_dep),
360 # TODO: This test currently uses some functions that don't exist on Windows.
361 if cc.get_id() != 'msvc'
364 executable('test-context', 'test/context.c', dependencies: test_dep),
370 executable('test-rules-file', 'test/rules-file.c', dependencies: test_dep),
374 'rules-file-includes',
375 executable('test-rules-file-includes', 'test/rules-file-includes.c', dependencies: test_dep),
380 executable('test-stringcomp', 'test/stringcomp.c', dependencies: test_dep),
385 executable('test-buffercomp', 'test/buffercomp.c', dependencies: test_dep),
390 executable('test-log', 'test/log.c', dependencies: test_dep),
395 executable('test-atom', 'test/atom.c', dependencies: test_dep),
400 executable('test-utf8', 'test/utf8.c', dependencies: test_dep),
405 executable('test-state', 'test/state.c', dependencies: test_dep),
410 executable('test-keyseq', 'test/keyseq.c', dependencies: test_dep),
415 executable('test-rulescomp', 'test/rulescomp.c', dependencies: test_dep),
420 executable('test-compose', 'test/compose.c', dependencies: test_dep),
425 find_program('test/symbols-leak-test.bash'),
428 if get_option('enable-x11')
431 executable('test-x11', 'test/x11.c', dependencies: x11_test_dep),
434 # test/x11comp is meant to be run, but it is (temporarily?) disabled.
435 # See: https://github.com/xkbcommon/libxkbcommon/issues/30
436 executable('test-x11comp', 'test/x11comp.c', dependencies: x11_test_dep)
440 # Fuzzing target programs.
441 executable('fuzz-keymap', 'fuzz/keymap/target.c', dependencies: test_dep)
442 executable('fuzz-compose', 'fuzz/compose/target.c', dependencies: test_dep)
446 libxkbcommon_tools_internal = static_library(
448 'tools/tools-common.h',
449 'tools/tools-common.c',
450 libxkbcommon_sources,
451 include_directories: include_directories('src'),
453 tools_dep = declare_dependency(
454 include_directories: [include_directories('src'), include_directories('tools')],
455 link_with: libxkbcommon_tools_internal,
458 if cc.has_header_symbol('getopt.h', 'getopt_long', prefix: '#define _GNU_SOURCE')
459 executable('rmlvo-to-kccgst', 'tools/rmlvo-to-kccgst.c', dependencies: tools_dep)
460 executable('rmlvo-to-keymap', 'tools/rmlvo-to-keymap.c', dependencies: tools_dep)
461 executable('print-compiled-keymap', 'tools/print-compiled-keymap.c', dependencies: tools_dep)
462 executable('how-to-type', 'tools/how-to-type.c', dependencies: tools_dep)
464 if cc.has_header('linux/input.h')
465 executable('interactive-evdev', 'test/interactive-evdev.c', dependencies: tools_dep)
467 if get_option('enable-x11')
468 x11_tools_dep = declare_dependency(
469 link_with: libxkbcommon_x11_internal,
476 executable('interactive-x11', 'test/interactive-x11.c', dependencies: x11_tools_dep)
478 if get_option('enable-wayland')
479 wayland_client_dep = dependency('wayland-client', version: '>=1.2.0', required: false)
480 wayland_protocols_dep = dependency('wayland-protocols', version: '>=1.12', required: false)
481 wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)
482 if not wayland_client_dep.found() or not wayland_protocols_dep.found() or not wayland_scanner_dep.found()
483 error('''The Wayland demo programs require wayland-client >= 1.2.0, wayland-protocols >= 1.7 which were not found.
484 You can disable the Wayland demo programs with -Denable-wayland=false.''')
487 wayland_scanner = find_program(wayland_scanner_dep.get_pkgconfig_variable('wayland_scanner'))
488 wayland_scanner_code_gen = generator(
490 output: '@BASENAME@-protocol.c',
491 arguments: ['code', '@INPUT@', '@OUTPUT@'],
493 wayland_scanner_client_header_gen = generator(
495 output: '@BASENAME@-client-protocol.h',
496 arguments: ['client-header', '@INPUT@', '@OUTPUT@'],
498 wayland_protocols_datadir = wayland_protocols_dep.get_pkgconfig_variable('pkgdatadir')
499 xdg_shell_xml = join_paths(wayland_protocols_datadir, 'stable/xdg-shell/xdg-shell.xml')
500 xdg_shell_sources = [
501 wayland_scanner_code_gen.process(xdg_shell_xml),
502 wayland_scanner_client_header_gen.process(xdg_shell_xml),
504 executable('interactive-wayland', 'test/interactive-wayland.c', xdg_shell_sources, dependencies: [test_dep, wayland_client_dep])
507 # xkeyboard-config "verifier"
508 xkct_config = configuration_data()
509 xkct_config.set('MESON_BUILD_ROOT', meson.build_root())
510 xkct_config.set('XKB_CONFIG_ROOT', XKBCONFIGROOT)
511 configure_file(input: 'test/xkeyboard-config-test.py.in',
512 output: 'xkeyboard-config-test',
513 configuration: xkct_config,
518 libxkbcommon_bench_internal = static_library(
519 'xkbcommon-bench-internal',
522 link_with: libxkbcommon_test_internal,
524 bench_dep = declare_dependency(
525 include_directories: include_directories('src'),
526 link_with: libxkbcommon_bench_internal,
528 bench_env = environment()
529 bench_env.set('top_srcdir', meson.source_root())
532 executable('bench-key-proc', 'bench/key-proc.c', dependencies: bench_dep),
537 executable('bench-rules', 'bench/rules.c', dependencies: bench_dep),
542 executable('bench-rulescomp', 'bench/rulescomp.c', dependencies: bench_dep),
547 executable('bench-compose', 'bench/compose.c', dependencies: bench_dep),
553 if get_option('enable-docs')
554 doxygen = find_program('doxygen', required: false)
555 if not doxygen.found()
556 error('''Documentation requires doxygen which was not found.
557 You can disable the documentation with -Denable-docs=false.''')
559 doxygen_wrapper = find_program('scripts/doxygen-wrapper')
563 'doc/doxygen-extra.css',
564 'doc/quick-guide.md',
566 'doc/user-configuration.md',
567 'doc/rules-format.md',
568 'xkbcommon/xkbcommon.h',
569 'xkbcommon/xkbcommon-names.h',
570 'xkbcommon/xkbcommon-x11.h',
571 'xkbcommon/xkbcommon-compose.h',
573 doxygen_data = configuration_data()
574 doxygen_data.set('PACKAGE_NAME', meson.project_name())
575 doxygen_data.set('PACKAGE_VERSION', meson.project_version())
576 doxygen_data.set('INPUT', ' '.join(doxygen_input))
577 doxygen_data.set('OUTPUT_DIRECTORY', meson.build_root())
578 doxyfile = configure_file(
579 input: 'doc/Doxyfile.in',
581 configuration: doxygen_data,
583 # TODO: Meson should provide this.
584 docdir = join_paths(get_option('datadir'), 'doc', meson.project_name())
587 input: [doxyfile] + doxygen_input,
589 command: [doxygen_wrapper, doxygen.path(), join_paths(meson.build_root(), 'Doxyfile'), meson.source_root()],
592 build_by_default: true,