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