screenshooter: Add agl-screenshooter protocol
[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 agl_shell_xml = files('protocol/agl-shell.xml')
67 agl_shell_desktop_xml = files('protocol/agl-shell-desktop.xml')
68 agl_screenshooter = files('protocol/agl-screenshooter.xml')
69 xdg_shell_xml = join_paths(dir_wp_base, 'stable', 'xdg-shell', 'xdg-shell.xml')
70
71 protocols = [
72   { 'name': 'agl-shell', 'source': 'internal' },
73   { 'name': 'agl-shell-desktop', 'source': 'internal' },
74   { 'name': 'agl-screenshooter', 'source': 'internal' },
75   { 'name': 'xdg-shell', 'source': 'wp-stable' },
76 ]
77
78 foreach proto: protocols
79     proto_name = proto['name']
80     if proto['source'] == 'internal'
81         base_file = proto_name
82         xml_path = join_paths('protocol', '@0@.xml'.format(base_file))
83     elif proto['source'] == 'wp-stable'
84         base_file = proto_name
85         xml_path = join_paths(dir_wp_base, 'stable', proto_name, '@0@.xml'.format(base_file))
86     else
87         base_file = '@0@-unstable-@1@'.format(proto_name, proto['version'])
88         xml_path = join_paths(dir_wp_base, 'unstable', proto_name, '@0@.xml'.format(base_file))
89     endif
90
91     foreach output_type: [ 'client-header', 'server-header', 'private-code' ]
92         if output_type == 'client-header'
93             output_file = '@0@-client-protocol.h'.format(base_file)
94         elif output_type == 'server-header'
95             output_file = '@0@-server-protocol.h'.format(base_file)
96         else
97             output_file = '@0@-protocol.c'.format(base_file)
98             if dep_scanner.version().version_compare('< 1.14.91')
99                 output_type = 'code'
100             endif
101         endif
102
103         var_name = output_file.underscorify()
104         target = custom_target(
105             '@0@ @1@'.format(base_file, output_type),
106             command: [ prog_scanner, output_type, '@INPUT@', '@OUTPUT@' ],
107             input: xml_path,
108             output: output_file,
109         )
110
111         set_variable(var_name, target)
112     endforeach
113 endforeach
114
115 # libweston-6 pkg-config file already has 'libweston-6' as prefix but
116 # agl-compositor uses 'libweston-6' also. This makes use of the prefix
117 # path as to allow building and installing the compositor locally
118 prefix_path = get_option('prefix')
119 message('prefix_path ' + prefix_path)
120 if not prefix_path.contains('/usr')
121   additional_include_dir = include_directories(prefix_path + '/' + 'include')
122   local_dep = declare_dependency(include_directories: additional_include_dir)
123 else
124   local_dep = []
125 endif
126
127 dir_data = join_paths(prefix_path, get_option('datadir'))
128 dir_data_agl_compositor = join_paths('agl-compositor', 'protocols')
129 dir_data_pc = join_paths(dir_data, 'pkgconfig')
130 libweston_dep = dependency(libweston_version)
131
132 deps_libweston = [
133   dependency('wayland-server'),
134   libweston_dep,
135   dependency('libweston-desktop-8'),
136   local_dep,
137 ]
138
139 srcs_agl_compositor = [
140         'src/main.c',
141         'src/desktop.c',
142         'src/layout.c',
143         'src/policy.c',
144         'src/shell.c',
145         'src/screenshooter.c',
146         'shared/option-parser.c',
147         'shared/os-compatibility.c',
148         agl_shell_server_protocol_h,
149         agl_shell_desktop_server_protocol_h,
150         agl_screenshooter_server_protocol_h,
151         agl_shell_protocol_c,
152         agl_shell_desktop_protocol_c,
153         agl_screenshooter_protocol_c,
154         xdg_shell_protocol_c,
155 ]
156
157 policy_to_install = get_option('policy-default')
158 if policy_to_install == 'auto' or policy_to_install == 'allow-all'
159   srcs_agl_compositor += 'src/policy-default.c'
160   message('Installing allow all policy')
161 elif policy_to_install == 'deny-all'
162   srcs_agl_compositor += 'src/policy-deny.c'
163   message('Installing deny all policy')
164 endif
165
166
167 # From meson documentation:
168 # In order to look for headers in a specific directory you can use args :
169 # '-I/extra/include/dir, but this should only be used in exceptional cases for
170 # includes that can't be detected via pkg-config and passed via dependencies.
171 if libweston_dep.found()
172   if not prefix_path.contains('/usr')
173     dir_path_x11_backend = join_paths(prefix_path, 'include', libweston_version, 'libweston', 'backend-x11.h')
174   else
175     dir_path_x11_backend = join_paths(libweston_version, 'libweston', 'backend-x11.h')
176   endif
177
178   # do the test
179   if cc.has_header(dir_path_x11_backend)
180     config_h.set('HAVE_BACKEND_X11', 1)
181   endif
182 endif
183
184 if dep_libsystemd.found()
185   config_h.set('HAVE_SYSTEMD', 1)
186
187   srcs_agl_compositor += 'src/systemd-notify.c'
188   deps_libweston += dep_libsystemd
189
190   message('Found systemd, enabling notify support')
191 endif
192
193 if deps_remoting.length() == depnames.length()
194   config_h.set('HAVE_REMOTING', 1)
195   message('Found remoting depends, enabling remoting')
196 endif
197
198 if dep_libsmack.found()
199   config_h.set('HAVE_SMACK', 1)
200   deps_libweston += dep_libsmack
201 endif
202
203 configure_file(output: 'config.h', configuration: config_h)
204
205 exe_agl_compositor = executable(
206         'agl-compositor',
207         srcs_agl_compositor,
208         dependencies: deps_libweston,
209         install: true
210 )
211
212 pkgconfig.generate(
213         filebase: 'agl-compositor-@0@-protocols'.format(agl_compositor_version),
214         name: 'agl-compositor private protocols',
215         version: agl_compositor_version,
216         description: 'agl-compositor protocol files',
217         variables: [
218                 'datarootdir=' + join_paths('${prefix}', get_option('datadir')),
219                 'pkgdatadir=' + join_paths('${pc_sysrootdir}${datarootdir}', dir_data_agl_compositor)
220         ],
221         install_dir: dir_data_pc
222 )
223
224 install_data(
225         [ agl_shell_xml, agl_shell_desktop_xml ],
226         install_dir: join_paths(dir_data, dir_data_agl_compositor)
227 )