]> git.tdb.fi Git - builder.git/blob - source/component.h
Replace per-file copyright notices with a single file
[builder.git] / source / component.h
1 #ifndef COMPONENT_H_
2 #define COMPONENT_H_
3
4 #include <string>
5 #include <msp/datafile/loader.h>
6 #include <msp/fs/path.h>
7 #include "buildinfo.h"
8 #include "misc.h"
9 #include "package.h"
10
11 class SourcePackage;
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         class Loader: public Msp::DataFile::Loader
23         {
24         private:
25                 Component &comp;
26                 std::string inst_hdr;
27
28         public:
29                 Loader(Component &);
30                 Component &get_object() { return comp; }
31         private:
32                 virtual void finish();
33                 void source(const std::string &);
34                 void require(const std::string &);
35                 void modular();
36                 void host(const std::string &);
37                 void install_headers(const std::string &);
38                 void build_info();
39         };
40
41         enum Type
42         {
43                 HEADERS,
44                 LIBRARY,
45                 PROGRAM,
46                 MODULE,
47                 DATAFILE,
48                 INSTALL,
49                 TARBALL
50         };
51
52 protected:
53         SourcePackage &pkg;
54         Type type;
55         std::string name;
56         StringList sources;
57         bool install;
58         BuildInfo build_info;
59         PackageList requires;
60         bool deflt;
61
62 public:
63         Component(SourcePackage &, Type, const std::string &);
64         const SourcePackage &get_package() const { return pkg; }
65         Type get_type() const { return type; }
66         const std::string &get_name() const { return name; }
67         const StringList &get_sources() const { return sources; }
68         const BuildInfo &get_build_info() const { return build_info; }
69         bool get_install() const { return install; }
70         const PackageList &get_requires() const { return requires; }
71         bool is_default() const { return deflt; }
72
73         void configure(const StringMap &, unsigned);
74
75         /** Prepares the build information for building.  Pulls build info from the
76         parent and dependency packages, and adds any component-specific flags. */
77         void create_build_info();
78
79         void create_targets() const;
80
81 protected:
82         /** Returns a list of all source files for the component. */
83         PathList collect_source_files() const;
84 };
85
86 typedef std::list<Component> ComponentList;
87
88 #endif