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