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