protocol: Add agl-shell-desktop protocol
[src/agl-compositor.git] / meson.build
1 project('agl-compositor',
2   'c',
3   version: '0.0.15',
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.15'
14 pkgconfig = import('pkgconfig')
15
16 cc = meson.get_compiler('c')
17 add_project_arguments(
18   cc.get_supported_arguments([
19     '-Wno-unused-parameter',
20     '-Wno-pedantic',
21     '-Wextra',
22     '-Werror'
23   ]),
24   language: 'c'
25 )
26
27 add_project_arguments([
28     '-DPACKAGE_STRING="agl-compositor @0@"'.format(meson.project_version()),
29     '-D_GNU_SOURCE',
30     '-D_ALL_SOURCE',
31   ],
32   language: 'c'
33 )
34
35 optional_libc_funcs = [ 'memfd_create', 'strchrnul' ]
36 foreach func: optional_libc_funcs
37     if cc.has_function(func)
38         add_project_arguments('-DHAVE_@0@=1'.format(func.to_upper()), language: 'c')
39     endif
40 endforeach
41
42 dep_libsystemd = dependency('libsystemd', required: false)
43 dep_scanner = dependency('wayland-scanner', native: true)
44 prog_scanner = find_program(dep_scanner.get_pkgconfig_variable('wayland_scanner'))
45 dep_wp = dependency('wayland-protocols', version: '>= 1.18')
46 dir_wp_base = dep_wp.get_pkgconfig_variable('pkgdatadir')
47
48 agl_shell_xml = files('protocol/agl-shell.xml')
49 xdg_shell_xml = join_paths(dir_wp_base, 'stable', 'xdg-shell', 'xdg-shell.xml')
50
51 protocols = [
52   { 'name': 'agl-shell', 'source': 'internal' },
53   { 'name': 'agl-shell-desktop', 'source': 'internal' },
54   { 'name': 'xdg-shell', 'source': 'wp-stable' },
55 ]
56
57 foreach proto: protocols
58     proto_name = proto['name']
59     if proto['source'] == 'internal'
60         base_file = proto_name
61         xml_path = join_paths('protocol', '@0@.xml'.format(base_file))
62     elif proto['source'] == 'wp-stable'
63         base_file = proto_name
64         xml_path = join_paths(dir_wp_base, 'stable', proto_name, '@0@.xml'.format(base_file))
65     else
66         base_file = '@0@-unstable-@1@'.format(proto_name, proto['version'])
67         xml_path = join_paths(dir_wp_base, 'unstable', proto_name, '@0@.xml'.format(base_file))
68     endif
69
70     foreach output_type: [ 'client-header', 'server-header', 'private-code' ]
71         if output_type == 'client-header'
72             output_file = '@0@-client-protocol.h'.format(base_file)
73         elif output_type == 'server-header'
74             output_file = '@0@-server-protocol.h'.format(base_file)
75         else
76             output_file = '@0@-protocol.c'.format(base_file)
77             if dep_scanner.version().version_compare('< 1.14.91')
78                 output_type = 'code'
79             endif
80         endif
81
82         var_name = output_file.underscorify()
83         target = custom_target(
84             '@0@ @1@'.format(base_file, output_type),
85             command: [ prog_scanner, output_type, '@INPUT@', '@OUTPUT@' ],
86             input: xml_path,
87             output: output_file,
88         )
89
90         set_variable(var_name, target)
91     endforeach
92 endforeach
93
94 # libweston-6 pkg-config file already has 'libweston-6' as prefix but
95 # agl-compositor uses 'libweston-6' also. This makes use of the prefix
96 # path as to allow building and installing the compositor locally
97 prefix_path = get_option('prefix')
98 message('prefix_path ' + prefix_path)
99 if not prefix_path.contains('/usr')
100   additional_include_dir = include_directories(prefix_path + '/' + 'include')
101   local_dep = declare_dependency(include_directories: additional_include_dir)
102 else
103   local_dep = []
104 endif
105
106 dir_data = join_paths(prefix_path, get_option('datadir'))
107 dir_data_agl_compositor = join_paths('agl-compositor', 'protocols')
108 dir_data_pc = join_paths(dir_data, 'pkgconfig')
109 libweston_dep = dependency('libweston-7')
110
111 deps_libweston = [
112   dependency('wayland-server'),
113   libweston_dep,
114   dependency('libweston-desktop-7'),
115   local_dep,
116 ]
117
118 srcs_agl_compositor = [
119         'src/main.c',
120         'src/desktop.c',
121         'src/layout.c',
122         'src/shell.c',
123         'shared/option-parser.c',
124         'shared/os-compatibility.c',
125         agl_shell_server_protocol_h,
126         agl_shell_desktop_server_protocol_h,
127         agl_shell_protocol_c,
128         agl_shell_desktop_protocol_c,
129         xdg_shell_protocol_c,
130 ]
131
132 # From meson documentation:
133 # In order to look for headers in a specific directory you can use args :
134 # '-I/extra/include/dir, but this should only be used in exceptional cases for
135 # includes that can't be detected via pkg-config and passed via dependencies.
136 if libweston_dep.found()
137   if not prefix_path.contains('/usr')
138     dir_path_x11_backend = join_paths(prefix_path, 'include', 'libweston-7', 'libweston', 'backend-x11.h')
139   else
140     dir_path_x11_backend = join_paths('libweston-7', 'libweston', 'backend-x11.h')
141   endif
142
143   # do the test
144   if cc.has_header(dir_path_x11_backend)
145     config_h.set('HAVE_BACKEND_X11', 1)
146   endif
147 endif
148
149 if dep_libsystemd.found()
150   config_h.set('HAVE_SYSTEMD', 1)
151
152   srcs_agl_compositor += 'src/systemd-notify.c'
153   deps_libweston += dep_libsystemd
154
155   message('Found systemd, enabling notify support')
156 endif
157
158 configure_file(output: 'config.h', configuration: config_h)
159
160 exe_agl_compositor = executable(
161         'agl-compositor',
162         srcs_agl_compositor,
163         dependencies: deps_libweston,
164         install: true
165 )
166
167 pkgconfig.generate(
168         filebase: 'agl-compositor-@0@-protocols'.format(agl_compositor_version),
169         name: 'agl-compositor private protocols',
170         version: agl_compositor_version,
171         description: 'agl-compositor protocol files',
172         variables: [
173                 'datarootdir=' + join_paths('${prefix}', get_option('datadir')),
174                 'pkgdatadir=' + join_paths('${pc_sysrootdir}${datarootdir}', dir_data_agl_compositor)
175         ],
176         install_dir: dir_data_pc
177 )
178
179 install_data(
180         [ agl_shell_xml ],
181         install_dir: join_paths(dir_data, dir_data_agl_compositor)
182 )