diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2017-01-23 23:15:50 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2017-01-24 01:21:43 +0530 |
commit | 7e1654bf083a78080ce92f0f2fe0310aae41e0d3 (patch) | |
tree | 478233d2abef3233376e6be395bd1801e4b4e683 | |
parent | f49b50d432a066e420d50f1f546c1b23fa87687d (diff) | |
download | meson-7e1654bf083a78080ce92f0f2fe0310aae41e0d3.zip meson-7e1654bf083a78080ce92f0f2fe0310aae41e0d3.tar.gz meson-7e1654bf083a78080ce92f0f2fe0310aae41e0d3.tar.bz2 |
compilers: Use __has_include macro for has_header checks
If it's available, it's much much faster than doing #include
+ preprocess. Speeds up has_header checks by about 40% for me.
Currently, only Clang supports this
-rw-r--r-- | mesonbuild/compilers.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index 40387ca..23e7bbe 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -716,8 +716,16 @@ class CCompiler(Compiler): def has_header(self, hname, prefix, env, extra_args=None, dependencies=None): if extra_args is None: extra_args = [] - code = '{}\n#include<{}>\nint someUselessSymbol;'.format(prefix, hname) - return self.compiles(code, env, extra_args, dependencies, 'preprocess') + code = '''{0} + #ifdef __has_include + #if !__has_include(<{1}>) + #error "Header '{1}' could not be found" + #endif + #else + #include<{1}> + #endif''' + return self.compiles(code.format(prefix, hname), env, extra_args, + dependencies, 'preprocess') def has_header_symbol(self, hname, symbol, prefix, env, extra_args=None, dependencies=None): if extra_args is None: |