From 206e9e509788dbfd21c41a84aac23b0e357694b1 Mon Sep 17 00:00:00 2001 From: Sahnvour Date: Tue, 22 Sep 2020 12:51:14 +0200 Subject: Properly handle the case of linking static library with custom targets --- mesonbuild/build.py | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'mesonbuild') diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 8d2a22f..bc1f54a 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1130,10 +1130,16 @@ You probably should put it in link_with instead.''') def link(self, target): for t in unholder(listify(target)): - if isinstance(self, StaticLibrary) and self.need_install and t.is_internal(): - # When we're a static library and we link_with to an - # internal/convenience library, promote to link_whole. - return self.link_whole(t) + if isinstance(self, StaticLibrary) and self.need_install: + if isinstance(t, (CustomTarget, CustomTargetIndex)): + if not t.should_install(): + mlog.warning('Try to link an installed static library target {} with a custom target ' + 'that is not installed, this might cause problems when you try to use ' + 'this static library'.format(self.name)) + elif t.is_internal(): + # When we're a static library and we link_with to an + # internal/convenience library, promote to link_whole. + return self.link_whole(t) if not isinstance(t, (Target, CustomTargetIndex)): raise InvalidArguments('{!r} is not a target.'.format(t)) if not t.is_linkable_target(): @@ -2274,6 +2280,18 @@ class CustomTarget(Target): def get_all_link_deps(self): return [] + def is_internal(self) -> bool: + if not self.should_install(): + return True + for out in self.get_outputs(): + # Can't check if this is a static library, so try to guess + if not out.endswith(('.a', '.lib')): + return False + return True + + def extract_all_objects_recurse(self): + return self.get_outputs() + def type_suffix(self): return "@cus" @@ -2419,6 +2437,15 @@ class CustomTargetIndex: if suf == '.a' or suf == '.dll' or suf == '.lib' or suf == '.so': return True + def should_install(self) -> bool: + return self.target.should_install() + + def is_internal(self) -> bool: + return self.target.is_internal() + + def extract_all_objects_recurse(self): + return self.target.extract_all_objects_recurse() + class ConfigureFile: def __init__(self, subdir, sourcename, targetname, configuration_data): -- cgit v1.1