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