]> git.tdb.fi Git - builder.git/blob - source/buildinfo.h
0af7374575e1a5979111ea12c999d99e8a288b45
[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 libmode_for_lib(const std::string &, LibraryMode);
32                 void libpath(const std::string &);
33                 void library(const std::string &);
34                 void local_incpath(const std::string &);
35                 void standard(Msp::DataFile::Symbol, const std::string &);
36                 void sysroot(const std::string &);
37         };
38         
39         enum UpdateLevel
40         {
41                 LOCAL,       //< Include all information
42                 DEPENDENCY,  //< Include all but code generation options
43                 CHAINED      //< Include only compilation options
44         };
45
46         /**
47         A wrapper which tracks the set status of the wrapped variable.  A default
48         value may be provided in initialization without causing it to be treated as
49         set.  Assigning from a raw value flags the Tracked object as set.  Assigning
50         from another Tracked object will only change the value of the target if the
51         source is set.  
52         */
53         template<typename T>
54         class Tracked
55         {
56         public:
57                 typedef T LoadType;
58
59         private:
60                 T value;
61                 bool set;
62
63         public:
64                 Tracked(): value(T()), set(false) { }
65                 Tracked(T v): value(v), set(false) { }
66                 Tracked &operator=(const Tracked &v) { if(v.set) { value = v.value; set = true; } return *this; }
67
68                 Tracked &operator=(T v) { value = v; set = true; return *this; }
69                 operator T() const { return value; }
70         };
71
72         typedef std::map<std::string, std::string> DefineMap;
73         typedef std::list<Msp::FS::Path> PathList;
74         typedef std::list<std::string> WordList;
75         typedef std::map<std::string, LibraryMode> LibModeMap;
76         typedef std::map<std::string, std::string> StandardMap;
77
78         Tracked<Msp::FS::Path> sysroot;
79         DefineMap defines;
80         PathList incpath;
81         PathList local_incpath;
82         PathList libpath;
83         WordList libs;
84         Tracked<LibraryMode> libmode;
85         LibModeMap libmodes;
86         StandardMap standards;
87         Tracked<bool> threads;
88         Tracked<bool> debug;
89         Tracked<int> optimize;
90         Tracked<bool> strip;
91         Tracked<unsigned> warning_level;
92         Tracked<bool> fatal_warnings;
93
94         BuildInfo();
95
96         /** Returns the library mode for linking a particular library.  If no mode
97         has been specified for that library, the the global library mode is
98         returned. */
99         LibraryMode get_libmode_for(const std::string &) const;
100
101         /** Updates the BuildInfo from another one.  Lists are concatenated, with
102         the first occurrence of each item preserved.  Scalars are overwritten.
103         
104         The update level determines what information is updated. */
105         void update_from(const BuildInfo &, UpdateLevel = LOCAL);
106 };
107
108 #endif