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