aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreter.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2017-09-29 11:52:06 -0700
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2018-09-07 11:52:15 -0700
commit51e9db370a0ebccaf220e171c3444a0f2c4e1723 (patch)
tree1636eec99faf01aeb6e08c0753fa4503fdbdbb38 /mesonbuild/interpreter.py
parent8ca463f9f1d432d059c12da42a18fd13b4604b57 (diff)
downloadmeson-51e9db370a0ebccaf220e171c3444a0f2c4e1723.zip
meson-51e9db370a0ebccaf220e171c3444a0f2c4e1723.tar.gz
meson-51e9db370a0ebccaf220e171c3444a0f2c4e1723.tar.bz2
Add method to check for C/C++ function attributes
It's fairly common on Linux and *BSD platforms to check for these attributes existence, so it makes sense to me to have this checking build into meson itself. Autotools also has a builtin for handling these, and by building them in we can short circuit cases that we know that these don't exist (MSVC). Additionally this adds support for two common MSVC __declspec attributes, dllimport and dllexport. This implements the declspec version (even though GCC has an __attribute__ version that both it and clang support), since GCC and Clang support the MSVC version as well. Thus it seems reasonable to assume that most projects will use the __declspec version over teh __attribute__ version.
Diffstat (limited to 'mesonbuild/interpreter.py')
-rw-r--r--mesonbuild/interpreter.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 98fab7c..0e6a041 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -975,6 +975,8 @@ class CompilerHolder(InterpreterObject):
'cmd_array': self.cmd_array_method,
'find_library': self.find_library_method,
'has_argument': self.has_argument_method,
+ 'has_function_attribute': self.has_func_attribute_method,
+ 'get_supported_function_attributes': self.get_supported_function_attributes_method,
'has_multi_arguments': self.has_multi_arguments_method,
'get_supported_arguments': self.get_supported_arguments_method,
'first_supported_argument': self.first_supported_argument_method,
@@ -1545,6 +1547,24 @@ class CompilerHolder(InterpreterObject):
mlog.log('First supported link argument:', mlog.red('None'))
return []
+ @FeatureNew('compiler.has_function_attribute', '0.48.0')
+ @permittedKwargs({})
+ def has_func_attribute_method(self, args, kwargs):
+ args = mesonlib.stringlistify(args)
+ if len(args) != 1:
+ raise InterpreterException('has_func_attribute takes exactly one argument.')
+ result = self.compiler.has_func_attribute(args[0], self.environment)
+ h = mlog.green('YES') if result else mlog.red('NO')
+ mlog.log('Compiler for {} supports function attribute {}:'.format(self.compiler.get_display_language(), args[0]), h)
+ return result
+
+ @FeatureNew('compiler.get_supported_function_attributes', '0.48.0')
+ @permittedKwargs({})
+ def get_supported_function_attributes_method(self, args, kwargs):
+ args = mesonlib.stringlistify(args)
+ return [a for a in args if self.has_func_attribute_method(a, kwargs)]
+
+
ModuleState = namedtuple('ModuleState', [
'build_to_src', 'subproject', 'subdir', 'current_lineno', 'environment',
'project_name', 'project_version', 'backend', 'compilers', 'targets',