Bump version to 0.8.4
[platform/upstream/libxkbcommon.git] / meson.build
1 project(
2     'libxkbcommon',
3     'c',
4     version: '0.8.4',
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_sources = [
126     'src/compose/parser.c',
127     'src/compose/parser.h',
128     'src/compose/paths.c',
129     'src/compose/paths.h',
130     'src/compose/state.c',
131     'src/compose/table.c',
132     'src/compose/table.h',
133     'src/xkbcomp/action.c',
134     'src/xkbcomp/action.h',
135     'src/xkbcomp/ast.h',
136     'src/xkbcomp/ast-build.c',
137     'src/xkbcomp/ast-build.h',
138     'src/xkbcomp/compat.c',
139     'src/xkbcomp/expr.c',
140     'src/xkbcomp/expr.h',
141     'src/xkbcomp/include.c',
142     'src/xkbcomp/include.h',
143     'src/xkbcomp/keycodes.c',
144     'src/xkbcomp/keymap.c',
145     'src/xkbcomp/keymap-dump.c',
146     'src/xkbcomp/keywords.c',
147     yacc_gen.process('src/xkbcomp/parser.y'),
148     'src/xkbcomp/parser-priv.h',
149     'src/xkbcomp/rules.c',
150     'src/xkbcomp/rules.h',
151     'src/xkbcomp/scanner.c',
152     'src/xkbcomp/symbols.c',
153     'src/xkbcomp/types.c',
154     'src/xkbcomp/vmod.c',
155     'src/xkbcomp/vmod.h',
156     'src/xkbcomp/xkbcomp.c',
157     'src/xkbcomp/xkbcomp-priv.h',
158     'src/atom.c',
159     'src/atom.h',
160     'src/context.c',
161     'src/context.h',
162     'src/context-priv.c',
163     'src/darray.h',
164     'src/keysym.c',
165     'src/keysym.h',
166     'src/keysym-utf.c',
167     'src/ks_tables.h',
168     'src/keymap.c',
169     'src/keymap.h',
170     'src/keymap-priv.c',
171     'src/scanner-utils.h',
172     'src/state.c',
173     'src/text.c',
174     'src/text.h',
175     'src/utf8.c',
176     'src/utf8.h',
177     'src/utils.c',
178     'src/utils.h',
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     libxkbcommon_sources,
188     link_args: libxkbcommon_link_args,
189     link_depends: 'xkbcommon.map',
190     version: '0.0.0',
191     install: true,
192     include_directories: include_directories('src'),
193 )
194 install_headers(
195     'xkbcommon/xkbcommon.h',
196     'xkbcommon/xkbcommon-compat.h',
197     'xkbcommon/xkbcommon-compose.h',
198     'xkbcommon/xkbcommon-keysyms.h',
199     'xkbcommon/xkbcommon-names.h',
200     subdir: 'xkbcommon',
201 )
202 pkgconfig.generate(
203     name: 'xkbcommon',
204     filebase: 'xkbcommon',
205     libraries: libxkbcommon,
206     version: meson.project_version(),
207     description: 'XKB API common to servers and clients',
208 )
209
210
211 # libxkbcommon-x11.
212 if get_option('enable-x11')
213     xcb_dep = dependency('xcb', version: '>=1.10', required: false)
214     xcb_xkb_dep = dependency('xcb-xkb', version: '>=1.10', required: false)
215     if not xcb_dep.found() or not xcb_xkb_dep.found()
216         error('''X11 support requires xcb-xkb >= 1.10 which was not found.
217 You can disable X11 support with -Denable-x11=false.''')
218     endif
219
220     libxkbcommon_x11_sources = [
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     ]
232     libxkbcommon_x11_internal = static_library(
233         'xkbcommon-x11-internal',
234         libxkbcommon_x11_sources,
235         include_directories: include_directories('src'),
236         link_with: libxkbcommon,
237         dependencies: [
238             xcb_dep,
239             xcb_xkb_dep,
240         ],
241     )
242     libxkbcommon_x11_link_args = []
243     if have_version_script
244         libxkbcommon_x11_link_args += '-Wl,--version-script=' + join_paths(meson.source_root(), 'xkbcommon-x11.map')
245     endif
246     libxkbcommon_x11 = library(
247         'xkbcommon-x11',
248         'xkbcommon/xkbcommon-x11.h',
249         libxkbcommon_x11_sources,
250         link_args: libxkbcommon_x11_link_args,
251         link_depends: 'xkbcommon-x11.map',
252         version: '0.0.0',
253         install: true,
254         include_directories: include_directories('src'),
255         link_with: libxkbcommon,
256         dependencies: [
257             xcb_dep,
258             xcb_xkb_dep,
259         ],
260     )
261     install_headers(
262         'xkbcommon/xkbcommon-x11.h',
263         subdir: 'xkbcommon',
264     )
265     pkgconfig.generate(
266         name: 'xkbcommon-x11',
267         filebase: 'xkbcommon-x11',
268         libraries: libxkbcommon_x11,
269         version: meson.project_version(),
270         description: 'XKB API common to servers and clients - X11 support',
271         requires: ['xkbcommon'],
272         requires_private: ['xcb>=1.10', 'xcb-xkb>=1.10'],
273     )
274 endif
275
276
277 # Tests
278 test_env = environment()
279 test_env.set('XKB_LOG_LEVEL', 'debug')
280 test_env.set('XKB_LOG_VERBOSITY', '10')
281 test_env.set('top_srcdir', meson.source_root())
282 test_env.set('MALLOC_PERTURB_', '15')
283 test_env.set('MallocPreScribble', '1')
284 test_env.set('MallocScribble', '1')
285 # Some tests need to use unexported symbols, so we link them against
286 # an internal copy of libxkbcommon with all symbols exposed.
287 libxkbcommon_test_internal = static_library(
288     'xkbcommon-test-internal',
289     'test/common.c',
290     'test/test.h',
291     'test/evdev-scancodes.h',
292     libxkbcommon_sources,
293     include_directories: include_directories('src'),
294 )
295 test_dep = declare_dependency(
296     include_directories: include_directories('src'),
297     link_with: libxkbcommon_test_internal,
298 )
299 if get_option('enable-x11')
300     x11_test_dep = declare_dependency(
301         link_with: libxkbcommon_x11_internal,
302         dependencies: [
303             test_dep,
304             xcb_dep,
305             xcb_xkb_dep,
306         ],
307     )
308 endif
309 test(
310     'keysym',
311     executable('test-keysym', 'test/keysym.c', dependencies: test_dep),
312     env: test_env,
313 )
314 test(
315     'keymap',
316     executable('test-keymap', 'test/keymap.c', dependencies: test_dep),
317     env: test_env,
318 )
319 test(
320     'filecomp',
321     executable('test-filecomp', 'test/filecomp.c', dependencies: test_dep),
322     env: test_env,
323 )
324 test(
325     'context',
326     executable('test-context', 'test/context.c', dependencies: test_dep),
327     env: test_env,
328 )
329 test(
330     'rules-file',
331     executable('test-rules-file', 'test/rules-file.c', dependencies: test_dep),
332     env: test_env,
333 )
334 test(
335     'stringcomp',
336     executable('test-stringcomp', 'test/stringcomp.c', dependencies: test_dep),
337     env: test_env,
338 )
339 test(
340     'buffercomp',
341     executable('test-buffercomp', 'test/buffercomp.c', dependencies: test_dep),
342     env: test_env,
343 )
344 test(
345     'log',
346     executable('test-log', 'test/log.c', dependencies: test_dep),
347     env: test_env,
348 )
349 test(
350     'atom',
351     executable('test-atom', 'test/atom.c', dependencies: test_dep),
352     env: test_env,
353 )
354 test(
355     'utf8',
356     executable('test-utf8', 'test/utf8.c', dependencies: test_dep),
357     env: test_env,
358 )
359 test(
360     'state',
361     executable('test-state', 'test/state.c', dependencies: test_dep),
362     env: test_env,
363 )
364 test(
365     'keyseq',
366     executable('test-keyseq', 'test/keyseq.c', dependencies: test_dep),
367     env: test_env,
368 )
369 test(
370     'rulescomp',
371     executable('test-rulescomp', 'test/rulescomp.c', dependencies: test_dep),
372     env: test_env,
373 )
374 test(
375     'compose',
376     executable('test-compose', 'test/compose.c', dependencies: test_dep),
377     env: test_env,
378 )
379 test(
380     'symbols-leak-test',
381     find_program('test/symbols-leak-test.bash'),
382     env: test_env,
383 )
384 if get_option('enable-x11')
385     test(
386         'x11',
387         executable('test-x11', 'test/x11.c', dependencies: x11_test_dep),
388         env: test_env,
389     )
390     # test/x11comp is meant to be run, but it is (temporarily?) disabled.
391     # See: https://github.com/xkbcommon/libxkbcommon/issues/30
392     executable('test-x11comp', 'test/x11comp.c', dependencies: x11_test_dep)
393 endif
394
395
396 # Fuzzing target programs.
397 executable('fuzz-keymap', 'fuzz/keymap/target.c', dependencies: test_dep)
398 executable('fuzz-compose', 'fuzz/compose/target.c', dependencies: test_dep)
399
400
401 # Demo programs.
402 executable('rmlvo-to-kccgst', 'test/rmlvo-to-kccgst.c', dependencies: test_dep)
403 executable('rmlvo-to-keymap', 'test/rmlvo-to-keymap.c', dependencies: test_dep)
404 executable('print-compiled-keymap', 'test/print-compiled-keymap.c', dependencies: test_dep)
405 if cc.has_header('linux/input.h')
406     executable('interactive-evdev', 'test/interactive-evdev.c', dependencies: test_dep)
407 endif
408 if get_option('enable-x11')
409     executable('interactive-x11', 'test/interactive-x11.c', dependencies: x11_test_dep)
410 endif
411 if get_option('enable-wayland')
412     wayland_client_dep = dependency('wayland-client', version: '>=1.2.0', required: false)
413     wayland_protocols_dep = dependency('wayland-protocols', version: '>=1.7', required: false)
414     wayland_scanner_dep = dependency('wayland-scanner', required: false)
415     if not wayland_client_dep.found() or not wayland_protocols_dep.found() or not wayland_scanner_dep.found()
416         error('''The Wayland demo programs require wayland-client >= 1.2.0, wayland-protocols >= 1.7 which were not found.
417 You can disable the Wayland demo programs with -Denable-wayland=false.''')
418     endif
419
420     wayland_scanner = find_program(wayland_scanner_dep.get_pkgconfig_variable('wayland_scanner'))
421     wayland_scanner_code_gen = generator(
422         wayland_scanner,
423         output: '@BASENAME@-protocol.c',
424         arguments: ['code', '@INPUT@', '@OUTPUT@'],
425     )
426     wayland_scanner_client_header_gen = generator(
427         wayland_scanner,
428         output: '@BASENAME@-client-protocol.h',
429         arguments: ['client-header', '@INPUT@', '@OUTPUT@'],
430     )
431     wayland_protocols_datadir = wayland_protocols_dep.get_pkgconfig_variable('pkgdatadir')
432     xdg_shell_xml = join_paths(wayland_protocols_datadir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml')
433     xdg_shell_sources = [
434         wayland_scanner_code_gen.process(xdg_shell_xml),
435         wayland_scanner_client_header_gen.process(xdg_shell_xml),
436     ]
437     executable('interactive-wayland', 'test/interactive-wayland.c', xdg_shell_sources, dependencies: [test_dep, wayland_client_dep])
438 endif
439
440 # xkeyboard-config "verifier"
441 xkct_config = configuration_data()
442 xkct_config.set('MESON_BUILD_ROOT', meson.build_root())
443 xkct_config.set('XKB_CONFIG_ROOT', XKBCONFIGROOT)
444 configure_file(input: 'test/xkeyboard-config-test.py.in',
445                output: 'xkeyboard-config-test',
446                configuration: xkct_config,
447                install: false)
448
449
450 # Benchmarks.
451 libxkbcommon_bench_internal = static_library(
452     'xkbcommon-bench-internal',
453     'bench/bench.c',
454     'bench/bench.h',
455     link_with: libxkbcommon_test_internal,
456 )
457 bench_dep = declare_dependency(
458     include_directories: include_directories('src'),
459     link_with: libxkbcommon_bench_internal,
460 )
461 bench_env = environment()
462 bench_env.set('top_srcdir', meson.source_root())
463 benchmark(
464     'key-proc',
465     executable('bench-key-proc', 'bench/key-proc.c', dependencies: bench_dep),
466     env: bench_env,
467 )
468 benchmark(
469     'rules',
470     executable('bench-rules', 'bench/rules.c', dependencies: bench_dep),
471     env: bench_env,
472 )
473 benchmark(
474     'rulescomp',
475     executable('bench-rulescomp', 'bench/rulescomp.c', dependencies: bench_dep),
476     env: bench_env,
477 )
478 benchmark(
479     'compose',
480     executable('bench-compose', 'bench/compose.c', dependencies: bench_dep),
481     env: bench_env,
482 )
483
484
485 # Documentation.
486 if get_option('enable-docs')
487     doxygen = find_program('doxygen', required: false)
488     if not doxygen.found()
489         error('''Documentation requires doxygen which was not found.
490 You can disable the documentation with -Denable-docs=false.''')
491     endif
492     doxygen_wrapper = find_program('scripts/doxygen-wrapper')
493
494     doxygen_input = [
495         'README.md',
496         'doc/doxygen-extra.css',
497         'doc/quick-guide.md',
498         'doc/compat.md',
499         'xkbcommon/xkbcommon.h',
500         'xkbcommon/xkbcommon-names.h',
501         'xkbcommon/xkbcommon-x11.h',
502         'xkbcommon/xkbcommon-compose.h',
503     ]
504     doxygen_data = configuration_data()
505     doxygen_data.set('PACKAGE_NAME', meson.project_name())
506     doxygen_data.set('PACKAGE_VERSION', meson.project_version())
507     doxygen_data.set('INPUT', ' '.join(doxygen_input))
508     doxygen_data.set('OUTPUT_DIRECTORY', meson.build_root())
509     doxyfile = configure_file(
510         input: 'doc/Doxyfile.in',
511         output: 'Doxyfile',
512         configuration: doxygen_data,
513     )
514     # TODO: Meson should provide this.
515     docdir = join_paths(get_option('datadir'), 'doc', meson.project_name())
516     custom_target(
517         'doc',
518         input: [doxyfile] + doxygen_input,
519         output: 'html',
520         command: [doxygen_wrapper, doxygen.path(), join_paths(meson.build_root(), 'Doxyfile'), meson.source_root()],
521         install: true,
522         install_dir: docdir,
523         build_by_default: true,
524     )
525 endif