diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2017-11-02 19:44:47 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2017-11-11 23:06:48 +0530 |
commit | 22f459a7dd8d6d815ade836b6ea9404572cbc92b (patch) | |
tree | f8f461d97eb2d073ad283d55e22b05689c6adc7d | |
parent | d2a250412c208a38a4c82a8b2615aad90dc15df9 (diff) | |
download | meson-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.py | 17 |
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): |