]> git.tdb.fi Git - builder.git/blob - source/component.h
Flexible way to specify install locations for components
[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 "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::Loader
24         {
25         private:
26                 Component &comp;
27                 std::string inst_hdr;
28
29         public:
30                 Loader(Component &);
31                 Component &get_object() { return comp; }
32         private:
33                 virtual void finish();
34                 void source(const std::string &);
35                 void require(const std::string &);
36                 void build_info();
37                 void install_map();
38         };
39
40         enum Type
41         {
42                 HEADERS,
43                 LIBRARY,
44                 PROGRAM,
45                 MODULE,
46                 DATAFILE,
47                 INSTALL,
48                 TARBALL
49         };
50
51 protected:
52         SourcePackage &pkg;
53         Type type;
54         std::string name;
55         StringList sources;
56         bool install;
57         BuildInfo build_info;
58         PackageList requires;
59         bool deflt;
60         InstallMap install_map;
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         const InstallMap &get_install_map() const { return install_map; }
73
74         void configure(const StringMap &, unsigned);
75
76         /** Prepares the build information for building.  Pulls build info from the
77         parent and dependency packages, and adds any component-specific flags. */
78         void create_build_info();
79
80         void create_targets() const;
81
82 protected:
83         /** Returns a list of all source files for the component. */
84         PathList collect_source_files() const;
85 };
86
87 typedef std::list<Component> ComponentList;
88
89 #endif