Testing
[src/agl-compositor.git] / meson.build
1 project('agl-compositor',
2   'c','cpp',
3   version: '0.0.21',
4   default_options: [
5     'warning_level=3',
6     'c_std=gnu99',
7     'werror=true',
8   ],
9   meson_version: '>= 0.53',
10   license: 'MIT/Expat',
11 )
12
13 config_h = configuration_data()
14 libweston_version = 'libweston-10'
15 pkgconfig = import('pkgconfig')
16 fs = import('fs')
17
18 cc = meson.get_compiler('c')
19 cxx = meson.get_compiler('cpp')
20
21 add_project_arguments(
22   cc.get_supported_arguments([
23     '-Wno-unused-parameter',
24     '-Wno-pedantic',
25   ]),
26   language: 'c'
27 )
28
29 add_project_arguments([
30     '-DPACKAGE_STRING="agl-compositor @0@"'.format(meson.project_version()),
31     '-D_GNU_SOURCE',
32     '-D_ALL_SOURCE',
33   ],
34   language: 'c'
35 )
36
37 optional_libc_funcs = [ 'memfd_create', 'strchrnul' ]
38 foreach func: optional_libc_funcs
39     if cc.has_function(func)
40         add_project_arguments('-DHAVE_@0@=1'.format(func.to_upper()), language: 'c')
41     endif
42 endforeach
43
44 dep_libsystemd = dependency('libsystemd', required: false)
45 dep_libsmack = dependency('libsmack', required: false)
46 dep_scanner = dependency('wayland-scanner')
47 prog_scanner = find_program(dep_scanner.get_pkgconfig_variable('wayland_scanner'))
48 dep_wp = dependency('wayland-protocols', version: '>= 1.18')
49 dir_wp_base = dep_wp.get_pkgconfig_variable('pkgdatadir')
50
51 depnames = [
52   'gstreamer-1.0', 'gstreamer-allocators-1.0',
53   'gstreamer-app-1.0', 'gstreamer-video-1.0',
54   'gobject-2.0', 'glib-2.0'
55 ]
56
57 deps_remoting = []
58 foreach depname : depnames
59   dep = dependency(depname, required: false)
60   if not dep.found()
61     message('Remoting requires @0@ which was not found. '.format(depname))
62   endif
63   deps_remoting += dep
64 endforeach
65
66
67 # the transmitter plug-in requires waltham but we don't have a cflags or libs
68 # for it so we add waltham depends here. Further more, the output is being
69 # handled by remoting plug-in
70 depnames_waltham = [
71   'waltham', 'waltham-transmitter',
72 ]
73
74 deps_waltham = []
75 foreach depname : depnames_waltham
76   dep = dependency(depname, required: false)
77   if dep.found()
78     deps_waltham += dep
79   else
80     message('Waltham requires @0@ which was not found. '.format(depname))
81   endif
82 endforeach
83
84 deps_waltham += deps_remoting
85
86 agl_shell_xml = files('protocol/agl-shell.xml')
87 agl_shell_desktop_xml = files('protocol/agl-shell-desktop.xml')
88 agl_screenshooter = files('protocol/agl-screenshooter.xml')
89 xdg_shell_xml = join_paths(dir_wp_base, 'stable', 'xdg-shell', 'xdg-shell.xml')
90
91 protocols = [
92   { 'name': 'agl-shell', 'source': 'internal' },
93   { 'name': 'agl-shell-desktop', 'source': 'internal' },
94   { 'name': 'agl-screenshooter', 'source': 'internal' },
95   { 'name': 'xdg-shell', 'source': 'wp-stable' },
96   { 'name': 'xdg-output', 'source': 'unstable', 'version': 'v1' },
97 ]
98
99 foreach proto: protocols
100     proto_name = proto['name']
101     if proto['source'] == 'internal'
102         base_file = proto_name
103         xml_path = join_paths('protocol', '@0@.xml'.format(base_file))
104     elif proto['source'] == 'wp-stable'
105         base_file = proto_name
106         xml_path = join_paths(dir_wp_base, 'stable', proto_name, '@0@.xml'.format(base_file))
107     else
108         base_file = '@0@-unstable-@1@'.format(proto_name, proto['version'])
109         xml_path = join_paths(dir_wp_base, 'unstable', proto_name, '@0@.xml'.format(base_file))
110     endif
111
112     foreach output_type: [ 'client-header', 'server-header', 'private-code' ]
113         if output_type == 'client-header'
114             output_file = '@0@-client-protocol.h'.format(base_file)
115         elif output_type == 'server-header'
116             output_file = '@0@-server-protocol.h'.format(base_file)
117         else
118             output_file = '@0@-protocol.c'.format(base_file)
119             if dep_scanner.version().version_compare('< 1.14.91')
120                 output_type = 'code'
121             endif
122         endif
123
124         var_name = output_file.underscorify()
125         target = custom_target(
126             '@0@ @1@'.format(base_file, output_type),
127             command: [ prog_scanner, output_type, '@INPUT@', '@OUTPUT@' ],
128             input: xml_path,
129             output: output_file,
130         )
131
132         set_variable(var_name, target)
133     endforeach
134 endforeach
135
136 prefix_path = get_option('prefix')
137 dir_data = join_paths(prefix_path, get_option('datadir'))
138 dir_data_agl_compositor = join_paths('agl-compositor', 'protocols')
139 dir_data_pc = join_paths(dir_data, 'pkgconfig')
140 libweston_dep = dependency(libweston_version)
141
142 deps_libweston = [
143   dependency('wayland-server'),
144   dependency('weston'),
145   libweston_dep,
146   dependency('libweston-desktop-10'),
147 ]
148
149
150 srcs_agl_compositor = [
151         'src/compositor.c',
152         'src/desktop.c',
153         'src/layout.c',
154         'src/policy.c',
155         'src/shell.c',
156         'src/screenshooter.c',
157         'src/input.c',
158         'shared/option-parser.c',
159         'shared/os-compatibility.c',
160         'shared/process-util.c',
161         agl_shell_server_protocol_h,
162         agl_shell_desktop_server_protocol_h,
163         agl_screenshooter_server_protocol_h,
164         agl_shell_protocol_c,
165         agl_shell_desktop_protocol_c,
166         agl_screenshooter_protocol_c,
167         xdg_shell_protocol_c,
168 ]
169
170 policy_to_install = get_option('policy-default')
171 if policy_to_install == 'auto' or policy_to_install == 'allow-all'
172   srcs_agl_compositor += 'src/policy-default.c'
173   message('Installing allow all policy')
174 elif policy_to_install == 'deny-all'
175   srcs_agl_compositor += 'src/policy-deny.c'
176   message('Installing deny all policy')
177 elif policy_to_install == 'rba'
178   srcs_agl_compositor += ['src/policy-rba.c', 'src/rba_adapter.cpp']
179   deps_libweston += dependency('librba')
180   message('Installing rba policy')
181 endif
182
183 # From meson documentation:
184 # In order to look for headers in a specific directory you can use args :
185 # '-I/extra/include/dir, but this should only be used in exceptional cases for
186 # includes that can't be detected via pkg-config and passed via dependencies.
187 if libweston_dep.found()
188   if not meson.is_cross_build()
189     if not prefix_path.contains('/usr')
190       dir_path_x11_backend = join_paths(prefix_path, 'include', libweston_version, 'libweston', 'backend-x11.h')
191       dir_path_headless_backend = join_paths(prefix_path, 'include', libweston_version, 'libweston', 'backend-headless.h')
192     else
193       dir_path_x11_backend = join_paths(libweston_version, 'libweston', 'backend-x11.h')
194       dir_path_x11_backend = join_paths(libweston_version, 'libweston', 'backend-headless.h')
195     endif
196   else
197     message('Building with cross environment')
198     dir_path_x11_backend = join_paths(libweston_version, 'libweston', 'backend-x11.h')
199     dir_path_headless_backend = join_paths(libweston_version, 'libweston', 'backend-headless.h')
200   endif
201
202   # do the test
203   if cc.has_header(dir_path_x11_backend)
204     config_h.set('HAVE_BACKEND_X11', 1)
205     message('Building with X11 backend')
206   endif
207
208   if cc.has_header(dir_path_headless_backend)
209     config_h.set('HAVE_BACKEND_HEADLESS', 1)
210     message('Building with headless backend')
211   endif
212 endif
213
214 if dep_libsystemd.found()
215   config_h.set('HAVE_SYSTEMD', 1)
216
217   srcs_agl_compositor += 'src/systemd-notify.c'
218   deps_libweston += dep_libsystemd
219
220   message('Found systemd, enabling notify support')
221 endif
222
223 if deps_remoting.length() == depnames.length()
224   config_h.set('HAVE_REMOTING', 1)
225   message('Found remoting depends, enabling remoting')
226 endif
227
228 if deps_waltham.length() == depnames_waltham.length() + depnames.length() and not get_option('waltham')
229   message('Found waltham depends, but waltham is deprecated')
230 elif deps_waltham.length() == depnames_waltham.length() + depnames.length() and get_option('waltham')
231   config_h.set('HAVE_WALTHAM', 1)
232   message('Found waltham depends, enabling waltham')
233 endif
234
235 if dep_libsmack.found()
236   config_h.set('HAVE_SMACK', 1)
237   deps_libweston += dep_libsmack
238 endif
239
240 if get_option('xwayland')
241         config_h.set('BUILD_XWAYLAND', '1')
242
243         srcs_agl_compositor += 'src/xwayland.c'
244         config_h.set_quoted('XSERVER_PATH', get_option('xwayland-path'))
245 endif
246
247 dir_module_agl_compositor = join_paths(join_paths(prefix_path, get_option('libdir')), 'agl-compositor')
248
249 libexec_compositor = shared_library(
250         'exec_compositor',
251         sources: srcs_agl_compositor,
252         dependencies: deps_libweston,
253         install_dir: dir_module_agl_compositor,
254         install: true,
255         version: meson.project_version(),
256         soversion: 0
257 )
258
259 dep_libexec_compositor = declare_dependency(
260         link_with: libexec_compositor,
261         include_directories: [ include_directories('.') ],
262         dependencies: deps_libweston,
263 )
264
265 configure_file(output: 'config.h', configuration: config_h)
266
267 exe_agl_compositor = executable(
268         'agl-compositor',
269         'src/main.c',
270         dependencies: dep_libexec_compositor,
271         install_rpath: dir_module_agl_compositor,
272         install: true
273 )
274
275 pkgconfig.generate(
276         filebase: 'agl-compositor-@0@-protocols'.format(meson.project_version()),
277         name: 'agl-compositor private protocols',
278         version: meson.project_version(),
279         description: 'agl-compositor protocol files',
280         variables: [
281                 'datarootdir=' + join_paths('${prefix}', get_option('datadir')),
282                 'pkgdatadir=' + join_paths('${pc_sysrootdir}${datarootdir}', dir_data_agl_compositor)
283         ],
284         install_dir: dir_data_pc
285 )
286
287 install_data(
288         [ agl_shell_xml, agl_shell_desktop_xml ],
289         install_dir: join_paths(dir_data, dir_data_agl_compositor)
290 )
291
292 common_inc = [ include_directories('src'), include_directories('.') ]
293 subdir('clients')
294
295 if get_option('grpc-proxy')
296   subdir('grpc-proxy')
297 endif