* compile .S files with MSVC2002/2003 too
[reactos.git] / reactos / tools / rbuild / backend / msvc / vcprojmaker.cpp
1 /*
2 * Copyright (C) 2002 Patrik Stridvall
3 * Copyright (C) 2005 Royce Mitchell III
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
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #ifdef _MSC_VER
21 #pragma warning ( disable : 4786 )
22 #endif//_MSC_VER
23
24 #include <string>
25 #include <vector>
26
27 #include <stdio.h>
28
29 #include "msvc.h"
30
31 using std::string;
32 using std::vector;
33
34 #ifdef OUT
35 #undef OUT
36 #endif//OUT
37
38 void
39 MSVCBackend::_generate_vcproj ( const Module& module )
40 {
41 size_t i;
42 // TODO FIXME wine hack?
43 //const bool wine = false;
44
45 string vcproj_file = VcprojFileName(module);
46 printf ( "Creating MSVC.NET project: '%s'\n", vcproj_file.c_str() );
47 FILE* OUT = fopen ( vcproj_file.c_str(), "wb" );
48
49 vector<string> imports;
50 for ( i = 0; i < module.non_if_data.libraries.size(); i++ )
51 {
52 imports.push_back ( module.non_if_data.libraries[i]->name );
53 }
54
55 string module_type = GetExtension(module.GetTargetName());
56 bool lib = (module.type == ObjectLibrary) || (module_type == ".lib") || (module_type == ".a");
57 bool dll = (module_type == ".dll") || (module_type == ".cpl");
58 bool exe = (module_type == ".exe");
59 // TODO FIXME - need more checks here for 'sys' and possibly 'drv'?
60
61 bool console = exe && (module.type == Win32CUI);
62
63 // TODO FIXME - not sure if the count here is right...
64 int parts = 0;
65 const char* p = strpbrk ( vcproj_file.c_str(), "/\\" );
66 while ( p )
67 {
68 ++parts;
69 p = strpbrk ( p+1, "/\\" );
70 }
71 string msvc_wine_dir = "..";
72 while ( --parts )
73 msvc_wine_dir += "\\..";
74
75 string wine_include_dir = msvc_wine_dir + "\\include";
76
77 //$progress_current++;
78 //$output->progress("$dsp_file (file $progress_current of $progress_max)");
79
80 // TODO FIXME - what's diff. betw. 'c_srcs' and 'source_files'?
81 string vcproj_path = module.GetBasePath();
82 vector<string> c_srcs, source_files, resource_files, includes, libraries, defines;
83 vector<const IfableData*> ifs_list;
84 ifs_list.push_back ( &module.project.non_if_data );
85 ifs_list.push_back ( &module.non_if_data );
86
87 // this is a define in MinGW w32api, but not Microsoft's headers
88 defines.push_back ( "STDCALL=__stdcall" );
89
90 while ( ifs_list.size() )
91 {
92 const IfableData& data = *ifs_list.back();
93 ifs_list.pop_back();
94 // TODO FIXME - refactor needed - we're discarding if conditions
95 for ( i = 0; i < data.ifs.size(); i++ )
96 ifs_list.push_back ( &data.ifs[i]->data );
97 const vector<File*>& files = data.files;
98 for ( i = 0; i < files.size(); i++ )
99 {
100 // TODO FIXME - do we want the full path of the file here?
101 string file = string(".") + &files[i]->name[vcproj_path.size()];
102
103 source_files.push_back ( file );
104 if ( !stricmp ( Right(file,2).c_str(), ".c" ) )
105 c_srcs.push_back ( file );
106 if ( !stricmp ( Right(file,3).c_str(), ".rc" ) )
107 resource_files.push_back ( file );
108 }
109 const vector<Include*>& incs = data.includes;
110 for ( i = 0; i < incs.size(); i++ )
111 {
112 // explicitly omit win32api directories
113 if ( !strncmp(incs[i]->directory.c_str(), "w32api", 6 ) )
114 continue;
115
116 // explicitly omit include/wine directories
117 if ( !strncmp(incs[i]->directory.c_str(), "include\\wine", 12 ) )
118 continue;
119
120 string path = Path::RelativeFromDirectory (
121 incs[i]->directory,
122 module.GetBasePath() );
123 includes.push_back ( path );
124 }
125 const vector<Library*>& libs = data.libraries;
126 for ( i = 0; i < libs.size(); i++ )
127 {
128 libraries.push_back ( libs[i]->name + ".lib" );
129 }
130 const vector<Define*>& defs = data.defines;
131 for ( i = 0; i < defs.size(); i++ )
132 {
133 if ( defs[i]->value[0] )
134 defines.push_back ( defs[i]->name + "=" + defs[i]->value );
135 else
136 defines.push_back ( defs[i]->name );
137 }
138 }
139
140 vector<string> header_files;
141
142 bool no_cpp = true;
143 bool no_msvc_headers = true;
144
145 std::vector<std::string> cfgs;
146
147 cfgs.push_back ( "Debug" );
148 cfgs.push_back ( "Release" );
149
150 if (!no_cpp)
151 {
152 std::vector<std::string> _cfgs;
153 for ( i = 0; i < cfgs.size(); i++ )
154 {
155 _cfgs.push_back ( cfgs[i] + " C" );
156 _cfgs.push_back ( cfgs[i] + " C++" );
157 }
158 cfgs.resize(0);
159 cfgs = _cfgs;
160 }
161
162 if (!no_msvc_headers)
163 {
164 std::vector<std::string> _cfgs;
165 for ( i = 0; i < cfgs.size(); i++ )
166 {
167 _cfgs.push_back ( cfgs[i] + " MSVC Headers" );
168 _cfgs.push_back ( cfgs[i] + " Wine Headers" );
169 }
170 cfgs.resize(0);
171 cfgs = _cfgs;
172 }
173
174 string default_cfg = cfgs.back();
175
176 fprintf ( OUT, "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\r\n" );
177 fprintf ( OUT, "<VisualStudioProject\r\n" );
178 fprintf ( OUT, "\tProjectType=\"Visual C++\"\r\n" );
179
180 if (configuration.VSProjectVersion.empty())
181 configuration.VSProjectVersion = MS_VS_DEF_VERSION;
182
183 fprintf ( OUT, "\tVersion=\"%s\"\r\n", configuration.VSProjectVersion.c_str() );
184 fprintf ( OUT, "\tName=\"%s\"\r\n", module.name.c_str() );
185 fprintf ( OUT, "\tProjectGUID=\"%s\"\r\n", module.guid.c_str() );
186 fprintf ( OUT, "\tKeyword=\"Win32Proj\">\r\n" );
187
188 fprintf ( OUT, "\t<Platforms>\r\n" );
189 fprintf ( OUT, "\t\t<Platform\r\n" );
190 fprintf ( OUT, "\t\t\tName=\"Win32\"/>\r\n" );
191 fprintf ( OUT, "\t</Platforms>\r\n" );
192
193 fprintf ( OUT, "\t<ToolFiles>\r\n" );
194 fprintf ( OUT, "\t\t<ToolFile\r\n" );
195
196 string path = Path::RelativeFromDirectory ( ProjectNode.name, module.GetBasePath() );
197 path.erase(path.find(ProjectNode.name, 0), ProjectNode.name.size() + 1);
198
199 fprintf ( OUT, "\t\t\tRelativePath=\"%s/gccasm.rules\"/>\r\n", path.c_str() );
200 fprintf ( OUT, "\t</ToolFiles>\r\n" );
201
202 int n = 0;
203
204 std::string output_dir;
205
206 fprintf ( OUT, "\t<Configurations>\r\n" );
207 for ( size_t icfg = 0; icfg < cfgs.size(); icfg++ )
208 {
209 std::string& cfg = cfgs[icfg];
210
211 bool debug = !strstr ( cfg.c_str(), "Release" );
212 //bool msvc_headers = ( 0 != strstr ( cfg.c_str(), "MSVC Headers" ) );
213
214 fprintf ( OUT, "\t\t<Configuration\r\n" );
215 fprintf ( OUT, "\t\t\tName=\"%s|Win32\"\r\n", cfg.c_str() );
216 fprintf ( OUT, "\t\t\tOutputDirectory=\"%s\"\r\n", cfg.c_str() );
217 fprintf ( OUT, "\t\t\tIntermediateDirectory=\"%s\"\r\n", cfg.c_str() );
218 fprintf ( OUT, "\t\t\tConfigurationType=\"%d\"\r\n", exe ? 1 : dll ? 2 : lib ? 4 : -1 );
219 fprintf ( OUT, "\t\t\tCharacterSet=\"2\">\r\n" );
220
221 fprintf ( OUT, "\t\t\t<Tool\r\n" );
222 fprintf ( OUT, "\t\t\t\tName=\"VCCLCompilerTool\"\r\n" );
223 fprintf ( OUT, "\t\t\t\tOptimization=\"%d\"\r\n", debug ? 0 : 2 );
224
225 fprintf ( OUT, "\t\t\t\tAdditionalIncludeDirectories=\"" );
226 bool multiple_includes = false;
227 fprintf ( OUT, "./;" );
228 for ( i = 0; i < includes.size(); i++ )
229 {
230 const string& include = includes[i];
231 if ( strcmp ( include.c_str(), "." ) )
232 {
233 if ( multiple_includes )
234 fprintf ( OUT, ";" );
235 fprintf ( OUT, "%s", include.c_str() );
236 multiple_includes = true;
237 }
238 }
239 fprintf ( OUT, "\"\r\n " );
240
241 if ( debug )
242 {
243 defines.push_back ( "_DEBUG" );
244 if ( lib || exe )
245 {
246 defines.push_back ( "_LIB" );
247 }
248 else
249 {
250 defines.push_back ( "_WINDOWS" );
251 defines.push_back ( "_USRDLL" );
252 }
253 }
254 else
255 {
256 defines.push_back ( "NDEBUG" );
257 if ( lib || exe )
258 {
259 defines.push_back ( "_LIB" );
260 }
261 else
262 {
263 defines.push_back ( "_WINDOWS" );
264 defines.push_back ( "_USRDLL" );
265 }
266 }
267
268 fprintf ( OUT, "\t\t\t\tPreprocessorDefinitions=\"" );
269 for ( i = 0; i < defines.size(); i++ )
270 {
271 if ( i > 0 )
272 fprintf ( OUT, ";" );
273
274 defines[i] = _replace_str(defines[i], "\"","&quot;");
275 fprintf ( OUT, "%s", defines[i].c_str() );
276 }
277 fprintf ( OUT, "\"\r\n" );
278
279 fprintf ( OUT, "\t\t\t\tMinimalRebuild=\"TRUE\"\r\n" );
280 fprintf ( OUT, "\t\t\t\tBasicRuntimeChecks=\"3\"\r\n" );
281 fprintf ( OUT, "\t\t\t\tRuntimeLibrary=\"5\"\r\n" );
282 fprintf ( OUT, "\t\t\t\tBufferSecurityCheck=\"%s\"\r\n", debug ? "TRUE" : "FALSE" );
283 fprintf ( OUT, "\t\t\t\tEnableFunctionLevelLinking=\"%s\"\r\n", debug ? "TRUE" : "FALSE" );
284 fprintf ( OUT, "\t\t\t\tUsePrecompiledHeader=\"0\"\r\n" );
285 fprintf ( OUT, "\t\t\t\tWarningLevel=\"1\"\r\n" );
286 fprintf ( OUT, "\t\t\t\tDetect64BitPortabilityProblems=\"TRUE\"\r\n" );
287 fprintf ( OUT, "\t\t\t\tDebugInformationFormat=\"4\"/>\r\n" );
288
289 fprintf ( OUT, "\t\t\t<Tool\r\n" );
290 fprintf ( OUT, "\t\t\t\tName=\"VCCustomBuildTool\"/>\r\n" );
291
292 if ( lib )
293 {
294 fprintf ( OUT, "\t\t\t<Tool\r\n" );
295 fprintf ( OUT, "\t\t\t\tName=\"VCLibrarianTool\"\r\n" );
296 fprintf ( OUT, "\t\t\t\tOutputFile=\"$(OutDir)/%s%s\"/>\r\n", module.name.c_str(), module_type.c_str() );
297 }
298 else
299 {
300 fprintf ( OUT, "\t\t\t<Tool\r\n" );
301 fprintf ( OUT, "\t\t\t\tName=\"VCLinkerTool\"\r\n" );
302
303 fprintf ( OUT, "\t\t\t\tAdditionalDependencies=\"" );
304 for ( i = 0; i < libraries.size(); i++ )
305 {
306 if ( i > 0 )
307 fprintf ( OUT, " " );
308 fprintf ( OUT, "%s", libraries[i].c_str() );
309 }
310 fprintf ( OUT, "\"\r\n" );
311
312 fprintf ( OUT, "\t\t\t\tOutputFile=\"$(OutDir)/%s%s\"\r\n", module.name.c_str(), module_type.c_str() );
313 fprintf ( OUT, "\t\t\t\tLinkIncremental=\"%d\"\r\n", debug ? 2 : 1 );
314 fprintf ( OUT, "\t\t\t\tGenerateDebugInformation=\"TRUE\"\r\n" );
315
316 if ( debug )
317 fprintf ( OUT, "\t\t\t\tProgramDatabaseFile=\"$(OutDir)/%s.pdb\"\r\n", module.name.c_str() );
318
319 fprintf ( OUT, "\t\t\t\tSubSystem=\"%d\"\r\n", console ? 1 : 2 );
320 fprintf ( OUT, "\t\t\t\tTargetMachine=\"%d\"/>\r\n", 1 );
321 }
322
323 fprintf ( OUT, "\t\t\t<Tool\r\n" );
324 fprintf ( OUT, "\t\t\t\tName=\"VCResourceCompilerTool\"\r\n" );
325 fprintf ( OUT, "\t\t\t\tAdditionalIncludeDirectories=\"" );
326 multiple_includes = false;
327 fprintf ( OUT, "./;" );
328 for ( i = 0; i < includes.size(); i++ )
329 {
330 const string& include = includes[i];
331 if ( strcmp ( include.c_str(), "." ) )
332 {
333 if ( multiple_includes )
334 fprintf ( OUT, ";" );
335 fprintf ( OUT, "%s", include.c_str() );
336 multiple_includes = true;
337 }
338 }
339 fprintf ( OUT, "\"/>\r\n " );
340
341 fprintf ( OUT, "\t\t\t<Tool\r\n" );
342 fprintf ( OUT, "\t\t\t\tName=\"VCMIDLTool\"/>\r\n" );
343 fprintf ( OUT, "\t\t\t<Tool\r\n" );
344 fprintf ( OUT, "\t\t\t\tName=\"VCPostBuildEventTool\"/>\r\n" );
345 fprintf ( OUT, "\t\t\t<Tool\r\n" );
346 fprintf ( OUT, "\t\t\t\tName=\"VCPreBuildEventTool\"/>\r\n" );
347 fprintf ( OUT, "\t\t\t<Tool\r\n" );
348 fprintf ( OUT, "\t\t\t\tName=\"VCPreLinkEventTool\"/>\r\n" );
349 fprintf ( OUT, "\t\t\t<Tool\r\n" );
350 fprintf ( OUT, "\t\t\t\tName=\"VCWebServiceProxyGeneratorTool\"/>\r\n" );
351 fprintf ( OUT, "\t\t\t<Tool\r\n" );
352 fprintf ( OUT, "\t\t\t\tName=\"VCWebDeploymentTool\"/>\r\n" );
353 fprintf ( OUT, "\t\t</Configuration>\r\n" );
354
355 n++;
356 }
357 fprintf ( OUT, "\t</Configurations>\r\n" );
358
359 fprintf ( OUT, "\t<Files>\r\n" );
360
361 // Source files
362 fprintf ( OUT, "\t\t<Filter\r\n" );
363 fprintf ( OUT, "\t\t\tName=\"Source Files\"\r\n" );
364 fprintf ( OUT, "\t\t\tFilter=\"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;S\">\r\n" );
365 for ( size_t isrcfile = 0; isrcfile < source_files.size(); isrcfile++ )
366 {
367 const string& source_file = DosSeparator(source_files[isrcfile]);
368 fprintf ( OUT, "\t\t\t<File\r\n" );
369 fprintf ( OUT, "\t\t\t\tRelativePath=\"%s\">\r\n", source_file.c_str() );
370
371 if (configuration.VSProjectVersion < "8.00") {
372 if (source_file.at(source_file.size() - 1) == 'S') {
373 for ( size_t iconfig = 0; iconfig < cfgs.size(); iconfig++ )
374 {
375 std::string& config = cfgs[iconfig];
376 fprintf ( OUT, "\t\t\t\t<FileConfiguration\r\n" );
377 fprintf ( OUT, "\t\t\t\t\tName=\"" );
378 fprintf ( OUT, config.c_str());
379 fprintf ( OUT, "|Win32\">\r\n" );
380 fprintf ( OUT, "\t\t\t\t\t<Tool\r\n" );
381 fprintf ( OUT, "\t\t\t\t\t\tName=\"VCCustomBuildTool\"\r\n" );
382 fprintf ( OUT, "\t\t\t\t\t\tCommandLine=\"cl /E &quot;$(InputPath)&quot; | as -o &quot;$(OutDir)\\$(InputName).obj&quot;\"\r\n" );
383 fprintf ( OUT, "\t\t\t\t\t\tOutputs=\"$(OutDir)\\$(InputName).obj\"/>\r\n" );
384 fprintf ( OUT, "\t\t\t\t</FileConfiguration>\r\n" );
385 }
386 }
387 }
388 fprintf ( OUT, "\t\t\t</File>\r\n" );
389 }
390 fprintf ( OUT, "\t\t</Filter>\r\n" );
391
392 // Header files
393 fprintf ( OUT, "\t\t<Filter\r\n" );
394 fprintf ( OUT, "\t\t\tName=\"Header Files\"\r\n" );
395 fprintf ( OUT, "\t\t\tFilter=\"h;hpp;hxx;hm;inl\">\r\n" );
396 for ( i = 0; i < header_files.size(); i++ )
397 {
398 const string& header_file = header_files[i];
399 fprintf ( OUT, "\t\t\t<File\r\n" );
400 fprintf ( OUT, "\t\t\t\tRelativePath=\"%s\">\r\n", header_file.c_str() );
401 fprintf ( OUT, "\t\t\t</File>\r\n" );
402 }
403 fprintf ( OUT, "\t\t</Filter>\r\n" );
404
405 // Resource files
406 fprintf ( OUT, "\t\t<Filter\r\n" );
407 fprintf ( OUT, "\t\t\tName=\"Resource Files\"\r\n" );
408 fprintf ( OUT, "\t\t\tFilter=\"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\">\r\n" );
409 for ( i = 0; i < header_files.size(); i++ )
410 {
411 const string& resource_file = resource_files[i];
412 fprintf ( OUT, "\t\t\t<File\r\n" );
413 fprintf ( OUT, "\t\t\t\tRelativePath=\"%s\">\r\n", resource_file.c_str() );
414 fprintf ( OUT, "\t\t\t</File>\r\n" );
415 }
416 fprintf ( OUT, "\t\t</Filter>\r\n" );
417
418 fprintf ( OUT, "\t</Files>\r\n" );
419 fprintf ( OUT, "\t<Globals>\r\n" );
420 fprintf ( OUT, "\t</Globals>\r\n" );
421 fprintf ( OUT, "</VisualStudioProject>\r\n" );
422 fclose(OUT);
423 }
424
425 std::string
426 MSVCBackend::_replace_str(std::string string1, const std::string &find_str, const std::string &replace_str)
427 {
428 std::string::size_type pos = string1.find(find_str, 0);
429 int intLen = find_str.length();
430
431 while(std::string::npos != pos)
432 {
433 string1.replace(pos, intLen, replace_str);
434 pos = string1.find(find_str, intLen + pos);
435 }
436
437 return string1;
438 }
439
440 std::string
441 MSVCBackend::_get_solution_verion ( void ) {
442 string version;
443
444 if (configuration.VSProjectVersion.empty())
445 configuration.VSProjectVersion = MS_VS_DEF_VERSION;
446
447 if (configuration.VSProjectVersion == "7.00")
448 version = "7.00";
449
450 if (configuration.VSProjectVersion == "7.10")
451 version = "8.00";
452
453 if (configuration.VSProjectVersion == "8.00")
454 version = "9.00";
455
456 return version;
457 }
458
459
460 void
461 MSVCBackend::_generate_rules_file ( FILE* OUT )
462 {
463 fprintf ( OUT, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" );
464 fprintf ( OUT, "<VisualStudioToolFile\r\n" );
465 fprintf ( OUT, "\tName=\"GCC Assembler\"\r\n" );
466 fprintf ( OUT, "\tVersion=\"%s\"\r\n", _get_solution_verion().c_str() );
467 fprintf ( OUT, "\t>\r\n" );
468 fprintf ( OUT, "\t<Rules>\r\n" );
469 fprintf ( OUT, "\t\t<CustomBuildRule\r\n" );
470 fprintf ( OUT, "\t\t\tName=\"Assembler\"\r\n" );
471 fprintf ( OUT, "\t\t\tDisplayName=\"Assembler Files\"\r\n" );
472 fprintf ( OUT, "\t\t\tCommandLine=\"cl /E &quot;$(InputPath)&quot; | as -o &quot;$(OutDir)\\$(InputName).obj&quot;\"\r\n" );
473 fprintf ( OUT, "\t\t\tOutputs=\"$(OutDir)\\$(InputName).obj\"\r\n" );
474 fprintf ( OUT, "\t\t\tFileExtensions=\"*.S\"\r\n" );
475 fprintf ( OUT, "\t\t\tExecutionDescription=\"asm\"\r\n" );
476 fprintf ( OUT, "\t\t\t>\r\n" );
477 fprintf ( OUT, "\t\t\t<Properties>\r\n" );
478 fprintf ( OUT, "\t\t\t</Properties>\r\n" );
479 fprintf ( OUT, "\t\t</CustomBuildRule>\r\n" );
480 fprintf ( OUT, "\t</Rules>\r\n" );
481 fprintf ( OUT, "</VisualStudioToolFile>\r\n" );
482 }
483
484 void
485 MSVCBackend::_generate_sln_header ( FILE* OUT )
486 {
487 fprintf ( OUT, "Microsoft Visual Studio Solution File, Format Version %s\r\n", _get_solution_verion().c_str() );
488 fprintf ( OUT, "# Visual Studio 2005\r\n" );
489 fprintf ( OUT, "\r\n" );
490 }
491
492
493 void
494 MSVCBackend::_generate_sln_project (
495 FILE* OUT,
496 const Module& module,
497 std::string vcproj_file,
498 std::string sln_guid,
499 std::string vcproj_guid,
500 const std::vector<Dependency*>& dependencies )
501 {
502 vcproj_file = DosSeparator ( std::string(".\\") + vcproj_file );
503
504 fprintf ( OUT, "Project(\"%s\") = \"%s\", \"%s\", \"%s\"\r\n", sln_guid.c_str() , module.name.c_str(), vcproj_file.c_str(), vcproj_guid.c_str() );
505
506 //FIXME: only omit ProjectDependencies in VS 2005 when there are no dependencies
507 //NOTE: VS 2002 do not use ProjectSection; it uses GlobalSection instead
508 if ((configuration.VSProjectVersion == "7.10") || (dependencies.size() > 0)) {
509 fprintf ( OUT, "\tProjectSection(ProjectDependencies) = postProject\r\n" );
510 for ( size_t i = 0; i < dependencies.size(); i++ )
511 {
512 Dependency& dependency = *dependencies[i];
513 fprintf ( OUT, "\t\t%s = %s\r\n", dependency.module.guid.c_str(), dependency.module.guid.c_str() );
514 }
515 fprintf ( OUT, "\tEndProjectSection\r\n" );
516 }
517
518 fprintf ( OUT, "EndProject\r\n" );
519 }
520
521
522 void
523 MSVCBackend::_generate_sln_footer ( FILE* OUT )
524 {
525 fprintf ( OUT, "Global\r\n" );
526 fprintf ( OUT, "\tGlobalSection(SolutionConfiguration) = preSolution\r\n" );
527 fprintf ( OUT, "\t\tDebug = Debug\r\n" );
528 fprintf ( OUT, "\t\tRelease = Release\r\n" );
529 fprintf ( OUT, "\tEndGlobalSection\r\n" );
530 fprintf ( OUT, "\tGlobalSection(ProjectConfiguration) = postSolution\r\n" );
531 for ( size_t i = 0; i < ProjectNode.modules.size(); i++ )
532 {
533 Module& module = *ProjectNode.modules[i];
534 std::string guid = module.guid;
535 _generate_sln_configurations ( OUT, guid.c_str() );
536 }
537 fprintf ( OUT, "\tEndGlobalSection\r\n" );
538 fprintf ( OUT, "\tGlobalSection(ExtensibilityGlobals) = postSolution\r\n" );
539 fprintf ( OUT, "\tEndGlobalSection\r\n" );
540 fprintf ( OUT, "\tGlobalSection(ExtensibilityAddIns) = postSolution\r\n" );
541 fprintf ( OUT, "\tEndGlobalSection\r\n" );
542
543 if (configuration.VSProjectVersion == "7.00") {
544 fprintf ( OUT, "\tGlobalSection(ProjectDependencies) = postSolution\r\n" );
545 //FIXME: Add dependencies for VS 2002
546 fprintf ( OUT, "\tEndGlobalSection\r\n" );
547 }
548
549 if (configuration.VSProjectVersion == "8.00") {
550 fprintf ( OUT, "\tGlobalSection(SolutionProperties) = preSolution\r\n" );
551 fprintf ( OUT, "\t\tHideSolutionNode = FALSE\r\n" );
552 fprintf ( OUT, "\tEndGlobalSection\r\n" );
553 }
554
555 fprintf ( OUT, "EndGlobal\r\n" );
556 fprintf ( OUT, "\r\n" );
557 }
558
559
560 void
561 MSVCBackend::_generate_sln_configurations ( FILE* OUT, std::string vcproj_guid )
562 {
563 fprintf ( OUT, "\t\t%s.Debug.ActiveCfg = Debug|Win32\r\n", vcproj_guid.c_str() );
564 fprintf ( OUT, "\t\t%s.Debug.Build.0 = Debug|Win32\r\n", vcproj_guid.c_str() );
565 fprintf ( OUT, "\t\t%s.Debug.Release.ActiveCfg = Release|Win32\r\n", vcproj_guid.c_str() );
566 fprintf ( OUT, "\t\t%s.Debug.Release.Build.0 = Release|Win32\r\n", vcproj_guid.c_str() );
567 }
568
569 void
570 MSVCBackend::_generate_sln ( FILE* OUT )
571 {
572 string sln_guid = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}";
573 vector<string> guids;
574
575 _generate_sln_header(OUT);
576 // TODO FIXME - is it necessary to sort them?
577 for ( size_t i = 0; i < ProjectNode.modules.size(); i++ )
578 {
579 Module& module = *ProjectNode.modules[i];
580
581 std::string vcproj_file = VcprojFileName ( module );
582 _generate_sln_project ( OUT, module, vcproj_file, sln_guid, module.guid, module.dependencies );
583 }
584 _generate_sln_footer ( OUT );
585 }
586