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