]> git.tdb.fi Git - builder.git/blob - source/lib/buildinfo.h
Add visibility decorations to the library and plugins
[builder.git] / source / lib / buildinfo.h
1 #ifndef BUILDINFO_H_
2 #define BUILDINFO_H_
3
4 #include <string>
5 #include <vector>
6 #include <msp/datafile/objectloader.h>
7 #include <msp/fs/path.h>
8 #include "libbuilder_api.h"
9
10 /**
11 Stores information about compiler command line parameters in a more abstract
12 form.  Allows combining with other BuildInfos to support package dependencies.
13 */
14 class LIBBUILDER_API BuildInfo
15 {
16 public:
17         enum LibraryMode
18         {
19                 FORCE_STATIC,  //< Only accept static libraries
20                 STATIC,        //< Prefer static libraries but accept dynamic as well
21                 DYNAMIC,       //< Prefer dynamic libraries but accept static as well
22                 FORCE_DYNAMIC  //< Only accept dynamic libraries
23         };
24
25         enum RuntimePathMode
26         {
27                 NO_RPATH,  //< Do not record rpath in binaries
28                 RELATIVE,  //< Record relative rpath in binaries
29                 ABSOLUTE   //< Record absolute rpath in binaries
30         };
31
32         class LIBBUILDER_API Loader: public Msp::DataFile::ObjectLoader<BuildInfo>
33         {
34         public:
35                 Loader(BuildInfo &);
36         private:
37                 void incpath(const std::string &);
38                 void define(const std::string &, const std::string &);
39                 void keep_symbol(const std::string &);
40                 void libmode_for_lib(const std::string &, LibraryMode);
41                 void libpath(const std::string &);
42                 void library(const std::string &);
43                 void local_incpath(const std::string &);
44                 void standard(Msp::DataFile::Symbol, const std::string &);
45                 void sysroot(const std::string &);
46         };
47         
48         enum UpdateLevel
49         {
50                 LOCAL,       //< Include all information
51                 DEPENDENCY,  //< Include all but code generation options
52                 CHAINED      //< Include only compilation options
53         };
54
55         struct LIBBUILDER_API LanguageStandard
56         {
57                 std::string type;
58                 unsigned year = 0;
59
60                 LanguageStandard() = default;
61                 LanguageStandard(const std::string &);
62
63                 std::string str() const;
64         };
65
66         /**
67         A wrapper which tracks the set status of the wrapped variable.  A default
68         value may be provided in initialization without causing it to be treated as
69         set.  Assigning from a raw value flags the Tracked object as set.  Assigning
70         from another Tracked object will only change the value of the target if the
71         source is set.  
72         */
73         template<typename T>
74         class Tracked
75         {
76         public:
77                 using LoadType = T;
78
79         private:
80                 T value{};
81                 bool set = false;
82
83         public:
84                 Tracked() = default;
85                 Tracked(T v): value(v) { }
86                 Tracked(const Tracked &t) = default;
87                 Tracked &operator=(const Tracked &v) { if(v.set) { value = v.value; set = true; } return *this; }
88
89                 Tracked &operator=(const T &v) { value = v; set = true; return *this; }
90                 operator const T &() const { return value; }
91         };
92
93         Tracked<Msp::FS::Path> sysroot;
94         std::map<std::string, std::string> defines;
95         std::vector<Msp::FS::Path> incpath;
96         std::vector<Msp::FS::Path> local_incpath;
97         std::vector<Msp::FS::Path> libpath;
98         std::vector<std::string> libs;
99         Tracked<LibraryMode> libmode = DYNAMIC;
100         Tracked<RuntimePathMode> rpath_mode = NO_RPATH;
101         std::map<std::string, LibraryMode> libmodes;
102         std::vector<std::string> keep_symbols;
103         std::map<std::string, LanguageStandard> standards;
104         Tracked<bool> threads = false;
105         Tracked<bool> debug = false;
106         Tracked<int> optimize = 0;
107         Tracked<bool> strip = false;
108         Tracked<unsigned> warning_level = 0;
109         Tracked<bool> fatal_warnings = false;
110
111         /** Returns the library mode for linking a particular library.  If no mode
112         has been specified for that library, the the global library mode is
113         returned. */
114         LibraryMode get_libmode_for(const std::string &) const;
115
116         /** Updates the BuildInfo from another one.  Lists are concatenated, with
117         the first occurrence of each item preserved.  Scalars are overwritten.
118         
119         The update level determines what information is updated. */
120         void update_from(const BuildInfo &, UpdateLevel = LOCAL);
121 };
122
123 #endif