aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2016-11-08 15:04:19 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2016-11-08 16:05:32 +0530
commit4d84241ccf515446b49ddbe19683184b5a4e5a13 (patch)
tree81f0580798e88c745ca298f5ab8f52564fdb5136
parentf6dfd362393fb1e999bcc0dbc7ef65c48d8b204f (diff)
downloadmeson-4d84241ccf515446b49ddbe19683184b5a4e5a13.zip
meson-4d84241ccf515446b49ddbe19683184b5a4e5a13.tar.gz
meson-4d84241ccf515446b49ddbe19683184b5a4e5a13.tar.bz2
has_header_symbol: Also detect C++ classes and templates
With the `using` keyword we can try to use the specified class or template which will tell us if it exists.
-rw-r--r--mesonbuild/compilers.py14
-rw-r--r--test cases/common/111 has header symbol/meson.build9
2 files changed, 23 insertions, 0 deletions
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py
index ce137cb..31cafa6 100644
--- a/mesonbuild/compilers.py
+++ b/mesonbuild/compilers.py
@@ -1059,6 +1059,20 @@ class CPPCompiler(CCompiler):
code = 'class breakCCompiler;int main(int argc, char **argv) { return 0; }\n'
return self.sanity_check_impl(work_dir, environment, 'sanitycheckcpp.cc', code)
+ def has_header_symbol(self, hname, symbol, prefix, env, extra_args=None, dependencies=None):
+ # Check if it's a C-like symbol
+ if super().has_header_symbol(hname, symbol, prefix, env, extra_args, dependencies):
+ return True
+ # Check if it's a class or a template
+ if extra_args is None:
+ extra_args = []
+ templ = '''{2}
+#include <{0}>
+using {1};
+int main () {{ return 0; }}'''
+ args = extra_args + self.get_compiler_check_args()
+ return self.compiles(templ.format(hname, symbol, prefix), env, args, dependencies)
+
class ObjCCompiler(CCompiler):
def __init__(self, exelist, version, is_cross, exe_wrap):
self.language = 'objc'
diff --git a/test cases/common/111 has header symbol/meson.build b/test cases/common/111 has header symbol/meson.build
index c62e7c0..b5c865f 100644
--- a/test cases/common/111 has header symbol/meson.build
+++ b/test cases/common/111 has header symbol/meson.build
@@ -20,4 +20,13 @@ if cc.has_function('ppoll')
assert (cc.has_header_symbol('poll.h', 'ppoll', prefix : '#define _GNU_SOURCE'), 'ppoll should be accessible with _GNU_SOURCE')
endif
+assert (cpp.has_header_symbol('iostream', 'std::iostream'), 'iostream not found in iostream.h')
+assert (cpp.has_header_symbol('vector', 'std::vector'), 'vector not found in vector.h')
+assert (not cpp.has_header_symbol('limits.h', 'std::iostream'), 'iostream should not be defined in limits.h')
+boost = dependency('boost', required : false)
+if boost.found()
+ assert (cpp.has_header_symbol('boost/math/quaternion.hpp', 'boost::math::quaternion', dependencies : boost), 'quaternion not found')
+else
+ assert (not cpp.has_header_symbol('boost/math/quaternion.hpp', 'boost::math::quaternion', dependencies : boost), 'quaternion found?!')
+endif