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