From 7e1654bf083a78080ce92f0f2fe0310aae41e0d3 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Mon, 23 Jan 2017 23:15:50 +0530 Subject: [PATCH] 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 --- mesonbuild/compilers.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index 40387ca33..23e7bbe4b 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: