- Initial re-architecture of the msvc backend.
[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 SlnFileName ( const Module& module ) const;
107 std::string SuoFileName ( const Module& module ) const;
108 std::string NcbFileName ( const Module& module ) const;
109
110 std::vector<MSVCConfiguration*> m_configurations;
111
112 std::vector<FileUnit> m_fileUnits;
113 std::vector<std::string> m_folders;
114
115 int m_unitCount;
116
117 std::string _gen_guid();
118
119 std::string _get_solution_version ( void );
120 std::string _get_studio_version ( void );
121 std::string _get_vc_dir ( void ) const;
122
123 void _clean_project_files ( void );
124 void _get_object_files ( const Module& module, std::vector<std::string>& out ) const;
125 void _get_def_files ( const Module& module, std::vector<std::string>& out ) const;
126 void _install_files ( const std::string& vcdir, const std::string& config );
127 bool _copy_file ( const std::string& inputname, const std::string& targetname ) const;
128 const Property* _lookup_property ( const Module& module, const std::string& name ) const;
129 };
130
131
132 // Abstract class
133 class ProjMaker
134 {
135 public:
136 ProjMaker ( );
137 ProjMaker ( Configuration& buildConfig, const std::vector<MSVCConfiguration*>& msvc_configs, std::string filename );
138 virtual ~ProjMaker() {}
139
140 virtual void _generate_proj_file ( const Module& module ) = 0;
141 virtual void _generate_user_configuration ();
142
143 protected:
144 Configuration configuration;
145 std::vector<MSVCConfiguration*> m_configurations;
146 std::string vcproj_file;
147 FILE* OUT;
148
149 std::vector<std::string> header_files;
150 std::vector<std::string> includes;
151 std::vector<std::string> includes_ros;
152 std::vector<std::string> libraries;
153 std::set<std::string> common_defines;
154 std::string baseaddr;
155
156 std::string VcprojFileName ( const Module& module ) const;
157 std::string _get_vc_dir ( void ) const;
158
159 std::string _strip_gcc_deffile(std::string Filename, std::string sourcedir, std::string objdir);
160 std::string _get_solution_version ( void );
161 std::string _get_studio_version ( void );
162 std::string _replace_str( std::string string1, const std::string &find_str, const std::string &replace_str);
163
164 void _generate_standard_configuration( const Module& module, const MSVCConfiguration& cfg, BinaryType binaryType );
165 void _generate_makefile_configuration( const Module& module, const MSVCConfiguration& cfg );
166 };
167
168 class VCProjMaker : public ProjMaker
169 {
170 public:
171 VCProjMaker ( );
172 VCProjMaker ( Configuration& buildConfig, const std::vector<MSVCConfiguration*>& msvc_configs, std::string filename );
173 virtual ~VCProjMaker ();
174
175 void _generate_proj_file ( const Module& module );
176 void _generate_user_configuration ();
177
178 private:
179 void _generate_standard_configuration( const Module& module, const MSVCConfiguration& cfg, BinaryType binaryType );
180 void _generate_makefile_configuration( const Module& module, const MSVCConfiguration& cfg );
181 };
182
183 class VCXProjMaker : public ProjMaker
184 {
185 public:
186 VCXProjMaker ( );
187 VCXProjMaker ( Configuration& buildConfig, const std::vector<MSVCConfiguration*>& msvc_configs, std::string filename );
188 virtual ~VCXProjMaker ();
189
190 void _generate_proj_file ( const Module& module );
191 void _generate_user_configuration ();
192
193 private:
194 void _generate_standard_configuration( const Module& module, const MSVCConfiguration& cfg, BinaryType binaryType );
195 void _generate_makefile_configuration( const Module& module, const MSVCConfiguration& cfg );
196 };
197
198 class SlnMaker
199 {
200 public:
201 SlnMaker ( Configuration& buildConfig, Project& ProjectNode, const std::vector<MSVCConfiguration*>& configurations, std::string filename_sln );
202 ~SlnMaker ();
203
204 void _generate_sln ( std::string solution_version, std::string studio_version );
205
206 private:
207 Configuration m_configuration;
208 Project* m_ProjectNode;
209 std::vector<MSVCConfiguration*> m_configurations;
210 FILE* OUT;
211
212 void _generate_sln_header ( std::string solution_version, std::string studio_version );
213 void _generate_sln_footer ( );
214 //void _generate_rules_file ( FILE* OUT );
215 void _generate_sln_project (
216 const Module& module,
217 std::string vcproj_file,
218 std::string sln_guid,
219 std::string vcproj_guid,
220 const std::vector<Library*>& libraries );
221 void _generate_sln_configurations ( std::string vcproj_guid );
222 };
223
224 #endif // __MSVC_H__