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