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