xref: /aosp_15_r20/external/libfuse/meson.build (revision 9e5649576b786774a32d7b0252c9cd8c6538fa49)
1*9e564957SAndroid Build Coastguard Workerproject('libfuse3', ['c'], version: '3.17.0',
2*9e564957SAndroid Build Coastguard Worker        meson_version: '>= 0.51',
3*9e564957SAndroid Build Coastguard Worker        default_options: [
4*9e564957SAndroid Build Coastguard Worker            'buildtype=debugoptimized',
5*9e564957SAndroid Build Coastguard Worker            'c_std=gnu11',
6*9e564957SAndroid Build Coastguard Worker            'cpp_std=c++11',
7*9e564957SAndroid Build Coastguard Worker            'warning_level=2',
8*9e564957SAndroid Build Coastguard Worker        ])
9*9e564957SAndroid Build Coastguard Worker
10*9e564957SAndroid Build Coastguard Worker# Would be better to create the version string
11*9e564957SAndroid Build Coastguard Worker# from integers, i.e. concatenating strings instead
12*9e564957SAndroid Build Coastguard Worker# of splitting a string, but 'project' needs to be
13*9e564957SAndroid Build Coastguard Worker# the first meson.build keyword...
14*9e564957SAndroid Build Coastguard Workerversion_list = meson.project_version().split('.')
15*9e564957SAndroid Build Coastguard WorkerFUSE_MAJOR_VERSION = version_list[0]
16*9e564957SAndroid Build Coastguard WorkerFUSE_MINOR_VERSION = version_list[1]
17*9e564957SAndroid Build Coastguard WorkerFUSE_HOTFIX_VERSION = version_list[2]
18*9e564957SAndroid Build Coastguard Worker
19*9e564957SAndroid Build Coastguard Workerplatform = host_machine.system()
20*9e564957SAndroid Build Coastguard Workerif platform == 'darwin'
21*9e564957SAndroid Build Coastguard Worker  error('libfuse does not support OS-X.\n' +
22*9e564957SAndroid Build Coastguard Worker        'Take a look at http://osxfuse.github.io/ or the more recent\n' +
23*9e564957SAndroid Build Coastguard Worker        'https://www.fuse-t.org/ instead')
24*9e564957SAndroid Build Coastguard Workerelif platform == 'cygwin' or platform == 'windows'
25*9e564957SAndroid Build Coastguard Worker  error('libfuse does not support Windows.\n' +
26*9e564957SAndroid Build Coastguard Worker        'Take a look at http://www.secfs.net/winfsp/ instead')
27*9e564957SAndroid Build Coastguard Workerendif
28*9e564957SAndroid Build Coastguard Worker
29*9e564957SAndroid Build Coastguard Workercc = meson.get_compiler('c')
30*9e564957SAndroid Build Coastguard Worker
31*9e564957SAndroid Build Coastguard Worker#
32*9e564957SAndroid Build Coastguard Worker# Feature detection, only available at libfuse compilation time,
33*9e564957SAndroid Build Coastguard Worker# but not for application linking to libfuse.
34*9e564957SAndroid Build Coastguard Worker#
35*9e564957SAndroid Build Coastguard Workerprivate_cfg = configuration_data()
36*9e564957SAndroid Build Coastguard Worker
37*9e564957SAndroid Build Coastguard Worker#
38*9e564957SAndroid Build Coastguard Worker# Feature detection, the resulting config file is installed
39*9e564957SAndroid Build Coastguard Worker# with the package.
40*9e564957SAndroid Build Coastguard Worker# Note: Symbols need to be care fully named, to avoid conflicts
41*9e564957SAndroid Build Coastguard Worker#       with applications linking to libfuse and including
42*9e564957SAndroid Build Coastguard Worker#       this config.
43*9e564957SAndroid Build Coastguard Worker#
44*9e564957SAndroid Build Coastguard Workerpublic_cfg = configuration_data()
45*9e564957SAndroid Build Coastguard Worker
46*9e564957SAndroid Build Coastguard Workerpublic_cfg.set('FUSE_MAJOR_VERSION', FUSE_MAJOR_VERSION)
47*9e564957SAndroid Build Coastguard Workerpublic_cfg.set('FUSE_MINOR_VERSION', FUSE_MINOR_VERSION)
48*9e564957SAndroid Build Coastguard Workerpublic_cfg.set('FUSE_HOTFIX_VERSION', FUSE_HOTFIX_VERSION)
49*9e564957SAndroid Build Coastguard Worker
50*9e564957SAndroid Build Coastguard Worker# Default includes when checking for presence of functions and
51*9e564957SAndroid Build Coastguard Worker# struct members
52*9e564957SAndroid Build Coastguard Workerinclude_default = '''
53*9e564957SAndroid Build Coastguard Worker#include <stdio.h>
54*9e564957SAndroid Build Coastguard Worker#include <stdlib.h>
55*9e564957SAndroid Build Coastguard Worker#include <stddef.h>
56*9e564957SAndroid Build Coastguard Worker#include <unistd.h>
57*9e564957SAndroid Build Coastguard Worker#include <sys/types.h>
58*9e564957SAndroid Build Coastguard Worker#include <sys/stat.h>
59*9e564957SAndroid Build Coastguard Worker#include <fcntl.h>
60*9e564957SAndroid Build Coastguard Worker'''
61*9e564957SAndroid Build Coastguard Workerargs_default = [ '-D_GNU_SOURCE' ]
62*9e564957SAndroid Build Coastguard Worker
63*9e564957SAndroid Build Coastguard Workerprivate_cfg.set_quoted('PACKAGE_VERSION', meson.project_version())
64*9e564957SAndroid Build Coastguard Worker
65*9e564957SAndroid Build Coastguard Worker# Test for presence of some functions
66*9e564957SAndroid Build Coastguard Workertest_funcs = [ 'fork', 'fstatat', 'openat', 'readlinkat', 'pipe2',
67*9e564957SAndroid Build Coastguard Worker               'splice', 'vmsplice', 'posix_fallocate', 'fdatasync',
68*9e564957SAndroid Build Coastguard Worker               'utimensat', 'copy_file_range', 'fallocate' ]
69*9e564957SAndroid Build Coastguard Workerforeach func : test_funcs
70*9e564957SAndroid Build Coastguard Worker    private_cfg.set('HAVE_' + func.to_upper(),
71*9e564957SAndroid Build Coastguard Worker        cc.has_function(func, prefix: include_default, args: args_default))
72*9e564957SAndroid Build Coastguard Workerendforeach
73*9e564957SAndroid Build Coastguard Workerprivate_cfg.set('HAVE_SETXATTR',
74*9e564957SAndroid Build Coastguard Worker        cc.has_function('setxattr', prefix: '#include <sys/xattr.h>'))
75*9e564957SAndroid Build Coastguard Workerprivate_cfg.set('HAVE_ICONV',
76*9e564957SAndroid Build Coastguard Worker        cc.has_function('iconv', prefix: '#include <iconv.h>'))
77*9e564957SAndroid Build Coastguard Workerprivate_cfg.set('HAVE_BACKTRACE',
78*9e564957SAndroid Build Coastguard Worker        cc.has_function('backtrace', prefix: '#include <execinfo.h>'))
79*9e564957SAndroid Build Coastguard Worker
80*9e564957SAndroid Build Coastguard Worker# Test if structs have specific member
81*9e564957SAndroid Build Coastguard Workerprivate_cfg.set('HAVE_STRUCT_STAT_ST_ATIM',
82*9e564957SAndroid Build Coastguard Worker         cc.has_member('struct stat', 'st_atim',
83*9e564957SAndroid Build Coastguard Worker                       prefix: include_default,
84*9e564957SAndroid Build Coastguard Worker                       args: args_default))
85*9e564957SAndroid Build Coastguard Workerprivate_cfg.set('HAVE_STRUCT_STAT_ST_ATIMESPEC',
86*9e564957SAndroid Build Coastguard Worker         cc.has_member('struct stat', 'st_atimespec',
87*9e564957SAndroid Build Coastguard Worker                       prefix: include_default,
88*9e564957SAndroid Build Coastguard Worker                       args: args_default))
89*9e564957SAndroid Build Coastguard Worker
90*9e564957SAndroid Build Coastguard Worker#
91*9e564957SAndroid Build Coastguard Worker# Compiler configuration
92*9e564957SAndroid Build Coastguard Worker#
93*9e564957SAndroid Build Coastguard Workeradd_project_arguments('-D_REENTRANT', '-DHAVE_LIBFUSE_PRIVATE_CONFIG_H', '-Wno-sign-compare', '-D_FILE_OFFSET_BITS=64',
94*9e564957SAndroid Build Coastguard Worker                      '-Wstrict-prototypes', '-Wmissing-declarations', '-Wwrite-strings',
95*9e564957SAndroid Build Coastguard Worker                      '-fno-strict-aliasing', language: 'c')
96*9e564957SAndroid Build Coastguard Workeradd_project_arguments('-D_REENTRANT', '-DHAVE_LIBFUSE_PRIVATE_CONFIG_H', '-D_GNU_SOURCE', '-D_FILE_OFFSET_BITS=64',
97*9e564957SAndroid Build Coastguard Worker                     '-Wno-sign-compare', '-Wmissing-declarations',
98*9e564957SAndroid Build Coastguard Worker                     '-Wwrite-strings', '-fno-strict-aliasing', language: 'cpp')
99*9e564957SAndroid Build Coastguard Worker
100*9e564957SAndroid Build Coastguard Worker# Some (stupid) GCC versions warn about unused return values even when they are
101*9e564957SAndroid Build Coastguard Worker# casted to void. This makes -Wunused-result pretty useless, since there is no
102*9e564957SAndroid Build Coastguard Worker# way to suppress the warning when we really *want* to ignore the value.
103*9e564957SAndroid Build Coastguard Workercode = '''
104*9e564957SAndroid Build Coastguard Worker__attribute__((warn_unused_result)) int get_4() {
105*9e564957SAndroid Build Coastguard Worker    return 4;
106*9e564957SAndroid Build Coastguard Worker}
107*9e564957SAndroid Build Coastguard Workerint main(void) {
108*9e564957SAndroid Build Coastguard Worker    (void) get_4();
109*9e564957SAndroid Build Coastguard Worker    return 0;
110*9e564957SAndroid Build Coastguard Worker}'''
111*9e564957SAndroid Build Coastguard Workerif not cc.compiles(code, args: [ '-O0', '-Werror=unused-result' ])
112*9e564957SAndroid Build Coastguard Worker     message('Compiler warns about unused result even when casting to void')
113*9e564957SAndroid Build Coastguard Worker     add_project_arguments('-Wno-unused-result', language: 'c')
114*9e564957SAndroid Build Coastguard Workerendif
115*9e564957SAndroid Build Coastguard Worker
116*9e564957SAndroid Build Coastguard Worker# It is hard to detect if the libc supports versioned symbols. Only gnu-libc
117*9e564957SAndroid Build Coastguard Worker# seems to provide that, but then glibc is the main target for libfuse, so
118*9e564957SAndroid Build Coastguard Worker# enable it by default
119*9e564957SAndroid Build Coastguard Workerversioned_symbols = 1
120*9e564957SAndroid Build Coastguard Worker
121*9e564957SAndroid Build Coastguard Worker# This is an attempt to detect if another libc is used.
122*9e564957SAndroid Build Coastguard Workercode = '''
123*9e564957SAndroid Build Coastguard Workerint main(void) {
124*9e564957SAndroid Build Coastguard Worker#if (defined(__UCLIBC__) || defined(__APPLE__))
125*9e564957SAndroid Build Coastguard Worker#error /* libc does not have versioned symbols */
126*9e564957SAndroid Build Coastguard Worker#endif
127*9e564957SAndroid Build Coastguard Worker    return 0;
128*9e564957SAndroid Build Coastguard Worker}'''
129*9e564957SAndroid Build Coastguard Workerif not cc.compiles(code, args: [ '-O0' ])
130*9e564957SAndroid Build Coastguard Worker  versioned_symbols = 0
131*9e564957SAndroid Build Coastguard Workerendif
132*9e564957SAndroid Build Coastguard Worker
133*9e564957SAndroid Build Coastguard Worker# The detection can be overridden, which is useful for other (above unhandled)
134*9e564957SAndroid Build Coastguard Worker# libcs and also especially useful for testing
135*9e564957SAndroid Build Coastguard Workerif get_option('disable-libc-symbol-version')
136*9e564957SAndroid Build Coastguard Worker     versioned_symbols = 0
137*9e564957SAndroid Build Coastguard Workerendif
138*9e564957SAndroid Build Coastguard Worker
139*9e564957SAndroid Build Coastguard Workerif versioned_symbols == 1
140*9e564957SAndroid Build Coastguard Worker     message('Enabling versioned libc symbols')
141*9e564957SAndroid Build Coastguard Worker     public_cfg.set('LIBFUSE_BUILT_WITH_VERSIONED_SYMBOLS', 1)
142*9e564957SAndroid Build Coastguard Worker
143*9e564957SAndroid Build Coastguard Worker     # gcc-10 and newer support the symver attribute which we need to use if we
144*9e564957SAndroid Build Coastguard Worker     # want to support LTO
145*9e564957SAndroid Build Coastguard Worker     # recent clang and gcc both support __has_attribute (and if they are too old
146*9e564957SAndroid Build Coastguard Worker     # to have __has_attribute, then they are too old to support symver)
147*9e564957SAndroid Build Coastguard Worker     # other compilers might not have __has_attribute, but in those cases
148*9e564957SAndroid Build Coastguard Worker     # it is safe for this check to fail and for us to fallback to the old _asm_
149*9e564957SAndroid Build Coastguard Worker     # method for symver. Anyway the attributes not supported by __has_attribute()
150*9e564957SAndroid Build Coastguard Worker     # unfortunately return true giving a false positive. So let's try to build
151*9e564957SAndroid Build Coastguard Worker     # using __attribute__ ((symver )) and see the result.
152*9e564957SAndroid Build Coastguard Worker     code = '''
153*9e564957SAndroid Build Coastguard Worker     __attribute__ ((symver ("test@TEST")))
154*9e564957SAndroid Build Coastguard Worker     void foo(void) {
155*9e564957SAndroid Build Coastguard Worker     }
156*9e564957SAndroid Build Coastguard Worker
157*9e564957SAndroid Build Coastguard Worker     int main(void) {
158*9e564957SAndroid Build Coastguard Worker         return 0;
159*9e564957SAndroid Build Coastguard Worker     }'''
160*9e564957SAndroid Build Coastguard Worker     if cc.compiles(code, args: [ '-O0', '-c', '-Werror'])
161*9e564957SAndroid Build Coastguard Worker          message('Compiler supports symver attribute')
162*9e564957SAndroid Build Coastguard Worker          add_project_arguments('-DHAVE_SYMVER_ATTRIBUTE', language: 'c')
163*9e564957SAndroid Build Coastguard Worker     else
164*9e564957SAndroid Build Coastguard Worker          message('Compiler does not support symver attribute')
165*9e564957SAndroid Build Coastguard Worker     endif
166*9e564957SAndroid Build Coastguard Workerelse
167*9e564957SAndroid Build Coastguard Worker     message('Disabling versioned libc symbols')
168*9e564957SAndroid Build Coastguard Workerendif
169*9e564957SAndroid Build Coastguard Worker
170*9e564957SAndroid Build Coastguard Worker# Older versions of musl libc don't unescape entries in /etc/mtab
171*9e564957SAndroid Build Coastguard Worker# Try to detect this behaviour, and work around, if necessary.
172*9e564957SAndroid Build Coastguard Workerdetect_getmntent_needs_unescape = '''
173*9e564957SAndroid Build Coastguard Worker#define _GNU_SOURCE
174*9e564957SAndroid Build Coastguard Worker#include <mntent.h>
175*9e564957SAndroid Build Coastguard Worker#include <stdio.h>
176*9e564957SAndroid Build Coastguard Worker#include <string.h>
177*9e564957SAndroid Build Coastguard Worker#include <stdlib.h>
178*9e564957SAndroid Build Coastguard Worker
179*9e564957SAndroid Build Coastguard Worker#define dir_space_tab "dir\\040space\\011tab"
180*9e564957SAndroid Build Coastguard Worker
181*9e564957SAndroid Build Coastguard Workerint main()
182*9e564957SAndroid Build Coastguard Worker{
183*9e564957SAndroid Build Coastguard Worker    const char *fake_mtab = "name " dir_space_tab " type opts 0 0\n";
184*9e564957SAndroid Build Coastguard Worker    FILE *f = fmemopen((void *)fake_mtab, strlen(fake_mtab) + 1, "r");
185*9e564957SAndroid Build Coastguard Worker    struct mntent *entp = getmntent(f);
186*9e564957SAndroid Build Coastguard Worker    fclose(f);
187*9e564957SAndroid Build Coastguard Worker    if(NULL == entp)
188*9e564957SAndroid Build Coastguard Worker        exit(EXIT_FAILURE);
189*9e564957SAndroid Build Coastguard Worker    if (0 == strcmp(entp->mnt_dir, dir_space_tab))
190*9e564957SAndroid Build Coastguard Worker        printf("needs escaping\n");
191*9e564957SAndroid Build Coastguard Worker    else
192*9e564957SAndroid Build Coastguard Worker        printf("no need to escape\n");
193*9e564957SAndroid Build Coastguard Worker}
194*9e564957SAndroid Build Coastguard Worker'''
195*9e564957SAndroid Build Coastguard Worker
196*9e564957SAndroid Build Coastguard Workerif not meson.is_cross_build()
197*9e564957SAndroid Build Coastguard Worker  result = cc.run(detect_getmntent_needs_unescape)
198*9e564957SAndroid Build Coastguard Worker  if result.compiled() and result.returncode() == 0 and result.stdout().strip() == 'needs escaping'
199*9e564957SAndroid Build Coastguard Worker    message('getmntent does not unescape')
200*9e564957SAndroid Build Coastguard Worker    add_project_arguments('-DGETMNTENT_NEEDS_UNESCAPING', language: 'c')
201*9e564957SAndroid Build Coastguard Worker  endif
202*9e564957SAndroid Build Coastguard Workerendif
203*9e564957SAndroid Build Coastguard Worker
204*9e564957SAndroid Build Coastguard Worker# Write private test results into fuse_config.h (stored in build directory)
205*9e564957SAndroid Build Coastguard Workerconfigure_file(output: 'fuse_config.h', configuration : private_cfg)
206*9e564957SAndroid Build Coastguard Worker
207*9e564957SAndroid Build Coastguard Worker# Write the test results, installed with the package,
208*9e564957SAndroid Build Coastguard Worker# symbols need to be properly prefixed to avoid
209*9e564957SAndroid Build Coastguard Worker# symbol (define) conflicts
210*9e564957SAndroid Build Coastguard Workerconfigure_file(output: 'libfuse_config.h',
211*9e564957SAndroid Build Coastguard Worker               configuration : public_cfg,
212*9e564957SAndroid Build Coastguard Worker               install: true, install_dir: join_paths(get_option('includedir'), 'fuse3'))
213*9e564957SAndroid Build Coastguard Worker
214*9e564957SAndroid Build Coastguard Worker# '.' will refer to current build directory, which contains config.h
215*9e564957SAndroid Build Coastguard Workerinclude_dirs = include_directories('include', 'lib', '.')
216*9e564957SAndroid Build Coastguard Worker
217*9e564957SAndroid Build Coastguard Worker# Common dependencies
218*9e564957SAndroid Build Coastguard Workerthread_dep = dependency('threads')
219*9e564957SAndroid Build Coastguard Worker
220*9e564957SAndroid Build Coastguard Worker#
221*9e564957SAndroid Build Coastguard Worker# Read build files from sub-directories
222*9e564957SAndroid Build Coastguard Worker#
223*9e564957SAndroid Build Coastguard Workersubdirs = [ 'lib', 'include']
224*9e564957SAndroid Build Coastguard Workerif get_option('utils') and not platform.endswith('bsd') and platform != 'dragonfly'
225*9e564957SAndroid Build Coastguard Worker  subdirs += [ 'util', 'doc' ]
226*9e564957SAndroid Build Coastguard Workerendif
227*9e564957SAndroid Build Coastguard Worker
228*9e564957SAndroid Build Coastguard Workerif get_option('examples')
229*9e564957SAndroid Build Coastguard Worker  subdirs += 'example'
230*9e564957SAndroid Build Coastguard Workerendif
231*9e564957SAndroid Build Coastguard Worker
232*9e564957SAndroid Build Coastguard Workerif get_option('tests')
233*9e564957SAndroid Build Coastguard Worker  subdirs += 'test'
234*9e564957SAndroid Build Coastguard Workerendif
235*9e564957SAndroid Build Coastguard Worker
236*9e564957SAndroid Build Coastguard Workerforeach n : subdirs
237*9e564957SAndroid Build Coastguard Worker    subdir(n)
238*9e564957SAndroid Build Coastguard Workerendforeach
239*9e564957SAndroid Build Coastguard Worker
240