]> git.tdb.fi Git - builder.git/blob - source/component.h
Comments and member ordering
[builder.git] / source / component.h
1 #ifndef COMPONENT_H_
2 #define COMPONENT_H_
3
4 #include <string>
5 #include <msp/datafile/objectloader.h>
6 #include <msp/fs/path.h>
7 #include "buildinfo.h"
8 #include "installmap.h"
9 #include "misc.h"
10 #include "package.h"
11
12 class SourcePackage;
13
14 /**
15 Components specify things to be built.  Each component may build one binary (it
16 may also build none), as well as install a bunch of headers.  Components inherit
17 dependencies and build info from the package they belong to, and may also add
18 their own.
19 */
20 class Component
21 {
22 public:
23         class Loader: public Msp::DataFile::ObjectLoader<Component>
24         {
25         public:
26                 Loader(Component &);
27         private:
28                 void source(const std::string &);
29                 void require(const std::string &);
30                 void build_info();
31                 void install_map();
32         };
33
34         enum Type
35         {
36                 LIBRARY,
37                 PROGRAM,
38                 MODULE,
39                 DATAFILE,
40                 INSTALL,
41                 TARBALL
42         };
43
44 protected:
45         SourcePackage &package;
46         Type type;
47         std::string name;
48         StringList sources;
49         bool install;
50         BuildInfo build_info;
51         PackageList requires;
52         bool deflt;
53         InstallMap install_map;
54
55 public:
56         Component(SourcePackage &, Type, const std::string &);
57
58         const SourcePackage &get_package() const { return package; }
59         Type get_type() const { return type; }
60         const std::string &get_name() const { return name; }
61
62         /** Returns a list of sources for the component.  They may refer to
63         directories or individual files. */
64         const StringList &get_sources() const { return sources; }
65
66 protected:
67         /** Returns a list of all source files for the component. */
68         PathList collect_source_files() const;
69
70 public:
71         bool get_install() const { return install; }
72         const InstallMap &get_install_map() const { return install_map; }
73         const PackageList &get_required_packages() const { return requires; }
74         bool is_default() const { return deflt; }
75
76         /** Prepares any required packages. */
77         void prepare();
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         const BuildInfo &get_build_info() const { return build_info; }
84
85         void create_targets() const;
86 };
87
88 #endif