summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2018-02-20 13:33:19 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2018-02-20 14:05:33 +0530
commitb78f6f38f738d05d1c447ad991d158b355805e55 (patch)
tree054d31b3e76e353cc33a573b0fc7e19fe8a6174f
parent37b702e9aa4255e1d0c5fa706e52842877cf01b3 (diff)
downloadmeson-nirbheek/stable-fix-pkgconfig-dependency-static.tar.gz
pkgconfig deps: Warn when a static library isn't foundnirbheek/stable-fix-pkgconfig-dependency-static
A hard error makes this feature useless in most cases since a static library usually won't be found for every library, particularly system libraries like -lm. Instead, warn so the user can provide the static library if they wish. This feature will be expanded and made more extensible and more usable in the future. Closes https://github.com/mesonbuild/meson/issues/2785
-rw-r--r--mesonbuild/compilers/c.py5
-rw-r--r--mesonbuild/dependencies/base.py20
-rwxr-xr-xrun_unittests.py6
-rw-r--r--test cases/frameworks/7 gnome/meson.build3
-rw-r--r--test cases/unit/17 pkgconfig static/foo.pc.in1
5 files changed, 30 insertions, 5 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index a59b7d384..1c9b9b4fa 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -780,9 +780,12 @@ class CCompiler(Compiler):
args = ['-l' + libname]
if self.links(code, env, extra_args=args):
return args
+ # Ensure that we won't modify the list that was passed to us
+ extra_dirs = extra_dirs[:]
+ # Search in the system libraries too
+ extra_dirs += self.get_library_dirs()
# Not found or we want to use a specific libtype? Try to find the
# library file itself.
- extra_dirs += self.get_library_dirs()
prefixes, suffixes = self.get_library_naming(env, libtype)
# Triply-nested loop!
for d in extra_dirs:
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
index 66bc3b470..fefab3f3f 100644
--- a/mesonbuild/dependencies/base.py
+++ b/mesonbuild/dependencies/base.py
@@ -516,6 +516,7 @@ class PkgConfigDependency(ExternalDependency):
(self.name, out))
self.link_args = []
libpaths = []
+ static_libs_notfound = []
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
@@ -524,13 +525,26 @@ class PkgConfigDependency(ExternalDependency):
if self.static:
if lib.startswith('-L'):
libpaths.append(lib[2:])
+ print(lib)
continue
+ # FIXME: try to handle .la files in static mode too?
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]
+ if lib in static_libs_notfound:
+ continue
+ mlog.warning('Static library {!r} not found for dependency {!r}, may '
+ 'not be statically linked'.format(lib[2:], self.name))
+ static_libs_notfound.append(lib)
+ # Preserve the -l arg since we couldn't resolve it to
+ # a static library. Also need all previous -L args now.
+ for p in libpaths:
+ lp = '-L' + p
+ if lp not in self.link_args:
+ self.link_args.append(lp)
+ else:
+ # Replace -l arg with full path to static library
+ 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)
diff --git a/run_unittests.py b/run_unittests.py
index 3a66211a4..6c71861d9 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -1563,9 +1563,13 @@ int main(int argc, char **argv) {
def test_pkgconfig_static(self):
'''
- Test that the we only use static libraries when `static: true` is
+ Test that the we prefer static libraries when `static: true` is
passed to dependency() with pkg-config. Can't be an ordinary test
because we need to build libs and try to find them from meson.build
+
+ Also test that it's not a hard error to have unsatisfiable library deps
+ since system libraries -lm will never be found statically.
+ https://github.com/mesonbuild/meson/issues/2785
'''
if not shutil.which('pkg-config'):
raise unittest.SkipTest('pkg-config not found')
diff --git a/test cases/frameworks/7 gnome/meson.build b/test cases/frameworks/7 gnome/meson.build
index c75c0490f..1f754d6cd 100644
--- a/test cases/frameworks/7 gnome/meson.build
+++ b/test cases/frameworks/7 gnome/meson.build
@@ -17,6 +17,9 @@ gobj = dependency('gobject-2.0')
gir = dependency('gobject-introspection-1.0')
gmod = dependency('gmodule-2.0')
+# Test that static deps don't error out when static libraries aren't found
+glib_static = dependency('glib-2.0', static : true)
+
subdir('resources-data')
subdir('resources')
subdir('gir')
diff --git a/test cases/unit/17 pkgconfig static/foo.pc.in b/test cases/unit/17 pkgconfig static/foo.pc.in
index 94d803154..b26c0b0a2 100644
--- a/test cases/unit/17 pkgconfig static/foo.pc.in
+++ b/test cases/unit/17 pkgconfig static/foo.pc.in
@@ -7,4 +7,5 @@ Name: libfoo
Description: A foo library.
Version: 1.0
Libs: -L${libdir} -lfoo
+Libs.private: -lm
Cflags: -I${includedir}