10 meson_version : '>= 0.41.0',
12 pkgconfig = import('pkgconfig')
13 cc = meson.get_compiler('c')
18 '-fvisibility=hidden',
20 '-Wno-unused-parameter',
21 '-Wno-missing-field-initializers',
23 '-Wmissing-declarations',
25 '-Wstrict-prototypes',
26 '-Wmissing-prototypes',
28 '-Wbad-function-cast',
34 if cc.has_argument(cflag)
35 add_project_arguments(cflag, language: 'c')
40 # The XKB config root.
41 XKBCONFIGROOT = get_option('xkb-config-root')
42 if XKBCONFIGROOT == ''
43 xkeyboard_config_dep = dependency('xkeyboard-config', required: false)
44 if xkeyboard_config_dep.found()
45 XKBCONFIGROOT = xkeyboard_config_dep.get_pkgconfig_variable('xkb_base')
47 XKBCONFIGROOT = join_paths(get_option('prefix'), get_option('datadir'), 'X11', 'xkb')
52 # The X locale directory for compose.
53 XLOCALEDIR = get_option('x-locale-root')
55 XLOCALEDIR = join_paths(get_option('prefix'), get_option('datadir'), 'X11', 'locale')
60 configh_data = configuration_data()
61 configh_data.set('_GNU_SOURCE', 1)
62 configh_data.set_quoted('DFLT_XKB_CONFIG_ROOT', XKBCONFIGROOT)
63 configh_data.set_quoted('XLOCALEDIR', XLOCALEDIR)
64 configh_data.set_quoted('DEFAULT_XKB_RULES', get_option('default-rules'))
65 configh_data.set_quoted('DEFAULT_XKB_MODEL', get_option('default-model'))
66 configh_data.set_quoted('DEFAULT_XKB_LAYOUT', get_option('default-layout'))
67 if get_option('default-variant') != ''
68 configh_data.set_quoted('DEFAULT_XKB_VARIANT', get_option('default-variant'))
70 if get_option('default-options') != ''
71 configh_data.set_quoted('DEFAULT_XKB_OPTIONS', get_option('default-options'))
73 if cc.links('int main(){if(__builtin_expect(1<0,0)){}}', name: '__builtin_expect')
74 configh_data.set('HAVE___BUILTIN_EXPECT', 1)
76 if cc.links('int main(){__builtin_popcount(1);}', name: '__builtin_popcount')
77 configh_data.set('HAVE___BUILTIN_POPCOUNT', 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 link_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_internal = static_library(
123 'xkbcommon-internal',
124 'src/compose/parser.c',
125 'src/compose/parser.h',
126 'src/compose/paths.c',
127 'src/compose/paths.h',
128 'src/compose/state.c',
129 'src/compose/table.c',
130 'src/compose/table.h',
131 'src/xkbcomp/action.c',
132 'src/xkbcomp/action.h',
134 'src/xkbcomp/ast-build.c',
135 'src/xkbcomp/ast-build.h',
136 'src/xkbcomp/compat.c',
137 'src/xkbcomp/expr.c',
138 'src/xkbcomp/expr.h',
139 'src/xkbcomp/include.c',
140 'src/xkbcomp/include.h',
141 'src/xkbcomp/keycodes.c',
142 'src/xkbcomp/keymap.c',
143 'src/xkbcomp/keymap-dump.c',
144 'src/xkbcomp/keywords.c',
145 yacc_gen.process('src/xkbcomp/parser.y'),
146 'src/xkbcomp/parser-priv.h',
147 'src/xkbcomp/rules.c',
148 'src/xkbcomp/rules.h',
149 'src/xkbcomp/scanner.c',
150 'src/xkbcomp/symbols.c',
151 'src/xkbcomp/types.c',
152 'src/xkbcomp/vmod.c',
153 'src/xkbcomp/vmod.h',
154 'src/xkbcomp/xkbcomp.c',
155 'src/xkbcomp/xkbcomp-priv.h',
160 'src/context-priv.c',
169 'src/scanner-utils.h',
177 include_directories: include_directories('src'),
179 libxkbcommon_link_args = []
180 if have_version_script
181 libxkbcommon_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon.map')
183 libxkbcommon = library(
185 'xkbcommon/xkbcommon.h',
186 link_whole: libxkbcommon_internal,
187 link_args: libxkbcommon_link_args,
188 link_depends: 'xkbcommon.map',
193 'xkbcommon/xkbcommon.h',
194 'xkbcommon/xkbcommon-compat.h',
195 'xkbcommon/xkbcommon-compose.h',
196 'xkbcommon/xkbcommon-keysyms.h',
197 'xkbcommon/xkbcommon-names.h',
202 filebase: 'xkbcommon',
203 libraries: libxkbcommon,
204 version: meson.project_version(),
205 description: 'XKB API common to servers and clients',
210 if get_option('enable-x11')
211 xcb_dep = dependency('xcb', version: '>=1.10', required: false)
212 xcb_xkb_dep = dependency('xcb-xkb', version: '>=1.10', required: false)
213 if not xcb_dep.found() or not xcb_xkb_dep.found()
214 error('''X11 support requires xcb-xkb >= 1.10 which was not found.
215 You can disable X11 support with -Denable-x11=false.''')
218 libxkbcommon_x11_internal = static_library(
219 'xkbcommon-x11-internal',
223 'src/x11/x11-priv.h',
225 'src/context-priv.c',
230 include_directories: include_directories('src'),
231 link_with: libxkbcommon,
237 libxkbcommon_x11_link_args = []
238 if have_version_script
239 libxkbcommon_x11_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon-x11.map')
241 libxkbcommon_x11 = library(
243 'xkbcommon/xkbcommon-x11.h',
244 link_whole: libxkbcommon_x11_internal,
245 link_args: libxkbcommon_x11_link_args,
246 link_depends: 'xkbcommon-x11.map',
251 'xkbcommon/xkbcommon-x11.h',
255 name: 'xkbcommon-x11',
256 filebase: 'xkbcommon-x11',
257 libraries: libxkbcommon_x11,
258 version: meson.project_version(),
259 description: 'XKB API common to servers and clients - X11 support',
265 test_env = environment()
266 test_env.set('XKB_LOG_LEVEL', 'debug')
267 test_env.set('XKB_LOG_VERBOSITY', '10')
268 test_env.set('top_srcdir', meson.source_root())
269 test_env.set('MALLOC_PERTURB_', '15')
270 test_env.set('MallocPreScribble', '1')
271 test_env.set('MallocScribble', '1')
272 # Some tests need to use unexported symbols, so we link them against
273 # the internal copy of libxkbcommon with all symbols exposed.
274 libxkbcommon_test_internal = static_library(
275 'xkbcommon-test-internal',
278 'test/evdev-scancodes.h',
279 include_directories: include_directories('src'),
280 link_with: libxkbcommon_internal,
282 test_dep = declare_dependency(
283 include_directories: include_directories('src'),
284 link_with: libxkbcommon_test_internal,
288 executable('test-keysym', 'test/keysym.c', dependencies: test_dep),
293 executable('test-keymap', 'test/keymap.c', dependencies: test_dep),
298 executable('test-filecomp', 'test/filecomp.c', dependencies: test_dep),
303 executable('test-context', 'test/context.c', dependencies: test_dep),
308 executable('test-rules-file', 'test/rules-file.c', dependencies: test_dep),
313 executable('test-stringcomp', 'test/stringcomp.c', dependencies: test_dep),
318 executable('test-buffercomp', 'test/buffercomp.c', dependencies: test_dep),
323 executable('test-log', 'test/log.c', dependencies: test_dep),
328 executable('test-atom', 'test/atom.c', dependencies: test_dep),
333 executable('test-utf8', 'test/utf8.c', dependencies: test_dep),
338 executable('test-state', 'test/state.c', dependencies: test_dep),
343 executable('test-keyseq', 'test/keyseq.c', dependencies: test_dep),
348 executable('test-rulescomp', 'test/rulescomp.c', dependencies: test_dep),
353 executable('test-compose', 'test/compose.c', dependencies: test_dep),
358 find_program('test/symbols-leak-test.bash'),
361 if get_option('enable-x11')
364 executable('test-x11', 'test/x11.c', dependencies: test_dep, link_with: libxkbcommon_x11_internal),
367 # test/x11comp is meant to be run, but it is (temporarily?) disabled.
368 # See: https://github.com/xkbcommon/libxkbcommon/issues/30
369 executable('test-x11comp', 'test/x11comp.c', dependencies: test_dep, link_with: libxkbcommon_x11_internal)
374 executable('rmlvo-to-kccgst', 'test/rmlvo-to-kccgst.c', dependencies: test_dep)
375 executable('print-compiled-keymap', 'test/print-compiled-keymap.c', dependencies: test_dep)
376 if cc.has_header('linux/input.h')
377 executable('interactive-evdev', 'test/interactive-evdev.c', dependencies: test_dep)
379 if get_option('enable-x11')
380 executable('interactive-x11', 'test/interactive-x11.c', dependencies: test_dep, link_with: libxkbcommon_x11_internal)
382 if get_option('enable-wayland')
383 wayland_client_dep = dependency('wayland-client', version: '>=1.2.0', required: false)
384 wayland_protocols_dep = dependency('wayland-protocols', version: '>=1.7', required: false)
385 wayland_scanner_dep = dependency('wayland-scanner', required: false)
386 if not wayland_client_dep.found() or not wayland_protocols_dep.found() or not wayland_scanner_dep.found()
387 error('''The Wayland demo programs require wayland-client >= 1.2.0, wayland-protocols >= 1.7 which were not found.
388 You can disable the Wayland demo programs with -Denable-wayland=false.''')
391 wayland_scanner = find_program(wayland_scanner_dep.get_pkgconfig_variable('wayland_scanner'))
392 wayland_scanner_code_gen = generator(
394 output: '@BASENAME@-protocol.c',
395 arguments: ['code', '@INPUT@', '@OUTPUT@'],
397 wayland_scanner_client_header_gen = generator(
399 output: '@BASENAME@-client-protocol.h',
400 arguments: ['client-header', '@INPUT@', '@OUTPUT@'],
402 wayland_protocols_datadir = wayland_protocols_dep.get_pkgconfig_variable('pkgdatadir')
403 xdg_shell_xml = join_paths(wayland_protocols_datadir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml')
404 xdg_shell_sources = [
405 wayland_scanner_code_gen.process(xdg_shell_xml),
406 wayland_scanner_client_header_gen.process(xdg_shell_xml),
408 executable('interactive-wayland', 'test/interactive-wayland.c', xdg_shell_sources, dependencies: [test_dep, wayland_client_dep])
413 # For clock_gettime, on some systems.
414 rt_dep = cc.find_library('rt', required: false)
415 libxkbcommon_bench_internal = static_library(
416 'xkbcommon-bench-internal',
419 dependencies: rt_dep,
420 link_with: libxkbcommon_test_internal,
422 bench_dep = declare_dependency(
423 include_directories: include_directories('src'),
424 link_with: libxkbcommon_bench_internal,
426 bench_env = environment()
427 bench_env.set('top_srcdir', meson.source_root())
430 executable('bench-key-proc', 'bench/key-proc.c', dependencies: bench_dep),
435 executable('bench-rules', 'bench/rules.c', dependencies: bench_dep),
440 executable('bench-rulescomp', 'bench/rulescomp.c', dependencies: bench_dep),
445 executable('bench-compose', 'bench/compose.c', dependencies: bench_dep),
451 if get_option('enable-docs')
452 doxygen = find_program('doxygen', required: false)
453 if not doxygen.found()
454 error('''Documentation requires doxygen which was not found.
455 You can disable the documentation with -Denable-docs=false.''')
457 doxygen_wrapper = find_program('scripts/doxygen-wrapper')
461 'doc/doxygen-extra.css',
462 'doc/quick-guide.md',
464 'xkbcommon/xkbcommon.h',
465 'xkbcommon/xkbcommon-names.h',
466 'xkbcommon/xkbcommon-x11.h',
467 'xkbcommon/xkbcommon-compose.h',
469 doxygen_data = configuration_data()
470 doxygen_data.set('PACKAGE_NAME', meson.project_name())
471 doxygen_data.set('PACKAGE_VERSION', meson.project_version())
472 doxygen_data.set('INPUT', ' '.join(doxygen_input))
473 doxygen_data.set('OUTPUT_DIRECTORY', meson.build_root())
474 doxyfile = configure_file(
475 input: 'doc/Doxyfile.in',
477 configuration: doxygen_data,
479 # TODO: Meson should provide this.
480 docdir = join_paths(get_option('datadir'), 'doc', meson.project_name())
483 input: [doxyfile] + doxygen_input,
485 command: [doxygen_wrapper, doxygen.path(), join_paths(meson.build_root(), 'Doxyfile'), meson.source_root()],
488 build_by_default: true,