]> git.tdb.fi Git - builder.git/blob - source/installmap.h
Refactor transitive dependencies to work on all targets
[builder.git] / source / installmap.h
1 #ifndef INSTALLMAP_H_
2 #define INSTALLMAP_H_
3
4 #include <list>
5 #include <msp/datafile/objectloader.h>
6 #include <msp/fs/path.h>
7
8 class FileTarget;
9
10 /**
11 Maps install locations based on location in the source tree.  Mappings are
12 defined as pairs of source and install locations.  Targets within a source
13 location are mapped if their default install location shares a common prefix
14 with the mapped install location.  The remainder of the source location is
15 appended to the mapped install location to form the final install location.
16 */
17 class InstallMap
18 {
19 public:
20         class Loader: public Msp::DataFile::ObjectLoader<InstallMap>
21         {
22         private:
23                 Msp::FS::Path source_base;
24
25         public:
26                 Loader(InstallMap &, const Msp::FS::Path &);
27
28         private:
29                 void map(const std::string &, const std::string &);
30         };
31
32 private:
33         struct Entry
34         {
35                 Msp::FS::Path source;
36                 Msp::FS::Path install;
37         };
38
39         std::list<Entry> entries;
40
41 public:
42         /** Adds an install mapping.  Multiple mappings can be specified for the
43         same source location, but the first one that matches both that and the
44         target's default install location will be used. */
45         void add_mapping(const Msp::FS::Path &, const Msp::FS::Path &);
46
47         /** Returns the install location for a target.  If no defined mappings match
48         the target, its default install location is returned. */
49         Msp::FS::Path get_install_location(const FileTarget &) const;
50 };
51
52 #endif