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