diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2017-12-01 19:08:44 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2017-12-03 10:06:11 +0530 |
commit | 61d1e9596ac97983617be0ddcb20f2afacc731bb (patch) | |
tree | c0f570ff42ba16f7424f0c452ae719ef8877ccc2 | |
parent | 133df3b045c8b70b2750fac5961dc85cea2e19b2 (diff) | |
download | meson-61d1e9596ac97983617be0ddcb20f2afacc731bb.tar.gz |
dependencies: Also convert MinGW compile args
For the same reason as the library paths.
-rw-r--r-- | mesonbuild/dependencies/base.py | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index 7249b0165..d347735ec 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -412,12 +412,39 @@ class PkgConfigDependency(ExternalDependency): p, out = Popen_safe([self.pkgbin] + args, env=env)[0:2] return p.returncode, out.strip() + def _convert_mingw_paths(self, args): + ''' + MSVC cannot handle MinGW-esque /c/foo paths, convert them to C:/foo. + We cannot resolve other paths starting with / like /home/foo so leave + them as-is so the user gets an error/warning from the compiler/linker. + ''' + if not self.compiler or self.compiler.id != 'msvc': + return args + converted = [] + for arg in args: + pargs = [] + # Library search path + if arg.startswith('-L/'): + pargs = PurePath(arg[2:]).parts + tmpl = '-L{}:/{}' + elif arg.startswith('-I/'): + pargs = PurePath(arg[2:]).parts + tmpl = '-I{}:/{}' + # Full path to library or .la file + elif arg.startswith('/'): + pargs = PurePath(arg).parts + tmpl = '{}:/{}' + if len(pargs) > 1 and len(pargs[1]) == 1: + arg = tmpl.format(pargs[1], '/'.join(pargs[2:])) + converted.append(arg) + return converted + def _set_cargs(self): ret, out = self._call_pkgbin(['--cflags', self.name]) if ret != 0: raise DependencyException('Could not generate cargs for %s:\n\n%s' % (self.name, out)) - self.compile_args = shlex.split(out) + self.compile_args = self._convert_mingw_paths(shlex.split(out)) def _set_libs(self): env = None @@ -434,21 +461,7 @@ class PkgConfigDependency(ExternalDependency): (self.name, out)) self.link_args = [] libpaths = [] - for lib in shlex.split(out): - # MSVC cannot handle MinGW-esque /c/foo paths, convert them to C:/foo. - # We cannot resolve other paths starting with / like /home/foo so leave - # them as-is so the user gets an error/warning from the compiler/linker. - if self.compiler and self.compiler.id == 'msvc': - # Library search path - if lib.startswith('-L/'): - pargs = PurePath(lib[2:]).parts - if len(pargs) > 1 and len(pargs[1]) == 1: - lib = '-L{}:/{}'.format(pargs[1], '/'.join(pargs[2:])) - # Full path to library or .la file - elif lib.startswith('/'): - pargs = PurePath(lib).parts - if len(pargs) > 1 and len(pargs[1]) == 1: - lib = '{}:/{}'.format(pargs[1], '/'.join(pargs[2:])) + for lib in self._convert_mingw_paths(shlex.split(out)): # If we want to use only static libraries, we have to look for the # file ourselves instead of depending on the compiler to find it # with -lfoo or foo.lib. However, we can only do this if we already |