summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2018-06-03 16:57:29 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2018-06-03 18:40:20 +0530
commit3713c97ce9c1718fc25cf43cb6989c3a6118e3be (patch)
tree12490926b1d65827106d8c560032834f8f9fd545
parent9e7b0dd70430cf0aa71869c46342cb908e99274f (diff)
downloadmeson-3713c97ce9c1718fc25cf43cb6989c3a6118e3be.tar.gz
has_function: Improve built-in detection with headers
* __has_builtin(foo) is more correct and more reliable than __has_builtin(__builtin_foo) * If detection of built-ins with headers fails in the first check because we can't take the address of a built-in, we can do an ordinary check. We can't always do this ordinary check because clang on macOS ld removes the symbol when using -Wl,-no_weak_imports, which is needed for being able to target the correct platform with XCode 8 and newer. Closes https://github.com/mesonbuild/meson/issues/3672
-rw-r--r--mesonbuild/compilers/c.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index 4cc966054..99bdc6c52 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -656,7 +656,7 @@ class CCompiler(Compiler):
# glibc defines functions that are not available on Linux as stubs that
# fail with ENOSYS (such as e.g. lchmod). In this case we want to fail
# instead of detecting the stub as a valid symbol.
- # We already included limits.h earlier to ensure that these are defined
+ # We also include limits.h to ensure that these are defined
# for stub functions.
stubs_fail = '''
#if defined __stub_{func} || defined __stub___{func}
@@ -693,9 +693,10 @@ class CCompiler(Compiler):
# can just directly use the __has_builtin() macro.
fargs['no_includes'] = '#include' not in prefix
t = '''{prefix}
+ #include <limits.h>
int main() {{
#ifdef __has_builtin
- #if !__has_builtin(__builtin_{func})
+ #if !__has_builtin({func})
#error "__builtin_{func} not found"
#endif
#elif ! defined({func})
@@ -706,8 +707,11 @@ class CCompiler(Compiler):
* give them a workaround. */
#if {no_includes:d}
__builtin_{func};
+ // See above for why this is needed
+ #elif defined(__stub_{func}) || defined(_stub__{func})
+ #error "unusable function {func}"
#else
- #error "No definition for __builtin_{func} found in the prefix"
+ {func};
#endif
#endif
}}'''