* Bring back rbuild build to be used until bug 6372 is fixed.
[reactos.git] / tools / rbuild / backend / msvc / msvc.h
1 /*
2 * Copyright (C) 2005 Trevor McCort
3 * Copyright (C) 2005 Casper S. Hornstrup
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #pragma once
21
22 #include <fstream>
23 #include <vector>
24 #include <string>
25
26 #include "../backend.h"
27
28 #ifdef OUT
29 #undef OUT
30 #endif//OUT
31
32
33 class FileUnit
34 {
35 public:
36 std::string filename;
37 std::string folder;
38 };
39
40 enum OptimizationType
41 {
42 RosBuild,
43 Debug,
44 Release,
45 Speed,
46 };
47
48 enum ConfigurationType
49 {
50 ConfigUnknown,
51 ConfigApp,
52 ConfigDll,
53 ConfigEmpty,
54 ConfigLib
55 };
56
57 enum BinaryType
58 {
59 BinUnknown,
60 Lib,
61 Dll,
62 Exe,
63 Sys
64 };
65
66 enum HeadersType
67 {
68 MSVCHeaders,
69 ReactOSHeaders
70 };
71
72 class MSVCConfiguration
73 {
74 public:
75 MSVCConfiguration(const OptimizationType optimization,
76 const HeadersType headers = MSVCHeaders,
77 const std::string &name = "");
78 virtual ~MSVCConfiguration() {}
79 std::string name;
80 OptimizationType optimization;
81 HeadersType headers;
82 };
83
84 class MSVCBackend : public Backend
85 {
86 public:
87
88 MSVCBackend(Project &project,
89 Configuration& configuration);
90 virtual ~MSVCBackend() {}
91
92 virtual void Process();
93
94 private:
95
96 void ProcessModules();
97 void ProcessFile(std::string &filename);
98
99 bool CheckFolderAdded(std::string &folder);
100 void AddFolders(std::string &folder);
101
102 void OutputFolders();
103 void OutputFileUnits();
104
105 std::string VcprojFileName ( const Module& module ) const;
106 std::string VcxprojFileName ( const Module& module ) const;
107 std::string SlnFileName ( const Module& module ) const;
108 std::string SuoFileName ( const Module& module ) const;
109 std::string UserFileName ( const Module& module, std::string vcproj_file ) const;
110 std::string NcbFileName ( const Module& module ) const;
111
112 std::vector<MSVCConfiguration*> m_configurations;
113
114 std::vector<FileUnit> m_fileUnits;
115 std::vector<std::string> m_folders;
116
117 int m_unitCount;
118
119 std::string _gen_guid();
120
121 std::string _get_solution_version ( void );
122 std::string _get_studio_version ( void );
123 std::string _get_vc_dir ( void ) const;
124
125 void _clean_project_files ( void );
126 void _get_object_files ( const Module& module, std::vector<std::string>& out ) const;
127 void _get_def_files ( const Module& module, std::vector<std::string>& out ) const;
128 void _install_files ( const std::string& vcdir, const std::string& config );
129 bool _copy_file ( const std::string& inputname, const std::string& targetname ) const;
130 const Property* _lookup_property ( const Module& module, const std::string& name ) const;
131 };
132
133
134 // Abstract class
135 class ProjMaker
136 {
137 public:
138 ProjMaker ( );
139 ProjMaker ( Configuration& buildConfig, const std::vector<MSVCConfiguration*>& msvc_configs, std::string filename );
140 virtual ~ProjMaker() {}
141
142 virtual void _generate_proj_file ( const Module& module ) = 0;
143 virtual void _generate_user_configuration ();
144
145 std::string VcprojFileName ( const Module& module ) const;
146
147 protected:
148 Configuration configuration;
149 std::vector<MSVCConfiguration*> m_configurations;
150 std::string vcproj_file;
151 FILE* OUT;
152
153 std::vector<std::string> header_files;
154 std::vector<std::string> source_files;
155 std::vector<std::string> resource_files;
156 std::vector<std::string> generated_files;
157 std::vector<std::string> defines;
158 std::vector<std::string> includes;
159 std::vector<std::string> libraries;
160
161 std::string baseaddr;
162 BinaryType binaryType;
163
164 std::string _get_vc_dir ( void ) const;
165 std::string _strip_gcc_deffile(std::string Filename, std::string sourcedir, std::string objdir);
166 std::string _get_solution_version ( void );
167 std::string _get_studio_version ( void );
168 std::string _replace_str( std::string string1, const std::string &find_str, const std::string &replace_str);
169 std::string _get_file_path( FileLocation* file, std::string relative_path);
170
171 void _collect_files(const Module& module);
172 void _generate_standard_configuration( const Module& module, const MSVCConfiguration& cfg, BinaryType binaryType );
173 void _generate_makefile_configuration( const Module& module, const MSVCConfiguration& cfg );
174 };
175
176 class VCProjMaker : public ProjMaker
177 {
178 public:
179 VCProjMaker ( );
180 VCProjMaker ( Configuration& buildConfig, const std::vector<MSVCConfiguration*>& msvc_configs, std::string filename, const Module& module );
181 virtual ~VCProjMaker ();
182
183 void _generate_proj_file ( const Module& module );
184 void _generate_user_configuration ();
185
186 private:
187
188 void _generate_standard_configuration( const Module& module, const MSVCConfiguration& cfg, BinaryType binaryType );
189 void _generate_makefile_configuration( const Module& module, const MSVCConfiguration& cfg );
190 std::string _get_file_path( FileLocation* file, std::string relative_path);
191 };
192
193 class VCXProjMaker : public ProjMaker
194 {
195 public:
196 VCXProjMaker ( );
197 VCXProjMaker ( Configuration& buildConfig, const std::vector<MSVCConfiguration*>& msvc_configs, std::string filename, const Module& module );
198 virtual ~VCXProjMaker ();
199
200 void _generate_proj_file ( const Module& module );
201 void _generate_user_configuration ();
202
203 private:
204 std::string _get_configuration_type ();
205 void _generate_item_group (std::vector<std::string>);
206 void _generate_standard_configuration( const Module& module, const MSVCConfiguration& cfg, BinaryType binaryType );
207 void _generate_makefile_configuration( const Module& module, const MSVCConfiguration& cfg );
208 };
209
210 class SlnMaker
211 {
212 public:
213 SlnMaker ( Configuration& buildConfig, const std::vector<MSVCConfiguration*>& configurations, std::string filename_sln, std::string solution_version, std::string studio_version);
214 ~SlnMaker ();
215
216 void _add_project(ProjMaker &project, Module &module);
217 private:
218 Configuration m_configuration;
219 std::vector<MSVCConfiguration*> m_configurations;
220 FILE* OUT;
221 std::vector<Module*> modules;
222
223 void _generate_sln_header ( std::string solution_version, std::string studio_version );
224 void _generate_sln_footer ( );
225 void _generate_sln_configurations ( std::string vcproj_guid );
226 };
227
228 class VSPropsMaker
229 {
230 public:
231 VSPropsMaker ( Configuration& buildConfig,
232 Project* ProjectNode,
233 std::string filename_props,
234 MSVCConfiguration* msvc_configs);
235
236 ~VSPropsMaker ();
237
238 void _generate_props ( std::string solution_version, std::string studio_version );
239
240 private:
241 Configuration m_configuration;
242 Project* m_ProjectNode;
243 FILE* OUT;
244 MSVCConfiguration* m_msvc_config;
245 bool debug;
246 bool release;
247 bool speed;
248 bool use_ros_headers;
249
250 void _generate_header();
251 void _generate_tools_defaults();
252 void _generate_macro(std::string Name, std::string Value, bool EvairomentVariable);
253 void _generate_global_includes();
254 void _generate_global_definitions();
255 void _generate_footer();
256
257 };
258
259
260 class PropsMaker
261 {
262 public:
263 PropsMaker ( Project* ProjectNode,
264 std::string filename_props,
265 std::vector<MSVCConfiguration*> configurations);
266
267 ~PropsMaker ();
268
269 void _generate_props ( std::string solution_version, std::string studio_version );
270
271 private:
272 Project* m_ProjectNode;
273 FILE* OUT;
274 std::vector<MSVCConfiguration*> m_configurations;
275
276 void _generate_macro(std::string Name, std::string Value);
277 void _generate_global_includes(bool debug, bool use_ros_headers);
278 void _generate_global_definitions(bool debug, bool use_ros_headers);
279 void _generate_header();
280 void _generate_footer();
281
282 };