]> git.tdb.fi Git - builder.git/blob - source/binary.cpp
Move nested build signature creation to FileTarget
[builder.git] / source / binary.cpp
1 #include <msp/fs/utils.h>
2 #include <msp/strings/format.h>
3 #include <msp/strings/utils.h>
4 #include "binary.h"
5 #include "builder.h"
6 #include "component.h"
7 #include "objectfile.h"
8 #include "sharedlibrary.h"
9 #include "sourcepackage.h"
10 #include "staticlibrary.h"
11 #include "tool.h"
12
13 using namespace std;
14 using namespace Msp;
15
16 Binary::Binary(Builder &b, const FS::Path &p):
17         FileTarget(b, p)
18 { }
19
20 Binary::Binary(Builder &b, const Component &c, const string &p, const list<ObjectFile *> &objs):
21         FileTarget(b, c.get_package(), c.get_package().get_output_directory()/p),
22         objects(objs)
23 {
24         component = &c;
25         for(list<ObjectFile *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
26                 add_dependency(**i);
27
28         nested_build_sig = true;
29         arch_in_build_sig = true;
30 }
31
32 void Binary::find_dependencies()
33 {
34         if(!component)
35                 return;
36
37         list<const Component *> queue;
38         list<Target *> dep_libs;
39         set<string> missing_libs;
40         queue.push_back(component);
41         while(!queue.empty())
42         {
43                 const Component *c = queue.front();
44                 queue.erase(queue.begin());
45
46                 const BuildInfo &binfo = c->get_build_info();
47                 for(BuildInfo::WordList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
48                 {
49                         if(i->size()>10 && !i->compare(i->size()-10, 10, ".framework"))
50                                 continue;
51
52                         BuildInfo::LibraryMode libmode = component->get_build_info().get_libmode_for(*i);
53                         Target *lib = builder.get_vfs().find_library(*i, binfo.libpath, libmode);
54                         if(lib)
55                         {
56                                 Target *real = lib->get_real_target();
57                                 if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(real))
58                                 {
59                                         dep_libs.push_back(stlib);
60                                         if(stlib->get_component())
61                                                 queue.push_back(stlib->get_component());
62                                 }
63                                 else
64                                         dep_libs.push_back(lib);
65                         }
66                         else if(missing_libs.insert(*i).second)
67                                 problems.push_back(format("Required library %s not found", *i));
68                 }
69         }
70
71         /* Add only the last occurrence of each library to the actual dependencies.
72         This ensures that static library ordering is correct. */
73         for(list<Target *>::iterator i=dep_libs.begin(); i!=dep_libs.end(); ++i)
74         {
75                 bool last = true;
76                 for(list<Target *>::iterator j=i; (last && j!=dep_libs.end()); ++j)
77                         last = (j==i || *j!=*i);
78                 if(last)
79                         add_dependency(**i);
80         }
81 }