]> git.proxmox.com Git - mirror_lxcfs.git/blob - meson.build
build: use dependency() for fuse detection
[mirror_lxcfs.git] / meson.build
1 # SPDX-License-Identifier: LGPL-2.1-or-later
2
3 project('lxcfs', 'c',
4 version : '4.0.0',
5 license : 'LGPLv2+',
6 default_options: [
7 'b_colorout=always',
8 'b_asneeded=true',
9 'b_pie=true',
10 'c_std=gnu11',
11 'warning_level=2',
12 ],
13 meson_version : '>= 0.45',
14 )
15
16 conf = configuration_data()
17 conf.set_quoted('PROJECT_URL', 'https://linuxcontainers.org/lxcfs/introduction/')
18 conf.set('PROJECT_VERSION', meson.project_version(),
19 description : 'Numerical project version (used where a simple number is expected)')
20 project_source_root = meson.current_source_dir()
21 project_build_root = meson.current_build_dir()
22
23 # join_paths ignores the preceding arguments if an absolute component is
24 # encountered, so this should canonicalize various paths when they are
25 # absolute or relative.
26 prefixdir = get_option('prefix')
27 if not prefixdir.startswith('/')
28 error('Prefix is not absolute: "@0@"'.format(prefixdir))
29 endif
30 bindir = join_paths(prefixdir, get_option('bindir'))
31 libdir = join_paths(prefixdir, get_option('libdir'))
32 lxcfsdir = join_paths(libdir, 'lxcfs')
33 sysconfdir = join_paths(prefixdir, get_option('sysconfdir'))
34 runtimepath = join_paths(prefixdir, get_option('runtime-path'))
35 localstatedir = join_paths('/', get_option('localstatedir'))
36 datadir = join_paths(prefixdir, get_option('datadir'))
37
38 conf.set_quoted('BINDIR', bindir)
39 conf.set_quoted('LIBDIR', libdir)
40 conf.set_quoted('LOCALSTATEDIR', localstatedir)
41 conf.set_quoted('RUNTIME_PATH', runtimepath)
42 conf.set_quoted('SYSCONFDIR', sysconfdir)
43
44 conf.set_quoted('LXCFS_BUILD_ROOT', project_build_root)
45 conf.set_quoted('LXCFS_SOURCE_ROOT', project_source_root)
46
47 lxcfssharedir = join_paths(datadir, 'lxcfs')
48 conf.set_quoted('LXCFSSHAREDIR', lxcfssharedir)
49
50 lxcconfdir = join_paths(datadir, 'lxc/config/common.conf.d')
51 conf.set_quoted('LXCCONFDIR', lxcconfdir)
52
53 init_script = get_option('init-script')
54
55 cc = meson.get_compiler('c')
56 meson_build_sh = find_program('tools/meson-build.sh')
57
58 want_tests = get_option('tests')
59
60 possible_cc_flags = [
61 '-Wvla',
62 '-Wimplicit-fallthrough=5',
63 '-Wcast-align',
64 '-Wstrict-prototypes',
65 '-fno-strict-aliasing',
66 '-fstack-clash-protection',
67 '-fstack-protector-strong',
68 '--param=ssp-buffer-size=4',
69 '--mcet -fcf-protection',
70 '-Werror=implicit-function-declaration',
71 '-Wlogical-op',
72 '-Wmissing-include-dirs',
73 '-Wold-style-definition',
74 '-Winit-self',
75 '-Wunused-but-set-variable',
76 '-Wno-unused-parameter',
77 '-Wfloat-equal',
78 '-Wsuggest-attribute=noreturn',
79 '-Werror=return-type',
80 '-Werror=incompatible-pointer-types',
81 '-Wformat=2',
82 '-Wshadow',
83 '-Wendif-labels',
84 '-Werror=overflow',
85 '-fdiagnostics-show-option',
86 '-Werror=shift-count-overflow',
87 '-Werror=shift-overflow=2',
88 '-Wdate-time',
89 '-Wnested-externs',
90 '-fasynchronous-unwind-tables',
91 '-fexceptions',
92 '-Warray-bounds',
93 '-Wrestrict',
94 '-Wreturn-local-addr',
95 '-fsanitize=cfi',
96 '-Wstringop-overflow',
97 ]
98
99 possible_link_flags = [
100 '-Wl,--gc-sections',
101 '-Wl,-z,relro',
102 '-Wl,-z,now',
103 '-Wl,-fuse-ld=gold',
104 ]
105
106 if meson.version().version_compare('>=0.46')
107 add_project_link_arguments(cc.get_supported_link_arguments(possible_link_flags), language : 'c')
108 else
109 add_project_link_arguments(possible_link_flags, language : 'c')
110 endif
111
112 add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language : 'c')
113
114 foreach ident : [
115 ['strlcpy', '''#include <string.h>'''],
116 ['strlcat', '''#include <string.h>'''],
117 ['pidfd_send_signal', '''#include <stdlib.h>
118 #include <unistd.h>
119 #include <signal.h>
120 #include <sys/wait.h>'''],
121 ['pidfd_open', '''#include <stdlib.h>
122 #include <unistd.h>
123 #include <signal.h>
124 #include <sys/wait.h>'''],
125 ]
126
127 have = cc.has_function(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE')
128 conf.set10('HAVE_' + ident[0].to_upper(), have)
129 endforeach
130
131 conf.set('_FILE_OFFSET_BITS', 64)
132
133 libfuse = dependency('fuse3', required : false)
134 if libfuse.found()
135 conf.set10('HAVE_FUSE3', true)
136 conf.set('FUSE_USE_VERSION', 30)
137 else
138 if dependency('fuse').found()
139 conf.set10('HAVE_FUSE', true)
140 conf.set('FUSE_USE_VERSION', 26)
141 endif
142 endif
143
144 libdl = cc.find_library('dl')
145 threads = dependency('threads')
146
147 config_h = configure_file(
148 output : 'config.h',
149 configuration : conf)
150 config_include = include_directories('.')
151
152 add_project_arguments('-include', 'config.h', language : 'c')
153
154 subdir('tests')
155
156 public_programs = []
157
158 lxcfs_sources = files('src/lxcfs.c')
159
160 public_programs += executable(
161 'lxcfs',
162 lxcfs_sources,
163 dependencies : [threads,
164 libdl,
165 libfuse],
166 install : true,
167 install_dir : bindir)
168
169 liblxcfs_sources = files(
170 'src/api_extensions.h',
171 'src/bindings.c',
172 'src/bindings.h',
173 'src/cgroups/cgfsng.c',
174 'src/cgroups/cgroup.c',
175 'src/cgroups/cgroup.h',
176 'src/cgroups/cgroup2_devices.c',
177 'src/cgroups/cgroup2_devices.h',
178 'src/cgroups/cgroup_utils.c',
179 'src/cgroups/cgroup_utils.h',
180 'src/cgroup_fuse.c',
181 'src/cgroup_fuse.h',
182 'src/cpuset_parse.c',
183 'src/cpuset_parse.h',
184 'src/lxcfs.c',
185 'src/lxcfs_fuse_compat.h',
186 'src/macro.h',
187 'src/memory_utils.h',
188 'src/proc_cpuview.c',
189 'src/proc_cpuview.h',
190 'src/proc_fuse.c',
191 'src/proc_fuse.h',
192 'src/proc_loadavg.c',
193 'src/proc_loadavg.h',
194 'src/syscall_numbers.h',
195 'src/sysfs_fuse.c',
196 'src/sysfs_fuse.h',
197 'src/utils.c',
198 'src/utils.h')
199
200 liblxcfs = shared_library(
201 'lxcfs',
202 liblxcfs_sources,
203 link_args : ['-shared'],
204 dependencies : [threads,
205 libdl,
206 libfuse],
207 install : true,
208 install_dir : lxcfsdir)
209
210 if want_tests == true
211 liblxcfs_test = shared_library(
212 'lxcfstest',
213 liblxcfs_sources,
214 link_args : ['-shared'],
215 dependencies : [threads,
216 libdl,
217 libfuse],
218 install : false,
219 install_dir : lxcfsdir,
220 c_args : '-DRELOADTEST -DDEBUG')
221 endif
222
223 if init_script == 'systemd'
224 systemd_service_data = configuration_data()
225 systemd_service_data.set_quoted('LXCFSTARGETDIR', join_paths(localstatedir, 'lib/lxcfs'))
226 systemd_service = configure_file(
227 configuration : systemd_service_data,
228 input : 'config/init/systemd/lxcfs.service.in',
229 output : 'lxcfs.service')
230 install_data(join_paths(project_build_root, 'lxcfs.service'), install_dir : '/lib/systemd/system')
231 elif init_script == 'upstart'
232 install_data('config/init/upstart/lxcfs.conf', install_dir : join_paths(sysconfdir, 'init'))
233 elif init_script == 'openrc'
234 install_data('config/init/sysvinit/lxcfs', install_dir : join_paths(sysconfdir, 'rc.d/init.d/lxcfs'))
235 elif init_script == 'sysvinit'
236 install_data('config/init/sysvinit/lxcfs', install_dir : join_paths(sysconfdir, 'rc.d/init.d/lxcfs'))
237 endif
238
239 status = [
240 '@0@ @1@'.format(meson.project_name(), meson.project_version()),
241
242 'FUSE version: @0@'.format(libfuse.version()),
243 'bin directory: @0@'.format(bindir),
244 'lib directory: @0@'.format(libdir),
245 'data directory: @0@'.format(datadir),
246 'local state directory: @0@'.format(localstatedir),
247 'prefix directory: @0@'.format(prefixdir),
248 'runtime directory: @0@'.format(runtimepath),
249 'sysconf directory: @0@'.format(sysconfdir),
250 'lxc conf directory: @0@'.format(lxcconfdir),
251 'lxcfs directory: @0@'.format(lxcfsdir),
252 'lxcfs shared directory: @0@'.format(lxcfssharedir),
253 'lxcfs build root directory: @0@'.format(project_build_root),
254 'lxcfs source root directory: @0@'.format(project_source_root),
255 'init system: @0@'.format(init_script),
256 'tests: @0@'.format(want_tests)]
257
258 message('\n '.join(status))