]> git.tdb.fi Git - builder.git/blobdiff - source/installmap.h
Flexible way to specify install locations for components
[builder.git] / source / installmap.h
diff --git a/source/installmap.h b/source/installmap.h
new file mode 100644 (file)
index 0000000..955decc
--- /dev/null
@@ -0,0 +1,52 @@
+#ifndef INSTALLMAP_H_
+#define INSTALLMAP_H_
+
+#include <list>
+#include <msp/datafile/objectloader.h>
+#include <msp/fs/path.h>
+
+class FileTarget;
+
+/**
+Maps install locations based on location in the source tree.  Mappings are
+defined as pairs of source and install locations.  Targets within a source
+location are mapped if their default install location shares a common prefix
+with the mapped install location.  The remainder of the source location is
+appended to the mapped install location to form the final install location.
+*/
+class InstallMap
+{
+public:
+       class Loader: public Msp::DataFile::ObjectLoader<InstallMap>
+       {
+       private:
+               Msp::FS::Path source_base;
+
+       public:
+               Loader(InstallMap &, const Msp::FS::Path &);
+
+       private:
+               void map(const std::string &, const std::string &);
+       };
+
+private:
+       struct Entry
+       {
+               Msp::FS::Path source;
+               Msp::FS::Path install;
+       };
+
+       std::list<Entry> entries;
+
+public:
+       /** Adds an install mapping.  Multiple mappings can be specified for the
+       same source location, but the first one that matches both that and the
+       target's default install location will be used. */
+       void add_mapping(const Msp::FS::Path &, const Msp::FS::Path &);
+
+       /** Returns the install location for a target.  If no defined mappings match
+       the target, its default install location is returned. */
+       Msp::FS::Path get_install_location(const FileTarget &) const;
+};
+
+#endif