4be80c64c99378b6b6f17a912e43726d1b630c8b
[reactos.git] / reactos / 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 #ifndef __MSVC_H__
20 #define __MSVC_H__
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 NcbFileName ( const Module& module ) const;
110
111 std::vector<MSVCConfiguration*> m_configurations;
112
113 std::vector<FileUnit> m_fileUnits;
114 std::vector<std::string> m_folders;
115
116 int m_unitCount;
117
118 std::string _gen_guid();
119
120 std::string _get_solution_version ( void );
121 std::string _get_studio_version ( void );
122 std::string _get_vc_dir ( void ) const;
123
124 void _clean_project_files ( void );
125 void _get_object_files ( const Module& module, std::vector<std::string>& out ) const;
126 void _get_def_files ( const Module& module, std::vector<std::string>& out ) const;
127 void _install_files ( const std::string& vcdir, const std::string& config );
128 bool _copy_file ( const std::string& inputname, const std::string& targetname ) const;
129 const Property* _lookup_property ( const Module& module, const std::string& name ) const;
130 };
131
132
133 // Abstract class
134 class ProjMaker
135 {
136 public:
137 ProjMaker ( );
138 ProjMaker ( Configuration& buildConfig, const std::vector<MSVCConfiguration*>& msvc_configs, std::string filename );
139 virtual ~ProjMaker() {}
140
141 virtual void _generate_proj_file ( const Module& module ) = 0;
142 virtual void _generate_user_configuration ();
143
144 protected:
145 Configuration configuration;
146 std::vector<MSVCConfiguration*> m_configurations;
147 std::string vcproj_file;
148 FILE* OUT;
149
150 std::vector<std::string> header_files;
151 std::vector<std::string> includes;
152 std::vector<std::string> includes_ros;
153 std::vector<std::string> libraries;
154 std::set<std::string> common_defines;
155 std::string baseaddr;
156
157 std::string VcprojFileName ( const Module& module ) const;
158 std::string _get_vc_dir ( void ) const;
159
160 std::string _strip_gcc_deffile(std::string Filename, std::string sourcedir, std::string objdir);
161 std::string _get_solution_version ( void );
162 std::string _get_studio_version ( void );
163 std::string _replace_str( std::string string1, const std::string &find_str, const std::string &replace_str);
164
165 void _generate_standard_configuration( const Module& module, const MSVCConfiguration& cfg, BinaryType binaryType );
166 void _generate_makefile_configuration( const Module& module, const MSVCConfiguration& cfg );
167 };
168
169 class VCProjMaker : public ProjMaker
170 {
171 public:
172 VCProjMaker ( );
173 VCProjMaker ( Configuration& buildConfig, const std::vector<MSVCConfiguration*>& msvc_configs, std::string filename );
174 virtual ~VCProjMaker ();
175
176 void _generate_proj_file ( const Module& module );
177 void _generate_user_configuration ();
178
179 private:
180 void _generate_standard_configuration( const Module& module, const MSVCConfiguration& cfg, BinaryType binaryType );
181 void _generate_makefile_configuration( const Module& module, const MSVCConfiguration& cfg );
182 std::string _get_file_path( FileLocation* file, std::string relative_path);
183 };
184
185 class VCXProjMaker : public ProjMaker
186 {
187 public:
188 VCXProjMaker ( );
189 VCXProjMaker ( Configuration& buildConfig, const std::vector<MSVCConfiguration*>& msvc_configs, std::string filename );
190 virtual ~VCXProjMaker ();
191
192 void _generate_proj_file ( const Module& module );
193 void _generate_user_configuration ();
194
195 private:
196 void _generate_standard_configuration( const Module& module, const MSVCConfiguration& cfg, BinaryType binaryType );
197 void _generate_makefile_configuration( const Module& module, const MSVCConfiguration& cfg );
198 };
199
200 class SlnMaker
201 {
202 public:
203 SlnMaker ( Configuration& buildConfig, Project& ProjectNode, const std::vector<MSVCConfiguration*>& configurations, std::string filename_sln );
204 ~SlnMaker ();
205
206 void _generate_sln ( std::string solution_version, std::string studio_version );
207
208 private:
209 Configuration m_configuration;
210 Project* m_ProjectNode;
211 std::vector<MSVCConfiguration*> m_configurations;
212 FILE* OUT;
213
214 void _generate_sln_header ( std::string solution_version, std::string studio_version );
215 void _generate_sln_footer ( );
216 //void _generate_rules_file ( FILE* OUT );
217 void _generate_sln_project (
218 const Module& module,
219 std::string vcproj_file,
220 std::string sln_guid,
221 std::string vcproj_guid,
222 const std::vector<Library*>& libraries );
223 void _generate_sln_configurations ( std::string vcproj_guid );
224 };
225
226 class PropsMaker
227 {
228 public:
229 PropsMaker ( Configuration& buildConfig,
230 Project* ProjectNode,
231 std::string filename_props,
232 MSVCConfiguration* msvc_configs);
233
234 ~PropsMaker ();
235
236 void _generate_props ( std::string solution_version, std::string studio_version );
237
238 private:
239 Configuration m_configuration;
240 Project* m_ProjectNode;
241 FILE* OUT;
242 MSVCConfiguration* m_msvc_config;
243 bool debug;
244 bool release;
245 bool speed;
246 bool use_ros_headers;
247
248 void _generate_header();
249 void _generate_tools_defaults();
250 void _generate_macro(std::string Name, std::string Value, bool EvairomentVariable);
251 void _generate_global_includes();
252 void _generate_global_definitions();
253 void _generate_footer();
254
255 };
256 #endif // __MSVC_H__