dependencies: Also convert MinGW compile args
For the same reason as the library paths.
@@ -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
