aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/build.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2017-04-02 19:06:16 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2017-04-08 22:14:09 +0300
commitd152c1b5d549769c7977688fbb8c4cde037192e7 (patch)
tree0503da8250ec18a3e3f7787fc8bc2c9e038c2d58 /mesonbuild/build.py
parent79208fd9c4e6c865f4ef12ce992d5e3d8c7f4ad4 (diff)
downloadmeson-d152c1b5d549769c7977688fbb8c4cde037192e7.zip
meson-d152c1b5d549769c7977688fbb8c4cde037192e7.tar.gz
meson-d152c1b5d549769c7977688fbb8c4cde037192e7.tar.bz2
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.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 537c91b..f379a68 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
@@ -560,6 +562,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]
@@ -698,7 +709,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()
@@ -790,6 +801,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