]> git.tdb.fi Git - builder.git/blob - source/component.h
Add a way for components to use libraries from the same package
[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 "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::ObjectLoader<Component>
23         {
24         public:
25                 Loader(Component &);
26         private:
27                 void source(const std::string &);
28                 void require(const std::string &);
29                 void build_info();
30                 void install_map();
31                 void use(const std::string &);
32         };
33
34         enum Type
35         {
36                 LIBRARY,
37                 PROGRAM,
38                 MODULE,
39                 DATAFILE,
40                 INSTALL,
41                 TARBALL
42         };
43
44         typedef std::list<Msp::FS::Path> SourceList;
45         typedef std::list<const Component *> UseList;
46
47 protected:
48         SourcePackage &package;
49         Type type;
50         std::string name;
51         SourceList sources;
52         bool install;
53         BuildInfo build_info;
54         Package::Requirements requires;
55         UseList uses;
56         bool deflt;
57         InstallMap install_map;
58
59 public:
60         Component(SourcePackage &, Type, const std::string &);
61
62         const SourcePackage &get_package() const { return package; }
63         Type get_type() const { return type; }
64         const std::string &get_name() const { return name; }
65
66         /** Returns a list of sources for the component.  They may refer to
67         directories or individual files. */
68         const SourceList &get_sources() const { return sources; }
69
70 protected:
71         /** Returns a list of all source files for the component. */
72         SourceList collect_source_files() const;
73
74 public:
75         bool get_install() const { return install; }
76         const InstallMap &get_install_map() const { return install_map; }
77         const Package::Requirements &get_required_packages() const { return requires; }
78         const UseList &get_used_components() const { return uses; }
79         bool is_default() const { return deflt; }
80
81         /** Prepares any required packages. */
82         void prepare();
83
84         /** Prepares the build information for building.  Pulls build info from the
85         parent and dependency packages, and adds any component-specific flags. */
86         void create_build_info();
87
88         const BuildInfo &get_build_info() const { return build_info; }
89
90         void create_targets() const;
91 };
92
93 #endif