]> git.tdb.fi Git - builder.git/blob - source/component.h
Move the logic for creating targets into the Component class
[builder.git] / source / component.h
1 #ifndef COMPONENT_H_
2 #define COMPONENT_H_
3
4 #include <string>
5 #include <msp/parser/loader.h>
6 #include <msp/path/path.h>
7 #include "buildinfo.h"
8 #include "misc.h"
9 #include "packageref.h"
10
11 class Package;
12
13 /**
14 Components specify things to be built.  Each component may build one binary (it
15 may also build none), as well as install a bunch of headers.  Components inherit
16 dependencies and build info from the package they belong to, and may also add
17 their own.
18 */
19 class Component
20 {
21 public:
22         /// Loads a Component from file.  Used from Package::Loader.
23         class Loader: public Msp::Parser::Loader
24         {
25         public:
26                 Loader(Component &);
27                 Component &get_object() { return comp; }
28         private:
29                 Component &comp;
30
31                 void source(const std::string &);
32                 void require(const std::string &);
33                 void modular();
34                 void host(const std::string &);
35                 void build_info();
36         };
37
38         enum Type
39         {
40                 PROGRAM,
41                 LIBRARY,
42                 MODULE,
43                 HEADERS
44         };
45
46         Component(Package &, Type, const std::string &);
47         const Package     &get_package() const         { return pkg; }
48         Type              get_type() const             { return type; }
49         const std::string &get_name() const            { return name; }
50         const PathList    &get_sources() const         { return sources; }
51         const BuildInfo   &get_build_info() const      { return build_info; }
52         bool              get_install() const          { return install; }
53         const std::string &get_install_headers() const { return install_headers; }
54         bool              get_modular() const          { return modular; }
55         const PkgRefList  &get_requires() const        { return requires; }
56         bool              get_default() const          { return deflt; }
57         void              resolve_refs();
58         void              create_build_info();
59         void              create_targets() const;
60 protected:
61         Package     &pkg;
62         Type        type;
63         std::string name;
64         PathList    sources;
65         bool        install;
66         std::string install_headers;
67         const Component *module_host;
68         bool        modular;
69         BuildInfo   build_info;
70         PkgRefList  requires;
71         bool        deflt;
72
73         PathList    collect_source_files() const;
74 };
75 typedef std::list<Component> ComponentList;
76
77 #endif