aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2017-11-02 19:44:47 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2017-11-11 23:06:48 +0530
commit22f459a7dd8d6d815ade836b6ea9404572cbc92b (patch)
treef8f461d97eb2d073ad283d55e22b05689c6adc7d
parentd2a250412c208a38a4c82a8b2615aad90dc15df9 (diff)
downloadmeson-22f459a7dd8d6d815ade836b6ea9404572cbc92b.zip
meson-22f459a7dd8d6d815ade836b6ea9404572cbc92b.tar.gz
meson-22f459a7dd8d6d815ade836b6ea9404572cbc92b.tar.bz2
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.
-rw-r--r--mesonbuild/dependencies/base.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
index 05170ff..6592495 100644
--- a/mesonbuild/dependencies/base.py
+++ b/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):