meson.build: Allow to install the private extension
[src/agl-compositor.git] / meson.build
1 project('agl-compositor',
2   'c',
3   version: '0.0.13',
4   default_options: [
5     'warning_level=3',
6     'c_std=gnu99',
7   ],
8   meson_version: '>= 0.47',
9   license: 'MIT/Expat',
10 )
11
12 config_h = configuration_data()
13 agl_compositor_version = '0.0.13'
14 pkgconfig = import('pkgconfig')
15
16 cc = meson.get_compiler('c')
17 add_project_arguments(
18   cc.get_supported_arguments([
19     '-Wno-unused-parameter',
20     '-Wno-pedantic',
21     '-Wextra',
22     '-Werror'
23   ]),
24   language: 'c'
25 )
26
27 add_project_arguments([
28     '-DPACKAGE_STRING="agl-compositor @0@"'.format(meson.project_version()),
29     '-D_GNU_SOURCE',
30     '-D_ALL_SOURCE',
31   ],
32   language: 'c'
33 )
34
35 optional_libc_funcs = [ 'memfd_create', 'strchrnul' ]
36 foreach func: optional_libc_funcs
37     if cc.has_function(func)
38         add_project_arguments('-DHAVE_@0@=1'.format(func.to_upper()), language: 'c')
39     endif
40 endforeach
41
42 dep_libsystemd = dependency('libsystemd', required: false)
43 dep_scanner = dependency('wayland-scanner', native: true)
44 prog_scanner = find_program(dep_scanner.get_pkgconfig_variable('wayland_scanner'))
45 dep_wp = dependency('wayland-protocols', version: '>= 1.12')
46 dir_wp_base = dep_wp.get_pkgconfig_variable('pkgdatadir')
47
48 agl_shell_xml = files('protocol/agl-shell.xml')
49 xdg_shell_xml = join_paths(dir_wp_base, 'stable', 'xdg-shell', 'xdg-shell.xml')
50
51 protocols = [
52   { 'name': 'agl-shell', 'source': 'internal' },
53   { 'name': 'xdg-shell', 'source': 'wp-stable' },
54 ]
55
56 foreach proto: protocols
57     proto_name = proto['name']
58     if proto['source'] == 'internal'
59         base_file = proto_name
60         xml_path = join_paths('protocol', '@0@.xml'.format(base_file))
61     elif proto['source'] == 'wp-stable'
62         base_file = proto_name
63         xml_path = join_paths(dir_wp_base, 'stable', proto_name, '@0@.xml'.format(base_file))
64     else
65         base_file = '@0@-unstable-@1@'.format(proto_name, proto['version'])
66         xml_path = join_paths(dir_wp_base, 'unstable', proto_name, '@0@.xml'.format(base_file))
67     endif
68
69     foreach output_type: [ 'client-header', 'server-header', 'private-code' ]
70         if output_type == 'client-header'
71             output_file = '@0@-client-protocol.h'.format(base_file)
72         elif output_type == 'server-header'
73             output_file = '@0@-server-protocol.h'.format(base_file)
74         else
75             output_file = '@0@-protocol.c'.format(base_file)
76             if dep_scanner.version().version_compare('< 1.14.91')
77                 output_type = 'code'
78             endif
79         endif
80
81         var_name = output_file.underscorify()
82         target = custom_target(
83             '@0@ @1@'.format(base_file, output_type),
84             command: [ prog_scanner, output_type, '@INPUT@', '@OUTPUT@' ],
85             input: xml_path,
86             output: output_file,
87         )
88
89         set_variable(var_name, target)
90     endforeach
91 endforeach
92
93 # libweston-6 pkg-config file already has 'libweston-6' as prefix but
94 # agl-compositor uses 'libweston-6' also. This makes use of the prefix
95 # path as to allow building and installing the compositor locally
96 prefix_path = get_option('prefix')
97 message('prefix_path ' + prefix_path)
98 if not prefix_path.contains('/usr')
99   additional_include_dir = include_directories(prefix_path + '/' + 'include')
100   local_dep = declare_dependency(include_directories: additional_include_dir)
101 else
102   local_dep = []
103 endif
104
105 dir_data = join_paths(prefix_path, get_option('datadir'))
106 dir_data_agl_compositor = join_paths('agl-compositor', 'protocols')
107 dir_data_pc = join_paths(dir_data, 'pkgconfig')
108
109 deps_libweston = [
110   dependency('wayland-server'),
111   dependency('libweston-6'),
112   dependency('libweston-desktop-6'),
113   local_dep,
114 ]
115
116 srcs_agl_compositor = [
117         'src/main.c',
118         'src/desktop.c',
119         'src/layout.c',
120         'src/shell.c',
121         'shared/option-parser.c',
122         'shared/os-compatibility.c',
123         agl_shell_server_protocol_h,
124         agl_shell_protocol_c,
125         xdg_shell_protocol_c,
126 ]
127
128 if dep_libsystemd.found()
129   config_h.set('HAVE_SYSTEMD', 1)
130
131   srcs_agl_compositor += 'src/systemd-notify.c'
132   deps_libweston += dep_libsystemd
133
134   message('Found systemd, enabling notify support')
135 endif
136
137 configure_file(output: 'config.h', configuration: config_h)
138
139 exe_agl_compositor = executable(
140         'agl-compositor',
141         srcs_agl_compositor,
142         dependencies: deps_libweston,
143         install: true
144 )
145
146 pkgconfig.generate(
147         filebase: 'agl-compositor-@0@-protocols'.format(agl_compositor_version),
148         name: 'agl-compositor private protocols',
149         version: agl_compositor_version,
150         description: 'agl-compositor protocol files',
151         variables: [
152                 'datarootdir=' + join_paths('${prefix}', get_option('datadir')),
153                 'pkgdatadir=' + join_paths('${pc_sysrootdir}${datarootdir}', dir_data_agl_compositor)
154         ],
155         install_dir: dir_data_pc
156 )
157
158 install_data(
159         [ agl_shell_xml ],
160         install_dir: join_paths(dir_data, dir_data_agl_compositor)
161 )