packaging: Bump to version 0.4.3
[platform/upstream/libxkbcommon.git] / meson.build
1 project(
2     'libxkbcommon',
3     'c',
4     version: '1.6.0',
5     default_options: [
6         'c_std=c11',
7         'warning_level=2',
8         'b_lundef=true',
9     ],
10     meson_version : '>= 0.52.0',
11 )
12 pkgconfig = import('pkgconfig')
13 cc = meson.get_compiler('c')
14
15 dir_libexec = get_option('prefix')/get_option('libexecdir')/'xkbcommon'
16
17 # Compiler flags.
18 cflags = [
19     '-fno-strict-aliasing',
20     '-Wno-unused-parameter',
21     '-Wno-missing-field-initializers',
22     '-Wpointer-arith',
23     '-Wmissing-declarations',
24     '-Wformat=2',
25     '-Wstrict-prototypes',
26     '-Wmissing-prototypes',
27     '-Wnested-externs',
28     '-Wbad-function-cast',
29     '-Wshadow',
30     '-Wlogical-op',
31     '-Wdate-time',
32     '-Wwrite-strings',
33     '-Wno-documentation-deprecated-sync',
34 ]
35 add_project_arguments(cc.get_supported_arguments(cflags), language: 'c')
36
37
38 # The XKB config root.
39 XKBCONFIGROOT = get_option('xkb-config-root')
40 if XKBCONFIGROOT == ''
41     xkeyboard_config_dep = dependency('xkeyboard-config', required: false)
42     if xkeyboard_config_dep.found()
43         XKBCONFIGROOT = xkeyboard_config_dep.get_variable(pkgconfig: 'xkb_base')
44     else
45         XKBCONFIGROOT = get_option('prefix')/get_option('datadir')/'X11'/'xkb'
46   endif
47 endif
48
49 XKBCONFIGEXTRAPATH = get_option('xkb-config-extra-path')
50 if XKBCONFIGEXTRAPATH == ''
51     XKBCONFIGEXTRAPATH = get_option('prefix')/get_option('sysconfdir')/'xkb'
52 endif
53
54 # The X locale directory for compose.
55 XLOCALEDIR = get_option('x-locale-root')
56 if XLOCALEDIR == ''
57     XLOCALEDIR = get_option('prefix')/get_option('datadir')/'X11'/'locale'
58 endif
59
60
61 # config.h.
62 configh_data = configuration_data()
63 configh_data.set('EXIT_INVALID_USAGE', '2')
64 configh_data.set_quoted('LIBXKBCOMMON_VERSION', meson.project_version())
65 configh_data.set_quoted('LIBXKBCOMMON_TOOL_PATH', dir_libexec)
66 # Like AC_USE_SYSTEM_EXTENSIONS, what #define to use to get extensions
67 # beyond the base POSIX function set.
68 if host_machine.system() == 'sunos'
69   system_extensions = '__EXTENSIONS__'
70 else
71   system_extensions = '_GNU_SOURCE'
72 endif
73 configh_data.set(system_extensions, 1)
74 system_ext_define = '#define ' + system_extensions
75 configh_data.set_quoted('DFLT_XKB_CONFIG_ROOT', XKBCONFIGROOT)
76 configh_data.set_quoted('DFLT_XKB_CONFIG_EXTRA_PATH', XKBCONFIGEXTRAPATH)
77 configh_data.set_quoted('XLOCALEDIR', XLOCALEDIR)
78 configh_data.set_quoted('DEFAULT_XKB_RULES', get_option('default-rules'))
79 configh_data.set_quoted('DEFAULT_XKB_MODEL', get_option('default-model'))
80 configh_data.set_quoted('DEFAULT_XKB_LAYOUT', get_option('default-layout'))
81 if get_option('default-variant') != ''
82     configh_data.set_quoted('DEFAULT_XKB_VARIANT', get_option('default-variant'))
83 else
84     configh_data.set('DEFAULT_XKB_VARIANT', 'NULL')
85 endif
86 if get_option('default-options') != ''
87     configh_data.set_quoted('DEFAULT_XKB_OPTIONS', get_option('default-options'))
88 else
89     configh_data.set('DEFAULT_XKB_OPTIONS', 'NULL')
90 endif
91 if cc.has_header('unistd.h')
92     configh_data.set('HAVE_UNISTD_H', 1)
93 endif
94 if cc.links('int main(){if(__builtin_expect(1<0,0)){}}', name: '__builtin_expect')
95     configh_data.set('HAVE___BUILTIN_EXPECT', 1)
96 endif
97 if cc.has_header_symbol('unistd.h', 'eaccess', prefix: system_ext_define)
98     configh_data.set('HAVE_EACCESS', 1)
99 endif
100 if cc.has_header_symbol('unistd.h', 'euidaccess', prefix: system_ext_define)
101     configh_data.set('HAVE_EUIDACCESS', 1)
102 endif
103 if cc.has_header_symbol('sys/mman.h', 'mmap')
104     configh_data.set('HAVE_MMAP', 1)
105 endif
106 if cc.has_header_symbol('stdlib.h', 'mkostemp', prefix: system_ext_define)
107     configh_data.set('HAVE_MKOSTEMP', 1)
108 endif
109 if cc.has_header_symbol('fcntl.h', 'posix_fallocate', prefix: system_ext_define)
110     configh_data.set('HAVE_POSIX_FALLOCATE', 1)
111 endif
112 if cc.has_header_symbol('string.h', 'strndup', prefix: system_ext_define)
113     configh_data.set('HAVE_STRNDUP', 1)
114 endif
115 if cc.has_header_symbol('stdio.h', 'asprintf', prefix: system_ext_define)
116     configh_data.set('HAVE_ASPRINTF', 1)
117 elif cc.has_header_symbol('stdio.h', 'vasprintf', prefix: system_ext_define)
118     configh_data.set('HAVE_VASPRINTF', 1)
119 endif
120 if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix: system_ext_define)
121     configh_data.set('HAVE_SECURE_GETENV', 1)
122 elif cc.has_header_symbol('stdlib.h', '__secure_getenv', prefix: system_ext_define)
123     configh_data.set('HAVE___SECURE_GETENV', 1)
124 else
125     message('C library does not support secure_getenv, using getenv instead')
126 endif
127 if not cc.has_header_symbol('limits.h', 'PATH_MAX', prefix: system_ext_define)
128     if host_machine.system() == 'windows'
129         # see https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation
130         configh_data.set('PATH_MAX', 260)
131     else
132         configh_data.set('PATH_MAX', 4096)
133     endif
134 endif
135
136 # Silence some security & deprecation warnings on MSVC
137 # for some unix/C functions we use.
138 # https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4996?view=vs-2019
139 configh_data.set('_CRT_SECURE_NO_WARNINGS', 1)
140 configh_data.set('_CRT_NONSTDC_NO_WARNINGS', 1)
141 configh_data.set('_CRT_NONSTDC_NO_DEPRECATE', 1)
142 # Reduce unnecessary includes on MSVC.
143 configh_data.set('WIN32_LEAN_AND_MEAN', 1)
144
145 # Supports -Wl,--version-script?
146 have_version_script = cc.links(
147     'int main(){}',
148     args: '-Wl,--version-script=' + meson.current_source_dir()/'xkbcommon.map',
149     name: '-Wl,--version-script',
150 )
151
152 map_to_def = find_program('scripts/map-to-def')
153
154 # libxkbcommon.
155 # Note: we use some yacc extensions, which work with either GNU bison
156 # (preferred) or byacc (with backtracking enabled).
157 bison = find_program('bison', 'win_bison', required: false, version: '>= 2.3a')
158 if bison.found()
159     yacc = bison
160     yacc_gen = generator(
161         bison,
162         output: ['@BASENAME@.c', '@BASENAME@.h'],
163         arguments: ['--defines=@OUTPUT1@', '-o', '@OUTPUT0@', '-p', '_xkbcommon_', '@INPUT@'],
164     )
165 else
166     byacc = find_program('byacc', required: false)
167     if byacc.found()
168         yacc = byacc
169         yacc_gen = generator(
170             byacc,
171             output: ['@BASENAME@.c', '@BASENAME@.h'],
172             arguments: ['-H', '@OUTPUT1@', '-o', '@OUTPUT0@', '-p', '_xkbcommon_', '@INPUT@'],
173         )
174     else
175         error('Could not find a compatible YACC program (bison or byacc)')
176     endif
177 endif
178 libxkbcommon_sources = [
179     'src/compose/parser.c',
180     'src/compose/parser.h',
181     'src/compose/paths.c',
182     'src/compose/paths.h',
183     'src/compose/state.c',
184     'src/compose/table.c',
185     'src/compose/table.h',
186     'src/xkbcomp/action.c',
187     'src/xkbcomp/action.h',
188     'src/xkbcomp/ast.h',
189     'src/xkbcomp/ast-build.c',
190     'src/xkbcomp/ast-build.h',
191     'src/xkbcomp/compat.c',
192     'src/xkbcomp/expr.c',
193     'src/xkbcomp/expr.h',
194     'src/xkbcomp/include.c',
195     'src/xkbcomp/include.h',
196     'src/xkbcomp/keycodes.c',
197     'src/xkbcomp/keymap.c',
198     'src/xkbcomp/keymap-dump.c',
199     'src/xkbcomp/keywords.c',
200     yacc_gen.process('src/xkbcomp/parser.y'),
201     'src/xkbcomp/parser-priv.h',
202     'src/xkbcomp/rules.c',
203     'src/xkbcomp/rules.h',
204     'src/xkbcomp/scanner.c',
205     'src/xkbcomp/symbols.c',
206     'src/xkbcomp/types.c',
207     'src/xkbcomp/vmod.c',
208     'src/xkbcomp/vmod.h',
209     'src/xkbcomp/xkbcomp.c',
210     'src/xkbcomp/xkbcomp-priv.h',
211     'src/atom.c',
212     'src/atom.h',
213     'src/context.c',
214     'src/context.h',
215     'src/context-priv.c',
216     'src/darray.h',
217     'src/keysym.c',
218     'src/keysym.h',
219     'src/keysym-utf.c',
220     'src/ks_tables.h',
221     'src/keymap.c',
222     'src/keymap.h',
223     'src/keymap-priv.c',
224     'src/messages-codes.h',
225     'src/scanner-utils.h',
226     'src/state.c',
227     'src/text.c',
228     'src/text.h',
229     'src/utf8.c',
230     'src/utf8.h',
231     'src/utils.c',
232     'src/utils.h',
233 ]
234 libxkbcommon_link_args = []
235 libxkbcommon_link_deps = []
236 if have_version_script
237     libxkbcommon_link_args += '-Wl,--version-script=' + meson.current_source_dir()/'xkbcommon.map'
238     libxkbcommon_link_deps += 'xkbcommon.map'
239 elif cc.get_argument_syntax() == 'msvc'
240     libxkbcommon_def = custom_target('xkbcommon.def',
241         command: [map_to_def, '@INPUT@', '@OUTPUT@'],
242         input: 'xkbcommon.map',
243         output: 'kxbcommon.def',
244     )
245     libxkbcommon_link_deps += libxkbcommon_def
246     libxkbcommon_link_args += '/DEF:' + libxkbcommon_def.full_path()
247 endif
248 libxkbcommon = library(
249     'xkbcommon',
250     'include/xkbcommon/xkbcommon.h',
251     libxkbcommon_sources,
252     link_args: libxkbcommon_link_args,
253     link_depends: libxkbcommon_link_deps,
254     gnu_symbol_visibility: 'hidden',
255     version: '0.0.0',
256     install: true,
257     include_directories: include_directories('src', 'include'),
258 )
259 install_headers(
260     'include/xkbcommon/xkbcommon.h',
261     'include/xkbcommon/xkbcommon-compat.h',
262     'include/xkbcommon/xkbcommon-compose.h',
263     'include/xkbcommon/xkbcommon-keysyms.h',
264     'include/xkbcommon/xkbcommon-names.h',
265     subdir: 'xkbcommon',
266 )
267
268 dep_libxkbcommon = declare_dependency(
269     link_with: libxkbcommon,
270     include_directories: include_directories('include'),
271 )
272 if meson.version().version_compare('>= 0.54.0')
273     meson.override_dependency('xkbcommon', dep_libxkbcommon)
274 endif
275 pkgconfig.generate(
276     libxkbcommon,
277     name: 'xkbcommon',
278     filebase: 'xkbcommon',
279     version: meson.project_version(),
280     description: 'XKB API common to servers and clients',
281 )
282
283
284 # libxkbcommon-x11.
285 if get_option('enable-x11')
286     xcb_dep = dependency('xcb', version: '>=1.10', required: false)
287     xcb_xkb_dep = dependency('xcb-xkb', version: '>=1.10', required: false)
288     if not xcb_dep.found() or not xcb_xkb_dep.found()
289         error('''X11 support requires xcb-xkb >= 1.10 which was not found.
290 You can disable X11 support with -Denable-x11=false.''')
291     endif
292
293     libxkbcommon_x11_sources = [
294         'src/x11/keymap.c',
295         'src/x11/state.c',
296         'src/x11/util.c',
297         'src/x11/x11-priv.h',
298         'src/context.h',
299         'src/context-priv.c',
300         'src/keymap.h',
301         'src/keymap-priv.c',
302         'src/atom.h',
303         'src/atom.c',
304     ]
305     libxkbcommon_x11_link_args = []
306     libxkbcommon_x11_link_deps = []
307     if have_version_script
308         libxkbcommon_x11_link_args += '-Wl,--version-script=' + meson.current_source_dir()/'xkbcommon-x11.map'
309         libxkbcommon_x11_link_deps += 'xkbcommon-x11.map'
310     elif cc.get_argument_syntax() == 'msvc'
311         libxkbcommon_x11_def = custom_target('xkbcommon-x11.def',
312             command: [map_to_def, '@INPUT@', '@OUTPUT@'],
313             input: 'xkbcommon-x11.map',
314             output: 'xkbcommon-x11.def',
315         )
316         libxkbcommon_x11_link_deps += libxkbcommon_x11_def
317         libxkbcommon_x11_link_args += '/DEF:' + libxkbcommon_x11_def.full_path()
318     endif
319     libxkbcommon_x11 = library(
320         'xkbcommon-x11',
321         'include/xkbcommon/xkbcommon-x11.h',
322         libxkbcommon_x11_sources,
323         link_args: libxkbcommon_x11_link_args,
324         link_depends: libxkbcommon_x11_link_deps,
325         gnu_symbol_visibility: 'hidden',
326         version: '0.0.0',
327         install: true,
328         include_directories: include_directories('src', 'include'),
329         link_with: libxkbcommon,
330         dependencies: [
331             xcb_dep,
332             xcb_xkb_dep,
333         ],
334     )
335     install_headers(
336         'include/xkbcommon/xkbcommon-x11.h',
337         subdir: 'xkbcommon',
338     )
339     dep_libxkbcommon_x11 = declare_dependency(
340         link_with: libxkbcommon_x11,
341         include_directories: include_directories('include'),
342     )
343     if meson.version().version_compare('>= 0.54.0')
344         meson.override_dependency('xkbcommon-x11', dep_libxkbcommon_x11)
345     endif
346     pkgconfig.generate(
347         libxkbcommon_x11,
348         name: 'xkbcommon-x11',
349         filebase: 'xkbcommon-x11',
350         version: meson.project_version(),
351         description: 'XKB API common to servers and clients - X11 support',
352         requires: ['xkbcommon'],
353         requires_private: ['xcb>=1.10', 'xcb-xkb>=1.10'],
354     )
355 endif
356
357 # libxkbregistry
358 if get_option('enable-xkbregistry')
359     dep_libxml = dependency('libxml-2.0')
360     deps_libxkbregistry = [dep_libxml]
361     libxkbregistry_sources = [
362         'src/registry.c',
363         'src/utils.h',
364         'src/utils.c',
365         'src/util-list.h',
366         'src/util-list.c',
367     ]
368     libxkbregistry_link_args = []
369     libxkbregistry_link_deps = []
370     if have_version_script
371         libxkbregistry_link_args += '-Wl,--version-script=' + meson.current_source_dir()/'xkbregistry.map'
372         libxkbregistry_link_deps += 'xkbregistry.map'
373     elif cc.get_argument_syntax() == 'msvc'
374         libxkbregistry_def = custom_target('xkbregistry.def',
375             command: [map_to_def, '@INPUT@', '@OUTPUT@'],
376             input: 'xkbregistry.map',
377             output: 'xkbregistry.def',
378         )
379         libxkbregistry_link_deps += libxkbregistry_def
380         libxkbregistry_link_args += '/DEF:' + libxkbregistry_def.full_path()
381     endif
382     libxkbregistry = library(
383         'xkbregistry',
384         'include/xkbcommon/xkbregistry.h',
385         libxkbregistry_sources,
386         link_args: libxkbregistry_link_args,
387         link_depends: libxkbregistry_link_deps,
388         gnu_symbol_visibility: 'hidden',
389         dependencies: deps_libxkbregistry,
390         version: '0.0.0',
391         install: true,
392         include_directories: include_directories('src', 'include'),
393     )
394     install_headers(
395         'include/xkbcommon/xkbregistry.h',
396         subdir: 'xkbcommon',
397     )
398     pkgconfig.generate(
399         libxkbregistry,
400         name: 'xkbregistry',
401         filebase: 'xkbregistry',
402         version: meson.project_version(),
403         description: 'XKB API to query available rules, models, layouts, variants and options',
404     )
405
406     dep_libxkbregistry = declare_dependency(
407         link_with: libxkbregistry,
408         include_directories: include_directories('include'),
409     )
410     if meson.version().version_compare('>= 0.54.0')
411         meson.override_dependency('xkbregistry', dep_libxkbregistry)
412     endif
413 endif
414
415 man_pages = []
416
417 # Tools
418 build_tools = get_option('enable-tools') and cc.has_header_symbol('getopt.h', 'getopt_long', prefix: '#define _GNU_SOURCE')
419 if build_tools
420     # Common resources
421     libxkbcommon_tools_internal_sources = [
422         'tools/tools-common.h',
423         'tools/tools-common.c',
424     ]
425     libxkbcommon_tools_internal = static_library(
426         'tools-internal',
427         libxkbcommon_tools_internal_sources,
428         dependencies: dep_libxkbcommon,
429     )
430     tools_dep = declare_dependency(
431         include_directories: [include_directories('tools', 'include')],
432         link_with: libxkbcommon_tools_internal,
433         dependencies: dep_libxkbcommon,
434     )
435
436     # Tool: xkbcli
437     executable('xkbcli', 'tools/xkbcli.c',
438                dependencies: tools_dep, install: true)
439     install_man('tools/xkbcli.1')
440
441     if get_option('enable-bash-completion')
442         bash_completion_path = get_option('bash-completion-path')
443         if bash_completion_path == ''
444             bash_completion = dependency('bash-completion', required: false)
445             if bash_completion.found()
446                 bash_completion_path = bash_completion.get_variable(pkgconfig: 'completionsdir')
447             else
448                 bash_completion_path = get_option('datadir') / 'bash-completion/completions'
449             endif
450         endif
451         install_data('tools/xkbcli-bash-completion.sh',
452                      rename: 'xkbcli',
453                      install_dir: bash_completion_path)
454     endif
455
456     # Tool: compile-keymap
457     xkbcli_compile_keymap = executable('xkbcli-compile-keymap',
458                                        'tools/compile-keymap.c',
459                                        dependencies: tools_dep,
460                                        install: true,
461                                        install_dir: dir_libexec)
462     install_man('tools/xkbcli-compile-keymap.1')
463     # The same tool again, but with access to some private APIs.
464     executable('compile-keymap',
465                'tools/compile-keymap.c',
466                libxkbcommon_sources,
467                dependencies: [tools_dep],
468                c_args: ['-DENABLE_PRIVATE_APIS'],
469                include_directories: [include_directories('src', 'include')],
470                install: false)
471
472     # Tool: compose
473     executable('compose',
474                'tools/compose.c',
475                dependencies: tools_dep,
476                include_directories: [include_directories('src', 'include')],
477                install: false)
478     configh_data.set10('HAVE_XKBCLI_COMPILE_KEYMAP', true)
479
480     # Tool: how-to-type
481     executable('xkbcli-how-to-type',
482                'tools/how-to-type.c',
483                dependencies: tools_dep,
484                install: true,
485                install_dir: dir_libexec)
486     install_man('tools/xkbcli-how-to-type.1')
487     configh_data.set10('HAVE_XKBCLI_HOW_TO_TYPE', true)
488
489     # Tool: interactive-evdev
490     if cc.has_header('linux/input.h')
491         executable('xkbcli-interactive-evdev',
492                    'tools/interactive-evdev.c',
493                    dependencies: tools_dep,
494                    install: true,
495                    install_dir: dir_libexec)
496         configh_data.set10('HAVE_XKBCLI_INTERACTIVE_EVDEV', true)
497         install_man('tools/xkbcli-interactive-evdev.1')
498         # The same tool again, but with access to some private APIs.
499         executable('interactive-evdev',
500                 'tools/interactive-evdev.c',
501                 libxkbcommon_sources,
502                 libxkbcommon_tools_internal_sources,
503                 dependencies: [tools_dep],
504                 c_args: ['-DENABLE_PRIVATE_APIS'],
505                 include_directories: [include_directories('src', 'include')],
506                 install: false)
507     endif
508
509     # Tool: interactive-x11
510     if get_option('enable-x11')
511         x11_tools_dep = declare_dependency(
512             link_with: libxkbcommon_x11,
513             dependencies: [
514                 tools_dep,
515                 xcb_dep,
516                 xcb_xkb_dep,
517             ],
518         )
519         executable('xkbcli-interactive-x11',
520                    'tools/interactive-x11.c',
521                    dependencies: x11_tools_dep,
522                    install: true,
523                    install_dir: dir_libexec)
524         install_man('tools/xkbcli-interactive-x11.1')
525         configh_data.set10('HAVE_XKBCLI_INTERACTIVE_X11', true)
526     endif
527
528     # Tool: interactive-wayland
529     if get_option('enable-wayland')
530         wayland_client_dep = dependency('wayland-client', version: '>=1.2.0', required: false)
531         wayland_protocols_dep = dependency('wayland-protocols', version: '>=1.12', required: false)
532         wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)
533         if not wayland_client_dep.found() or not wayland_protocols_dep.found() or not wayland_scanner_dep.found()
534             error('''The Wayland xkbcli programs require wayland-client >= 1.2.0, wayland-protocols >= 1.7 which were not found.
535 You can disable the Wayland xkbcli programs with -Denable-wayland=false.''')
536         endif
537
538         wayland_scanner = find_program(wayland_scanner_dep.get_variable(pkgconfig: 'wayland_scanner'))
539         wayland_scanner_code_gen = generator(
540             wayland_scanner,
541             output: '@BASENAME@-protocol.c',
542             arguments: ['private-code', '@INPUT@', '@OUTPUT@'],
543         )
544         wayland_scanner_client_header_gen = generator(
545             wayland_scanner,
546             output: '@BASENAME@-client-protocol.h',
547             arguments: ['client-header', '@INPUT@', '@OUTPUT@'],
548         )
549         wayland_protocols_datadir = wayland_protocols_dep.get_variable(pkgconfig: 'pkgdatadir')
550         xdg_shell_xml = wayland_protocols_datadir/'stable/xdg-shell/xdg-shell.xml'
551         xdg_shell_sources = [
552             wayland_scanner_code_gen.process(xdg_shell_xml),
553             wayland_scanner_client_header_gen.process(xdg_shell_xml),
554         ]
555         executable('xkbcli-interactive-wayland',
556                    'tools/interactive-wayland.c',
557                    xdg_shell_sources,
558                    dependencies: [tools_dep, wayland_client_dep],
559                    install: true,
560                    install_dir: dir_libexec)
561         install_man('tools/xkbcli-interactive-wayland.1')
562         configh_data.set10('HAVE_XKBCLI_INTERACTIVE_WAYLAND', true)
563     endif
564
565     # Tool: list
566     if get_option('enable-xkbregistry')
567         configh_data.set10('HAVE_XKBCLI_LIST', true)
568         executable('xkbcli-list',
569                    'tools/registry-list.c',
570                    dependencies: dep_libxkbregistry,
571                    install: true,
572                    install_dir: dir_libexec)
573         install_man('tools/xkbcli-list.1')
574     endif
575
576     # Tool: check-messages
577     executable('xkb-check-messages',
578                'tools/check-messages.c',
579                'tools/messages.c',
580                'tools/messages.h',
581                'src/messages-codes.h',
582                dependencies: [tools_dep],
583                include_directories: [include_directories('src', 'include', 'tools')],
584                install: false)
585 endif
586
587
588 # xkeyboard-config "verifier"
589 xkct_config = configuration_data()
590 xkct_config.set('MESON_BUILD_ROOT', meson.current_build_dir())
591 xkct_config.set('XKB_CONFIG_ROOT', XKBCONFIGROOT)
592 configure_file(input: 'test/xkeyboard-config-test.py.in',
593                output: 'xkeyboard-config-test',
594                configuration: xkct_config)
595
596 # Tests
597 test_env = environment()
598 test_env.set('XKB_LOG_LEVEL', 'debug')
599 test_env.set('XKB_LOG_VERBOSITY', '10')
600 test_env.set('top_srcdir', meson.current_source_dir())
601 test_env.set('top_builddir', meson.current_build_dir())
602 test_env.set('HAVE_XKBCLI_INTERACTIVE_EVDEV', configh_data.get('HAVE_XKBCLI_INTERACTIVE_EVDEV', 0).to_string())
603 test_env.set('HAVE_XKBCLI_INTERACTIVE_WAYLAND', configh_data.get('HAVE_XKBCLI_INTERACTIVE_WAYLAND', 0).to_string())
604 test_env.set('HAVE_XKBCLI_INTERACTIVE_X11', configh_data.get('HAVE_XKBCLI_INTERACTIVE_X11', 0).to_string())
605 test_env.set('HAVE_XKBCLI_LIST', configh_data.get('HAVE_XKBCLI_LIST', 0).to_string())
606
607 test_configh_data = configuration_data()
608 test_configh_data.set_quoted('TEST_XKB_CONFIG_ROOT', meson.current_source_dir()/'test'/'data')
609 configure_file(output: 'test-config.h', configuration: test_configh_data)
610
611 # Some tests need to use unexported symbols, so we link them against
612 # an internal copy of libxkbcommon with all symbols exposed.
613 libxkbcommon_test_internal = static_library(
614     'xkbcommon-test-internal',
615     'test/common.c',
616     'test/test.h',
617     'test/evdev-scancodes.h',
618     'bench/bench.c',
619     'bench/bench.h',
620     libxkbcommon_sources,
621     include_directories: include_directories('src', 'include'),
622 )
623 test_dep = declare_dependency(
624     include_directories: include_directories('src', 'include'),
625     link_with: libxkbcommon_test_internal,
626 )
627 if get_option('enable-x11')
628     libxkbcommon_x11_test_internal = static_library(
629         'xkbcommon-x11-internal',
630         libxkbcommon_x11_sources,
631         'test/xvfb-wrapper.c',
632         'test/xvfb-wrapper.h',
633         include_directories: include_directories('src', 'include'),
634         link_with: libxkbcommon_test_internal,
635         dependencies: [
636             xcb_dep,
637             xcb_xkb_dep,
638         ],
639     )
640     x11_test_dep = declare_dependency(
641         link_with: libxkbcommon_x11_test_internal,
642         dependencies: [
643             test_dep,
644             xcb_dep,
645             xcb_xkb_dep,
646         ],
647     )
648 endif
649 test(
650     'keysym',
651     executable('test-keysym', 'test/keysym.c', dependencies: test_dep),
652     env: test_env,
653 )
654 test(
655     'keymap',
656     executable('test-keymap', 'test/keymap.c', dependencies: test_dep),
657     env: test_env,
658 )
659 test(
660     'filecomp',
661     executable('test-filecomp', 'test/filecomp.c', dependencies: test_dep),
662     env: test_env,
663 )
664 test(
665     'context',
666     executable('test-context', 'test/context.c', dependencies: test_dep),
667     env: test_env,
668 )
669 test(
670     'rules-file',
671     executable('test-rules-file', 'test/rules-file.c', dependencies: test_dep),
672     env: test_env,
673 )
674 test(
675     'rules-file-includes',
676     executable('test-rules-file-includes', 'test/rules-file-includes.c', dependencies: test_dep),
677     env: test_env,
678 )
679 test(
680     'stringcomp',
681     executable('test-stringcomp', 'test/stringcomp.c', dependencies: test_dep),
682     env: test_env,
683 )
684 test(
685     'buffercomp',
686     executable('test-buffercomp', 'test/buffercomp.c', dependencies: test_dep),
687     env: test_env,
688 )
689 test(
690     'log',
691     executable('test-log', 'test/log.c', dependencies: test_dep),
692     env: test_env,
693 )
694 test(
695     'atom',
696     executable('test-atom', 'test/atom.c', dependencies: test_dep),
697     env: test_env,
698 )
699 test(
700     'utf8',
701     executable('test-utf8', 'test/utf8.c', dependencies: test_dep),
702     env: test_env,
703 )
704 test(
705     'state',
706     executable('test-state', 'test/state.c', dependencies: test_dep),
707     env: test_env,
708 )
709 test(
710     'keyseq',
711     executable('test-keyseq', 'test/keyseq.c', dependencies: test_dep),
712     env: test_env,
713 )
714 test(
715     'rulescomp',
716     executable('test-rulescomp', 'test/rulescomp.c', dependencies: test_dep),
717     env: test_env,
718 )
719 test(
720     'compose',
721     executable('test-compose', 'test/compose.c', dependencies: test_dep),
722     env: test_env,
723 )
724 test(
725     'utils',
726     executable('test-utils', 'test/utils.c', dependencies: test_dep),
727     env: test_env,
728 )
729 test(
730     'symbols-leak-test',
731     find_program('test/symbols-leak-test.py'),
732     env: test_env,
733     suite: ['python-tests'],
734 )
735 test(
736     'modifiers',
737     executable('test-modifiers', 'test/modifiers.c', dependencies: test_dep),
738     env: test_env,
739 )
740 test(
741     'messages',
742     executable(
743         'test-messages',
744         'test/messages.c',
745         'tools/messages.c',
746         'tools/messages.h',
747         include_directories: include_directories('src', 'include', 'tools'),
748         dependencies: test_dep),
749     env: test_env,
750 )
751 if get_option('enable-x11')
752     test(
753         'x11',
754         executable('test-x11', 'test/x11.c', dependencies: x11_test_dep),
755         env: test_env,
756     )
757     test(
758         'x11comp',
759         executable('test-x11comp', 'test/x11comp.c', dependencies: x11_test_dep),
760         env: test_env,
761     )
762 endif
763 if get_option('enable-xkbregistry')
764     test(
765         'registry',
766         executable('test-registry', 'test/registry.c',
767                    include_directories: include_directories('src'),
768                    dependencies: [dep_libxkbregistry, test_dep]),
769         env: test_env,
770     )
771 endif
772 if build_tools
773     test('tool-option-parsing',
774          find_program('test/tool-option-parsing.py'),
775          env: test_env,
776          suite: ['python-tests'])
777
778     # A set of keysyms to test for. Add one or two symbols to this array
779     # whenever the xorgproto gets updated to make sure we resolve them.
780     keysyms_to_test = [
781         'XF86Macro23',
782     ]
783
784     env = environment()
785     env.set('XKB_CONFIG_ROOT', meson.current_source_dir()/'test'/'data')
786     foreach keysym: keysyms_to_test
787         test('keysym-test-@0@'.format(keysym),
788              find_program('test/test-keysym.py'),
789              env: env,
790              args: [keysym, '--tool', xkbcli_compile_keymap],
791              suite: ['python-tests'])
792     endforeach
793 endif
794
795 valgrind = find_program('valgrind', required: false)
796 if valgrind.found()
797     add_test_setup('valgrind',
798         exe_wrapper: [valgrind,
799                        '--leak-check=full',
800                        '--track-origins=yes',
801                        '--gen-suppressions=all',
802                        '--error-exitcode=99'],
803         timeout_multiplier : 10)
804 else
805     message('valgrind not found, disabling valgrind test setup')
806 endif
807
808
809 # Fuzzing target programs.
810 executable('fuzz-keymap', 'fuzz/keymap/target.c', dependencies: test_dep)
811 executable('fuzz-compose', 'fuzz/compose/target.c', dependencies: test_dep)
812
813
814 # Benchmarks.
815 bench_env = environment()
816 bench_env.set('top_srcdir', meson.current_source_dir())
817 benchmark(
818     'key-proc',
819     executable('bench-key-proc', 'bench/key-proc.c', dependencies: test_dep),
820     env: bench_env,
821 )
822 benchmark(
823     'rules',
824     executable('bench-rules', 'bench/rules.c', dependencies: test_dep),
825     env: bench_env,
826 )
827 benchmark(
828     'rulescomp',
829     executable('bench-rulescomp', 'bench/rulescomp.c', dependencies: test_dep),
830     env: bench_env,
831 )
832 benchmark(
833     'compose',
834     executable('bench-compose', 'bench/compose.c', dependencies: test_dep),
835     env: bench_env,
836 )
837 benchmark(
838     'compose-traversal',
839     executable('bench-compose-traversal', 'bench/compose-traversal.c', dependencies: test_dep),
840     env: bench_env,
841 )
842 benchmark(
843     'atom',
844     executable('bench-atom', 'bench/atom.c', dependencies: test_dep),
845     env: bench_env,
846 )
847 if get_option('enable-x11')
848   benchmark(
849       'x11',
850       executable('bench-x11', 'bench/x11.c', dependencies: x11_test_dep),
851       env: bench_env,
852   )
853 endif
854
855
856 # Documentation.
857 if get_option('enable-docs')
858     doxygen = find_program('doxygen', required: false)
859     if not doxygen.found()
860         error('''Documentation requires doxygen which was not found.
861 You can disable the documentation with -Denable-docs=false.''')
862     endif
863     doxygen_wrapper = find_program('scripts/doxygen-wrapper')
864
865     doxygen_input = [
866         'README.md',
867         'doc/diagrams/xkb-configuration.dot',
868         'doc/doxygen-extra.css',
869         'doc/introduction-to-xkb.md',
870         'doc/quick-guide.md',
871         'doc/compatibility.md',
872         'doc/user-configuration.md',
873         'doc/rules-format.md',
874         'doc/keymap-format-text-v1.md',
875         'doc/message-registry.md',
876         'include/xkbcommon/xkbcommon.h',
877         'include/xkbcommon/xkbcommon-compose.h',
878         'include/xkbcommon/xkbcommon-keysyms.h',
879         'include/xkbcommon/xkbcommon-names.h',
880         'include/xkbcommon/xkbcommon-x11.h',
881         'include/xkbcommon/xkbregistry.h',
882     ]
883     doxygen_data = configuration_data()
884     doxygen_data.set('PACKAGE_NAME', meson.project_name())
885     doxygen_data.set('PACKAGE_VERSION', meson.project_version())
886     doxygen_data.set('INPUT', ' '.join(doxygen_input))
887     doxygen_data.set('OUTPUT_DIRECTORY', meson.current_build_dir())
888     doxyfile = configure_file(
889         input: 'doc/Doxyfile.in',
890         output: 'Doxyfile',
891         configuration: doxygen_data,
892     )
893     # TODO: Meson should provide this.
894     docdir = get_option('datadir')/'doc'/meson.project_name()
895     doc_gen = custom_target(
896         'doc',
897         input: [doxyfile] + doxygen_input,
898         output: 'html',
899         command: [
900             doxygen_wrapper,
901             doxygen,
902             meson.current_build_dir()/'Doxyfile',
903             meson.current_source_dir(),
904         ],
905         install: true,
906         install_dir: docdir,
907         build_by_default: true,
908     )
909     if get_option('enable-cool-uris')
910         ensure_stable_urls = find_program('scripts'/'ensure-stable-doc-urls.py')
911         custom_target(
912             'doc-cool-uris',
913             input: [doc_gen, 'doc'/'cool-uris.yaml'],
914             output: 'html-xtra',
915             command: [
916                 ensure_stable_urls,
917                 'generate-redirections',
918                 meson.current_source_dir()/'doc'/'cool-uris.yaml',
919                 meson.current_build_dir()/'html'
920             ],
921             install: false,
922             build_by_default: true,
923         )
924     endif
925 endif
926
927 configure_file(output: 'config.h', configuration: configh_data)
928
929
930 # Stable variables for projects using xkbcommon as a subproject.
931 # These variables should not be renamed.
932 libxkbcommon_dep = dep_libxkbcommon
933 if get_option('enable-x11')
934   libxkbcommon_x11_dep = dep_libxkbcommon_x11
935 endif
936 if get_option('enable-xkbregistry')
937   libxkbregistry_dep = dep_libxkbregistry
938 endif
939
940 if meson.version().version_compare('>=0.62.0')
941     summary({
942       'backend': meson.backend(),
943       'buildtype': get_option('buildtype'),
944       'c_args': get_option('c_args'),
945       'c_link_args': get_option('c_link_args'),
946       'yacc': yacc.full_path() + ' ' + yacc.version(),
947     }, section: 'Compiler')
948     summary({
949       'prefix': get_option('prefix'),
950       'bindir': get_option('bindir'),
951       'libdir': get_option('libdir'),
952       'datadir': get_option('datadir'),
953       'xkb-config-root': XKBCONFIGROOT,
954       'xkb-config-extra-path': XKBCONFIGEXTRAPATH,
955       'xlocaledir': XLOCALEDIR,
956     }, section: 'Directories')
957     summary({
958       'docs': get_option('enable-docs'),
959       'tools': get_option('enable-tools'),
960       'wayland': get_option('enable-wayland'),
961       'x11': get_option('enable-x11'),
962     }, section: 'Features')
963     summary({
964       'layout': get_option('default-layout'),
965       'model': get_option('default-model'),
966       'options': get_option('default-options'),
967       'rules': get_option('default-rules'),
968       'variant': get_option('default-variant'),
969     }, section: 'Defaults')
970 endif