diff --git a/docs/markdown/snippets/prebuilt.md b/docs/markdown/snippets/prebuilt.md index a51176acc..19741c463 100644 --- a/docs/markdown/snippets/prebuilt.md +++ b/docs/markdown/snippets/prebuilt.md @@ -1,9 +1,14 @@ -# Better support for prebuilt shared libraries +# Better support for shared libraries in non-system paths Meson has had support for prebuilt object files and static libraries. -This release adds feature parity to shared libraries. This means -that e.g. shipping prebuilt libraries as subprojects now can -be as simple as writing a definition file that looks like this. +This release adds feature parity to shared libraries that are either +in non-standard system paths or shipped as part of your project. On +systems that support rpath, Meson automatically adds rpath entries +to built targets using manually found external libraries. + +This means that e.g. supporting prebuilt libraries shipped with your +source or provided by subprojects or wrap definitions by writing a +build file like this: project('myprebuiltlibrary', 'c') diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index c737d491f..e0e2abc2c 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -303,13 +303,16 @@ class Backend: for dep in target.external_deps: if isinstance(dep, dependencies.ExternalLibrary): la = dep.link_args - if len(la) == 1 and la[0].startswith(self.environment.get_source_dir()): + if len(la) == 1 and os.path.isabs(la[0]): # The only link argument is an absolute path to a library file. libpath = la[0] + if libpath.startswith(('/usr/lib', '/lib')): + # No point in adding system paths. + continue if os.path.splitext(libpath)[1] not in ['.dll', '.lib', '.so']: continue absdir = os.path.split(libpath)[0] - rel_to_src = absdir[len(self.environment.get_source_dir())+1:] + rel_to_src = absdir[len(self.environment.get_source_dir()) + 1:] assert(not os.path.isabs(rel_to_src)) paths.append(os.path.join(self.build_to_src, rel_to_src)) return paths @@ -321,7 +324,9 @@ class Backend: prospective = self.get_target_dir(ld) if prospective not in result: result.append(prospective) - result += self.rpaths_for_bundled_shared_libraries(target) + for rp in self.rpaths_for_bundled_shared_libraries(target): + if rp not in result: + result += [rp] return result def object_filename_from_source(self, target, source, is_unity):