2 #include <msp/fs/utils.h>
3 #include <msp/strings/format.h>
4 #include <msp/strings/utils.h>
8 #include "objectfile.h"
9 #include "sharedlibrary.h"
10 #include "sourcepackage.h"
11 #include "staticlibrary.h"
17 Binary::Binary(Builder &b, const FS::Path &p):
21 Binary::Binary(Builder &b, const Component &c, const string &p, const list<ObjectFile *> &objs):
22 FileTarget(b, c.get_package(), c.get_package().get_output_directory()/p),
26 for(ObjectFile *o: objects)
29 nested_build_sig = true;
30 arch_in_build_sig = true;
33 void Binary::collect_build_info(BuildInfo &binfo) const
35 for(ObjectFile *o: objects)
36 if(const Tool *obj_tool = o->get_tool())
37 binfo.update_from(obj_tool->get_build_info());
39 Target::collect_build_info(binfo);
41 binfo.update_from(static_binfo);
44 void Binary::find_dependencies()
50 list<Target *> dep_libs;
51 set<string> missing_libs;
52 queue.push_back(this);
53 for(auto j=queue.begin(); j!=queue.end(); ++j)
58 tgt->collect_build_info(binfo);
61 static_binfo.libpath.insert(static_binfo.libpath.end(), binfo.libpath.begin(), binfo.libpath.end());
62 static_binfo.keep_symbols.insert(static_binfo.keep_symbols.end(), binfo.keep_symbols.begin(), binfo.keep_symbols.end());
64 static_binfo.threads = true;
69 for(const string &l: binfo.libs)
71 if(l.size()>10 && !l.compare(l.size()-10, 10, ".framework"))
74 BuildInfo::LibraryMode libmode = component->get_build_info().get_libmode_for(l);
75 Target *lib = builder.get_vfs().find_library(l, binfo.libpath, libmode);
78 Target *real = lib->get_real_target();
79 if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(real))
80 queue.insert(insert_pos, stlib);
82 dep_libs.push_back(lib);
84 else if(missing_libs.insert(l).second)
85 problems.push_back(format("Required library %s not found", l));
90 dep_libs.splice(dep_libs.begin(), queue);
92 /* Add only the last occurrence of each library to the actual dependencies.
93 This ensures that static library ordering is correct. */
94 for(auto i=dep_libs.begin(); i!=dep_libs.end(); ++i)
95 if(!any_of(next(i), dep_libs.end(), [i](Target *d){ return d==*i; }))