diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2017-04-15 18:16:35 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-15 18:16:35 +0300 |
commit | 4e1249c920a6f64e2ca953334e9ec700f30693da (patch) | |
tree | 4ff1e03ac95c0827c6519b0fe684f41602bb47c3 /mesonbuild/build.py | |
parent | dcc95d7f705c5fbc036d7d6511f6df50beaac44a (diff) | |
parent | 62b86824f03d6b401f7bc8da6ce68b334726df44 (diff) | |
download | meson-4e1249c920a6f64e2ca953334e9ec700f30693da.zip meson-4e1249c920a6f64e2ca953334e9ec700f30693da.tar.gz meson-4e1249c920a6f64e2ca953334e9ec700f30693da.tar.bz2 |
Merge pull request #1549 from mesonbuild/linkwhole
Add option to link the entire contents of a static library to a target.
Diffstat (limited to 'mesonbuild/build.py')
-rw-r--r-- | mesonbuild/build.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 6c16cf9..6815b0c 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -37,6 +37,7 @@ known_basic_kwargs = {'install': True, 'link_args': True, 'link_depends': True, 'link_with': True, + 'link_whole': True, 'include_directories': True, 'dependencies': True, 'install_dir': True, @@ -314,6 +315,7 @@ class BuildTarget(Target): self.external_deps = [] self.include_dirs = [] self.link_targets = [] + self.link_whole_targets = [] self.link_depends = [] self.name_prefix_set = False self.name_suffix_set = False @@ -566,6 +568,15 @@ class BuildTarget(Target): if hasattr(linktarget, "held_object"): linktarget = linktarget.held_object self.link(linktarget) + lwhole = kwargs.get('link_whole', []) + if not isinstance(lwhole, list): + lwhole = [lwhole] + for linktarget in lwhole: + # Sorry for this hack. Keyword targets are kept in holders + # in kwargs. Unpack here without looking at the exact type. + if hasattr(linktarget, "held_object"): + linktarget = linktarget.held_object + self.link_whole(linktarget) c_pchlist = kwargs.get('c_pch', []) if not isinstance(c_pchlist, list): c_pchlist = [c_pchlist] @@ -704,7 +715,7 @@ class BuildTarget(Target): def get_dependencies(self): transitive_deps = [] - for t in self.link_targets: + for t in self.link_targets + self.link_whole_targets: transitive_deps.append(t) if isinstance(t, StaticLibrary): transitive_deps += t.get_dependencies() @@ -796,6 +807,22 @@ You probably should put it in link_with instead.''') raise InvalidArguments('Tried to mix cross built and native libraries in target {!r}'.format(self.name)) self.link_targets.append(t) + def link_whole(self, target): + if not isinstance(target, list): + target = [target] + for t in target: + if hasattr(t, 'held_object'): + t = t.held_object + if not isinstance(t, StaticLibrary): + raise InvalidArguments('{!r} is not a static library.'.format(t)) + if isinstance(self, SharedLibrary) and not t.pic: + msg = "Can't link non-PIC static library {!r} into shared library {!r}. ".format(t.name, self.name) + msg += "Use the 'pic' option to static_library to build with PIC." + raise InvalidArguments(msg) + if self.is_cross != t.is_cross: + raise InvalidArguments('Tried to mix cross built and native libraries in target {!r}'.format(self.name)) + self.link_whole_targets.append(t) + def add_pch(self, language, pchlist): if len(pchlist) == 0: return |