Add LICENSE.BSD-3-Clause file
[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
249 libxkbcommon = library(
250     'xkbcommon',
251     'include/xkbcommon/xkbcommon.h',
252     libxkbcommon_sources,
253     link_args: libxkbcommon_link_args,
254     link_depends: libxkbcommon_link_deps,
255     gnu_symbol_visibility: 'hidden',
256     version: '0.0.0',
257     install: true,
258     include_directories: include_directories('src', 'include'),
259 )
260 install_headers(
261     'include/xkbcommon/xkbcommon.h',
262     'include/xkbcommon/xkbcommon-compat.h',
263     'include/xkbcommon/xkbcommon-compose.h',
264     'include/xkbcommon/xkbcommon-keysyms.h',
265     'include/xkbcommon/xkbcommon-names.h',
266     subdir: 'xkbcommon',
267 )
268
269 dep_libxkbcommon = declare_dependency(
270     link_with: libxkbcommon,
271     include_directories: include_directories('include'),
272 )
273 if meson.version().version_compare('>= 0.54.0')
274     meson.override_dependency('xkbcommon', dep_libxkbcommon)
275 endif
276 pkgconfig.generate(
277     libxkbcommon,
278     name: 'xkbcommon',
279     filebase: 'xkbcommon',
280     version: meson.project_version(),
281     description: 'XKB API common to servers and clients',
282 )
283
284
285 # libxkbcommon-x11.
286 if get_option('enable-x11')
287     xcb_dep = dependency('xcb', version: '>=1.10', required: false)
288     xcb_xkb_dep = dependency('xcb-xkb', version: '>=1.10', required: false)
289     if not xcb_dep.found() or not xcb_xkb_dep.found()
290         error('''X11 support requires xcb-xkb >= 1.10 which was not found.
291 You can disable X11 support with -Denable-x11=false.''')
292     endif
293
294     libxkbcommon_x11_sources = [
295         'src/x11/keymap.c',
296         'src/x11/state.c',
297         'src/x11/util.c',
298         'src/x11/x11-priv.h',
299         'src/context.h',
300         'src/context-priv.c',
301         'src/keymap.h',
302         'src/keymap-priv.c',
303         'src/atom.h',
304         'src/atom.c',
305     ]
306     libxkbcommon_x11_link_args = []
307     libxkbcommon_x11_link_deps = []
308     if have_version_script
309         libxkbcommon_x11_link_args += '-Wl,--version-script=' + meson.current_source_dir()/'xkbcommon-x11.map'
310         libxkbcommon_x11_link_deps += 'xkbcommon-x11.map'
311     elif cc.get_argument_syntax() == 'msvc'
312         libxkbcommon_x11_def = custom_target('xkbcommon-x11.def',
313             command: [map_to_def, '@INPUT@', '@OUTPUT@'],
314             input: 'xkbcommon-x11.map',
315             output: 'xkbcommon-x11.def',
316         )
317         libxkbcommon_x11_link_deps += libxkbcommon_x11_def
318         libxkbcommon_x11_link_args += '/DEF:' + libxkbcommon_x11_def.full_path()
319     endif
320     libxkbcommon_x11 = library(
321         'xkbcommon-x11',
322         'include/xkbcommon/xkbcommon-x11.h',
323         libxkbcommon_x11_sources,
324         link_args: libxkbcommon_x11_link_args,
325         link_depends: libxkbcommon_x11_link_deps,
326         gnu_symbol_visibility: 'hidden',
327         version: '0.0.0',
328         install: true,
329         include_directories: include_directories('src', 'include'),
330         link_with: libxkbcommon,
331         dependencies: [
332             xcb_dep,
333             xcb_xkb_dep,
334         ],
335     )
336     install_headers(
337         'include/xkbcommon/xkbcommon-x11.h',
338         subdir: 'xkbcommon',
339     )
340     dep_libxkbcommon_x11 = declare_dependency(
341         link_with: libxkbcommon_x11,
342         include_directories: include_directories('include'),
343     )
344     if meson.version().version_compare('>= 0.54.0')
345         meson.override_dependency('xkbcommon-x11', dep_libxkbcommon_x11)
346     endif
347     pkgconfig.generate(
348         libxkbcommon_x11,
349         name: 'xkbcommon-x11',
350         filebase: 'xkbcommon-x11',
351         version: meson.project_version(),
352         description: 'XKB API common to servers and clients - X11 support',
353         requires: ['xkbcommon'],
354         requires_private: ['xcb>=1.10', 'xcb-xkb>=1.10'],
355     )
356 endif
357
358 # libxkbregistry
359 if get_option('enable-xkbregistry')
360     dep_libxml = dependency('libxml-2.0')
361     deps_libxkbregistry = [dep_libxml]
362     libxkbregistry_sources = [
363         'src/registry.c',
364         'src/utils.h',
365         'src/utils.c',
366         'src/util-list.h',
367         'src/util-list.c',
368     ]
369     libxkbregistry_link_args = []
370     libxkbregistry_link_deps = []
371     if have_version_script
372         libxkbregistry_link_args += '-Wl,--version-script=' + meson.current_source_dir()/'xkbregistry.map'
373         libxkbregistry_link_deps += 'xkbregistry.map'
374     elif cc.get_argument_syntax() == 'msvc'
375         libxkbregistry_def = custom_target('xkbregistry.def',
376             command: [map_to_def, '@INPUT@', '@OUTPUT@'],
377             input: 'xkbregistry.map',
378             output: 'xkbregistry.def',
379         )
380         libxkbregistry_link_deps += libxkbregistry_def
381         libxkbregistry_link_args += '/DEF:' + libxkbregistry_def.full_path()
382     endif
383     libxkbregistry = library(
384         'xkbregistry',
385         'include/xkbcommon/xkbregistry.h',
386         libxkbregistry_sources,
387         link_args: libxkbregistry_link_args,
388         link_depends: libxkbregistry_link_deps,
389         gnu_symbol_visibility: 'hidden',
390         dependencies: deps_libxkbregistry,
391         version: '0.0.0',
392         install: true,
393         include_directories: include_directories('src', 'include'),
394     )
395     install_headers(
396         'include/xkbcommon/xkbregistry.h',
397         subdir: 'xkbcommon',
398     )
399     pkgconfig.generate(
400         libxkbregistry,
401         name: 'xkbregistry',
402         filebase: 'xkbregistry',
403         version: meson.project_version(),
404         description: 'XKB API to query available rules, models, layouts, variants and options',
405     )
406
407     dep_libxkbregistry = declare_dependency(
408         link_with: libxkbregistry,
409         include_directories: include_directories('include'),
410     )
411     if meson.version().version_compare('>= 0.54.0')
412         meson.override_dependency('xkbregistry', dep_libxkbregistry)
413     endif
414 endif
415
416 man_pages = []
417
418 # Tools
419 if get_option('enable-tools')
420 build_tools = get_option('enable-tools') and cc.has_header_symbol('getopt.h', 'getopt_long', prefix: '#define _GNU_SOURCE')
421 else
422 build_tools = false
423 endif
424
425 if build_tools
426     # Common resources
427     libxkbcommon_tools_internal_sources = [
428         'tools/tools-common.h',
429         'tools/tools-common.c',
430     ]
431     libxkbcommon_tools_internal = static_library(
432         'tools-internal',
433         libxkbcommon_tools_internal_sources,
434         dependencies: dep_libxkbcommon,
435     )
436     tools_dep = declare_dependency(
437         include_directories: [include_directories('tools', 'include')],
438         link_with: libxkbcommon_tools_internal,
439         dependencies: dep_libxkbcommon,
440     )
441
442     # Tool: xkbcli
443     executable('xkbcli', 'tools/xkbcli.c',
444                dependencies: tools_dep, install: true)
445     install_man('tools/xkbcli.1')
446
447     if get_option('enable-bash-completion')
448         bash_completion_path = get_option('bash-completion-path')
449         if bash_completion_path == ''
450             bash_completion = dependency('bash-completion', required: false)
451             if bash_completion.found()
452                 bash_completion_path = bash_completion.get_variable(pkgconfig: 'completionsdir')
453             else
454                 bash_completion_path = get_option('datadir') / 'bash-completion/completions'
455             endif
456         endif
457         install_data('tools/xkbcli-bash-completion.sh',
458                      rename: 'xkbcli',
459                      install_dir: bash_completion_path)
460     endif
461
462     # Tool: compile-keymap
463     xkbcli_compile_keymap = executable('xkbcli-compile-keymap',
464                                        'tools/compile-keymap.c',
465                                        dependencies: tools_dep,
466                                        install: true,
467                                        install_dir: dir_libexec)
468     install_man('tools/xkbcli-compile-keymap.1')
469     # The same tool again, but with access to some private APIs.
470     executable('compile-keymap',
471                'tools/compile-keymap.c',
472                libxkbcommon_sources,
473                dependencies: [tools_dep],
474                c_args: ['-DENABLE_PRIVATE_APIS'],
475                include_directories: [include_directories('src', 'include')],
476                install: false)
477
478     # Tool: compose
479     executable('compose',
480                'tools/compose.c',
481                dependencies: tools_dep,
482                include_directories: [include_directories('src', 'include')],
483                install: false)
484     configh_data.set10('HAVE_XKBCLI_COMPILE_KEYMAP', true)
485
486     # Tool: how-to-type
487     executable('xkbcli-how-to-type',
488                'tools/how-to-type.c',
489                dependencies: tools_dep,
490                install: true,
491                install_dir: dir_libexec)
492     install_man('tools/xkbcli-how-to-type.1')
493     configh_data.set10('HAVE_XKBCLI_HOW_TO_TYPE', true)
494
495     # Tool: interactive-evdev
496     if cc.has_header('linux/input.h')
497         executable('xkbcli-interactive-evdev',
498                    'tools/interactive-evdev.c',
499                    dependencies: tools_dep,
500                    install: true,
501                    install_dir: dir_libexec)
502         configh_data.set10('HAVE_XKBCLI_INTERACTIVE_EVDEV', true)
503         install_man('tools/xkbcli-interactive-evdev.1')
504         # The same tool again, but with access to some private APIs.
505         executable('interactive-evdev',
506                 'tools/interactive-evdev.c',
507                 libxkbcommon_sources,
508                 libxkbcommon_tools_internal_sources,
509                 dependencies: [tools_dep],
510                 c_args: ['-DENABLE_PRIVATE_APIS'],
511                 include_directories: [include_directories('src', 'include')],
512                 install: false)
513     endif
514
515     # Tool: interactive-x11
516     if get_option('enable-x11')
517         x11_tools_dep = declare_dependency(
518             link_with: libxkbcommon_x11,
519             dependencies: [
520                 tools_dep,
521                 xcb_dep,
522                 xcb_xkb_dep,
523             ],
524         )
525         executable('xkbcli-interactive-x11',
526                    'tools/interactive-x11.c',
527                    dependencies: x11_tools_dep,
528                    install: true,
529                    install_dir: dir_libexec)
530         install_man('tools/xkbcli-interactive-x11.1')
531         configh_data.set10('HAVE_XKBCLI_INTERACTIVE_X11', true)
532     endif
533
534     # Tool: interactive-wayland
535     if get_option('enable-wayland')
536         wayland_client_dep = dependency('wayland-client', version: '>=1.2.0', required: false)
537         wayland_protocols_dep = dependency('wayland-protocols', version: '>=1.12', required: false)
538         wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)
539         if not wayland_client_dep.found() or not wayland_protocols_dep.found() or not wayland_scanner_dep.found()
540             error('''The Wayland xkbcli programs require wayland-client >= 1.2.0, wayland-protocols >= 1.7 which were not found.
541 You can disable the Wayland xkbcli programs with -Denable-wayland=false.''')
542         endif
543
544         wayland_scanner = find_program(wayland_scanner_dep.get_variable(pkgconfig: 'wayland_scanner'))
545         wayland_scanner_code_gen = generator(
546             wayland_scanner,
547             output: '@BASENAME@-protocol.c',
548             arguments: ['private-code', '@INPUT@', '@OUTPUT@'],
549         )
550         wayland_scanner_client_header_gen = generator(
551             wayland_scanner,
552             output: '@BASENAME@-client-protocol.h',
553             arguments: ['client-header', '@INPUT@', '@OUTPUT@'],
554         )
555         wayland_protocols_datadir = wayland_protocols_dep.get_variable(pkgconfig: 'pkgdatadir')
556         xdg_shell_xml = wayland_protocols_datadir/'stable/xdg-shell/xdg-shell.xml'
557         xdg_shell_sources = [
558             wayland_scanner_code_gen.process(xdg_shell_xml),
559             wayland_scanner_client_header_gen.process(xdg_shell_xml),
560         ]
561         executable('xkbcli-interactive-wayland',
562                    'tools/interactive-wayland.c',
563                    xdg_shell_sources,
564                    dependencies: [tools_dep, wayland_client_dep],
565                    install: true,
566                    install_dir: dir_libexec)
567         install_man('tools/xkbcli-interactive-wayland.1')
568         configh_data.set10('HAVE_XKBCLI_INTERACTIVE_WAYLAND', true)
569     endif
570
571     # Tool: list
572     if get_option('enable-xkbregistry')
573         configh_data.set10('HAVE_XKBCLI_LIST', true)
574         executable('xkbcli-list',
575                    'tools/registry-list.c',
576                    dependencies: dep_libxkbregistry,
577                    install: true,
578                    install_dir: dir_libexec)
579         install_man('tools/xkbcli-list.1')
580     endif
581
582     # Tool: check-messages
583     executable('xkb-check-messages',
584                'tools/check-messages.c',
585                'tools/messages.c',
586                'tools/messages.h',
587                'src/messages-codes.h',
588                dependencies: [tools_dep],
589                include_directories: [include_directories('src', 'include', 'tools')],
590                install: false)
591 endif
592
593
594 # xkeyboard-config "verifier"
595 xkct_config = configuration_data()
596 xkct_config.set('MESON_BUILD_ROOT', meson.current_build_dir())
597 xkct_config.set('XKB_CONFIG_ROOT', XKBCONFIGROOT)
598 configure_file(input: 'test/xkeyboard-config-test.py.in',
599                output: 'xkeyboard-config-test',
600                configuration: xkct_config)
601
602 # Tests
603 test_env = environment()
604 test_env.set('XKB_LOG_LEVEL', 'debug')
605 test_env.set('XKB_LOG_VERBOSITY', '10')
606 test_env.set('top_srcdir', meson.current_source_dir())
607 test_env.set('top_builddir', meson.current_build_dir())
608 test_env.set('HAVE_XKBCLI_INTERACTIVE_EVDEV', configh_data.get('HAVE_XKBCLI_INTERACTIVE_EVDEV', 0).to_string())
609 test_env.set('HAVE_XKBCLI_INTERACTIVE_WAYLAND', configh_data.get('HAVE_XKBCLI_INTERACTIVE_WAYLAND', 0).to_string())
610 test_env.set('HAVE_XKBCLI_INTERACTIVE_X11', configh_data.get('HAVE_XKBCLI_INTERACTIVE_X11', 0).to_string())
611 test_env.set('HAVE_XKBCLI_LIST', configh_data.get('HAVE_XKBCLI_LIST', 0).to_string())
612
613 test_configh_data = configuration_data()
614 test_configh_data.set_quoted('TEST_XKB_CONFIG_ROOT', meson.current_source_dir()/'test'/'data')
615 configure_file(output: 'test-config.h', configuration: test_configh_data)
616
617 # Some tests need to use unexported symbols, so we link them against
618 # an internal copy of libxkbcommon with all symbols exposed.
619 libxkbcommon_test_internal = static_library(
620     'xkbcommon-test-internal',
621     'test/common.c',
622     'test/test.h',
623     'test/evdev-scancodes.h',
624     'bench/bench.c',
625     'bench/bench.h',
626     libxkbcommon_sources,
627     include_directories: include_directories('src', 'include'),
628 )
629 test_dep = declare_dependency(
630     include_directories: include_directories('src', 'include'),
631     link_with: libxkbcommon_test_internal,
632 )
633 if get_option('enable-x11')
634     libxkbcommon_x11_test_internal = static_library(
635         'xkbcommon-x11-internal',
636         libxkbcommon_x11_sources,
637         'test/xvfb-wrapper.c',
638         'test/xvfb-wrapper.h',
639         include_directories: include_directories('src', 'include'),
640         link_with: libxkbcommon_test_internal,
641         dependencies: [
642             xcb_dep,
643             xcb_xkb_dep,
644         ],
645     )
646     x11_test_dep = declare_dependency(
647         link_with: libxkbcommon_x11_test_internal,
648         dependencies: [
649             test_dep,
650             xcb_dep,
651             xcb_xkb_dep,
652         ],
653     )
654 endif
655 test(
656     'keysym',
657     executable('test-keysym', 'test/keysym.c', dependencies: test_dep),
658     env: test_env,
659 )
660 test(
661     'keymap',
662     executable('test-keymap', 'test/keymap.c', dependencies: test_dep),
663     env: test_env,
664 )
665 test(
666     'filecomp',
667     executable('test-filecomp', 'test/filecomp.c', dependencies: test_dep),
668     env: test_env,
669 )
670 test(
671     'context',
672     executable('test-context', 'test/context.c', dependencies: test_dep),
673     env: test_env,
674 )
675 test(
676     'rules-file',
677     executable('test-rules-file', 'test/rules-file.c', dependencies: test_dep),
678     env: test_env,
679 )
680 test(
681     'rules-file-includes',
682     executable('test-rules-file-includes', 'test/rules-file-includes.c', dependencies: test_dep),
683     env: test_env,
684 )
685 test(
686     'stringcomp',
687     executable('test-stringcomp', 'test/stringcomp.c', dependencies: test_dep),
688     env: test_env,
689 )
690 test(
691     'buffercomp',
692     executable('test-buffercomp', 'test/buffercomp.c', dependencies: test_dep),
693     env: test_env,
694 )
695 test(
696     'log',
697     executable('test-log', 'test/log.c', dependencies: test_dep),
698     env: test_env,
699 )
700 test(
701     'atom',
702     executable('test-atom', 'test/atom.c', dependencies: test_dep),
703     env: test_env,
704 )
705 test(
706     'utf8',
707     executable('test-utf8', 'test/utf8.c', dependencies: test_dep),
708     env: test_env,
709 )
710 test(
711     'state',
712     executable('test-state', 'test/state.c', dependencies: test_dep),
713     env: test_env,
714 )
715 test(
716     'keyseq',
717     executable('test-keyseq', 'test/keyseq.c', dependencies: test_dep),
718     env: test_env,
719 )
720 test(
721     'rulescomp',
722     executable('test-rulescomp', 'test/rulescomp.c', dependencies: test_dep),
723     env: test_env,
724 )
725 test(
726     'compose',
727     executable('test-compose', 'test/compose.c', dependencies: test_dep),
728     env: test_env,
729 )
730 test(
731     'utils',
732     executable('test-utils', 'test/utils.c', dependencies: test_dep),
733     env: test_env,
734 )
735 test(
736     'symbols-leak-test',
737     find_program('test/symbols-leak-test.py'),
738     env: test_env,
739     suite: ['python-tests'],
740 )
741 test(
742     'modifiers',
743     executable('test-modifiers', 'test/modifiers.c', dependencies: test_dep),
744     env: test_env,
745 )
746 test(
747     'messages',
748     executable(
749         'test-messages',
750         'test/messages.c',
751         'tools/messages.c',
752         'tools/messages.h',
753         include_directories: include_directories('src', 'include', 'tools'),
754         dependencies: test_dep),
755     env: test_env,
756 )
757 if get_option('enable-x11')
758     test(
759         'x11',
760         executable('test-x11', 'test/x11.c', dependencies: x11_test_dep),
761         env: test_env,
762     )
763     test(
764         'x11comp',
765         executable('test-x11comp', 'test/x11comp.c', dependencies: x11_test_dep),
766         env: test_env,
767     )
768 endif
769 if get_option('enable-xkbregistry')
770     test(
771         'registry',
772         executable('test-registry', 'test/registry.c',
773                    include_directories: include_directories('src'),
774                    dependencies: [dep_libxkbregistry, test_dep]),
775         env: test_env,
776     )
777 endif
778 if build_tools
779     test('tool-option-parsing',
780          find_program('test/tool-option-parsing.py'),
781          env: test_env,
782          suite: ['python-tests'])
783
784     # A set of keysyms to test for. Add one or two symbols to this array
785     # whenever the xorgproto gets updated to make sure we resolve them.
786     keysyms_to_test = [
787         'XF86Macro23',
788     ]
789
790     env = environment()
791     env.set('XKB_CONFIG_ROOT', meson.current_source_dir()/'test'/'data')
792     foreach keysym: keysyms_to_test
793         test('keysym-test-@0@'.format(keysym),
794              find_program('test/test-keysym.py'),
795              env: env,
796              args: [keysym, '--tool', xkbcli_compile_keymap],
797              suite: ['python-tests'])
798     endforeach
799 endif
800
801 valgrind = find_program('valgrind', required: false)
802 if valgrind.found()
803     add_test_setup('valgrind',
804         exe_wrapper: [valgrind,
805                        '--leak-check=full',
806                        '--track-origins=yes',
807                        '--gen-suppressions=all',
808                        '--error-exitcode=99'],
809         timeout_multiplier : 10)
810 else
811     message('valgrind not found, disabling valgrind test setup')
812 endif
813
814
815 # Fuzzing target programs.
816 executable('fuzz-keymap', 'fuzz/keymap/target.c', dependencies: test_dep)
817 executable('fuzz-compose', 'fuzz/compose/target.c', dependencies: test_dep)
818
819
820 # Benchmarks.
821 bench_env = environment()
822 bench_env.set('top_srcdir', meson.current_source_dir())
823 benchmark(
824     'key-proc',
825     executable('bench-key-proc', 'bench/key-proc.c', dependencies: test_dep),
826     env: bench_env,
827 )
828 benchmark(
829     'rules',
830     executable('bench-rules', 'bench/rules.c', dependencies: test_dep),
831     env: bench_env,
832 )
833 benchmark(
834     'rulescomp',
835     executable('bench-rulescomp', 'bench/rulescomp.c', dependencies: test_dep),
836     env: bench_env,
837 )
838 benchmark(
839     'compose',
840     executable('bench-compose', 'bench/compose.c', dependencies: test_dep),
841     env: bench_env,
842 )
843 benchmark(
844     'compose-traversal',
845     executable('bench-compose-traversal', 'bench/compose-traversal.c', dependencies: test_dep),
846     env: bench_env,
847 )
848 benchmark(
849     'atom',
850     executable('bench-atom', 'bench/atom.c', dependencies: test_dep),
851     env: bench_env,
852 )
853 if get_option('enable-x11')
854   benchmark(
855       'x11',
856       executable('bench-x11', 'bench/x11.c', dependencies: x11_test_dep),
857       env: bench_env,
858   )
859 endif
860
861
862 # Documentation.
863 if get_option('enable-docs')
864     doxygen = find_program('doxygen', required: false)
865     if not doxygen.found()
866         error('''Documentation requires doxygen which was not found.
867 You can disable the documentation with -Denable-docs=false.''')
868     endif
869     doxygen_wrapper = find_program('scripts/doxygen-wrapper')
870
871     doxygen_input = [
872         'README.md',
873         'doc/diagrams/xkb-configuration.dot',
874         'doc/doxygen-extra.css',
875         'doc/introduction-to-xkb.md',
876         'doc/quick-guide.md',
877         'doc/compatibility.md',
878         'doc/user-configuration.md',
879         'doc/rules-format.md',
880         'doc/keymap-format-text-v1.md',
881         'doc/message-registry.md',
882         'include/xkbcommon/xkbcommon.h',
883         'include/xkbcommon/xkbcommon-compose.h',
884         'include/xkbcommon/xkbcommon-keysyms.h',
885         'include/xkbcommon/xkbcommon-names.h',
886         'include/xkbcommon/xkbcommon-x11.h',
887         'include/xkbcommon/xkbregistry.h',
888     ]
889     doxygen_data = configuration_data()
890     doxygen_data.set('PACKAGE_NAME', meson.project_name())
891     doxygen_data.set('PACKAGE_VERSION', meson.project_version())
892     doxygen_data.set('INPUT', ' '.join(doxygen_input))
893     doxygen_data.set('OUTPUT_DIRECTORY', meson.current_build_dir())
894     doxyfile = configure_file(
895         input: 'doc/Doxyfile.in',
896         output: 'Doxyfile',
897         configuration: doxygen_data,
898     )
899     # TODO: Meson should provide this.
900     docdir = get_option('datadir')/'doc'/meson.project_name()
901     doc_gen = custom_target(
902         'doc',
903         input: [doxyfile] + doxygen_input,
904         output: 'html',
905         command: [
906             doxygen_wrapper,
907             doxygen,
908             meson.current_build_dir()/'Doxyfile',
909             meson.current_source_dir(),
910         ],
911         install: true,
912         install_dir: docdir,
913         build_by_default: true,
914     )
915     if get_option('enable-cool-uris')
916         ensure_stable_urls = find_program('scripts'/'ensure-stable-doc-urls.py')
917         custom_target(
918             'doc-cool-uris',
919             input: [doc_gen, 'doc'/'cool-uris.yaml'],
920             output: 'html-xtra',
921             command: [
922                 ensure_stable_urls,
923                 'generate-redirections',
924                 meson.current_source_dir()/'doc'/'cool-uris.yaml',
925                 meson.current_build_dir()/'html'
926             ],
927             install: false,
928             build_by_default: true,
929         )
930     endif
931 endif
932
933 configure_file(output: 'config.h', configuration: configh_data)
934
935
936 # Stable variables for projects using xkbcommon as a subproject.
937 # These variables should not be renamed.
938 libxkbcommon_dep = dep_libxkbcommon
939 if get_option('enable-x11')
940   libxkbcommon_x11_dep = dep_libxkbcommon_x11
941 endif
942 if get_option('enable-xkbregistry')
943   libxkbregistry_dep = dep_libxkbregistry
944 endif
945
946 if meson.version().version_compare('>=0.62.0')
947     summary({
948       'backend': meson.backend(),
949       'buildtype': get_option('buildtype'),
950       'c_args': get_option('c_args'),
951       'c_link_args': get_option('c_link_args'),
952       'yacc': yacc.full_path() + ' ' + yacc.version(),
953     }, section: 'Compiler')
954     summary({
955       'prefix': get_option('prefix'),
956       'bindir': get_option('bindir'),
957       'libdir': get_option('libdir'),
958       'datadir': get_option('datadir'),
959       'xkb-config-root': XKBCONFIGROOT,
960       'xkb-config-extra-path': XKBCONFIGEXTRAPATH,
961       'xlocaledir': XLOCALEDIR,
962     }, section: 'Directories')
963     summary({
964       'docs': get_option('enable-docs'),
965       'tools': get_option('enable-tools'),
966       'wayland': get_option('enable-wayland'),
967       'x11': get_option('enable-x11'),
968     }, section: 'Features')
969     summary({
970       'layout': get_option('default-layout'),
971       'model': get_option('default-model'),
972       'options': get_option('default-options'),
973       'rules': get_option('default-rules'),
974       'variant': get_option('default-variant'),
975     }, section: 'Defaults')
976 endif