diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2013-04-19 23:59:06 +0300 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2013-04-19 23:59:06 +0300 |
commit | 7b8d24a9d8d2c78c434f0f8ef6b208c0a5dc756a (patch) | |
tree | 580145468699236e0400776df2a7908bfe680a78 | |
parent | 7e3f2f7771b3fa0abb7a86fb8df78f41ff226d39 (diff) | |
download | meson-7b8d24a9d8d2c78c434f0f8ef6b208c0a5dc756a.zip meson-7b8d24a9d8d2c78c434f0f8ef6b208c0a5dc756a.tar.gz meson-7b8d24a9d8d2c78c434f0f8ef6b208c0a5dc756a.tar.bz2 |
Can use msvc static linker.
-rwxr-xr-x | backends.py | 5 | ||||
-rw-r--r-- | build.py | 7 | ||||
-rwxr-xr-x | environment.py | 56 | ||||
-rwxr-xr-x | interpreter.py | 2 |
4 files changed, 50 insertions, 20 deletions
diff --git a/backends.py b/backends.py index 5d16a64..2a561d8 100755 --- a/backends.py +++ b/backends.py @@ -473,8 +473,9 @@ class NinjaBackend(Backend): def generate_static_link_rules(self, outfile): static_linker = self.build.static_linker rule = 'rule STATIC_LINKER\n' - command = ' command = %s $LINK_FLAGS $out $in\n' % \ - ' '.join(static_linker.get_exelist()) + command = ' command = %s $LINK_FLAGS %s $in\n' % \ + (' '.join(static_linker.get_exelist()), + ' '.join(static_linker.get_output_flags('$out'))) description = ' description = Static linking library $out\n\n' outfile.write(rule) outfile.write(command) @@ -29,9 +29,14 @@ class Build: self.headers = [] self.man = [] self.data = [] - self.static_linker = self.environment.detect_static_linker() + self.static_linker = None self.configure_files = [] + def add_compiler(self, compiler): + if len(self.compilers) == 0: + self.static_linker = self.environment.detect_static_linker(compiler) + self.compilers.append(compiler) + def get_project(self): return self.project diff --git a/environment.py b/environment.py index 7611496..a5c3e8c 100755 --- a/environment.py +++ b/environment.py @@ -336,6 +336,22 @@ class ClangCXXCompiler(CXXCompiler): def get_pch_suffix(self): return 'pch' +class VisualStudioLinker(): + def __init__(self, exelist): + self.exelist = exelist + + def get_exelist(self): + return self.exelist + + def get_std_link_flags(self): + return [] + + def get_output_flags(self, target): + return ['/OUT:' + target] + + def get_coverage_link_flags(self): + return [] + class ArLinker(): std_flags = ['csr'] @@ -348,8 +364,8 @@ class ArLinker(): def get_std_link_flags(self): return self.std_flags - def get_output_flags(self): - return [] + def get_output_flags(self, target): + return [target] def get_coverage_link_flags(self): return [] @@ -419,7 +435,8 @@ class Environment(): self.default_cxx = ['c++'] self.default_objc = ['cc'] self.default_objcxx = ['c++'] - self.default_static_linker = ['ar'] + self.default_static_linker = 'ar' + self.vs_static_linker = 'lib' if is_windows(): self.exe_suffix = 'exe' @@ -558,20 +575,33 @@ class Environment(): return GnuObjCXXCompiler(exelist) raise EnvironmentException('Unknown compiler "' + ' '.join(exelist) + '"') - def detect_static_linker(self): - exelist = self.get_static_linker_exelist() + def detect_static_linker(self, compiler): + evar = 'AR' + if evar in os.environ: + linker = os.environ[evar].strip() + if isinstance(compiler, VisualStudioCCompiler): + linker= self.vs_static_linker + else: + linker = self.default_static_linker + basename = os.path.basename(linker).lower() + if basename == 'lib' or basename == 'lib.exe': + arg = '/?' + else: + arg = '--version' try: - p = subprocess.Popen(exelist + ['--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p = subprocess.Popen([linker, arg], stdout=subprocess.PIPE, stderr=subprocess.PIPE) except OSError: - raise EnvironmentException('Could not execute static linker "%s".' % ' '.join(exelist)) + raise EnvironmentException('Could not execute static linker "%s".' % linker) (out, err) = p.communicate() out = out.decode() err = err.decode() + if '/OUT:' in out or '/OUT:' in err: + return VisualStudioLinker([linker]) if p.returncode == 0: - return ArLinker(exelist) + return ArLinker([linker]) if p.returncode == 1 and err.startswith('usage'): # OSX - return ArLinker(exelist) - raise EnvironmentException('Unknown static linker "' + ' '.join(exelist) + '"') + return ArLinker([linker]) + raise EnvironmentException('Unknown static linker "%s"' % linker) def detect_ccache(self): try: @@ -598,12 +628,6 @@ class Environment(): return os.environ[evar].split() return ccachelist + self.default_objcxx - def get_static_linker_exelist(self): - evar = 'AR' - if evar in os.environ: - return os.environ[evar].split() - return self.default_static_linker - def get_source_dir(self): return self.source_dir diff --git a/interpreter.py b/interpreter.py index 2f2c3ff..22dee9d 100755 --- a/interpreter.py +++ b/interpreter.py @@ -653,7 +653,7 @@ class Interpreter(): raise InvalidCode('Tried to use unknown language "%s".' % lang) comp.sanity_check(self.environment.get_scratch_dir()) self.coredata.compilers[lang] = comp - self.build.compilers.append(comp) + self.build.add_compiler(comp) def func_find_program(self, node, args, kwargs): self.validate_arguments(args, 1, [str]) |