]> git.tdb.fi Git - builder.git/blob - source/component.h
Reorder class members
[builder.git] / source / component.h
1 /* $Id$
2
3 This file is part of builder
4 Copyright © 2006-2009  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/datafile/loader.h>
13 #include <msp/fs/path.h>
14 #include "buildinfo.h"
15 #include "misc.h"
16 #include "package.h"
17
18 class SourcePackage;
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         class Loader: public Msp::DataFile::Loader
30         {
31         private:
32                 Component &comp;
33
34         public:
35                 Loader(Component &);
36                 Component &get_object() { return comp; }
37         private:
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 protected:
54         SourcePackage &pkg;
55         Type type;
56         std::string name;
57         PathList sources;
58         bool install;
59         std::string install_headers;
60         const Component *module_host;
61         bool modular;
62         BuildInfo build_info;
63         PackageList requires;
64         bool deflt;
65
66 public:
67         Component(SourcePackage &, Type, const std::string &);
68         const SourcePackage &get_package() const { return pkg; }
69         Type get_type() const { return type; }
70         const std::string &get_name() const { return name; }
71         const PathList &get_sources() const { return sources; }
72         const BuildInfo &get_build_info() const { return build_info; }
73         bool get_install() const { return install; }
74         const std::string &get_install_headers() const { return install_headers; }
75         bool get_modular() const { return modular; }
76         const PackageList &get_requires() const { return requires; }
77         bool get_default() const { return deflt; }
78
79         /** Prepares the build information for building.  Pulls build info from the
80         parent and dependency packages, and adds any component-specific flags. */
81         void create_build_info();
82
83         void create_targets() const;
84
85 protected:
86         /** Returns a list of all source files for the component. */
87         PathList collect_source_files() const;
88 };
89
90 typedef std::list<Component> ComponentList;
91
92 #endif