aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers
diff options
context:
space:
mode:
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r--mesonbuild/compilers/c.py40
-rw-r--r--mesonbuild/compilers/compilers.py10
-rw-r--r--mesonbuild/compilers/cpp.py10
3 files changed, 37 insertions, 23 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index 29d44c2..b71c6e4 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -835,16 +835,30 @@ class CCompiler(Compiler):
return []
return ['-pthread']
+ def linker_to_compiler_args(self, args):
+ return args
+
+ def has_arguments(self, args, env, code, mode):
+ return self.compiles(code, env, extra_args=args, mode=mode)
+
def has_multi_arguments(self, args, env):
for arg in args:
if arg.startswith('-Wl,'):
- mlog.warning('''{} looks like a linker argument, but has_argument
-and other similar methods only support checking compiler arguments.
-Using them to check linker arguments are never supported, and results
-are likely to be wrong regardless of the compiler you are using.
-'''.format(arg))
- return self.compiles('int i;\n', env, extra_args=args)
+ mlog.warning('{} looks like a linker argument, '
+ 'but has_argument and other similar methods only '
+ 'support checking compiler arguments. Using them '
+ 'to check linker arguments are never supported, '
+ 'and results are likely to be wrong regardless of '
+ 'the compiler you are using. has_link_argument or '
+ 'other similar method can be used instead.'
+ .format(arg))
+ code = 'int i;\n'
+ return self.has_arguments(args, env, code, mode='compile')
+ def has_multi_link_arguments(self, args, env):
+ args = self.linker_to_compiler_args(args)
+ code = 'int main(int argc, char **argv) { return 0; }'
+ return self.has_arguments(args, env, code, mode='link')
class ClangCCompiler(ClangCompiler, CCompiler):
def __init__(self, exelist, version, clang_type, is_cross, exe_wrapper=None, **kwargs):
@@ -970,8 +984,8 @@ class IntelCCompiler(IntelCompiler, CCompiler):
def get_std_shared_lib_link_args(self):
return ['-shared']
- def has_multi_arguments(self, args, env):
- return super().has_multi_arguments(args + ['-diag-error', '10006'], env)
+ def has_arguments(self, args, env, code, mode):
+ return super().has_arguments(args + ['-diag-error', '10006'], env, code, mode)
class VisualStudioCCompiler(CCompiler):
@@ -1055,6 +1069,9 @@ class VisualStudioCCompiler(CCompiler):
def get_linker_search_args(self, dirname):
return ['/LIBPATH:' + dirname]
+ def linker_to_compiler_args(self, args):
+ return ['/link'] + args
+
def get_gui_app_args(self):
return ['/SUBSYSTEM:WINDOWS']
@@ -1135,10 +1152,9 @@ class VisualStudioCCompiler(CCompiler):
# Visual Studio is special. It ignores some arguments it does not
# understand and you can't tell it to error out on those.
# http://stackoverflow.com/questions/15259720/how-can-i-make-the-microsoft-c-compiler-treat-unknown-flags-as-errors-rather-t
- def has_multi_arguments(self, args, env):
- warning_text = '9002'
- code = 'int i;\n'
- with self._build_wrapper(code, env, extra_args=args, mode='compile') as p:
+ def has_arguments(self, args, env, code, mode):
+ warning_text = '4044' if mode == 'link' else '9002'
+ with self._build_wrapper(code, env, extra_args=args, mode=mode) as p:
if p.returncode != 0:
return False
return not(warning_text in p.stde or warning_text in p.stdo)
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 4ed7a79..c45b252 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -750,6 +750,11 @@ class Compiler:
'Language {} does not support has_multi_arguments.'.format(
self.get_display_language()))
+ def has_multi_link_arguments(self, args, env):
+ raise EnvironmentException(
+ 'Language {} does not support has_multi_link_arguments.'.format(
+ self.get_display_language()))
+
def get_cross_extra_flags(self, environment, link):
extra_flags = []
if self.is_cross and environment:
@@ -805,7 +810,6 @@ class Compiler:
# Construct the compiler command-line
commands = CompilerArgs(self)
commands.append(srcname)
- commands += extra_args
commands += self.get_always_args()
if mode == 'compile':
commands += self.get_compile_only_args()
@@ -815,6 +819,10 @@ class Compiler:
else:
output = self._get_compile_output(tmpdirname, mode)
commands += self.get_output_args(output)
+ # extra_args must be last because it could contain '/link' to
+ # pass args to VisualStudio's linker. In that case everything
+ # in the command line after '/link' is given to the linker.
+ commands += extra_args
# Generate full command-line with the exelist
commands = self.get_exelist() + commands.to_native()
mlog.debug('Running compile:')
diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py
index 238c6de..4c48052 100644
--- a/mesonbuild/compilers/cpp.py
+++ b/mesonbuild/compilers/cpp.py
@@ -199,16 +199,6 @@ class IntelCPPCompiler(IntelCompiler, CPPCompiler):
def get_option_link_args(self, options):
return []
- def has_multi_arguments(self, args, env):
- for arg in args:
- if arg.startswith('-Wl,'):
- mlog.warning('''{} looks like a linker argument, but has_argument
-and other similar methods only support checking compiler arguments.
-Using them to check linker arguments are never supported, and results
-are likely to be wrong regardless of the compiler you are using.
-'''.format(arg))
- return super().has_multi_arguments(args + ['-diag-error', '10006'], env)
-
class VisualStudioCPPCompiler(VisualStudioCCompiler, CPPCompiler):
def __init__(self, exelist, version, is_cross, exe_wrap, is_64):