]> git.tdb.fi Git - builder.git/blob - source/lib/component.h
Add visibility decorations to the library and plugins
[builder.git] / source / lib / 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 "conditionalloader.h"
9 #include "installmap.h"
10 #include "libbuilder_api.h"
11 #include "package.h"
12
13 class SourcePackage;
14
15 /**
16 Components specify things to be built.  Each component may build one binary (it
17 may also build none), as well as install a bunch of headers.  Components inherit
18 dependencies and build info from the package they belong to, and may also add
19 their own.
20 */
21 class LIBBUILDER_API Component
22 {
23 public:
24         class LIBBUILDER_API Loader: public Msp::DataFile::ObjectLoader<Component>, public ConditionalLoader
25         {
26         public:
27                 Loader(Component &);
28         private:
29                 void build_info();
30                 void install_map();
31                 void overlay(const std::string &);
32                 void require(const std::string &);
33                 void source(const std::string &);
34         };
35
36 protected:
37         SourcePackage &package;
38         std::string name;
39         std::vector<Msp::FS::Path> sources;
40         std::vector<std::string> overlays;
41         bool install = false;
42         BuildInfo build_info;
43         Package::Requirements requires;
44         bool deflt = true;
45         InstallMap install_map;
46         bool broken = false;
47         std::vector<std::string> problems;
48
49         Component(SourcePackage &p, const std::string &n): package(p), name(n) { }
50 public:
51         virtual ~Component() { }
52
53         const SourcePackage &get_package() const { return package; }
54         const std::string &get_name() const { return name; }
55
56         /** Returns a list of sources for the component.  They may refer to
57         directories or individual files. */
58         const std::vector<Msp::FS::Path> &get_sources() const { return sources; }
59
60         const std::vector<std::string> &get_overlays() const { return overlays; }
61
62 protected:
63         /** Returns a list of all source files for the component. */
64         std::vector<Msp::FS::Path> collect_source_files() const;
65
66 public:
67         bool get_install() const { return install; }
68         const InstallMap &get_install_map() const { return install_map; }
69         const Package::Requirements &get_required_packages() const { return requires; }
70         bool is_default() const { return deflt; }
71         bool is_broken() const { return broken; }
72         const std::vector<std::string> &get_problems() const { return problems; }
73
74         /** Prepares any required packages. */
75         void prepare();
76
77         /** Prepares the build information for building.  Pulls build info from the
78         parent and dependency packages, and adds any component-specific flags. */
79         virtual void create_build_info();
80
81         virtual void update_exported_build_info(BuildInfo &) const { }
82
83         const BuildInfo &get_build_info() const { return build_info; }
84
85         BuildInfo get_build_info_for_path(const Msp::FS::Path &) const;
86
87         virtual void create_targets() const = 0;
88 };
89
90 #endif