From fdbf98772a7bc43524d0a1f9a20397cea992c702 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 21 May 2016 00:11:42 +0200 Subject: Recursively link prerequisite libraries of static libraries --- build2/cxx/link.cxx | 56 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-) (limited to 'build2/cxx/link.cxx') diff --git a/build2/cxx/link.cxx b/build2/cxx/link.cxx index fdaab55..539a606 100644 --- a/build2/cxx/link.cxx +++ b/build2/cxx/link.cxx @@ -746,6 +746,38 @@ namespace build2 } } + // Recursively append/hash prerequisite libraries of a static library. + // + static void + append_libraries (strings& args, liba& a) + { + for (target* pt: a.prerequisite_targets) + { + if (liba* pa = pt->is_a ()) + { + args.push_back (relative (pa->path ()).string ()); // string()&& + append_libraries (args, *pa); + } + else if (libso* ps = pt->is_a ()) + args.push_back (relative (ps->path ()).string ()); // string()&& + } + } + + static void + hash_libraries (sha256& cs, liba& a) + { + for (target* pt: a.prerequisite_targets) + { + if (liba* pa = pt->is_a ()) + { + cs.append (pa->path ().string ()); + hash_libraries (cs, *pa); + } + else if (libso* ps = pt->is_a ()) + cs.append (ps->path ().string ()); + } + } + static void append_rpath_link (strings& args, libso& t) { @@ -945,13 +977,21 @@ namespace build2 for (target* pt: t.prerequisite_targets) { path_target* ppt; + liba* a (nullptr); if ((ppt = pt->is_a ()) || (ppt = pt->is_a ()) || - (ppt = pt->is_a ()) || - (ppt = pt->is_a ())) + (lt != type::a && + ((ppt = a = pt->is_a ()) || + (ppt = pt->is_a ())))) { cs.append (ppt->path ().string ()); + + // If this is a static library, link all the libraries it depends + // on, recursively. + // + if (a != nullptr) + hash_libraries (cs, *a); } } @@ -1003,13 +1043,21 @@ namespace build2 for (target* pt: t.prerequisite_targets) { path_target* ppt; + liba* a (nullptr); if ((ppt = pt->is_a ()) || (ppt = pt->is_a ()) || - (ppt = pt->is_a ()) || - (ppt = pt->is_a ())) + (lt != type::a && + ((ppt = a = pt->is_a ()) || + (ppt = pt->is_a ())))) { sargs.push_back (relative (ppt->path ()).string ()); // string()&& + + // If this is a static library, link all the libraries it depends + // on, recursively. + // + if (a != nullptr) + append_libraries (sargs, *a); } } -- cgit v1.1