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