Bump version to 0.9.1
[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 test_env.set('MALLOC_PERTURB_', '15')
289 test_env.set('MallocPreScribble', '1')
290 test_env.set('MallocScribble', '1')
291 # Some tests need to use unexported symbols, so we link them against
292 # an internal copy of libxkbcommon with all symbols exposed.
293 libxkbcommon_test_internal = static_library(
294     'xkbcommon-test-internal',
295     'test/common.c',
296     'test/test.h',
297     'test/evdev-scancodes.h',
298     libxkbcommon_sources,
299     include_directories: include_directories('src'),
300 )
301 test_dep = declare_dependency(
302     include_directories: include_directories('src'),
303     link_with: libxkbcommon_test_internal,
304 )
305 if get_option('enable-x11')
306     x11_test_dep = declare_dependency(
307         link_with: libxkbcommon_x11_internal,
308         dependencies: [
309             test_dep,
310             xcb_dep,
311             xcb_xkb_dep,
312         ],
313     )
314 endif
315 test(
316     'keysym',
317     executable('test-keysym', 'test/keysym.c', dependencies: test_dep),
318     env: test_env,
319 )
320 test(
321     'keymap',
322     executable('test-keymap', 'test/keymap.c', dependencies: test_dep),
323     env: test_env,
324 )
325 test(
326     'filecomp',
327     executable('test-filecomp', 'test/filecomp.c', dependencies: test_dep),
328     env: test_env,
329 )
330 test(
331     'context',
332     executable('test-context', 'test/context.c', dependencies: test_dep),
333     env: test_env,
334 )
335 test(
336     'rules-file',
337     executable('test-rules-file', 'test/rules-file.c', dependencies: test_dep),
338     env: test_env,
339 )
340 test(
341     'stringcomp',
342     executable('test-stringcomp', 'test/stringcomp.c', dependencies: test_dep),
343     env: test_env,
344 )
345 test(
346     'buffercomp',
347     executable('test-buffercomp', 'test/buffercomp.c', dependencies: test_dep),
348     env: test_env,
349 )
350 test(
351     'log',
352     executable('test-log', 'test/log.c', dependencies: test_dep),
353     env: test_env,
354 )
355 test(
356     'atom',
357     executable('test-atom', 'test/atom.c', dependencies: test_dep),
358     env: test_env,
359 )
360 test(
361     'utf8',
362     executable('test-utf8', 'test/utf8.c', dependencies: test_dep),
363     env: test_env,
364 )
365 test(
366     'state',
367     executable('test-state', 'test/state.c', dependencies: test_dep),
368     env: test_env,
369 )
370 test(
371     'keyseq',
372     executable('test-keyseq', 'test/keyseq.c', dependencies: test_dep),
373     env: test_env,
374 )
375 test(
376     'rulescomp',
377     executable('test-rulescomp', 'test/rulescomp.c', dependencies: test_dep),
378     env: test_env,
379 )
380 test(
381     'compose',
382     executable('test-compose', 'test/compose.c', dependencies: test_dep),
383     env: test_env,
384 )
385 test(
386     'symbols-leak-test',
387     find_program('test/symbols-leak-test.bash'),
388     env: test_env,
389 )
390 if get_option('enable-x11')
391     test(
392         'x11',
393         executable('test-x11', 'test/x11.c', dependencies: x11_test_dep),
394         env: test_env,
395     )
396     # test/x11comp is meant to be run, but it is (temporarily?) disabled.
397     # See: https://github.com/xkbcommon/libxkbcommon/issues/30
398     executable('test-x11comp', 'test/x11comp.c', dependencies: x11_test_dep)
399 endif
400
401
402 # Fuzzing target programs.
403 executable('fuzz-keymap', 'fuzz/keymap/target.c', dependencies: test_dep)
404 executable('fuzz-compose', 'fuzz/compose/target.c', dependencies: test_dep)
405
406
407 # Demo programs.
408 executable('rmlvo-to-kccgst', 'test/rmlvo-to-kccgst.c', dependencies: test_dep)
409 executable('rmlvo-to-keymap', 'test/rmlvo-to-keymap.c', dependencies: test_dep)
410 executable('print-compiled-keymap', 'test/print-compiled-keymap.c', dependencies: test_dep)
411 if cc.has_header('linux/input.h')
412     executable('interactive-evdev', 'test/interactive-evdev.c', dependencies: test_dep)
413 endif
414 if get_option('enable-x11')
415     executable('interactive-x11', 'test/interactive-x11.c', dependencies: x11_test_dep)
416 endif
417 if get_option('enable-wayland')
418     wayland_client_dep = dependency('wayland-client', version: '>=1.2.0', required: false)
419     wayland_protocols_dep = dependency('wayland-protocols', version: '>=1.12', required: false)
420     wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)
421     if not wayland_client_dep.found() or not wayland_protocols_dep.found() or not wayland_scanner_dep.found()
422         error('''The Wayland demo programs require wayland-client >= 1.2.0, wayland-protocols >= 1.7 which were not found.
423 You can disable the Wayland demo programs with -Denable-wayland=false.''')
424     endif
425
426     wayland_scanner = find_program(wayland_scanner_dep.get_pkgconfig_variable('wayland_scanner'))
427     wayland_scanner_code_gen = generator(
428         wayland_scanner,
429         output: '@BASENAME@-protocol.c',
430         arguments: ['code', '@INPUT@', '@OUTPUT@'],
431     )
432     wayland_scanner_client_header_gen = generator(
433         wayland_scanner,
434         output: '@BASENAME@-client-protocol.h',
435         arguments: ['client-header', '@INPUT@', '@OUTPUT@'],
436     )
437     wayland_protocols_datadir = wayland_protocols_dep.get_pkgconfig_variable('pkgdatadir')
438     xdg_shell_xml = join_paths(wayland_protocols_datadir, 'stable/xdg-shell/xdg-shell.xml')
439     xdg_shell_sources = [
440         wayland_scanner_code_gen.process(xdg_shell_xml),
441         wayland_scanner_client_header_gen.process(xdg_shell_xml),
442     ]
443     executable('interactive-wayland', 'test/interactive-wayland.c', xdg_shell_sources, dependencies: [test_dep, wayland_client_dep])
444 endif
445
446 # xkeyboard-config "verifier"
447 xkct_config = configuration_data()
448 xkct_config.set('MESON_BUILD_ROOT', meson.build_root())
449 xkct_config.set('XKB_CONFIG_ROOT', XKBCONFIGROOT)
450 configure_file(input: 'test/xkeyboard-config-test.py.in',
451                output: 'xkeyboard-config-test',
452                configuration: xkct_config,
453                install: false)
454
455
456 # Benchmarks.
457 libxkbcommon_bench_internal = static_library(
458     'xkbcommon-bench-internal',
459     'bench/bench.c',
460     'bench/bench.h',
461     link_with: libxkbcommon_test_internal,
462 )
463 bench_dep = declare_dependency(
464     include_directories: include_directories('src'),
465     link_with: libxkbcommon_bench_internal,
466 )
467 bench_env = environment()
468 bench_env.set('top_srcdir', meson.source_root())
469 benchmark(
470     'key-proc',
471     executable('bench-key-proc', 'bench/key-proc.c', dependencies: bench_dep),
472     env: bench_env,
473 )
474 benchmark(
475     'rules',
476     executable('bench-rules', 'bench/rules.c', dependencies: bench_dep),
477     env: bench_env,
478 )
479 benchmark(
480     'rulescomp',
481     executable('bench-rulescomp', 'bench/rulescomp.c', dependencies: bench_dep),
482     env: bench_env,
483 )
484 benchmark(
485     'compose',
486     executable('bench-compose', 'bench/compose.c', dependencies: bench_dep),
487     env: bench_env,
488 )
489
490
491 # Documentation.
492 if get_option('enable-docs')
493     doxygen = find_program('doxygen', required: false)
494     if not doxygen.found()
495         error('''Documentation requires doxygen which was not found.
496 You can disable the documentation with -Denable-docs=false.''')
497     endif
498     doxygen_wrapper = find_program('scripts/doxygen-wrapper')
499
500     doxygen_input = [
501         'README.md',
502         'doc/doxygen-extra.css',
503         'doc/quick-guide.md',
504         'doc/compat.md',
505         'xkbcommon/xkbcommon.h',
506         'xkbcommon/xkbcommon-names.h',
507         'xkbcommon/xkbcommon-x11.h',
508         'xkbcommon/xkbcommon-compose.h',
509     ]
510     doxygen_data = configuration_data()
511     doxygen_data.set('PACKAGE_NAME', meson.project_name())
512     doxygen_data.set('PACKAGE_VERSION', meson.project_version())
513     doxygen_data.set('INPUT', ' '.join(doxygen_input))
514     doxygen_data.set('OUTPUT_DIRECTORY', meson.build_root())
515     doxyfile = configure_file(
516         input: 'doc/Doxyfile.in',
517         output: 'Doxyfile',
518         configuration: doxygen_data,
519     )
520     # TODO: Meson should provide this.
521     docdir = join_paths(get_option('datadir'), 'doc', meson.project_name())
522     custom_target(
523         'doc',
524         input: [doxyfile] + doxygen_input,
525         output: 'html',
526         command: [doxygen_wrapper, doxygen.path(), join_paths(meson.build_root(), 'Doxyfile'), meson.source_root()],
527         install: true,
528         install_dir: docdir,
529         build_by_default: true,
530     )
531 endif