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