dependencies: Improve pkg-config library detection

When `static: true` is passed to dependency(), we parse the pkg-config
output and manually search for `-lfoo`, etc in the library paths
gathered from `-Lbar` arguments in the output.

If there are no `-L` arguments in the output, the behaviour is the
same as before. If there are `-L` arguments and we can't find a static
library, we will error out.
pull/2611/head
Nirbheek Chauhan 7 years ago
parent d2a250412c
commit 22f459a7dd
  1. 17
      mesonbuild/dependencies/base.py

@ -278,8 +278,23 @@ class PkgConfigDependency(ExternalDependency):
raise DependencyException('Could not generate libs for %s:\n\n%s' %
(self.name, out))
self.link_args = []
libpaths = []
for lib in out.split():
if lib.endswith(".la"):
# 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
# have some library paths gathered.
if self.static:
if lib.startswith('-L'):
libpaths.append(lib[2:])
continue
elif lib.startswith('-l') and libpaths:
args = self.compiler.find_library(lib[2:], self.env, libpaths, libtype='static')
if not args or len(args) < 1:
raise DependencyException('Static library not found for {!r}'
''.format(lib[2:]))
lib = args[0]
elif lib.endswith(".la"):
shared_libname = self.extract_libtool_shlib(lib)
shared_lib = os.path.join(os.path.dirname(lib), shared_libname)
if not os.path.exists(shared_lib):

Loading…
Cancel
Save