diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-05-21 00:11:42 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-05-21 00:11:42 +0200 |
commit | fdbf98772a7bc43524d0a1f9a20397cea992c702 (patch) | |
tree | 17649c5afef0a62bbdf11a44cff963b651f3b5c4 | |
parent | 68b1728921f6141542daa334b6a7ec840c7eeb35 (diff) |
Recursively link prerequisite libraries of static libraries
-rw-r--r-- | build2/cxx/link.cxx | 56 |
1 files changed, 52 insertions, 4 deletions
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<liba> ()) + { + args.push_back (relative (pa->path ()).string ()); // string()&& + append_libraries (args, *pa); + } + else if (libso* ps = pt->is_a<libso> ()) + 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<liba> ()) + { + cs.append (pa->path ().string ()); + hash_libraries (cs, *pa); + } + else if (libso* ps = pt->is_a<libso> ()) + 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<obja> ()) || (ppt = pt->is_a<objso> ()) || - (ppt = pt->is_a<liba> ()) || - (ppt = pt->is_a<libso> ())) + (lt != type::a && + ((ppt = a = pt->is_a<liba> ()) || + (ppt = pt->is_a<libso> ())))) { 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<obja> ()) || (ppt = pt->is_a<objso> ()) || - (ppt = pt->is_a<liba> ()) || - (ppt = pt->is_a<libso> ())) + (lt != type::a && + ((ppt = a = pt->is_a<liba> ()) || + (ppt = pt->is_a<libso> ())))) { 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); } } |