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