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('stdlib.h', 'secure_getenv', prefix: system_ext_define)
106 configh_data.set('HAVE_SECURE_GETENV', 1)
107 elif cc.has_header_symbol('stdlib.h', '__secure_getenv', prefix: system_ext_define)
108 configh_data.set('HAVE___SECURE_GETENV', 1)
110 message('C library does not support secure_getenv, using getenv instead')
112 configure_file(output: 'config.h', configuration: configh_data)
113 add_project_arguments('-include', 'config.h', language: 'c')
116 # Supports -Wl,--version-script?
117 have_version_script = cc.links(
119 args: '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon.map'),
120 name: '-Wl,--version-script',
125 # Note: we use some yacc extensions, which work with either GNU bison
126 # (preferred) or byacc. Other yacc's may or may not work.
127 yacc = find_program('bison', 'byacc')
128 yacc_gen = generator(
130 output: ['@BASENAME@.c', '@BASENAME@.h'],
131 arguments: ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@', '-p _xkbcommon_'],
133 libxkbcommon_sources = [
134 'src/compose/parser.c',
135 'src/compose/parser.h',
136 'src/compose/paths.c',
137 'src/compose/paths.h',
138 'src/compose/state.c',
139 'src/compose/table.c',
140 'src/compose/table.h',
141 'src/xkbcomp/action.c',
142 'src/xkbcomp/action.h',
144 'src/xkbcomp/ast-build.c',
145 'src/xkbcomp/ast-build.h',
146 'src/xkbcomp/compat.c',
147 'src/xkbcomp/expr.c',
148 'src/xkbcomp/expr.h',
149 'src/xkbcomp/include.c',
150 'src/xkbcomp/include.h',
151 'src/xkbcomp/keycodes.c',
152 'src/xkbcomp/keymap.c',
153 'src/xkbcomp/keymap-dump.c',
154 'src/xkbcomp/keywords.c',
155 yacc_gen.process('src/xkbcomp/parser.y'),
156 'src/xkbcomp/parser-priv.h',
157 'src/xkbcomp/rules.c',
158 'src/xkbcomp/rules.h',
159 'src/xkbcomp/scanner.c',
160 'src/xkbcomp/symbols.c',
161 'src/xkbcomp/types.c',
162 'src/xkbcomp/vmod.c',
163 'src/xkbcomp/vmod.h',
164 'src/xkbcomp/xkbcomp.c',
165 'src/xkbcomp/xkbcomp-priv.h',
170 'src/context-priv.c',
179 'src/scanner-utils.h',
188 libxkbcommon_link_args = []
189 if have_version_script
190 libxkbcommon_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon.map')
192 libxkbcommon = library(
194 'xkbcommon/xkbcommon.h',
195 libxkbcommon_sources,
196 link_args: libxkbcommon_link_args,
197 link_depends: 'xkbcommon.map',
200 include_directories: include_directories('src'),
203 'xkbcommon/xkbcommon.h',
204 'xkbcommon/xkbcommon-compat.h',
205 'xkbcommon/xkbcommon-compose.h',
206 'xkbcommon/xkbcommon-keysyms.h',
207 'xkbcommon/xkbcommon-names.h',
212 filebase: 'xkbcommon',
213 libraries: libxkbcommon,
214 version: meson.project_version(),
215 description: 'XKB API common to servers and clients',
220 if get_option('enable-x11')
221 xcb_dep = dependency('xcb', version: '>=1.10', required: false)
222 xcb_xkb_dep = dependency('xcb-xkb', version: '>=1.10', required: false)
223 if not xcb_dep.found() or not xcb_xkb_dep.found()
224 error('''X11 support requires xcb-xkb >= 1.10 which was not found.
225 You can disable X11 support with -Denable-x11=false.''')
228 libxkbcommon_x11_sources = [
232 'src/x11/x11-priv.h',
234 'src/context-priv.c',
240 libxkbcommon_x11_internal = static_library(
241 'xkbcommon-x11-internal',
242 libxkbcommon_x11_sources,
243 include_directories: include_directories('src'),
244 link_with: libxkbcommon,
250 libxkbcommon_x11_link_args = []
251 if have_version_script
252 libxkbcommon_x11_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon-x11.map')
254 libxkbcommon_x11 = library(
256 'xkbcommon/xkbcommon-x11.h',
257 libxkbcommon_x11_sources,
258 link_args: libxkbcommon_x11_link_args,
259 link_depends: 'xkbcommon-x11.map',
262 include_directories: include_directories('src'),
263 link_with: libxkbcommon,
270 'xkbcommon/xkbcommon-x11.h',
274 name: 'xkbcommon-x11',
275 filebase: 'xkbcommon-x11',
276 libraries: libxkbcommon_x11,
277 version: meson.project_version(),
278 description: 'XKB API common to servers and clients - X11 support',
279 requires: ['xkbcommon'],
280 requires_private: ['xcb>=1.10', 'xcb-xkb>=1.10'],
286 test_env = environment()
287 test_env.set('XKB_LOG_LEVEL', 'debug')
288 test_env.set('XKB_LOG_VERBOSITY', '10')
289 test_env.set('top_srcdir', meson.source_root())
290 test_env.set('top_builddir', meson.build_root())
292 test_configh_data = configuration_data()
293 test_configh_data.set_quoted('TEST_XKB_CONFIG_ROOT', join_paths(meson.source_root(), 'test', 'data'))
294 configure_file(output: 'test-config.h', configuration: test_configh_data)
296 # Some tests need to use unexported symbols, so we link them against
297 # an internal copy of libxkbcommon with all symbols exposed.
298 libxkbcommon_test_internal = static_library(
299 'xkbcommon-test-internal',
302 'test/evdev-scancodes.h',
303 libxkbcommon_sources,
304 include_directories: include_directories('src'),
306 test_dep = declare_dependency(
307 include_directories: include_directories('src'),
308 link_with: libxkbcommon_test_internal,
310 if get_option('enable-x11')
311 x11_test_dep = declare_dependency(
312 link_with: libxkbcommon_x11_internal,
322 executable('test-keysym', 'test/keysym.c', dependencies: test_dep),
327 executable('test-keymap', 'test/keymap.c', dependencies: test_dep),
332 executable('test-filecomp', 'test/filecomp.c', dependencies: test_dep),
337 executable('test-context', 'test/context.c', dependencies: test_dep),
342 executable('test-rules-file', 'test/rules-file.c', dependencies: test_dep),
346 'rules-file-includes',
347 executable('test-rules-file-includes', 'test/rules-file-includes.c', dependencies: test_dep),
352 executable('test-stringcomp', 'test/stringcomp.c', dependencies: test_dep),
357 executable('test-buffercomp', 'test/buffercomp.c', dependencies: test_dep),
362 executable('test-log', 'test/log.c', dependencies: test_dep),
367 executable('test-atom', 'test/atom.c', dependencies: test_dep),
372 executable('test-utf8', 'test/utf8.c', dependencies: test_dep),
377 executable('test-state', 'test/state.c', dependencies: test_dep),
382 executable('test-keyseq', 'test/keyseq.c', dependencies: test_dep),
387 executable('test-rulescomp', 'test/rulescomp.c', dependencies: test_dep),
392 executable('test-compose', 'test/compose.c', dependencies: test_dep),
397 find_program('test/symbols-leak-test.bash'),
400 if get_option('enable-x11')
403 executable('test-x11', 'test/x11.c', dependencies: x11_test_dep),
406 # test/x11comp is meant to be run, but it is (temporarily?) disabled.
407 # See: https://github.com/xkbcommon/libxkbcommon/issues/30
408 executable('test-x11comp', 'test/x11comp.c', dependencies: x11_test_dep)
412 # Fuzzing target programs.
413 executable('fuzz-keymap', 'fuzz/keymap/target.c', dependencies: test_dep)
414 executable('fuzz-compose', 'fuzz/compose/target.c', dependencies: test_dep)
418 executable('rmlvo-to-kccgst', 'test/rmlvo-to-kccgst.c', dependencies: test_dep)
419 executable('rmlvo-to-keymap', 'test/rmlvo-to-keymap.c', dependencies: test_dep)
420 executable('print-compiled-keymap', 'test/print-compiled-keymap.c', dependencies: test_dep)
421 if cc.has_header('linux/input.h')
422 executable('interactive-evdev', 'test/interactive-evdev.c', dependencies: test_dep)
424 if get_option('enable-x11')
425 executable('interactive-x11', 'test/interactive-x11.c', dependencies: x11_test_dep)
427 if get_option('enable-wayland')
428 wayland_client_dep = dependency('wayland-client', version: '>=1.2.0', required: false)
429 wayland_protocols_dep = dependency('wayland-protocols', version: '>=1.12', required: false)
430 wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)
431 if not wayland_client_dep.found() or not wayland_protocols_dep.found() or not wayland_scanner_dep.found()
432 error('''The Wayland demo programs require wayland-client >= 1.2.0, wayland-protocols >= 1.7 which were not found.
433 You can disable the Wayland demo programs with -Denable-wayland=false.''')
436 wayland_scanner = find_program(wayland_scanner_dep.get_pkgconfig_variable('wayland_scanner'))
437 wayland_scanner_code_gen = generator(
439 output: '@BASENAME@-protocol.c',
440 arguments: ['code', '@INPUT@', '@OUTPUT@'],
442 wayland_scanner_client_header_gen = generator(
444 output: '@BASENAME@-client-protocol.h',
445 arguments: ['client-header', '@INPUT@', '@OUTPUT@'],
447 wayland_protocols_datadir = wayland_protocols_dep.get_pkgconfig_variable('pkgdatadir')
448 xdg_shell_xml = join_paths(wayland_protocols_datadir, 'stable/xdg-shell/xdg-shell.xml')
449 xdg_shell_sources = [
450 wayland_scanner_code_gen.process(xdg_shell_xml),
451 wayland_scanner_client_header_gen.process(xdg_shell_xml),
453 executable('interactive-wayland', 'test/interactive-wayland.c', xdg_shell_sources, dependencies: [test_dep, wayland_client_dep])
456 # xkeyboard-config "verifier"
457 xkct_config = configuration_data()
458 xkct_config.set('MESON_BUILD_ROOT', meson.build_root())
459 xkct_config.set('XKB_CONFIG_ROOT', XKBCONFIGROOT)
460 configure_file(input: 'test/xkeyboard-config-test.py.in',
461 output: 'xkeyboard-config-test',
462 configuration: xkct_config,
467 libxkbcommon_bench_internal = static_library(
468 'xkbcommon-bench-internal',
471 link_with: libxkbcommon_test_internal,
473 bench_dep = declare_dependency(
474 include_directories: include_directories('src'),
475 link_with: libxkbcommon_bench_internal,
477 bench_env = environment()
478 bench_env.set('top_srcdir', meson.source_root())
481 executable('bench-key-proc', 'bench/key-proc.c', dependencies: bench_dep),
486 executable('bench-rules', 'bench/rules.c', dependencies: bench_dep),
491 executable('bench-rulescomp', 'bench/rulescomp.c', dependencies: bench_dep),
496 executable('bench-compose', 'bench/compose.c', dependencies: bench_dep),
502 if get_option('enable-docs')
503 doxygen = find_program('doxygen', required: false)
504 if not doxygen.found()
505 error('''Documentation requires doxygen which was not found.
506 You can disable the documentation with -Denable-docs=false.''')
508 doxygen_wrapper = find_program('scripts/doxygen-wrapper')
512 'doc/doxygen-extra.css',
513 'doc/quick-guide.md',
515 'xkbcommon/xkbcommon.h',
516 'xkbcommon/xkbcommon-names.h',
517 'xkbcommon/xkbcommon-x11.h',
518 'xkbcommon/xkbcommon-compose.h',
520 doxygen_data = configuration_data()
521 doxygen_data.set('PACKAGE_NAME', meson.project_name())
522 doxygen_data.set('PACKAGE_VERSION', meson.project_version())
523 doxygen_data.set('INPUT', ' '.join(doxygen_input))
524 doxygen_data.set('OUTPUT_DIRECTORY', meson.build_root())
525 doxyfile = configure_file(
526 input: 'doc/Doxyfile.in',
528 configuration: doxygen_data,
530 # TODO: Meson should provide this.
531 docdir = join_paths(get_option('datadir'), 'doc', meson.project_name())
534 input: [doxyfile] + doxygen_input,
536 command: [doxygen_wrapper, doxygen.path(), join_paths(meson.build_root(), 'Doxyfile'), meson.source_root()],
539 build_by_default: true,