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