aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/c.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/compilers/c.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/compilers/c.py')
-rw-r--r--mesonbuild/compilers/c.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index 436f699..bde9f63 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -24,9 +24,10 @@ from .. import mlog
from .. import coredata
from . import compilers
from ..mesonlib import (
- EnvironmentException, version_compare, Popen_safe, listify,
+ EnvironmentException, MesonException, version_compare, Popen_safe, listify,
for_windows, for_darwin, for_cygwin, for_haiku, for_openbsd,
)
+from .c_function_attributes import C_FUNC_ATTRIBUTES
from .compilers import (
GCC_MINGW,
@@ -57,6 +58,13 @@ class CCompiler(Compiler):
find_library_cache = {}
internal_libs = gnu_compiler_internal_libs
+ @staticmethod
+ def attribute_check_func(name):
+ try:
+ return C_FUNC_ATTRIBUTES[name]
+ except KeyError:
+ raise MesonException('Unknown function attribute "{}"'.format(name))
+
def __init__(self, exelist, version, is_cross, exe_wrapper=None, **kwargs):
# If a child ObjC or CPP class has already set it, don't set it ourselves
if not hasattr(self, 'language'):
@@ -1045,6 +1053,19 @@ class CCompiler(Compiler):
m = pattern.match(ret)
return ret
+ def has_func_attribute(self, name, env):
+ # Just assume that if we're not on windows that dllimport and dllexport
+ # don't work
+ if not (for_windows(env.is_cross_build(), env) or
+ for_cygwin(env.is_cross_build(), env)):
+ if name in ['dllimport', 'dllexport']:
+ return False
+
+ # Clang and GCC both return warnings if the __attribute__ is undefined,
+ # so set -Werror
+ return self.compiles(self.attribute_check_func(name), env, extra_args='-Werror')
+
+
class ClangCCompiler(ClangCompiler, CCompiler):
def __init__(self, exelist, version, clang_type, is_cross, exe_wrapper=None, **kwargs):
CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
@@ -1490,6 +1511,12 @@ class VisualStudioCCompiler(CCompiler):
assert(buildtype == 'custom')
raise EnvironmentException('Requested C runtime based on buildtype, but buildtype is "custom".')
+ def has_func_attribute(self, name, env):
+ # MSVC doesn't have __attribute__ like Clang and GCC do, so just return
+ # false without compiling anything
+ return name in ['dllimport', 'dllexport']
+
+
class ArmCCompiler(ArmCompiler, CCompiler):
def __init__(self, exelist, version, is_cross, exe_wrapper=None, **kwargs):
CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)