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('stdlib.h', 'secure_getenv', prefix: system_ext_define)
103 configh_data.set('HAVE_SECURE_GETENV', 1)
104 elif cc.has_header_symbol('stdlib.h', '__secure_getenv', prefix: system_ext_define)
105 configh_data.set('HAVE___SECURE_GETENV', 1)
107 message('C library does not support secure_getenv, using getenv instead')
109 configure_file(output: 'config.h', configuration: configh_data)
110 add_project_arguments('-include', 'config.h', language: 'c')
113 # Supports -Wl,--version-script?
114 have_version_script = cc.links(
116 args: '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon.map'),
117 name: '-Wl,--version-script',
122 # Note: we use some yacc extensions, which work with either GNU bison
123 # (preferred) or byacc. Other yacc's may or may not work.
124 yacc = find_program('bison', 'byacc')
125 yacc_gen = generator(
127 output: ['@BASENAME@.c', '@BASENAME@.h'],
128 arguments: ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@', '-p _xkbcommon_'],
130 libxkbcommon_sources = [
131 'src/compose/parser.c',
132 'src/compose/parser.h',
133 'src/compose/paths.c',
134 'src/compose/paths.h',
135 'src/compose/state.c',
136 'src/compose/table.c',
137 'src/compose/table.h',
138 'src/xkbcomp/action.c',
139 'src/xkbcomp/action.h',
141 'src/xkbcomp/ast-build.c',
142 'src/xkbcomp/ast-build.h',
143 'src/xkbcomp/compat.c',
144 'src/xkbcomp/expr.c',
145 'src/xkbcomp/expr.h',
146 'src/xkbcomp/include.c',
147 'src/xkbcomp/include.h',
148 'src/xkbcomp/keycodes.c',
149 'src/xkbcomp/keymap.c',
150 'src/xkbcomp/keymap-dump.c',
151 'src/xkbcomp/keywords.c',
152 yacc_gen.process('src/xkbcomp/parser.y'),
153 'src/xkbcomp/parser-priv.h',
154 'src/xkbcomp/rules.c',
155 'src/xkbcomp/rules.h',
156 'src/xkbcomp/scanner.c',
157 'src/xkbcomp/symbols.c',
158 'src/xkbcomp/types.c',
159 'src/xkbcomp/vmod.c',
160 'src/xkbcomp/vmod.h',
161 'src/xkbcomp/xkbcomp.c',
162 'src/xkbcomp/xkbcomp-priv.h',
167 'src/context-priv.c',
176 'src/scanner-utils.h',
185 libxkbcommon_link_args = []
186 if have_version_script
187 libxkbcommon_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon.map')
189 libxkbcommon = library(
191 'xkbcommon/xkbcommon.h',
192 libxkbcommon_sources,
193 link_args: libxkbcommon_link_args,
194 link_depends: 'xkbcommon.map',
197 include_directories: include_directories('src'),
200 'xkbcommon/xkbcommon.h',
201 'xkbcommon/xkbcommon-compat.h',
202 'xkbcommon/xkbcommon-compose.h',
203 'xkbcommon/xkbcommon-keysyms.h',
204 'xkbcommon/xkbcommon-names.h',
209 filebase: 'xkbcommon',
210 libraries: libxkbcommon,
211 version: meson.project_version(),
212 description: 'XKB API common to servers and clients',
217 if get_option('enable-x11')
218 xcb_dep = dependency('xcb', version: '>=1.10', required: false)
219 xcb_xkb_dep = dependency('xcb-xkb', version: '>=1.10', required: false)
220 if not xcb_dep.found() or not xcb_xkb_dep.found()
221 error('''X11 support requires xcb-xkb >= 1.10 which was not found.
222 You can disable X11 support with -Denable-x11=false.''')
225 libxkbcommon_x11_sources = [
229 'src/x11/x11-priv.h',
231 'src/context-priv.c',
237 libxkbcommon_x11_internal = static_library(
238 'xkbcommon-x11-internal',
239 libxkbcommon_x11_sources,
240 include_directories: include_directories('src'),
241 link_with: libxkbcommon,
247 libxkbcommon_x11_link_args = []
248 if have_version_script
249 libxkbcommon_x11_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon-x11.map')
251 libxkbcommon_x11 = library(
253 'xkbcommon/xkbcommon-x11.h',
254 libxkbcommon_x11_sources,
255 link_args: libxkbcommon_x11_link_args,
256 link_depends: 'xkbcommon-x11.map',
259 include_directories: include_directories('src'),
260 link_with: libxkbcommon,
267 'xkbcommon/xkbcommon-x11.h',
271 name: 'xkbcommon-x11',
272 filebase: 'xkbcommon-x11',
273 libraries: libxkbcommon_x11,
274 version: meson.project_version(),
275 description: 'XKB API common to servers and clients - X11 support',
276 requires: ['xkbcommon'],
277 requires_private: ['xcb>=1.10', 'xcb-xkb>=1.10'],
283 test_env = environment()
284 test_env.set('XKB_LOG_LEVEL', 'debug')
285 test_env.set('XKB_LOG_VERBOSITY', '10')
286 test_env.set('top_srcdir', meson.source_root())
287 test_env.set('top_builddir', meson.build_root())
288 # Some tests need to use unexported symbols, so we link them against
289 # an internal copy of libxkbcommon with all symbols exposed.
290 libxkbcommon_test_internal = static_library(
291 'xkbcommon-test-internal',
294 'test/evdev-scancodes.h',
295 libxkbcommon_sources,
296 include_directories: include_directories('src'),
298 test_dep = declare_dependency(
299 include_directories: include_directories('src'),
300 link_with: libxkbcommon_test_internal,
302 if get_option('enable-x11')
303 x11_test_dep = declare_dependency(
304 link_with: libxkbcommon_x11_internal,
314 executable('test-keysym', 'test/keysym.c', dependencies: test_dep),
319 executable('test-keymap', 'test/keymap.c', dependencies: test_dep),
324 executable('test-filecomp', 'test/filecomp.c', dependencies: test_dep),
329 executable('test-context', 'test/context.c', dependencies: test_dep),
334 executable('test-rules-file', 'test/rules-file.c', dependencies: test_dep),
339 executable('test-stringcomp', 'test/stringcomp.c', dependencies: test_dep),
344 executable('test-buffercomp', 'test/buffercomp.c', dependencies: test_dep),
349 executable('test-log', 'test/log.c', dependencies: test_dep),
354 executable('test-atom', 'test/atom.c', dependencies: test_dep),
359 executable('test-utf8', 'test/utf8.c', dependencies: test_dep),
364 executable('test-state', 'test/state.c', dependencies: test_dep),
369 executable('test-keyseq', 'test/keyseq.c', dependencies: test_dep),
374 executable('test-rulescomp', 'test/rulescomp.c', dependencies: test_dep),
379 executable('test-compose', 'test/compose.c', dependencies: test_dep),
384 find_program('test/symbols-leak-test.bash'),
387 if get_option('enable-x11')
390 executable('test-x11', 'test/x11.c', dependencies: x11_test_dep),
393 # test/x11comp is meant to be run, but it is (temporarily?) disabled.
394 # See: https://github.com/xkbcommon/libxkbcommon/issues/30
395 executable('test-x11comp', 'test/x11comp.c', dependencies: x11_test_dep)
399 # Fuzzing target programs.
400 executable('fuzz-keymap', 'fuzz/keymap/target.c', dependencies: test_dep)
401 executable('fuzz-compose', 'fuzz/compose/target.c', dependencies: test_dep)
405 executable('rmlvo-to-kccgst', 'test/rmlvo-to-kccgst.c', dependencies: test_dep)
406 executable('rmlvo-to-keymap', 'test/rmlvo-to-keymap.c', dependencies: test_dep)
407 executable('print-compiled-keymap', 'test/print-compiled-keymap.c', dependencies: test_dep)
408 if cc.has_header('linux/input.h')
409 executable('interactive-evdev', 'test/interactive-evdev.c', dependencies: test_dep)
411 if get_option('enable-x11')
412 executable('interactive-x11', 'test/interactive-x11.c', dependencies: x11_test_dep)
414 if get_option('enable-wayland')
415 wayland_client_dep = dependency('wayland-client', version: '>=1.2.0', required: false)
416 wayland_protocols_dep = dependency('wayland-protocols', version: '>=1.12', required: false)
417 wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)
418 if not wayland_client_dep.found() or not wayland_protocols_dep.found() or not wayland_scanner_dep.found()
419 error('''The Wayland demo programs require wayland-client >= 1.2.0, wayland-protocols >= 1.7 which were not found.
420 You can disable the Wayland demo programs with -Denable-wayland=false.''')
423 wayland_scanner = find_program(wayland_scanner_dep.get_pkgconfig_variable('wayland_scanner'))
424 wayland_scanner_code_gen = generator(
426 output: '@BASENAME@-protocol.c',
427 arguments: ['code', '@INPUT@', '@OUTPUT@'],
429 wayland_scanner_client_header_gen = generator(
431 output: '@BASENAME@-client-protocol.h',
432 arguments: ['client-header', '@INPUT@', '@OUTPUT@'],
434 wayland_protocols_datadir = wayland_protocols_dep.get_pkgconfig_variable('pkgdatadir')
435 xdg_shell_xml = join_paths(wayland_protocols_datadir, 'stable/xdg-shell/xdg-shell.xml')
436 xdg_shell_sources = [
437 wayland_scanner_code_gen.process(xdg_shell_xml),
438 wayland_scanner_client_header_gen.process(xdg_shell_xml),
440 executable('interactive-wayland', 'test/interactive-wayland.c', xdg_shell_sources, dependencies: [test_dep, wayland_client_dep])
443 # xkeyboard-config "verifier"
444 xkct_config = configuration_data()
445 xkct_config.set('MESON_BUILD_ROOT', meson.build_root())
446 xkct_config.set('XKB_CONFIG_ROOT', XKBCONFIGROOT)
447 configure_file(input: 'test/xkeyboard-config-test.py.in',
448 output: 'xkeyboard-config-test',
449 configuration: xkct_config,
454 libxkbcommon_bench_internal = static_library(
455 'xkbcommon-bench-internal',
458 link_with: libxkbcommon_test_internal,
460 bench_dep = declare_dependency(
461 include_directories: include_directories('src'),
462 link_with: libxkbcommon_bench_internal,
464 bench_env = environment()
465 bench_env.set('top_srcdir', meson.source_root())
468 executable('bench-key-proc', 'bench/key-proc.c', dependencies: bench_dep),
473 executable('bench-rules', 'bench/rules.c', dependencies: bench_dep),
478 executable('bench-rulescomp', 'bench/rulescomp.c', dependencies: bench_dep),
483 executable('bench-compose', 'bench/compose.c', dependencies: bench_dep),
489 if get_option('enable-docs')
490 doxygen = find_program('doxygen', required: false)
491 if not doxygen.found()
492 error('''Documentation requires doxygen which was not found.
493 You can disable the documentation with -Denable-docs=false.''')
495 doxygen_wrapper = find_program('scripts/doxygen-wrapper')
499 'doc/doxygen-extra.css',
500 'doc/quick-guide.md',
502 'xkbcommon/xkbcommon.h',
503 'xkbcommon/xkbcommon-names.h',
504 'xkbcommon/xkbcommon-x11.h',
505 'xkbcommon/xkbcommon-compose.h',
507 doxygen_data = configuration_data()
508 doxygen_data.set('PACKAGE_NAME', meson.project_name())
509 doxygen_data.set('PACKAGE_VERSION', meson.project_version())
510 doxygen_data.set('INPUT', ' '.join(doxygen_input))
511 doxygen_data.set('OUTPUT_DIRECTORY', meson.build_root())
512 doxyfile = configure_file(
513 input: 'doc/Doxyfile.in',
515 configuration: doxygen_data,
517 # TODO: Meson should provide this.
518 docdir = join_paths(get_option('datadir'), 'doc', meson.project_name())
521 input: [doxyfile] + doxygen_input,
523 command: [doxygen_wrapper, doxygen.path(), join_paths(meson.build_root(), 'Doxyfile'), meson.source_root()],
526 build_by_default: true,