1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Project generator classes.
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
17 The top-level object is wxProjectDatabase, which maintains a list of wxProjectGenerator
18 objects. Each wxProjectGenerator object contains a list of wxGeneratorConfiguration objects,
19 and each of these in turn stores a list of variants which represent compiler-specific options in that
20 configuration. wxProjectDatabase also stores a list of generic options (again variants),
21 which may cause compiler-specific options to be stored in configurations.
23 The usage is like this. The IDE (or other calling application) adds a number of project generators
24 at initialization, one for each kind of compiler. For a new project, the app should call InitializeGenerators
25 in order to call OnInitializeDefaults for each generator, which will call back into the wxProjectDatabase
26 to get user-settable defaults.
28 The app can then set generic options. When a generic option (such as 'use debug info')
29 is set for a particular configuration, all generator objects are notified via OnSetGenericOption and they
30 translate the generic option into a specific one (for that configuration).
32 The wxProjectDatabase object can also be used to set compiler-specific options directly if required,
33 but normally this would not be required. Each wxProjectGenerator should also have the opportunity
34 to set initial defaults. These defaults should be editable by the user.
36 Each wxProjectGenerator can access the parent wxProjectDatabase object at any time, since it
37 may need to make a judgement about several generic settings in order to know what specific
38 compiler options should be set.
40 TODO: make a list of generic compiler options that each generator should recognise.
48 #pragma interface "projgen.h"
52 #include "wx/string.h"
54 #include "wx/variant.h"
57 wxPROJECT_CAP_NONE
= 0,
58 wxPROJECT_CAP_MAKEFILE
= 1,
59 wxPROJECT_CAP_PROJECT
= 2,
60 } wxProjectCapability
;
62 class wxProjectGenerator
;
63 class wxGeneratorConfiguration
;
67 * This class maintains a list to all wxProjectGenerator objects, one for
69 * Setting a generic option in wxProjectDatabase causes the individual wxProjectGenerator
70 * objects to set their compiler-specific options for later generation.
73 class wxProjectDatabase
: public wxObject
75 DECLARE_CLASS(wxProjectDatabase
)
81 // Generate project or makefile for a named compiler. Give an optional compiler version.
82 virtual bool GenerateProject(const wxString
& compiler
, const wxString
& filename
, bool isMakefile
, int compilerVersion
= 0);
84 // This calls each wxProjectGenerator's OnInitializeDefaults function to fill out the
85 // defaults for each configuration. The generators will probably call back into the wxProjectDatabase
86 // to get the defaults from a file (see GetDefaultCompilerOptions below).
87 virtual bool InitializeGenerators();
90 // Get the capability: can it generate projects, or makefiles, or neither?
91 virtual wxProjectCapability
GetCapability(const wxString
& compiler
) const ;
93 // Override this for your app so that when the wxProjectGenerator initializes its defaults, it
94 // can call this to get specific option values that may be setup by the user.
95 virtual wxVariant
GetDefaultCompilerOption(const wxString
& compiler
, const wxString
& config
, const wxString
& option
) const ;
97 // Gets all the default options for the named compiler/config. Likewise, override this to provide
98 // a list of defaults to the calling wxProjectGenerator.
99 virtual wxStringList
GetDefaultCompilerOptionList(const wxString
& compiler
, const wxString
& config
) const ;
101 // Compiler/configuration-specific options
102 // Get a compiler-specific option value from the name.
103 virtual wxVariant
GetCompilerOption(const wxString
& compiler
, const wxString
& config
, const wxString
& name
) const;
105 // Set the compiler-specific option
106 virtual void SetCompilerOption(const wxString
& compiler
, const wxString
& config
, const wxString
& name
, const wxVariant
& value
);
108 // Removes the compiler-specific option
109 virtual void RemoveCompilerOption(const wxString
& compiler
, const wxString
& config
, const wxString
& name
);
111 // Does this option exist?
112 virtual bool HasCompilerOption(const wxString
& compiler
, const wxString
& config
, const wxString
& name
) const;
115 // Get a generic option value from the name.
116 virtual wxVariant
GetGenericOption(const wxString
& config
, const wxString
& name
) const;
118 // Set the generic option value. This calls SetGenericOption for each wxProjectGenerator,
119 // which will cause compiler-specific values to be placed in the relevant config
120 virtual void SetGenericOption(const wxString
& config
, const wxString
& name
, const wxVariant
& value
);
122 // Removes the generic option.
123 virtual void RemoveGenericOption(const wxString
& config
, const wxString
& name
);
125 // Does this option exist?
126 virtual bool HasGenericOption(const wxString
& config
, const wxString
& name
) const;
129 inline void SetProjectPath(const wxString
& path
) { m_projectPath
= path
; };
130 inline wxString
GetProjectPath() const { return m_projectPath
; };
133 inline void SetProjectName(const wxString
& name
) { m_projectName
= name
; };
134 inline wxString
GetProjectName() const { return m_projectName
; };
136 // The source files in the project
137 // Add a file to the project. Normally this will be relative to the project path.
138 // TODO: Files are managed within the wxProjectDatabase, but what about extra files
139 // for specific platforms? Well, let's assume that even on Unix, you'd create a .rc
140 // file, even if this isn't used in the resulting project/makefile on Unix.
141 virtual void AddFile(const wxString
& filename
);
142 virtual void RemoveFile(const wxString
& filename
);
143 virtual bool FileExists(const wxString
& filename
) const;
145 // TODO: management of include paths, library paths, libraries
147 // Generator management
148 virtual void AddGenerator(wxProjectGenerator
* generator
) ;
149 virtual void RemoveGenerator(wxProjectGenerator
* generator
) ; // Doesn't delete it, just removes it
150 virtual wxProjectGenerator
* FindGenerator(const wxString
& compiler
) const ;
151 virtual void ClearGenerators();
154 // List of wxProjectGenerator objects
157 // List of compiler-independent configurations, such as "debug".
158 wxList m_genericConfigurations
;
160 // List of source files
161 wxStringList m_sourceFiles
;
163 // List of library paths
164 wxStringList m_libraryPaths
;
166 // List of libraries: TODO this should be compiler-specific, surely?
167 wxStringList m_libraries
;
169 // List of include paths
170 wxStringList m_includePaths
;
173 wxString m_projectPath
;
176 wxString m_projectName
;
180 * wxGeneratorConfiguration
181 * A configuration, e.g. "debug", "release"
184 class wxGeneratorConfiguration
: public wxObject
186 DECLARE_CLASS(wxGeneratorConfiguration
)
188 wxGeneratorConfiguration(const wxString
& name
);
189 ~wxGeneratorConfiguration();
191 // Does this option exist?
192 virtual bool HasOption(const wxString
& name
) const;
194 // Find option: returns NULL if there is no such option.
195 wxVariant
* FindOption(const wxString
& name
) const;
197 // Get an option value
198 virtual wxVariant
GetOption(const wxString
& name
) const;
201 virtual void SetOption(const wxString
& name
, const wxVariant
& value
);
204 virtual void RemoveOption(const wxString
& name
);
206 // Does this option exist?
207 virtual bool HasOption(const wxString
& name
) const;
209 // Get the list of options
210 inline const wxList
& GetOptions() const { return m_options
; }
212 inline void SetName(const wxString
& name
) { m_name
= name
; }
213 inline wxString
GetName() const { return m_name
; }
216 // Configuration name
219 // List of wxVariants
224 * wxProjectGenerator.
225 * Only derived classes can be instantiated.
228 class wxProjectGenerator
: public wxObject
230 DECLARE_CLASS(wxProjectGenerator
)
232 wxProjectGenerator(const wxString
& name
, wxProjectDatabase
* topLevel
);
233 ~wxProjectGenerator();
236 // Generate project or makefile. Give an optional compiler version.
237 virtual bool GenerateProject(bool isMakefile
, int compilerVersion
= 0) = 0;
239 // Called when the defaults should be initialized.
240 // It would recognise e.g. the "Debug" configuration name and set specific defaults, possibly
241 // reading them from a database to allow for tailoring.
242 // It is likely to call wxProjectDatabase::GetDefaultCompilerOption.
243 virtual bool OnInitializeDefaults(const wxString
& config
) = 0;
245 // This is called by wxProjectDatabase::SetGenericOption, and it tells this object
246 // to translate it to a specific option. Then this object will (probably) call SetOption.
247 virtual bool OnSetGenericOption(const wxString
& config
, const wxString
& name
, const wxVariant
& value
) = 0;
250 // Get the capability: can it generate projects, or makefiles, or neither?
251 virtual wxProjectCapability
GetCapability() const = 0;
254 inline void SetName(const wxString
& name
) { m_name
= name
; }
255 inline wxString
GetName() const { return m_name
; }
257 // Top-level wxProjectDatabase object
258 inline void SetTopLevel(wxProjectDatabase
* topLevel
) { m_topLevel
= topLevel
; }
259 inline wxProjectDatabase
* GetTopLevel() const { return m_topLevel
; }
262 // Get an option value
263 virtual wxVariant
GetOption(const wxString
& config
, const wxString
& name
) const;
266 virtual void SetOption(const wxString
& config
, const wxString
& name
, const wxVariant
& value
);
269 virtual void RemoveOption(const wxString
& config
, const wxString
& name
);
271 // Does this option exist?
272 virtual bool HasOption(const wxString
& name
) const;
274 // Get the list of options
275 inline const wxList
& GetConfigurations() const { return m_configs
; }
277 // Configuration management
278 wxGeneratorConfiguation
* FindConfiguration(const wxString
& config
) const ;
279 void AddConfiguration(wxGeneratorConfiguration
* config
) ;
280 void RemoveConfiguration(wxGeneratorConfiguration
* config
) ;
281 void ClearConfigurations() ;
284 // List of wxGeneratorConfiguration objects
291 wxProjectDatabase
* m_topLevel
;