11 pkgconfig = import('pkgconfig')
12 cc = meson.get_compiler('c')
17 '-fvisibility=hidden',
19 '-Wno-unused-parameter',
20 '-Wno-missing-field-initializers',
22 '-Wmissing-declarations',
24 '-Wstrict-prototypes',
25 '-Wmissing-prototypes',
27 '-Wbad-function-cast',
33 if cc.has_argument(cflag)
34 add_project_arguments(cflag, language: 'c')
39 # The XKB config root.
40 XKBCONFIGROOT = get_option('xkb-config-root')
41 if XKBCONFIGROOT == ''
42 xkeyboard_config_dep = dependency('xkeyboard-config', required: false)
43 if xkeyboard_config_dep.found()
44 XKBCONFIGROOT = xkeyboard_config_dep.get_pkgconfig_variable('xkb_base')
46 XKBCONFIGROOT = join_paths(get_option('prefix'), get_option('datadir'), 'X11', 'xkb')
51 # The X locale directory for compose.
52 XLOCALEDIR = get_option('x-locale-root')
54 XLOCALEDIR = join_paths(get_option('prefix'), get_option('datadir'), 'X11', 'locale')
59 configh_data = configuration_data()
60 configh_data.set('_GNU_SOURCE', 1)
61 configh_data.set_quoted('DFLT_XKB_CONFIG_ROOT', XKBCONFIGROOT)
62 configh_data.set_quoted('XLOCALEDIR', XLOCALEDIR)
63 configh_data.set_quoted('DEFAULT_XKB_RULES', get_option('default-rules'))
64 configh_data.set_quoted('DEFAULT_XKB_MODEL', get_option('default-model'))
65 configh_data.set_quoted('DEFAULT_XKB_LAYOUT', get_option('default-layout'))
66 if get_option('default-variant') != ''
67 configh_data.set_quoted('DEFAULT_XKB_VARIANT', get_option('default-variant'))
69 if get_option('default-options') != ''
70 configh_data.set_quoted('DEFAULT_XKB_OPTIONS', get_option('default-options'))
72 if cc.links('int main(){if(__builtin_expect(1<0,0)){}}', name: '__builtin_expect')
73 configh_data.set('HAVE___BUILTIN_EXPECT', 1)
75 if cc.links('int main(){__builtin_popcount(1);}', name: '__builtin_popcount')
76 configh_data.set('HAVE___BUILTIN_POPCOUNT', 1)
78 if cc.has_header_symbol('unistd.h', 'eaccess', prefix: '#define _GNU_SOURCE')
79 configh_data.set('HAVE_EACCESS', 1)
81 if cc.has_header_symbol('unistd.h', 'euidaccess', prefix: '#define _GNU_SOURCE')
82 configh_data.set('HAVE_EUIDACCESS', 1)
84 if cc.has_header_symbol('sys/mman.h', 'mmap')
85 configh_data.set('HAVE_MMAP', 1)
87 if cc.has_header_symbol('stdlib.h', 'mkostemp', prefix: '#define _GNU_SOURCE')
88 configh_data.set('HAVE_MKOSTEMP', 1)
90 if cc.has_header_symbol('fcntl.h', 'posix_fallocate', prefix: '#define _GNU_SOURCE')
91 configh_data.set('HAVE_POSIX_FALLOCATE', 1)
93 if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix: '#define _GNU_SOURCE')
94 configh_data.set('HAVE_SECURE_GETENV', 1)
95 elif cc.has_header_symbol('stdlib.h', '__secure_getenv', prefix: '#define _GNU_SOURCE')
96 configh_data.set('HAVE___SECURE_GETENV', 1)
98 message('C library does not support secure_getenv, using getenv instead')
100 configure_file(output: 'config.h', configuration: configh_data)
101 add_project_arguments('-include', 'config.h', language: 'c')
104 # Supports -Wl,--version-script?
105 have_version_script = cc.links(
107 link_args: '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon.map'),
108 name: '-Wl,--version-script',
113 # Note: we use some yacc extensions, which work with either GNU bison
114 # (preferred) or byacc. Other yacc's may or may not work.
115 yacc = find_program('bison', 'byacc')
116 yacc_gen = generator(
118 output: ['@BASENAME@.c', '@BASENAME@.h'],
119 arguments: ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@', '-p _xkbcommon_'],
121 libxkbcommon_internal = static_library(
122 'xkbcommon-internal',
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',
176 include_directories: include_directories('src'),
178 libxkbcommon_link_args = []
179 if have_version_script
180 libxkbcommon_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon.map')
182 libxkbcommon = library(
184 'xkbcommon/xkbcommon.h',
185 link_whole: libxkbcommon_internal,
186 link_args: libxkbcommon_link_args,
187 link_depends: 'xkbcommon.map',
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_internal = static_library(
218 'xkbcommon-x11-internal',
222 'src/x11/x11-priv.h',
224 'src/context-priv.c',
229 include_directories: include_directories('src'),
230 link_with: libxkbcommon,
236 libxkbcommon_x11_link_args = []
237 if have_version_script
238 libxkbcommon_x11_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon-x11.map')
240 libxkbcommon_x11 = library(
242 'xkbcommon/xkbcommon-x11.h',
243 link_whole: libxkbcommon_x11_internal,
244 link_args: libxkbcommon_x11_link_args,
245 link_depends: 'xkbcommon-x11.map',
250 'xkbcommon/xkbcommon-x11.h',
254 name: 'xkbcommon-x11',
255 filebase: 'xkbcommon-x11',
256 libraries: libxkbcommon_x11,
257 version: meson.project_version(),
258 description: 'XKB API common to servers and clients - X11 support',
264 test_env = environment()
265 test_env.set('XKB_LOG_LEVEL', 'debug')
266 test_env.set('XKB_LOG_VERBOSITY', '10')
267 test_env.set('top_srcdir', meson.source_root())
268 test_env.set('MALLOC_PERTURB_', '15')
269 test_env.set('MallocPreScribble', '1')
270 test_env.set('MallocScribble', '1')
271 # Some tests need to use unexported symbols, so we link them against
272 # the internal copy of libxkbcommon with all symbols exposed.
273 libxkbcommon_test_internal = static_library(
274 'xkbcommon-test-internal',
277 'test/evdev-scancodes.h',
278 include_directories: include_directories('src'),
279 link_with: libxkbcommon_internal,
281 test_dep = declare_dependency(
282 include_directories: include_directories('src'),
283 link_with: libxkbcommon_test_internal,
287 executable('test-keysym', 'test/keysym.c', dependencies: test_dep),
292 executable('test-keymap', 'test/keymap.c', dependencies: test_dep),
297 executable('test-filecomp', 'test/filecomp.c', dependencies: test_dep),
302 executable('test-context', 'test/context.c', dependencies: test_dep),
307 executable('test-rules-file', 'test/rules-file.c', dependencies: test_dep),
312 executable('test-stringcomp', 'test/stringcomp.c', dependencies: test_dep),
317 executable('test-buffercomp', 'test/buffercomp.c', dependencies: test_dep),
322 executable('test-log', 'test/log.c', dependencies: test_dep),
327 executable('test-atom', 'test/atom.c', dependencies: test_dep),
332 executable('test-utf8', 'test/utf8.c', dependencies: test_dep),
337 executable('test-state', 'test/state.c', dependencies: test_dep),
342 executable('test-keyseq', 'test/keyseq.c', dependencies: test_dep),
347 executable('test-rulescomp', 'test/rulescomp.c', dependencies: test_dep),
352 executable('test-compose', 'test/compose.c', dependencies: test_dep),
357 find_program('test/symbols-leak-test.bash'),
360 if get_option('enable-x11')
363 executable('test-x11', 'test/x11.c', dependencies: test_dep, link_with: libxkbcommon_x11_internal),
366 # test/x11comp is meant to be run, but it is (temporarily?) disabled.
367 # See: https://github.com/xkbcommon/libxkbcommon/issues/30
368 executable('test-x11comp', 'test/x11comp.c', dependencies: test_dep, link_with: libxkbcommon_x11_internal)
373 executable('rmlvo-to-kccgst', 'test/rmlvo-to-kccgst.c', dependencies: test_dep)
374 executable('print-compiled-keymap', 'test/print-compiled-keymap.c', dependencies: test_dep)
375 if cc.has_header('linux/input.h')
376 executable('interactive-evdev', 'test/interactive-evdev.c', dependencies: test_dep)
378 if get_option('enable-x11')
379 executable('interactive-x11', 'test/interactive-x11.c', dependencies: test_dep, link_with: libxkbcommon_x11_internal)
381 if get_option('enable-wayland')
382 wayland_client_dep = dependency('wayland-client', version: '>=1.2.0', required: false)
383 wayland_protocols_dep = dependency('wayland-protocols', version: '>=1.7', required: false)
384 wayland_scanner_dep = dependency('wayland-scanner', required: false)
385 if not wayland_client_dep.found() or not wayland_protocols_dep.found() or not wayland_scanner_dep.found()
386 error('''The Wayland demo programs require wayland-client >= 1.2.0, wayland-protocols >= 1.7 which were not found.
387 You can disable the Wayland demo programs with -Denable-wayland=false.''')
390 wayland_scanner = find_program(wayland_scanner_dep.get_pkgconfig_variable('wayland_scanner'))
391 wayland_scanner_code_gen = generator(
393 output: '@BASENAME@-protocol.c',
394 arguments: ['code', '@INPUT@', '@OUTPUT@'],
396 wayland_scanner_client_header_gen = generator(
398 output: '@BASENAME@-client-protocol.h',
399 arguments: ['client-header', '@INPUT@', '@OUTPUT@'],
401 wayland_protocols_datadir = wayland_protocols_dep.get_pkgconfig_variable('pkgdatadir')
402 xdg_shell_xml = join_paths(wayland_protocols_datadir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml')
403 xdg_shell_sources = [
404 wayland_scanner_code_gen.process(xdg_shell_xml),
405 wayland_scanner_client_header_gen.process(xdg_shell_xml),
407 executable('interactive-wayland', 'test/interactive-wayland.c', xdg_shell_sources, dependencies: [test_dep, wayland_client_dep])
412 # For clock_gettime, on some systems.
413 rt_dep = cc.find_library('rt', required: false)
414 libxkbcommon_bench_internal = static_library(
415 'xkbcommon-bench-internal',
418 dependencies: rt_dep,
419 link_with: libxkbcommon_test_internal,
421 bench_dep = declare_dependency(
422 include_directories: include_directories('src'),
423 link_with: libxkbcommon_bench_internal,
425 bench_env = environment()
426 bench_env.set('top_srcdir', meson.source_root())
429 executable('bench-key-proc', 'bench/key-proc.c', dependencies: bench_dep),
434 executable('bench-rules', 'bench/rules.c', dependencies: bench_dep),
439 executable('bench-rulescomp', 'bench/rulescomp.c', dependencies: bench_dep),
444 executable('bench-compose', 'bench/compose.c', dependencies: bench_dep),
450 if get_option('enable-docs')
451 doxygen = find_program('doxygen', required: false)
452 if not doxygen.found()
453 error('''Documentation requires doxygen which was not found.
454 You can disable the documentation with -Denable-docs=false.''')
456 doxygen_wrapper = find_program('scripts/doxygen-wrapper')
460 'doc/doxygen-extra.css',
461 'doc/quick-guide.md',
463 'xkbcommon/xkbcommon.h',
464 'xkbcommon/xkbcommon-names.h',
465 'xkbcommon/xkbcommon-x11.h',
466 'xkbcommon/xkbcommon-compose.h',
468 doxygen_data = configuration_data()
469 doxygen_data.set('PACKAGE_NAME', meson.project_name())
470 doxygen_data.set('PACKAGE_VERSION', meson.project_version())
471 doxygen_data.set('INPUT', ' '.join(doxygen_input))
472 doxygen_data.set('OUTPUT_DIRECTORY', meson.build_root())
473 doxyfile = configure_file(
474 input: 'doc/Doxyfile.in',
476 configuration: doxygen_data,
478 # TODO: Meson should provide this.
479 docdir = join_paths(get_option('datadir'), 'doc', meson.project_name())
482 input: [doxyfile] + doxygen_input,
484 command: [doxygen_wrapper, doxygen.path(), join_paths(meson.build_root(), 'Doxyfile'), meson.source_root()],
487 build_by_default: true,