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', 'secure_getenv', prefix: '#define _GNU_SOURCE')
88 configh_data.set('HAVE_SECURE_GETENV', 1)
89 elif cc.has_header_symbol('stdlib.h', '__secure_getenv', prefix: '#define _GNU_SOURCE')
90 configh_data.set('HAVE___SECURE_GETENV', 1)
92 message('C library does not support secure_getenv, using getenv instead')
94 configure_file(output: 'config.h', configuration: configh_data)
95 add_project_arguments('-include', 'config.h', language: 'c')
98 # Supports -Wl,--version-script?
99 have_version_script = cc.links(
101 link_args: '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon.map'),
102 name: '-Wl,--version-script',
107 # Note: we use some yacc extensions, which work with either GNU bison
108 # (preferred) or byacc. Other yacc's may or may not work.
109 yacc = find_program('bison', 'byacc')
110 yacc_gen = generator(
112 output: ['@BASENAME@.c', '@BASENAME@.h'],
113 arguments: ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@', '-p _xkbcommon_'],
115 libxkbcommon_internal = static_library(
116 'xkbcommon-internal',
117 'src/compose/parser.c',
118 'src/compose/parser.h',
119 'src/compose/paths.c',
120 'src/compose/paths.h',
121 'src/compose/state.c',
122 'src/compose/table.c',
123 'src/compose/table.h',
124 'src/xkbcomp/action.c',
125 'src/xkbcomp/action.h',
127 'src/xkbcomp/ast-build.c',
128 'src/xkbcomp/ast-build.h',
129 'src/xkbcomp/compat.c',
130 'src/xkbcomp/expr.c',
131 'src/xkbcomp/expr.h',
132 'src/xkbcomp/include.c',
133 'src/xkbcomp/include.h',
134 'src/xkbcomp/keycodes.c',
135 'src/xkbcomp/keymap.c',
136 'src/xkbcomp/keymap-dump.c',
137 'src/xkbcomp/keywords.c',
138 yacc_gen.process('src/xkbcomp/parser.y'),
139 'src/xkbcomp/parser-priv.h',
140 'src/xkbcomp/rules.c',
141 'src/xkbcomp/rules.h',
142 'src/xkbcomp/scanner.c',
143 'src/xkbcomp/symbols.c',
144 'src/xkbcomp/types.c',
145 'src/xkbcomp/vmod.c',
146 'src/xkbcomp/vmod.h',
147 'src/xkbcomp/xkbcomp.c',
148 'src/xkbcomp/xkbcomp-priv.h',
153 'src/context-priv.c',
162 'src/scanner-utils.h',
170 include_directories: include_directories('src'),
172 libxkbcommon_link_args = []
173 if have_version_script
174 libxkbcommon_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon.map')
176 libxkbcommon = library(
178 'xkbcommon/xkbcommon.h',
179 link_whole: libxkbcommon_internal,
180 link_args: libxkbcommon_link_args,
181 link_depends: 'xkbcommon.map',
186 'xkbcommon/xkbcommon.h',
187 'xkbcommon/xkbcommon-compat.h',
188 'xkbcommon/xkbcommon-compose.h',
189 'xkbcommon/xkbcommon-keysyms.h',
190 'xkbcommon/xkbcommon-names.h',
195 filebase: 'xkbcommon',
196 libraries: libxkbcommon,
197 version: meson.project_version(),
198 description: 'XKB API common to servers and clients',
203 if get_option('enable-x11')
204 xcb_dep = dependency('xcb', version: '>=1.10', required: false)
205 xcb_xkb_dep = dependency('xcb-xkb', version: '>=1.10', required: false)
206 if not xcb_dep.found() or not xcb_xkb_dep.found()
207 error('''X11 support requires xcb-xkb >= 1.10 which was not found.
208 You can disable X11 support with -Denable-x11=false.''')
211 libxkbcommon_x11_internal = static_library(
212 'xkbcommon-x11-internal',
216 'src/x11/x11-priv.h',
218 'src/context-priv.c',
223 include_directories: include_directories('src'),
224 link_with: libxkbcommon,
230 libxkbcommon_x11_link_args = []
231 if have_version_script
232 libxkbcommon_x11_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon-x11.map')
234 libxkbcommon_x11 = library(
236 'xkbcommon/xkbcommon-x11.h',
237 link_whole: libxkbcommon_x11_internal,
238 link_args: libxkbcommon_x11_link_args,
239 link_depends: 'xkbcommon-x11.map',
244 'xkbcommon/xkbcommon-x11.h',
248 name: 'xkbcommon-x11',
249 filebase: 'xkbcommon-x11',
250 libraries: libxkbcommon_x11,
251 version: meson.project_version(),
252 description: 'XKB API common to servers and clients - X11 support',
258 test_env = environment()
259 test_env.set('XKB_LOG_LEVEL', 'debug')
260 test_env.set('XKB_LOG_VERBOSITY', '10')
261 test_env.set('top_srcdir', meson.source_root())
262 test_env.set('MALLOC_PERTURB_', '15')
263 test_env.set('MallocPreScribble', '1')
264 test_env.set('MallocScribble', '1')
265 # Some tests need to use unexported symbols, so we link them against
266 # the internal copy of libxkbcommon with all symbols exposed.
267 libxkbcommon_test_internal = static_library(
268 'xkbcommon-test-internal',
271 'test/evdev-scancodes.h',
272 include_directories: include_directories('src'),
273 link_with: libxkbcommon_internal,
275 test_dep = declare_dependency(
276 include_directories: include_directories('src'),
277 link_with: libxkbcommon_test_internal,
281 executable('test-keysym', 'test/keysym.c', dependencies: test_dep),
286 executable('test-keymap', 'test/keymap.c', dependencies: test_dep),
291 executable('test-filecomp', 'test/filecomp.c', dependencies: test_dep),
296 executable('test-context', 'test/context.c', dependencies: test_dep),
301 executable('test-rules-file', 'test/rules-file.c', dependencies: test_dep),
306 executable('test-stringcomp', 'test/stringcomp.c', dependencies: test_dep),
311 executable('test-buffercomp', 'test/buffercomp.c', dependencies: test_dep),
316 executable('test-log', 'test/log.c', dependencies: test_dep),
321 executable('test-atom', 'test/atom.c', dependencies: test_dep),
326 executable('test-utf8', 'test/utf8.c', dependencies: test_dep),
331 executable('test-state', 'test/state.c', dependencies: test_dep),
336 executable('test-keyseq', 'test/keyseq.c', dependencies: test_dep),
341 executable('test-rulescomp', 'test/rulescomp.c', dependencies: test_dep),
346 executable('test-compose', 'test/compose.c', dependencies: test_dep),
351 find_program('test/symbols-leak-test.bash'),
354 if get_option('enable-x11')
357 executable('test-x11', 'test/x11.c', dependencies: test_dep, link_with: libxkbcommon_x11_internal),
360 # test/x11comp is meant to be run, but it is (temporarily?) disabled.
361 # See: https://github.com/xkbcommon/libxkbcommon/issues/30
362 executable('test-x11comp', 'test/x11comp.c', dependencies: test_dep, link_with: libxkbcommon_x11_internal)
367 executable('rmlvo-to-kccgst', 'test/rmlvo-to-kccgst.c', dependencies: test_dep)
368 executable('print-compiled-keymap', 'test/print-compiled-keymap.c', dependencies: test_dep)
369 if cc.has_header('linux/input.h')
370 executable('interactive-evdev', 'test/interactive-evdev.c', dependencies: test_dep)
372 if get_option('enable-x11')
373 executable('interactive-x11', 'test/interactive-x11.c', dependencies: test_dep, link_with: libxkbcommon_x11_internal)
375 if get_option('enable-wayland')
376 wayland_client_dep = dependency('wayland-client', version: '>=1.2.0', required: false)
377 wayland_protocols_dep = dependency('wayland-protocols', version: '>=1.7', required: false)
378 wayland_scanner_dep = dependency('wayland-scanner', required: false)
379 if not wayland_client_dep.found() or not wayland_protocols_dep.found() or not wayland_scanner_dep.found()
380 error('''The Wayland demo programs require wayland-client >= 1.2.0, wayland-protocols >= 1.7 which were not found.
381 You can disable the Wayland demo programs with -Denable-wayland=false.''')
384 wayland_scanner = find_program(wayland_scanner_dep.get_pkgconfig_variable('wayland_scanner'))
385 wayland_scanner_code_gen = generator(
387 output: '@BASENAME@-protocol.c',
388 arguments: ['code', '@INPUT@', '@OUTPUT@'],
390 wayland_scanner_client_header_gen = generator(
392 output: '@BASENAME@-client-protocol.h',
393 arguments: ['client-header', '@INPUT@', '@OUTPUT@'],
395 wayland_protocols_datadir = wayland_protocols_dep.get_pkgconfig_variable('pkgdatadir')
396 xdg_shell_xml = join_paths(wayland_protocols_datadir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml')
397 xdg_shell_sources = [
398 wayland_scanner_code_gen.process(xdg_shell_xml),
399 wayland_scanner_client_header_gen.process(xdg_shell_xml),
401 executable('interactive-wayland', 'test/interactive-wayland.c', xdg_shell_sources, dependencies: [test_dep, wayland_client_dep])
406 # For clock_gettime, on some systems.
407 rt_dep = cc.find_library('rt', required: false)
408 libxkbcommon_bench_internal = static_library(
409 'xkbcommon-bench-internal',
412 dependencies: rt_dep,
413 link_with: libxkbcommon_test_internal,
415 bench_dep = declare_dependency(
416 include_directories: include_directories('src'),
417 link_with: libxkbcommon_bench_internal,
419 bench_env = environment()
420 bench_env.set('top_srcdir', meson.source_root())
423 executable('bench-key-proc', 'bench/key-proc.c', dependencies: bench_dep),
428 executable('bench-rules', 'bench/rules.c', dependencies: bench_dep),
433 executable('bench-rulescomp', 'bench/rulescomp.c', dependencies: bench_dep),
438 executable('bench-compose', 'bench/compose.c', dependencies: bench_dep),
444 if get_option('enable-docs')
445 doxygen = find_program('doxygen', required: false)
446 if not doxygen.found()
447 error('''Documentation requires doxygen which was not found.
448 You can disable the documentation with -Denable-docs=false.''')
450 doxygen_wrapper = find_program('scripts/doxygen-wrapper')
454 'doc/doxygen-extra.css',
455 'doc/quick-guide.md',
457 'xkbcommon/xkbcommon.h',
458 'xkbcommon/xkbcommon-names.h',
459 'xkbcommon/xkbcommon-x11.h',
460 'xkbcommon/xkbcommon-compose.h',
462 doxygen_data = configuration_data()
463 doxygen_data.set('PACKAGE_NAME', meson.project_name())
464 doxygen_data.set('PACKAGE_VERSION', meson.project_version())
465 doxygen_data.set('INPUT', ' '.join(doxygen_input))
466 doxygen_data.set('OUTPUT_DIRECTORY', meson.build_root())
467 doxyfile = configure_file(
468 input: 'doc/Doxyfile.in',
470 configuration: doxygen_data,
472 # TODO: Meson should provide this.
473 docdir = join_paths(get_option('datadir'), 'doc', meson.project_name())
476 input: [doxyfile] + doxygen_input,
478 command: [doxygen_wrapper, doxygen.path(), join_paths(meson.build_root(), 'Doxyfile'), meson.source_root()],
481 build_by_default: true,