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