Merge pull request #68 from whot/wip/xkeyboard-config-tester
[platform/upstream/libxkbcommon.git] / meson.build
1 project(
2     'libxkbcommon',
3     'c',
4     version: '0.8.2',
5     default_options: [
6         'c_std=c99',
7         'warning_level=2',
8         'b_lundef=true',
9     ],
10     meson_version : '>= 0.41.0',
11 )
12 pkgconfig = import('pkgconfig')
13 cc = meson.get_compiler('c')
14
15
16 # Compiler flags.
17 foreach cflag: [
18     '-fvisibility=hidden',
19     '-fno-strict-aliasing',
20     '-fsanitize-undefined-trap-on-error',
21     '-Wextra',
22     '-Wno-unused-parameter',
23     '-Wno-missing-field-initializers',
24     '-Wpointer-arith',
25     '-Wmissing-declarations',
26     '-Wformat=2',
27     '-Wstrict-prototypes',
28     '-Wmissing-prototypes',
29     '-Wnested-externs',
30     '-Wbad-function-cast',
31     '-Wshadow',
32     '-Wlogical-op',
33     '-Wdate-time',
34     '-Wwrite-strings',
35     '-Wno-documentation-deprecated-sync',
36 ]
37     if cc.has_argument(cflag)
38         add_project_arguments(cflag, language: 'c')
39     endif
40 endforeach
41
42
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')
49     else
50         XKBCONFIGROOT = join_paths(get_option('prefix'), get_option('datadir'), 'X11', 'xkb')
51   endif
52 endif
53
54
55 # The X locale directory for compose.
56 XLOCALEDIR = get_option('x-locale-root')
57 if XLOCALEDIR == ''
58     XLOCALEDIR = join_paths(get_option('prefix'), get_option('datadir'), 'X11', 'locale')
59 endif
60
61
62 # config.h.
63 configh_data = configuration_data()
64 configh_data.set('_GNU_SOURCE', 1)
65 configh_data.set_quoted('DFLT_XKB_CONFIG_ROOT', XKBCONFIGROOT)
66 configh_data.set_quoted('XLOCALEDIR', XLOCALEDIR)
67 configh_data.set_quoted('DEFAULT_XKB_RULES', get_option('default-rules'))
68 configh_data.set_quoted('DEFAULT_XKB_MODEL', get_option('default-model'))
69 configh_data.set_quoted('DEFAULT_XKB_LAYOUT', get_option('default-layout'))
70 if get_option('default-variant') != ''
71     configh_data.set_quoted('DEFAULT_XKB_VARIANT', get_option('default-variant'))
72 endif
73 if get_option('default-options') != ''
74     configh_data.set_quoted('DEFAULT_XKB_OPTIONS', get_option('default-options'))
75 endif
76 if cc.links('int main(){if(__builtin_expect(1<0,0)){}}', name: '__builtin_expect')
77     configh_data.set('HAVE___BUILTIN_EXPECT', 1)
78 endif
79 if cc.links('int main(){__builtin_popcount(1);}', name: '__builtin_popcount')
80     configh_data.set('HAVE___BUILTIN_POPCOUNT', 1)
81 endif
82 if cc.has_header_symbol('unistd.h', 'eaccess', prefix: '#define _GNU_SOURCE')
83     configh_data.set('HAVE_EACCESS', 1)
84 endif
85 if cc.has_header_symbol('unistd.h', 'euidaccess', prefix: '#define _GNU_SOURCE')
86     configh_data.set('HAVE_EUIDACCESS', 1)
87 endif
88 if cc.has_header_symbol('sys/mman.h', 'mmap')
89     configh_data.set('HAVE_MMAP', 1)
90 endif
91 if cc.has_header_symbol('stdlib.h', 'mkostemp', prefix: '#define _GNU_SOURCE')
92     configh_data.set('HAVE_MKOSTEMP', 1)
93 endif
94 if cc.has_header_symbol('fcntl.h', 'posix_fallocate', prefix: '#define _GNU_SOURCE')
95     configh_data.set('HAVE_POSIX_FALLOCATE', 1)
96 endif
97 if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix: '#define _GNU_SOURCE')
98     configh_data.set('HAVE_SECURE_GETENV', 1)
99 elif cc.has_header_symbol('stdlib.h', '__secure_getenv', prefix: '#define _GNU_SOURCE')
100     configh_data.set('HAVE___SECURE_GETENV', 1)
101 else
102     message('C library does not support secure_getenv, using getenv instead')
103 endif
104 configure_file(output: 'config.h', configuration: configh_data)
105 add_project_arguments('-include', 'config.h', language: 'c')
106
107
108 # Supports -Wl,--version-script?
109 have_version_script = cc.links(
110     'int main(){}',
111     args: '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon.map'),
112     name: '-Wl,--version-script',
113 )
114
115
116 # libxkbcommon.
117 # Note: we use some yacc extensions, which work with either GNU bison
118 # (preferred) or byacc. Other yacc's may or may not work.
119 yacc = find_program('bison', 'byacc')
120 yacc_gen = generator(
121     yacc,
122     output: ['@BASENAME@.c', '@BASENAME@.h'],
123     arguments: ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@', '-p _xkbcommon_'],
124 )
125 libxkbcommon_internal = static_library(
126     'xkbcommon-internal',
127     'src/compose/parser.c',
128     'src/compose/parser.h',
129     'src/compose/paths.c',
130     'src/compose/paths.h',
131     'src/compose/state.c',
132     'src/compose/table.c',
133     'src/compose/table.h',
134     'src/xkbcomp/action.c',
135     'src/xkbcomp/action.h',
136     'src/xkbcomp/ast.h',
137     'src/xkbcomp/ast-build.c',
138     'src/xkbcomp/ast-build.h',
139     'src/xkbcomp/compat.c',
140     'src/xkbcomp/expr.c',
141     'src/xkbcomp/expr.h',
142     'src/xkbcomp/include.c',
143     'src/xkbcomp/include.h',
144     'src/xkbcomp/keycodes.c',
145     'src/xkbcomp/keymap.c',
146     'src/xkbcomp/keymap-dump.c',
147     'src/xkbcomp/keywords.c',
148     yacc_gen.process('src/xkbcomp/parser.y'),
149     'src/xkbcomp/parser-priv.h',
150     'src/xkbcomp/rules.c',
151     'src/xkbcomp/rules.h',
152     'src/xkbcomp/scanner.c',
153     'src/xkbcomp/symbols.c',
154     'src/xkbcomp/types.c',
155     'src/xkbcomp/vmod.c',
156     'src/xkbcomp/vmod.h',
157     'src/xkbcomp/xkbcomp.c',
158     'src/xkbcomp/xkbcomp-priv.h',
159     'src/atom.c',
160     'src/atom.h',
161     'src/context.c',
162     'src/context.h',
163     'src/context-priv.c',
164     'src/darray.h',
165     'src/keysym.c',
166     'src/keysym.h',
167     'src/keysym-utf.c',
168     'src/ks_tables.h',
169     'src/keymap.c',
170     'src/keymap.h',
171     'src/keymap-priv.c',
172     'src/scanner-utils.h',
173     'src/state.c',
174     'src/text.c',
175     'src/text.h',
176     'src/utf8.c',
177     'src/utf8.h',
178     'src/utils.c',
179     'src/utils.h',
180     include_directories: include_directories('src'),
181 )
182 libxkbcommon_link_args = []
183 if have_version_script
184     libxkbcommon_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon.map')
185 endif
186 libxkbcommon = library(
187     'xkbcommon',
188     'xkbcommon/xkbcommon.h',
189     link_whole: libxkbcommon_internal,
190     link_args: libxkbcommon_link_args,
191     link_depends: 'xkbcommon.map',
192     version: '0.0.0',
193     install: true,
194 )
195 install_headers(
196     'xkbcommon/xkbcommon.h',
197     'xkbcommon/xkbcommon-compat.h',
198     'xkbcommon/xkbcommon-compose.h',
199     'xkbcommon/xkbcommon-keysyms.h',
200     'xkbcommon/xkbcommon-names.h',
201     subdir: 'xkbcommon',
202 )
203 pkgconfig.generate(
204     name: 'xkbcommon',
205     filebase: 'xkbcommon',
206     libraries: libxkbcommon,
207     version: meson.project_version(),
208     description: 'XKB API common to servers and clients',
209 )
210
211
212 # libxkbcommon-x11.
213 if get_option('enable-x11')
214     xcb_dep = dependency('xcb', version: '>=1.10', required: false)
215     xcb_xkb_dep = dependency('xcb-xkb', version: '>=1.10', required: false)
216     if not xcb_dep.found() or not xcb_xkb_dep.found()
217         error('''X11 support requires xcb-xkb >= 1.10 which was not found.
218 You can disable X11 support with -Denable-x11=false.''')
219     endif
220
221     libxkbcommon_x11_internal = static_library(
222         'xkbcommon-x11-internal',
223         'src/x11/keymap.c',
224         'src/x11/state.c',
225         'src/x11/util.c',
226         'src/x11/x11-priv.h',
227         'src/context.h',
228         'src/context-priv.c',
229         'src/keymap.h',
230         'src/keymap-priv.c',
231         'src/atom.h',
232         'src/atom.c',
233         include_directories: include_directories('src'),
234         link_with: libxkbcommon,
235         dependencies: [
236             xcb_dep,
237             xcb_xkb_dep,
238         ],
239     )
240     libxkbcommon_x11_link_args = []
241     if have_version_script
242         libxkbcommon_x11_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon-x11.map')
243     endif
244     libxkbcommon_x11 = library(
245         'xkbcommon-x11',
246         'xkbcommon/xkbcommon-x11.h',
247         link_whole: libxkbcommon_x11_internal,
248         link_args: libxkbcommon_x11_link_args,
249         link_depends: 'xkbcommon-x11.map',
250         version: '0.0.0',
251         install: true,
252     )
253     install_headers(
254         'xkbcommon/xkbcommon-x11.h',
255         subdir: 'xkbcommon',
256     )
257     pkgconfig.generate(
258         name: 'xkbcommon-x11',
259         filebase: 'xkbcommon-x11',
260         libraries: libxkbcommon_x11,
261         version: meson.project_version(),
262         description: 'XKB API common to servers and clients - X11 support',
263         requires: ['xkbcommon'],
264         requires_private: ['xcb>=1.10', 'xcb-xkb>=1.10'],
265     )
266 endif
267
268
269 # Tests
270 test_env = environment()
271 test_env.set('XKB_LOG_LEVEL', 'debug')
272 test_env.set('XKB_LOG_VERBOSITY', '10')
273 test_env.set('top_srcdir', meson.source_root())
274 test_env.set('MALLOC_PERTURB_', '15')
275 test_env.set('MallocPreScribble', '1')
276 test_env.set('MallocScribble', '1')
277 # Some tests need to use unexported symbols, so we link them against
278 # the internal copy of libxkbcommon with all symbols exposed.
279 libxkbcommon_test_internal = static_library(
280     'xkbcommon-test-internal',
281     'test/common.c',
282     'test/test.h',
283     'test/evdev-scancodes.h',
284     include_directories: include_directories('src'),
285     link_with: libxkbcommon_internal,
286 )
287 test_dep = declare_dependency(
288     include_directories: include_directories('src'),
289     link_with: libxkbcommon_test_internal,
290 )
291 if get_option('enable-x11')
292     x11_test_dep = declare_dependency(
293         link_with: libxkbcommon_x11_internal,
294         dependencies: [
295             test_dep,
296             xcb_dep,
297             xcb_xkb_dep,
298         ],
299     )
300 endif
301 test(
302     'keysym',
303     executable('test-keysym', 'test/keysym.c', dependencies: test_dep),
304     env: test_env,
305 )
306 test(
307     'keymap',
308     executable('test-keymap', 'test/keymap.c', dependencies: test_dep),
309     env: test_env,
310 )
311 test(
312     'filecomp',
313     executable('test-filecomp', 'test/filecomp.c', dependencies: test_dep),
314     env: test_env,
315 )
316 test(
317     'context',
318     executable('test-context', 'test/context.c', dependencies: test_dep),
319     env: test_env,
320 )
321 test(
322     'rules-file',
323     executable('test-rules-file', 'test/rules-file.c', dependencies: test_dep),
324     env: test_env,
325 )
326 test(
327     'stringcomp',
328     executable('test-stringcomp', 'test/stringcomp.c', dependencies: test_dep),
329     env: test_env,
330 )
331 test(
332     'buffercomp',
333     executable('test-buffercomp', 'test/buffercomp.c', dependencies: test_dep),
334     env: test_env,
335 )
336 test(
337     'log',
338     executable('test-log', 'test/log.c', dependencies: test_dep),
339     env: test_env,
340 )
341 test(
342     'atom',
343     executable('test-atom', 'test/atom.c', dependencies: test_dep),
344     env: test_env,
345 )
346 test(
347     'utf8',
348     executable('test-utf8', 'test/utf8.c', dependencies: test_dep),
349     env: test_env,
350 )
351 test(
352     'state',
353     executable('test-state', 'test/state.c', dependencies: test_dep),
354     env: test_env,
355 )
356 test(
357     'keyseq',
358     executable('test-keyseq', 'test/keyseq.c', dependencies: test_dep),
359     env: test_env,
360 )
361 test(
362     'rulescomp',
363     executable('test-rulescomp', 'test/rulescomp.c', dependencies: test_dep),
364     env: test_env,
365 )
366 test(
367     'compose',
368     executable('test-compose', 'test/compose.c', dependencies: test_dep),
369     env: test_env,
370 )
371 test(
372     'symbols-leak-test',
373     find_program('test/symbols-leak-test.bash'),
374     env: test_env,
375 )
376 if get_option('enable-x11')
377     test(
378         'x11',
379         executable('test-x11', 'test/x11.c', dependencies: x11_test_dep),
380         env: test_env,
381     )
382     # test/x11comp is meant to be run, but it is (temporarily?) disabled.
383     # See: https://github.com/xkbcommon/libxkbcommon/issues/30
384     executable('test-x11comp', 'test/x11comp.c', dependencies: x11_test_dep)
385 endif
386
387
388 # Fuzzing target programs.
389 executable('fuzz-keymap', 'fuzz/keymap/target.c', dependencies: test_dep)
390 executable('fuzz-compose', 'fuzz/compose/target.c', dependencies: test_dep)
391
392
393 # Demo programs.
394 executable('rmlvo-to-kccgst', 'test/rmlvo-to-kccgst.c', dependencies: test_dep)
395 executable('rmlvo-to-keymap', 'test/rmlvo-to-keymap.c', dependencies: test_dep)
396 executable('print-compiled-keymap', 'test/print-compiled-keymap.c', dependencies: test_dep)
397 if cc.has_header('linux/input.h')
398     executable('interactive-evdev', 'test/interactive-evdev.c', dependencies: test_dep)
399 endif
400 if get_option('enable-x11')
401     executable('interactive-x11', 'test/interactive-x11.c', dependencies: x11_test_dep)
402 endif
403 if get_option('enable-wayland')
404     wayland_client_dep = dependency('wayland-client', version: '>=1.2.0', required: false)
405     wayland_protocols_dep = dependency('wayland-protocols', version: '>=1.7', required: false)
406     wayland_scanner_dep = dependency('wayland-scanner', required: false)
407     if not wayland_client_dep.found() or not wayland_protocols_dep.found() or not wayland_scanner_dep.found()
408         error('''The Wayland demo programs require wayland-client >= 1.2.0, wayland-protocols >= 1.7 which were not found.
409 You can disable the Wayland demo programs with -Denable-wayland=false.''')
410     endif
411
412     wayland_scanner = find_program(wayland_scanner_dep.get_pkgconfig_variable('wayland_scanner'))
413     wayland_scanner_code_gen = generator(
414         wayland_scanner,
415         output: '@BASENAME@-protocol.c',
416         arguments: ['code', '@INPUT@', '@OUTPUT@'],
417     )
418     wayland_scanner_client_header_gen = generator(
419         wayland_scanner,
420         output: '@BASENAME@-client-protocol.h',
421         arguments: ['client-header', '@INPUT@', '@OUTPUT@'],
422     )
423     wayland_protocols_datadir = wayland_protocols_dep.get_pkgconfig_variable('pkgdatadir')
424     xdg_shell_xml = join_paths(wayland_protocols_datadir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml')
425     xdg_shell_sources = [
426         wayland_scanner_code_gen.process(xdg_shell_xml),
427         wayland_scanner_client_header_gen.process(xdg_shell_xml),
428     ]
429     executable('interactive-wayland', 'test/interactive-wayland.c', xdg_shell_sources, dependencies: [test_dep, wayland_client_dep])
430 endif
431
432 # xkeyboard-config "verifier"
433 xkct_config = configuration_data()
434 xkct_config.set('MESON_BUILD_ROOT', meson.build_root())
435 xkct_config.set('XKB_CONFIG_ROOT', XKBCONFIGROOT)
436 configure_file(input: 'test/xkeyboard-config-test.py.in',
437                output: 'xkeyboard-config-test',
438                configuration: xkct_config,
439                install: false)
440
441
442 # Benchmarks.
443 libxkbcommon_bench_internal = static_library(
444     'xkbcommon-bench-internal',
445     'bench/bench.c',
446     'bench/bench.h',
447     link_with: libxkbcommon_test_internal,
448 )
449 bench_dep = declare_dependency(
450     include_directories: include_directories('src'),
451     link_with: libxkbcommon_bench_internal,
452 )
453 bench_env = environment()
454 bench_env.set('top_srcdir', meson.source_root())
455 benchmark(
456     'key-proc',
457     executable('bench-key-proc', 'bench/key-proc.c', dependencies: bench_dep),
458     env: bench_env,
459 )
460 benchmark(
461     'rules',
462     executable('bench-rules', 'bench/rules.c', dependencies: bench_dep),
463     env: bench_env,
464 )
465 benchmark(
466     'rulescomp',
467     executable('bench-rulescomp', 'bench/rulescomp.c', dependencies: bench_dep),
468     env: bench_env,
469 )
470 benchmark(
471     'compose',
472     executable('bench-compose', 'bench/compose.c', dependencies: bench_dep),
473     env: bench_env,
474 )
475
476
477 # Documentation.
478 if get_option('enable-docs')
479     doxygen = find_program('doxygen', required: false)
480     if not doxygen.found()
481         error('''Documentation requires doxygen which was not found.
482 You can disable the documentation with -Denable-docs=false.''')
483     endif
484     doxygen_wrapper = find_program('scripts/doxygen-wrapper')
485
486     doxygen_input = [
487         'README.md',
488         'doc/doxygen-extra.css',
489         'doc/quick-guide.md',
490         'doc/compat.md',
491         'xkbcommon/xkbcommon.h',
492         'xkbcommon/xkbcommon-names.h',
493         'xkbcommon/xkbcommon-x11.h',
494         'xkbcommon/xkbcommon-compose.h',
495     ]
496     doxygen_data = configuration_data()
497     doxygen_data.set('PACKAGE_NAME', meson.project_name())
498     doxygen_data.set('PACKAGE_VERSION', meson.project_version())
499     doxygen_data.set('INPUT', ' '.join(doxygen_input))
500     doxygen_data.set('OUTPUT_DIRECTORY', meson.build_root())
501     doxyfile = configure_file(
502         input: 'doc/Doxyfile.in',
503         output: 'Doxyfile',
504         configuration: doxygen_data,
505     )
506     # TODO: Meson should provide this.
507     docdir = join_paths(get_option('datadir'), 'doc', meson.project_name())
508     custom_target(
509         'doc',
510         input: [doxyfile] + doxygen_input,
511         output: 'html',
512         command: [doxygen_wrapper, doxygen.path(), join_paths(meson.build_root(), 'Doxyfile'), meson.source_root()],
513         install: true,
514         install_dir: docdir,
515         build_by_default: true,
516     )
517 endif