]> git.tdb.fi Git - builder.git/blob - source/buildinfo.h
Eliminate all global typedefs, making misc.h finally unnecessary
[builder.git] / source / buildinfo.h
1 #ifndef BUILDINFO_H_
2 #define BUILDINFO_H_
3
4 #include <list>
5 #include <string>
6 #include <msp/datafile/objectloader.h>
7 #include <msp/fs/path.h>
8
9 /**
10 Stores information about compiler command line parameters in a more abstract
11 form.  Allows combining with other BuildInfos to support package dependencies.
12 */
13 class BuildInfo
14 {
15 public:
16         enum LibraryMode
17         {
18                 FORCE_STATIC,  //< Only accept static libraries
19                 STATIC,        //< Prefer static libraries but accept dynamic as well
20                 DYNAMIC,       //< Prefer dynamic libraries but accept static as well
21                 FORCE_DYNAMIC  //< Only accept dynamic libraries
22         };
23
24         class Loader: public Msp::DataFile::ObjectLoader<BuildInfo>
25         {
26         public:
27                 Loader(BuildInfo &);
28         private:
29                 void incpath(const std::string &);
30                 void define(const std::string &, const std::string &);
31                 void libpath(const std::string &);
32                 void library(const std::string &);
33         };
34         
35         enum UpdateLevel
36         {
37                 LOCAL,       //< Include all information
38                 DEPENDENCY,  //< Include all but code generation options
39                 CHAINED      //< Include only compilation options
40         };
41
42         /**
43         A wrapper which tracks the set status of the wrapped variable.  A default
44         value may be provided in initialization without causing it to be treated as
45         set.  Assigning from a raw value flags the Tracked object as set.  Assigning
46         from another Tracked object will only change the value of the target if the
47         source is set.  
48         */
49         template<typename T>
50         class Tracked
51         {
52         public:
53                 typedef T LoadType;
54
55         private:
56                 T value;
57                 bool set;
58
59         public:
60                 Tracked(): value(T()), set(false) { }
61                 Tracked(T v): value(v), set(false) { }
62                 Tracked &operator=(const Tracked &v) { if(v.set) { value = v.value; set = true; } return *this; }
63
64                 Tracked &operator=(T v) { value = v; set = true; return *this; }
65                 operator T() const { return value; }
66         };
67
68         typedef std::map<std::string, std::string> DefineMap;
69         typedef std::list<Msp::FS::Path> PathList;
70         typedef std::list<std::string> WordList;
71
72         DefineMap defines;
73         PathList incpath;
74         PathList libpath;
75         WordList libs;
76         Tracked<LibraryMode> libmode;
77         Tracked<bool> threads;
78         Tracked<bool> debug;
79         Tracked<int> optimize;
80         Tracked<bool> strip;
81         Tracked<unsigned> warning_level;
82         Tracked<bool> fatal_warnings;
83
84         BuildInfo();
85
86         /** Updates the BuildInfo from another one.  Lists are concatenated, with
87         the first occurrence of each item preserved.  Scalars are overwritten.
88         
89         The update level determines what information is updated. */
90         void update_from(const BuildInfo &, UpdateLevel = LOCAL);
91 };
92
93 #endif