]> git.tdb.fi Git - builder.git/blob - source/component.h
Deprecate the install_headers statement
[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                 std::string inst_hdr;
34
35         public:
36                 Loader(Component &);
37                 Component &get_object() { return comp; }
38         private:
39                 virtual void finish();
40                 void source(const std::string &);
41                 void require(const std::string &);
42                 void modular();
43                 void host(const std::string &);
44                 void install_headers(const std::string &);
45                 void build_info();
46         };
47
48         enum Type
49         {
50                 PROGRAM,
51                 LIBRARY,
52                 MODULE,
53                 HEADERS
54         };
55
56 protected:
57         SourcePackage &pkg;
58         Type type;
59         std::string name;
60         PathList sources;
61         bool install;
62         const Component *module_host;
63         bool modular;
64         BuildInfo build_info;
65         PackageList requires;
66         bool deflt;
67
68 public:
69         Component(SourcePackage &, Type, const std::string &);
70         const SourcePackage &get_package() const { return pkg; }
71         Type get_type() const { return type; }
72         const std::string &get_name() const { return name; }
73         const PathList &get_sources() const { return sources; }
74         const BuildInfo &get_build_info() const { return build_info; }
75         bool get_install() const { return install; }
76         bool get_modular() const { return modular; }
77         const PackageList &get_requires() const { return requires; }
78         bool get_default() const { return deflt; }
79
80         /** Prepares the build information for building.  Pulls build info from the
81         parent and dependency packages, and adds any component-specific flags. */
82         void create_build_info();
83
84         void create_targets() const;
85
86 protected:
87         /** Returns a list of all source files for the component. */
88         PathList collect_source_files() const;
89 };
90
91 typedef std::list<Component> ComponentList;
92
93 #endif