aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2016-11-09 10:27:28 -0500
committerGitHub <noreply@github.com>2016-11-09 10:27:28 -0500
commitcf7b50364f5fec9c4b7ea520b31cfd5a1bb443d7 (patch)
tree5290c7d5220725ebfaa0192c5f403f7f633c98fe /mesonbuild
parentf7431fd5dba1f59ce70b07d7074999d1e7442887 (diff)
parent30392a3a8a2f14ee1b3b7e3f66be9728b6a6b52e (diff)
downloadmeson-cf7b50364f5fec9c4b7ea520b31cfd5a1bb443d7.zip
meson-cf7b50364f5fec9c4b7ea520b31cfd5a1bb443d7.tar.gz
meson-cf7b50364f5fec9c4b7ea520b31cfd5a1bb443d7.tar.bz2
Merge pull request #1006 from centricular/cpp-has-header-symbol
A bunch of fixes for compiler checks with C++
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/compilers.py58
1 files changed, 48 insertions, 10 deletions
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py
index 454cdba..2feae88 100644
--- a/mesonbuild/compilers.py
+++ b/mesonbuild/compilers.py
@@ -513,6 +513,13 @@ class CCompiler(Compiler):
def get_no_optimization_args(self):
return ['-O0']
+ def get_compiler_check_args(self):
+ '''
+ Get arguments useful for compiler checks such as being permissive in
+ the code quality and not doing any optimization.
+ '''
+ return self.get_no_optimization_args()
+
def get_output_args(self, target):
return ['-o', target]
@@ -644,9 +651,14 @@ int someSymbolHereJustForFun;
extra_args = []
templ = '''{2}
#include <{0}>
-int main () {{ {1}; }}'''
- # Pass -O0 to ensure that the symbol isn't optimized away
- args = extra_args + self.get_no_optimization_args()
+int main () {{
+ /* If it's not defined as a macro, try to use as a symbol */
+ #ifndef {1}
+ {1};
+ #endif
+ return 0;
+}}'''
+ args = extra_args + self.get_compiler_check_args()
return self.compiles(templ.format(hname, symbol, prefix), env, args, dependencies)
@contextlib.contextmanager
@@ -785,7 +797,7 @@ int main(int argc, char **argv) {{
%s
int temparray[%d-sizeof(%s)];
'''
- args = extra_args + self.get_no_optimization_args()
+ args = extra_args + self.get_compiler_check_args()
if not self.compiles(element_exists_templ.format(prefix, element), env, args, dependencies):
return -1
for i in range(1, 1024):
@@ -834,7 +846,7 @@ struct tmp {
int testarray[%d-offsetof(struct tmp, target)];
'''
- args = extra_args + self.get_no_optimization_args()
+ args = extra_args + self.get_compiler_check_args()
if not self.compiles(type_exists_templ.format(typename), env, args, dependencies):
return -1
for i in range(1, 1024):
@@ -919,7 +931,7 @@ int main(int argc, char **argv) {
head = '#include <limits.h>\n{0}\n'
# We don't know what the function takes or returns, so try to use it as
# a function pointer
- main = '\nint main() {{ int a = (int) &{1}; }}'
+ main = '\nint main() {{ void *a = (void*) &{1}; }}'
return head, main
def has_function(self, funcname, prefix, env, extra_args=None, dependencies=None):
@@ -968,9 +980,8 @@ int main(int argc, char **argv) {
head, main = self._no_prototype_templ()
templ = head + stubs_fail + main
- # Add -O0 to ensure that the symbol isn't optimized away by the compiler
- args = extra_args + self.get_no_optimization_args()
- if self.links(templ.format(prefix, funcname), env, extra_args, dependencies):
+ args = extra_args + self.get_compiler_check_args()
+ if self.links(templ.format(prefix, funcname), env, args, dependencies):
return True
# Some functions like alloca() are defined as compiler built-ins which
# are inlined by the compiler, so test for that instead. Built-ins are
@@ -1049,6 +1060,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'
@@ -1868,9 +1893,10 @@ class VisualStudioCCompiler(CCompiler):
pdbarr += ['pdb']
return ['/DEBUG', '/PDB:' + '.'.join(pdbarr)]
-class VisualStudioCPPCompiler(VisualStudioCCompiler):
+class VisualStudioCPPCompiler(VisualStudioCCompiler, CPPCompiler):
def __init__(self, exelist, version, is_cross, exe_wrap):
self.language = 'cpp'
+ CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
VisualStudioCCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
self.base_options = ['b_pch'] # FIXME add lto, pgo and the like
@@ -2045,6 +2071,12 @@ class GnuCPPCompiler(GnuCompiler, CPPCompiler):
return options['cpp_winlibs'].value
return []
+ def get_compiler_check_args(self):
+ # -fpermissive allows non-conforming code to compile which is necessary
+ # for many C++ checks. Particularly, the has_header_symbol check is
+ # too strict without this and always fails.
+ return self.get_no_optimization_args() + ['-fpermissive']
+
class GnuObjCCompiler(GnuCompiler,ObjCCompiler):
def __init__(self, exelist, version, is_cross, exe_wrapper=None, defines=None):
@@ -2067,6 +2099,12 @@ class GnuObjCPPCompiler(GnuCompiler, ObjCPPCompiler):
'2': ['-Wall', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor'],
'3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor']}
+ def get_compiler_check_args(self):
+ # -fpermissive allows non-conforming code to compile which is necessary
+ # for many ObjC++ checks. Particularly, the has_header_symbol check is
+ # too strict without this and always fails.
+ return self.get_no_optimization_args() + ['-fpermissive']
+
class ClangCompiler():
def __init__(self, clang_type):
self.id = 'clang'