diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2016-05-04 00:15:37 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2016-05-04 00:17:27 +0530 |
commit | 2300c022c24d12f1bf2f41171dc97ea9b318a9ce (patch) | |
tree | 74cb6fd0fd6d0f5ab02ee63e42727eeb9fefdb22 | |
parent | 46ce7a9d4ba3eb10f310657242524053a96e5ed9 (diff) | |
download | meson-2300c022c24d12f1bf2f41171dc97ea9b318a9ce.zip meson-2300c022c24d12f1bf2f41171dc97ea9b318a9ce.tar.gz meson-2300c022c24d12f1bf2f41171dc97ea9b318a9ce.tar.bz2 |
has_function: Also detect function implementations inside headers
This also detects when the header has re-defined the symbol to something
else that is then provided by libc, which is also a case we want to
support.
-rw-r--r-- | mesonbuild/compilers.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index a320e7d..d0950ef 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -680,6 +680,13 @@ int main(int argc, char **argv) { return align def has_function(self, funcname, prefix, env, extra_args=[]): + """ + First, this function looks for the symbol in the default libraries + provided by the compiler (stdlib + a few others usually). If that + fails, it checks if any of the headers specified in the prefix provide + an implementation of the function, and if that fails, it checks if it's + implemented as a compiler-builtin. + """ # Define the symbol to something else in case it is defined by the # includes or defines listed by the user `{0}` or by the compiler. # Then, undef the symbol to get rid of it completely. @@ -725,12 +732,17 @@ int main(int argc, char **argv) { raise EnvironmentException('Cross variable {0} is not a boolean.'.format(varname)) if self.links(templ.format(prefix, funcname), extra_args): return True + # Add -O0 to ensure that the symbol isn't optimized away by the compiler + extra_args += self.get_no_optimization_args() + # Sometimes the implementation is provided by the header, or the header + # redefines the symbol to be something else. In that case, we want to + # still detect the function. + if self.links('{0}\nint main() {{ {1}; }}'.format(prefix, funcname), extra_args): + return True # Some functions like alloca() are defined as compiler built-ins which # are inlined by the compiler, so test for that instead. Built-ins are # special functions that ignore all includes and defines, so we just # directly try to link via main(). - # Add -O0 to ensure that the symbol isn't optimized away by the compiler - extra_args += self.get_no_optimization_args() return self.links('int main() {{ {0}; }}'.format('__builtin_' + funcname), extra_args) def has_member(self, typename, membername, prefix, extra_args=[]): |