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 configh_data.set('_GNU_SOURCE', 1)
65 configh_data.set_quoted('DFLT_XKB_CONFIG_ROOT', XKBCONFIGROOT)
66 configh_data.set_quoted('XLOCALEDIR', XLOCALEDIR)
67 configh_data.set_quoted('DEFAULT_XKB_RULES', get_option('default-rules'))
68 configh_data.set_quoted('DEFAULT_XKB_MODEL', get_option('default-model'))
69 configh_data.set_quoted('DEFAULT_XKB_LAYOUT', get_option('default-layout'))
70 if get_option('default-variant') != ''
71 configh_data.set_quoted('DEFAULT_XKB_VARIANT', get_option('default-variant'))
73 if get_option('default-options') != ''
74 configh_data.set_quoted('DEFAULT_XKB_OPTIONS', get_option('default-options'))
76 if cc.links('int main(){if(__builtin_expect(1<0,0)){}}', name: '__builtin_expect')
77 configh_data.set('HAVE___BUILTIN_EXPECT', 1)
79 if cc.has_header_symbol('unistd.h', 'eaccess', prefix: '#define _GNU_SOURCE')
80 configh_data.set('HAVE_EACCESS', 1)
82 if cc.has_header_symbol('unistd.h', 'euidaccess', prefix: '#define _GNU_SOURCE')
83 configh_data.set('HAVE_EUIDACCESS', 1)
85 if cc.has_header_symbol('sys/mman.h', 'mmap')
86 configh_data.set('HAVE_MMAP', 1)
88 if cc.has_header_symbol('stdlib.h', 'mkostemp', prefix: '#define _GNU_SOURCE')
89 configh_data.set('HAVE_MKOSTEMP', 1)
91 if cc.has_header_symbol('fcntl.h', 'posix_fallocate', prefix: '#define _GNU_SOURCE')
92 configh_data.set('HAVE_POSIX_FALLOCATE', 1)
94 if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix: '#define _GNU_SOURCE')
95 configh_data.set('HAVE_SECURE_GETENV', 1)
96 elif cc.has_header_symbol('stdlib.h', '__secure_getenv', prefix: '#define _GNU_SOURCE')
97 configh_data.set('HAVE___SECURE_GETENV', 1)
99 message('C library does not support secure_getenv, using getenv instead')
101 configure_file(output: 'config.h', configuration: configh_data)
102 add_project_arguments('-include', 'config.h', language: 'c')
105 # Supports -Wl,--version-script?
106 have_version_script = cc.links(
108 args: '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon.map'),
109 name: '-Wl,--version-script',
114 # Note: we use some yacc extensions, which work with either GNU bison
115 # (preferred) or byacc. Other yacc's may or may not work.
116 yacc = find_program('bison', 'byacc')
117 yacc_gen = generator(
119 output: ['@BASENAME@.c', '@BASENAME@.h'],
120 arguments: ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@', '-p _xkbcommon_'],
122 libxkbcommon_sources = [
123 'src/compose/parser.c',
124 'src/compose/parser.h',
125 'src/compose/paths.c',
126 'src/compose/paths.h',
127 'src/compose/state.c',
128 'src/compose/table.c',
129 'src/compose/table.h',
130 'src/xkbcomp/action.c',
131 'src/xkbcomp/action.h',
133 'src/xkbcomp/ast-build.c',
134 'src/xkbcomp/ast-build.h',
135 'src/xkbcomp/compat.c',
136 'src/xkbcomp/expr.c',
137 'src/xkbcomp/expr.h',
138 'src/xkbcomp/include.c',
139 'src/xkbcomp/include.h',
140 'src/xkbcomp/keycodes.c',
141 'src/xkbcomp/keymap.c',
142 'src/xkbcomp/keymap-dump.c',
143 'src/xkbcomp/keywords.c',
144 yacc_gen.process('src/xkbcomp/parser.y'),
145 'src/xkbcomp/parser-priv.h',
146 'src/xkbcomp/rules.c',
147 'src/xkbcomp/rules.h',
148 'src/xkbcomp/scanner.c',
149 'src/xkbcomp/symbols.c',
150 'src/xkbcomp/types.c',
151 'src/xkbcomp/vmod.c',
152 'src/xkbcomp/vmod.h',
153 'src/xkbcomp/xkbcomp.c',
154 'src/xkbcomp/xkbcomp-priv.h',
159 'src/context-priv.c',
168 'src/scanner-utils.h',
177 libxkbcommon_link_args = []
178 if have_version_script
179 libxkbcommon_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon.map')
181 libxkbcommon = library(
183 'xkbcommon/xkbcommon.h',
184 libxkbcommon_sources,
185 link_args: libxkbcommon_link_args,
186 link_depends: 'xkbcommon.map',
189 include_directories: include_directories('src'),
192 'xkbcommon/xkbcommon.h',
193 'xkbcommon/xkbcommon-compat.h',
194 'xkbcommon/xkbcommon-compose.h',
195 'xkbcommon/xkbcommon-keysyms.h',
196 'xkbcommon/xkbcommon-names.h',
201 filebase: 'xkbcommon',
202 libraries: libxkbcommon,
203 version: meson.project_version(),
204 description: 'XKB API common to servers and clients',
209 if get_option('enable-x11')
210 xcb_dep = dependency('xcb', version: '>=1.10', required: false)
211 xcb_xkb_dep = dependency('xcb-xkb', version: '>=1.10', required: false)
212 if not xcb_dep.found() or not xcb_xkb_dep.found()
213 error('''X11 support requires xcb-xkb >= 1.10 which was not found.
214 You can disable X11 support with -Denable-x11=false.''')
217 libxkbcommon_x11_sources = [
221 'src/x11/x11-priv.h',
223 'src/context-priv.c',
229 libxkbcommon_x11_internal = static_library(
230 'xkbcommon-x11-internal',
231 libxkbcommon_x11_sources,
232 include_directories: include_directories('src'),
233 link_with: libxkbcommon,
239 libxkbcommon_x11_link_args = []
240 if have_version_script
241 libxkbcommon_x11_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon-x11.map')
243 libxkbcommon_x11 = library(
245 'xkbcommon/xkbcommon-x11.h',
246 libxkbcommon_x11_sources,
247 link_args: libxkbcommon_x11_link_args,
248 link_depends: 'xkbcommon-x11.map',
251 include_directories: include_directories('src'),
252 link_with: libxkbcommon,
259 'xkbcommon/xkbcommon-x11.h',
263 name: 'xkbcommon-x11',
264 filebase: 'xkbcommon-x11',
265 libraries: libxkbcommon_x11,
266 version: meson.project_version(),
267 description: 'XKB API common to servers and clients - X11 support',
268 requires: ['xkbcommon'],
269 requires_private: ['xcb>=1.10', 'xcb-xkb>=1.10'],
275 test_env = environment()
276 test_env.set('XKB_LOG_LEVEL', 'debug')
277 test_env.set('XKB_LOG_VERBOSITY', '10')
278 test_env.set('top_srcdir', meson.source_root())
279 test_env.set('top_builddir', meson.build_root())
280 test_env.set('MALLOC_PERTURB_', '15')
281 test_env.set('MallocPreScribble', '1')
282 test_env.set('MallocScribble', '1')
283 # Some tests need to use unexported symbols, so we link them against
284 # an internal copy of libxkbcommon with all symbols exposed.
285 libxkbcommon_test_internal = static_library(
286 'xkbcommon-test-internal',
289 'test/evdev-scancodes.h',
290 libxkbcommon_sources,
291 include_directories: include_directories('src'),
293 test_dep = declare_dependency(
294 include_directories: include_directories('src'),
295 link_with: libxkbcommon_test_internal,
297 if get_option('enable-x11')
298 x11_test_dep = declare_dependency(
299 link_with: libxkbcommon_x11_internal,
309 executable('test-keysym', 'test/keysym.c', dependencies: test_dep),
314 executable('test-keymap', 'test/keymap.c', dependencies: test_dep),
319 executable('test-filecomp', 'test/filecomp.c', dependencies: test_dep),
324 executable('test-context', 'test/context.c', dependencies: test_dep),
329 executable('test-rules-file', 'test/rules-file.c', dependencies: test_dep),
334 executable('test-stringcomp', 'test/stringcomp.c', dependencies: test_dep),
339 executable('test-buffercomp', 'test/buffercomp.c', dependencies: test_dep),
344 executable('test-log', 'test/log.c', dependencies: test_dep),
349 executable('test-atom', 'test/atom.c', dependencies: test_dep),
354 executable('test-utf8', 'test/utf8.c', dependencies: test_dep),
359 executable('test-state', 'test/state.c', dependencies: test_dep),
364 executable('test-keyseq', 'test/keyseq.c', dependencies: test_dep),
369 executable('test-rulescomp', 'test/rulescomp.c', dependencies: test_dep),
374 executable('test-compose', 'test/compose.c', dependencies: test_dep),
379 find_program('test/symbols-leak-test.bash'),
382 if get_option('enable-x11')
385 executable('test-x11', 'test/x11.c', dependencies: x11_test_dep),
388 # test/x11comp is meant to be run, but it is (temporarily?) disabled.
389 # See: https://github.com/xkbcommon/libxkbcommon/issues/30
390 executable('test-x11comp', 'test/x11comp.c', dependencies: x11_test_dep)
394 # Fuzzing target programs.
395 executable('fuzz-keymap', 'fuzz/keymap/target.c', dependencies: test_dep)
396 executable('fuzz-compose', 'fuzz/compose/target.c', dependencies: test_dep)
400 executable('rmlvo-to-kccgst', 'test/rmlvo-to-kccgst.c', dependencies: test_dep)
401 executable('rmlvo-to-keymap', 'test/rmlvo-to-keymap.c', dependencies: test_dep)
402 executable('print-compiled-keymap', 'test/print-compiled-keymap.c', dependencies: test_dep)
403 if cc.has_header('linux/input.h')
404 executable('interactive-evdev', 'test/interactive-evdev.c', dependencies: test_dep)
406 if get_option('enable-x11')
407 executable('interactive-x11', 'test/interactive-x11.c', dependencies: x11_test_dep)
409 if get_option('enable-wayland')
410 wayland_client_dep = dependency('wayland-client', version: '>=1.2.0', required: false)
411 wayland_protocols_dep = dependency('wayland-protocols', version: '>=1.12', required: false)
412 wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)
413 if not wayland_client_dep.found() or not wayland_protocols_dep.found() or not wayland_scanner_dep.found()
414 error('''The Wayland demo programs require wayland-client >= 1.2.0, wayland-protocols >= 1.7 which were not found.
415 You can disable the Wayland demo programs with -Denable-wayland=false.''')
418 wayland_scanner = find_program(wayland_scanner_dep.get_pkgconfig_variable('wayland_scanner'))
419 wayland_scanner_code_gen = generator(
421 output: '@BASENAME@-protocol.c',
422 arguments: ['code', '@INPUT@', '@OUTPUT@'],
424 wayland_scanner_client_header_gen = generator(
426 output: '@BASENAME@-client-protocol.h',
427 arguments: ['client-header', '@INPUT@', '@OUTPUT@'],
429 wayland_protocols_datadir = wayland_protocols_dep.get_pkgconfig_variable('pkgdatadir')
430 xdg_shell_xml = join_paths(wayland_protocols_datadir, 'stable/xdg-shell/xdg-shell.xml')
431 xdg_shell_sources = [
432 wayland_scanner_code_gen.process(xdg_shell_xml),
433 wayland_scanner_client_header_gen.process(xdg_shell_xml),
435 executable('interactive-wayland', 'test/interactive-wayland.c', xdg_shell_sources, dependencies: [test_dep, wayland_client_dep])
438 # xkeyboard-config "verifier"
439 xkct_config = configuration_data()
440 xkct_config.set('MESON_BUILD_ROOT', meson.build_root())
441 xkct_config.set('XKB_CONFIG_ROOT', XKBCONFIGROOT)
442 configure_file(input: 'test/xkeyboard-config-test.py.in',
443 output: 'xkeyboard-config-test',
444 configuration: xkct_config,
449 libxkbcommon_bench_internal = static_library(
450 'xkbcommon-bench-internal',
453 link_with: libxkbcommon_test_internal,
455 bench_dep = declare_dependency(
456 include_directories: include_directories('src'),
457 link_with: libxkbcommon_bench_internal,
459 bench_env = environment()
460 bench_env.set('top_srcdir', meson.source_root())
463 executable('bench-key-proc', 'bench/key-proc.c', dependencies: bench_dep),
468 executable('bench-rules', 'bench/rules.c', dependencies: bench_dep),
473 executable('bench-rulescomp', 'bench/rulescomp.c', dependencies: bench_dep),
478 executable('bench-compose', 'bench/compose.c', dependencies: bench_dep),
484 if get_option('enable-docs')
485 doxygen = find_program('doxygen', required: false)
486 if not doxygen.found()
487 error('''Documentation requires doxygen which was not found.
488 You can disable the documentation with -Denable-docs=false.''')
490 doxygen_wrapper = find_program('scripts/doxygen-wrapper')
494 'doc/doxygen-extra.css',
495 'doc/quick-guide.md',
497 'xkbcommon/xkbcommon.h',
498 'xkbcommon/xkbcommon-names.h',
499 'xkbcommon/xkbcommon-x11.h',
500 'xkbcommon/xkbcommon-compose.h',
502 doxygen_data = configuration_data()
503 doxygen_data.set('PACKAGE_NAME', meson.project_name())
504 doxygen_data.set('PACKAGE_VERSION', meson.project_version())
505 doxygen_data.set('INPUT', ' '.join(doxygen_input))
506 doxygen_data.set('OUTPUT_DIRECTORY', meson.build_root())
507 doxyfile = configure_file(
508 input: 'doc/Doxyfile.in',
510 configuration: doxygen_data,
512 # TODO: Meson should provide this.
513 docdir = join_paths(get_option('datadir'), 'doc', meson.project_name())
516 input: [doxyfile] + doxygen_input,
518 command: [doxygen_wrapper, doxygen.path(), join_paths(meson.build_root(), 'Doxyfile'), meson.source_root()],
521 build_by_default: true,