c39f840ffc314db073b576086436c670c1d34eba
2 * Copyright (C) 2002 Patrik Stridvall
3 * Copyright (C) 2005 Royce Mitchell III
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.
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.
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.
21 #pragma warning ( disable : 4786 )
39 MSVCBackend::_generate_vcproj ( const Module
& module
)
42 // TODO FIXME wine hack?
43 //const bool wine = false;
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" );
49 vector
<string
> imports
;
50 string module_type
= GetExtension(module
.GetTargetName());
51 bool lib
= (module
.type
== ObjectLibrary
) || (module_type
== ".lib") || (module_type
== ".a");
52 bool dll
= (module_type
== ".dll") || (module_type
== ".cpl");
53 bool exe
= (module_type
== ".exe");
54 bool sys
= (module_type
== ".sys");
56 string path_basedir
= module
.GetPathToBaseDir ();
57 string intenv
= Environment::GetIntermediatePath ();
58 string outenv
= Environment::GetOutputPath ();
62 if ( intenv
== "obj-i386" )
63 intdir
= path_basedir
+ "obj-i386"; /* append relative dir from project dir */
67 if ( outenv
== "output-i386" )
68 outdir
= path_basedir
+ "output-i386";
72 // TODO FIXME - need more checks here for 'sys' and possibly 'drv'?
74 bool console
= exe
&& (module
.type
== Win32CUI
);
76 // TODO FIXME - not sure if the count here is right...
78 const char* p
= strpbrk ( vcproj_file
.c_str(), "/\\" );
82 p
= strpbrk ( p
+1, "/\\" );
84 string msvc_wine_dir
= "..";
86 msvc_wine_dir
+= "\\..";
88 string wine_include_dir
= msvc_wine_dir
+ "\\include";
90 //$progress_current++;
91 //$output->progress("$dsp_file (file $progress_current of $progress_max)");
93 string vcproj_path
= module
.GetBasePath();
94 vector
<string
> source_files
, resource_files
, includes
, libraries
, defines
;
95 vector
<const IfableData
*> ifs_list
;
96 ifs_list
.push_back ( &module
.project
.non_if_data
);
97 ifs_list
.push_back ( &module
.non_if_data
);
99 // this is a define in MinGW w32api, but not Microsoft's headers
100 defines
.push_back ( "_CRT_SECURE_NO_DEPRECATE" );
101 defines
.push_back ( "_CRT_NON_CONFORMING_SWPRINTFS" );
102 defines
.push_back ( "STDCALL=__stdcall" );
106 while ( ifs_list
.size() )
108 const IfableData
& data
= *ifs_list
.back();
110 // TODO FIXME - refactor needed - we're discarding if conditions
111 for ( i
= 0; i
< data
.ifs
.size(); i
++ )
112 ifs_list
.push_back ( &data
.ifs
[i
]->data
);
113 const vector
<File
*>& files
= data
.files
;
114 for ( i
= 0; i
< files
.size(); i
++ )
116 // TODO FIXME - do we want the full path of the file here?
117 string file
= string(".") + &files
[i
]->name
[vcproj_path
.size()];
119 if ( !stricmp ( Right(file
,3).c_str(), ".rc" ) )
120 resource_files
.push_back ( file
);
122 source_files
.push_back ( file
);
124 const vector
<Include
*>& incs
= data
.includes
;
125 for ( i
= 0; i
< incs
.size(); i
++ )
127 // explicitly omit win32api directories
128 if ( !strncmp(incs
[i
]->directory
.c_str(), "w32api", 6 ) )
131 // explicitly omit include/wine directories
132 if ( !strncmp(incs
[i
]->directory
.c_str(), "include\\wine", 12 ) )
135 string path
= Path::RelativeFromDirectory (
137 module
.GetBasePath() );
138 includes
.push_back ( path
);
140 const vector
<Library
*>& libs
= data
.libraries
;
141 for ( i
= 0; i
< libs
.size(); i
++ )
144 // this code is deactivated untill the tree builds fine with msvc
145 // --- is appended to each library path which is later
146 // replaced by the configuration
147 // i.e. ../output-i386/lib/rtl/---/rtl.lib becomes
148 // ../output-i386/lib/rtl/Debug/rtl.lib
150 libs
[i
]->importedModule
->
151 string libpath
= outdir
+ "\\" + libs
[i
]->importedModule
->GetBasePath() + "\\---\\" + libs
[i
]->name
+ ".lib";
152 libraries
.push_back ( libpath
);
154 libraries
.push_back ( libs
[i
]->name
+ ".lib" );
157 const vector
<Define
*>& defs
= data
.defines
;
158 for ( i
= 0; i
< defs
.size(); i
++ )
160 if ( defs
[i
]->value
[0] )
161 defines
.push_back ( defs
[i
]->name
+ "=" + defs
[i
]->value
);
163 defines
.push_back ( defs
[i
]->name
);
165 for ( i
= 0; i
< data
.properties
.size(); i
++ )
167 Property
& prop
= *data
.properties
[i
];
168 if ( strstr ( module
.baseaddress
.c_str(), prop
.name
.c_str() ) )
169 baseaddr
= prop
.value
;
173 vector
<string
> header_files
;
176 bool no_msvc_headers
= true;
178 std::vector
<std::string
> cfgs
;
180 cfgs
.push_back ( "Debug" );
181 cfgs
.push_back ( "Release" );
182 cfgs
.push_back ( "Speed" );
186 std::vector
<std::string
> _cfgs
;
187 for ( i
= 0; i
< cfgs
.size(); i
++ )
189 _cfgs
.push_back ( cfgs
[i
] + " C" );
190 _cfgs
.push_back ( cfgs
[i
] + " C++" );
196 if (!no_msvc_headers
)
198 std::vector
<std::string
> _cfgs
;
199 for ( i
= 0; i
< cfgs
.size(); i
++ )
201 _cfgs
.push_back ( cfgs
[i
] + " MSVC Headers" );
202 _cfgs
.push_back ( cfgs
[i
] + " Wine Headers" );
208 string default_cfg
= cfgs
.back();
209 string include_string
;
211 fprintf ( OUT
, "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\r\n" );
212 fprintf ( OUT
, "<VisualStudioProject\r\n" );
213 fprintf ( OUT
, "\tProjectType=\"Visual C++\"\r\n" );
215 if (configuration
.VSProjectVersion
.empty())
216 configuration
.VSProjectVersion
= MS_VS_DEF_VERSION
;
218 fprintf ( OUT
, "\tVersion=\"%s\"\r\n", configuration
.VSProjectVersion
.c_str() );
219 fprintf ( OUT
, "\tName=\"%s\"\r\n", module
.name
.c_str() );
220 fprintf ( OUT
, "\tProjectGUID=\"%s\"\r\n", module
.guid
.c_str() );
221 fprintf ( OUT
, "\tKeyword=\"Win32Proj\">\r\n" );
223 fprintf ( OUT
, "\t<Platforms>\r\n" );
224 fprintf ( OUT
, "\t\t<Platform\r\n" );
225 fprintf ( OUT
, "\t\t\tName=\"Win32\"/>\r\n" );
226 fprintf ( OUT
, "\t</Platforms>\r\n" );
228 fprintf ( OUT
, "\t<ToolFiles>\r\n" );
229 fprintf ( OUT
, "\t\t<ToolFile\r\n" );
231 string path
= Path::RelativeFromDirectory ( ProjectNode
.name
, module
.GetBasePath() );
232 path
.erase(path
.find(ProjectNode
.name
, 0), ProjectNode
.name
.size() + 1);
234 fprintf ( OUT
, "\t\t\tRelativePath=\"%sgccasm.rules\"/>\r\n", path
.c_str() );
235 fprintf ( OUT
, "\t</ToolFiles>\r\n" );
239 std::string output_dir
;
241 fprintf ( OUT
, "\t<Configurations>\r\n" );
242 for ( size_t icfg
= 0; icfg
< cfgs
.size(); icfg
++ )
244 std::string
& cfg
= cfgs
[icfg
];
246 bool debug
= strstr ( cfg
.c_str(), "Debug" );
247 bool speed
= strstr ( cfg
.c_str(), "Speed" );
248 bool release
= (!debug
&& !speed
);
250 //bool msvc_headers = ( 0 != strstr ( cfg.c_str(), "MSVC Headers" ) );
252 fprintf ( OUT
, "\t\t<Configuration\r\n" );
253 fprintf ( OUT
, "\t\t\tName=\"%s|Win32\"\r\n", cfg
.c_str() );
254 fprintf ( OUT
, "\t\t\tOutputDirectory=\"%s\\%s\\%s\"\r\n", outdir
.c_str (), module
.GetBasePath ().c_str (), cfg
.c_str() );
255 fprintf ( OUT
, "\t\t\tIntermediateDirectory=\"%s\\%s\\%s\"\r\n", intdir
.c_str (), module
.GetBasePath ().c_str (), cfg
.c_str() );
256 fprintf ( OUT
, "\t\t\tConfigurationType=\"%d\"\r\n", exe
? 1 : dll
? 2 : lib
? 4 : -1 );
257 fprintf ( OUT
, "\t\t\tCharacterSet=\"2\">\r\n" );
259 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
260 fprintf ( OUT
, "\t\t\t\tName=\"VCCLCompilerTool\"\r\n" );
261 fprintf ( OUT
, "\t\t\t\tOptimization=\"%d\"\r\n", release
? 2 : 0 );
263 fprintf ( OUT
, "\t\t\t\tAdditionalIncludeDirectories=\"" );
264 bool multiple_includes
= false;
265 fprintf ( OUT
, "./;" );
266 for ( i
= 0; i
< includes
.size(); i
++ )
268 const string
& include
= includes
[i
];
269 if ( strcmp ( include
.c_str(), "." ) )
271 if ( multiple_includes
)
272 fprintf ( OUT
, ";" );
274 fprintf ( OUT
, "%s", include
.c_str() );
275 include_string
+= " /I " + include
;
276 multiple_includes
= true;
279 fprintf ( OUT
, "\"\r\n " );
283 defines
.push_back ( "_DEBUG" );
287 defines
.push_back ( "NDEBUG" );
292 defines
.push_back ( "_LIB" );
296 defines
.push_back ( "_WINDOWS" );
297 defines
.push_back ( "_USRDLL" );
300 fprintf ( OUT
, "\t\t\t\tPreprocessorDefinitions=\"" );
301 for ( i
= 0; i
< defines
.size(); i
++ )
304 fprintf ( OUT
, ";" );
306 defines
[i
] = _replace_str(defines
[i
], "\"",""");
307 fprintf ( OUT
, "%s", defines
[i
].c_str() );
309 fprintf ( OUT
, "\"\r\n" );
311 fprintf ( OUT
, "\t\t\t\tMinimalRebuild=\"%s\"\r\n", speed
? "FALSE" : "TRUE" );
312 fprintf ( OUT
, "\t\t\t\tBasicRuntimeChecks=\"%s\"\r\n", debug
? "3" : "0" );
313 fprintf ( OUT
, "\t\t\t\tRuntimeLibrary=\"5\"\r\n" );
314 fprintf ( OUT
, "\t\t\t\tBufferSecurityCheck=\"%s\"\r\n", debug
? "TRUE" : "FALSE" );
315 fprintf ( OUT
, "\t\t\t\tEnableFunctionLevelLinking=\"%s\"\r\n", debug
? "TRUE" : "FALSE" );
317 if ( module
.pch
!= NULL
)
319 fprintf ( OUT
, "\t\t\t\tUsePrecompiledHeader=\"2\"\r\n" );
320 string pch_path
= Path::RelativeFromDirectory (
321 module
.pch
->file
.name
,
322 module
.GetBasePath() );
323 fprintf ( OUT
, "\t\t\t\tPrecompiledHeaderThrough=\"%s\"\r\n", pch_path
.c_str() );
327 fprintf ( OUT
, "\t\t\t\tUsePrecompiledHeader=\"0\"\r\n" );
330 fprintf ( OUT
, "\t\t\t\tWholeProgramOptimization=\"%s\"\r\n", release
? "TRUE" : "FALSE");
333 fprintf ( OUT
, "\t\t\t\tFavorSizeOrSpeed=\"1\"\r\n" );
334 fprintf ( OUT
, "\t\t\t\tStringPooling=\"true\"\r\n" );
337 fprintf ( OUT
, "\t\t\t\tEnablePREfast=\"%s\"\r\n", debug
? "TRUE" : "FALSE");
338 fprintf ( OUT
, "\t\t\t\tDisableSpecificWarnings=\"4201;4127\"\r\n" );
339 fprintf ( OUT
, "\t\t\t\tWarningLevel=\"%s\"\r\n", release
? "0" : "4" );
340 fprintf ( OUT
, "\t\t\t\tDetect64BitPortabilityProblems=\"%s\"\r\n", release
? "FALSE" : "TRUE");
341 if ( !module
.cplusplus
)
342 fprintf ( OUT
, "\t\t\t\tCompileAs=\"1\"\r\n" );
343 fprintf ( OUT
, "\t\t\t\tDebugInformationFormat=\"%s\"/>\r\n", speed
? "0" : "4");
345 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
346 fprintf ( OUT
, "\t\t\t\tName=\"VCCustomBuildTool\"/>\r\n" );
350 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
351 fprintf ( OUT
, "\t\t\t\tName=\"VCLibrarianTool\"\r\n" );
352 fprintf ( OUT
, "\t\t\t\tOutputFile=\"$(OutDir)/%s.lib\"/>\r\n", module
.name
.c_str() );
356 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
357 fprintf ( OUT
, "\t\t\t\tName=\"VCLinkerTool\"\r\n" );
359 fprintf ( OUT
, "\t\t\t\tAdditionalDependencies=\"" );
360 for ( i
= 0; i
< libraries
.size(); i
++ )
363 fprintf ( OUT
, " " );
365 // this code is deactivated untill
366 // msvc can build the whole tree
367 string libpath
= libraries
[i
].c_str();
368 libpath
.replace (libpath
.find("---"), //See HACK
371 fprintf ( OUT
, "%s", libpath
.c_str() );
373 fprintf ( OUT
, "%s", libraries
[i
].c_str() );
376 fprintf ( OUT
, "\"\r\n" );
378 fprintf ( OUT
, "\t\t\t\tOutputFile=\"$(OutDir)/%s%s\"\r\n", module
.name
.c_str(), module_type
.c_str() );
379 fprintf ( OUT
, "\t\t\t\tLinkIncremental=\"%d\"\r\n", debug
? 2 : 1 );
380 fprintf ( OUT
, "\t\t\t\tGenerateDebugInformation=\"%s\"\r\n", speed
? "FALSE" : "TRUE" );
383 fprintf ( OUT
, "\t\t\t\tProgramDatabaseFile=\"$(OutDir)/%s.pdb\"\r\n", module
.name
.c_str() );
387 fprintf ( OUT
, "\t\t\t\tAdditionalOptions=\" /DRIVER /ALIGN:0x20 /SUBSYSTEM:NATIVE /SECTION:INIT,D /NODEFAULTLIB /IGNORE:4001,4037,4039,4065,4070,4078,4087,4089,4096\"\r\n" );
388 fprintf ( OUT
, "\t\t\t\tIgnoreAllDefaultLibraries=\"TRUE\"\r\n" );
389 fprintf ( OUT
, "\t\t\t\tEntryPointSymbol=\"%s\"\r\n", module
.entrypoint
== "" ? "DriverEntry" : module
.entrypoint
.c_str ());
390 fprintf ( OUT
, "\t\t\t\tBaseAddress=\"%s\"\r\n", baseaddr
== "" ? "0x10000" : baseaddr
.c_str ());
394 if ( module
.type
== Kernel
)
396 fprintf ( OUT
, "\t\t\t\tAdditionalOptions=\" /SUBSYSTEM:NATIVE /NODEFAULTLIB /SECTION:INIT,D /ALIGN:0x80\"\r\n" );
397 fprintf ( OUT
, "\t\t\t\tIgnoreAllDefaultLibraries=\"TRUE\"\r\n" );
398 fprintf ( OUT
, "\t\t\t\tEntryPointSymbol=\"KiSystemStartup\"\r\n" );
399 fprintf ( OUT
, "\t\t\t\tBaseAddress=\"%s\"\r\n", baseaddr
.c_str ());
401 else if ( module
.type
== NativeCUI
)
403 fprintf ( OUT
, "\t\t\t\tAdditionalOptions=\" /SUBSYSTEM:NATIVE /NODEFAULTLIB /ALIGN:0x20\"\r\n" );
404 fprintf ( OUT
, "\t\t\t\tIgnoreAllDefaultLibraries=\"TRUE\"\r\n" );
405 fprintf ( OUT
, "\t\t\t\tEntryPointSymbol=\"NtProcessStartup\"\r\n" );
406 fprintf ( OUT
, "\t\t\t\tBaseAddress=\"%s\"\r\n", baseaddr
.c_str ());
408 else if ( module
.type
== Win32CUI
|| module
.type
== Win32GUI
)
410 fprintf ( OUT
, "\t\t\t\tSubSystem=\"%d\"\r\n", console
? 1 : 2 );
415 fprintf ( OUT
, "\t\t\t\tEntryPointSymbol=\"%s\"\r\n", module
.entrypoint
== "" ? "DllMain" : module
.entrypoint
.c_str ());
416 fprintf ( OUT
, "\t\t\t\tBaseAddress=\"%s\"\r\n", baseaddr
== "" ? "0x40000" : baseaddr
.c_str ());
418 fprintf ( OUT
, "\t\t\t\tTargetMachine=\"%d\"/>\r\n", 1 );
421 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
422 fprintf ( OUT
, "\t\t\t\tName=\"VCResourceCompilerTool\"\r\n" );
423 fprintf ( OUT
, "\t\t\t\tAdditionalIncludeDirectories=\"" );
424 multiple_includes
= false;
425 fprintf ( OUT
, "./;" );
426 for ( i
= 0; i
< includes
.size(); i
++ )
428 const string
& include
= includes
[i
];
429 if ( strcmp ( include
.c_str(), "." ) )
431 if ( multiple_includes
)
432 fprintf ( OUT
, ";" );
433 fprintf ( OUT
, "%s", include
.c_str() );
434 multiple_includes
= true;
437 fprintf ( OUT
, "\"/>\r\n " );
439 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
440 fprintf ( OUT
, "\t\t\t\tName=\"VCMIDLTool\"/>\r\n" );
441 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
442 fprintf ( OUT
, "\t\t\t\tName=\"VCPostBuildEventTool\"/>\r\n" );
443 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
444 fprintf ( OUT
, "\t\t\t\tName=\"VCPreBuildEventTool\"/>\r\n" );
445 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
446 fprintf ( OUT
, "\t\t\t\tName=\"VCPreLinkEventTool\"/>\r\n" );
447 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
448 fprintf ( OUT
, "\t\t\t\tName=\"VCWebServiceProxyGeneratorTool\"/>\r\n" );
449 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
450 fprintf ( OUT
, "\t\t\t\tName=\"VCWebDeploymentTool\"/>\r\n" );
451 fprintf ( OUT
, "\t\t</Configuration>\r\n" );
455 fprintf ( OUT
, "\t</Configurations>\r\n" );
457 fprintf ( OUT
, "\t<Files>\r\n" );
460 fprintf ( OUT
, "\t\t<Filter\r\n" );
461 fprintf ( OUT
, "\t\t\tName=\"Source Files\"\r\n" );
462 fprintf ( OUT
, "\t\t\tFilter=\"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;S\">\r\n" );
463 for ( size_t isrcfile
= 0; isrcfile
< source_files
.size(); isrcfile
++ )
465 string source_file
= DosSeparator(source_files
[isrcfile
]);
466 fprintf ( OUT
, "\t\t\t<File\r\n" );
467 fprintf ( OUT
, "\t\t\t\tRelativePath=\"%s\">\r\n", source_file
.c_str() );
469 for ( size_t iconfig
= 0; iconfig
< cfgs
.size(); iconfig
++ )
471 std::string
& config
= cfgs
[iconfig
];
473 if (( isrcfile
== 0 ) && ( module
.pch
!= NULL
))
475 /* little hack to speed up PCH */
476 fprintf ( OUT
, "\t\t\t\t<FileConfiguration\r\n" );
477 fprintf ( OUT
, "\t\t\t\t\tName=\"" );
478 fprintf ( OUT
, config
.c_str() );
479 fprintf ( OUT
, "|Win32\">\r\n" );
480 fprintf ( OUT
, "\t\t\t\t\t<Tool\r\n" );
481 fprintf ( OUT
, "\t\t\t\t\t\tName=\"VCCLCompilerTool\"\r\n" );
482 fprintf ( OUT
, "\t\t\t\t\t\tUsePrecompiledHeader=\"1\"/>\r\n" );
483 fprintf ( OUT
, "\t\t\t\t</FileConfiguration>\r\n" );
486 if (configuration
.VSProjectVersion
< "8.00") {
487 if ((source_file
.find(".idl") != string::npos
) || ((source_file
.find(".asm") != string::npos
|| tolower(source_file
.at(source_file
.size() - 1)) == 's')))
489 fprintf ( OUT
, "\t\t\t\t<FileConfiguration\r\n" );
490 fprintf ( OUT
, "\t\t\t\t\tName=\"" );
491 fprintf ( OUT
, config
.c_str() );
492 fprintf ( OUT
, "|Win32\">\r\n" );
493 fprintf ( OUT
, "\t\t\t\t\t<Tool\r\n" );
494 if (source_file
.find(".idl") != string::npos
)
496 fprintf ( OUT
, "\t\t\t\t\t\tName=\"VCCustomBuildTool\"\r\n" );
497 fprintf ( OUT
, "\t\t\t\t\t\tOutputs=\"$(OutDir)\\(InputName).obj\"/>\r\n" );
499 else if ((source_file
.find(".asm") != string::npos
|| tolower(source_file
.at(source_file
.size() - 1)) == 's'))
501 fprintf ( OUT
, "\t\t\t\t\t\tName=\"VCCustomBuildTool\"\r\n" );
502 fprintf ( OUT
, "\t\t\t\t\t\tCommandLine=\"cl /E "$(InputPath)" %s /D__ASM__ | as -o "$(OutDir)\\(InputName).obj"\"\r\n",include_string
.c_str() );
503 fprintf ( OUT
, "\t\t\t\t\t\tOutputs=\"$(OutDir)\\(InputName).obj\"/>\r\n" );
505 fprintf ( OUT
, "\t\t\t\t</FileConfiguration>\r\n" );
509 fprintf ( OUT
, "\t\t\t</File>\r\n" );
511 fprintf ( OUT
, "\t\t</Filter>\r\n" );
514 fprintf ( OUT
, "\t\t<Filter\r\n" );
515 fprintf ( OUT
, "\t\t\tName=\"Header Files\"\r\n" );
516 fprintf ( OUT
, "\t\t\tFilter=\"h;hpp;hxx;hm;inl\">\r\n" );
517 for ( i
= 0; i
< header_files
.size(); i
++ )
519 const string
& header_file
= header_files
[i
];
520 fprintf ( OUT
, "\t\t\t<File\r\n" );
521 fprintf ( OUT
, "\t\t\t\tRelativePath=\"%s\">\r\n", header_file
.c_str() );
522 fprintf ( OUT
, "\t\t\t</File>\r\n" );
524 fprintf ( OUT
, "\t\t</Filter>\r\n" );
527 fprintf ( OUT
, "\t\t<Filter\r\n" );
528 fprintf ( OUT
, "\t\t\tName=\"Resource Files\"\r\n" );
529 fprintf ( OUT
, "\t\t\tFilter=\"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\">\r\n" );
530 for ( i
= 0; i
< resource_files
.size(); i
++ )
532 const string
& resource_file
= resource_files
[i
];
533 fprintf ( OUT
, "\t\t\t<File\r\n" );
534 fprintf ( OUT
, "\t\t\t\tRelativePath=\"%s\">\r\n", resource_file
.c_str() );
535 fprintf ( OUT
, "\t\t\t</File>\r\n" );
537 fprintf ( OUT
, "\t\t</Filter>\r\n" );
539 fprintf ( OUT
, "\t</Files>\r\n" );
540 fprintf ( OUT
, "\t<Globals>\r\n" );
541 fprintf ( OUT
, "\t</Globals>\r\n" );
542 fprintf ( OUT
, "</VisualStudioProject>\r\n" );
547 MSVCBackend::_replace_str(std::string string1
, const std::string
&find_str
, const std::string
&replace_str
)
549 std::string::size_type pos
= string1
.find(find_str
, 0);
550 int intLen
= find_str
.length();
552 while(std::string::npos
!= pos
)
554 string1
.replace(pos
, intLen
, replace_str
);
555 pos
= string1
.find(find_str
, intLen
+ pos
);
562 MSVCBackend::_get_solution_verion ( void ) {
565 if (configuration
.VSProjectVersion
.empty())
566 configuration
.VSProjectVersion
= MS_VS_DEF_VERSION
;
568 if (configuration
.VSProjectVersion
== "7.00")
571 if (configuration
.VSProjectVersion
== "7.10")
574 if (configuration
.VSProjectVersion
== "8.00")
582 MSVCBackend::_generate_rules_file ( FILE* OUT
)
584 fprintf ( OUT
, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" );
585 fprintf ( OUT
, "<VisualStudioToolFile\r\n" );
586 fprintf ( OUT
, "\tName=\"GCC Assembler\"\r\n" );
587 fprintf ( OUT
, "\tVersion=\"%s\"\r\n", _get_solution_verion().c_str() );
588 fprintf ( OUT
, "\t>\r\n" );
589 fprintf ( OUT
, "\t<Rules>\r\n" );
590 fprintf ( OUT
, "\t\t<CustomBuildRule\r\n" );
591 fprintf ( OUT
, "\t\t\tName=\"Assembler\"\r\n" );
592 fprintf ( OUT
, "\t\t\tDisplayName=\"Assembler Files\"\r\n" );
593 fprintf ( OUT
, "\t\t\tCommandLine=\"cl /E "$(InputPath)" | as -o "$(OutDir)\\$(InputName).obj"\"\r\n" );
594 fprintf ( OUT
, "\t\t\tOutputs=\"$(OutDir)\\$(InputName).obj\"\r\n" );
595 fprintf ( OUT
, "\t\t\tFileExtensions=\"*.S\"\r\n" );
596 fprintf ( OUT
, "\t\t\tExecutionDescription=\"asm\"\r\n" );
597 fprintf ( OUT
, "\t\t\t>\r\n" );
598 fprintf ( OUT
, "\t\t\t<Properties>\r\n" );
599 fprintf ( OUT
, "\t\t\t</Properties>\r\n" );
600 fprintf ( OUT
, "\t\t</CustomBuildRule>\r\n" );
601 fprintf ( OUT
, "\t</Rules>\r\n" );
602 fprintf ( OUT
, "</VisualStudioToolFile>\r\n" );
606 MSVCBackend::_generate_sln_header ( FILE* OUT
)
608 fprintf ( OUT
, "Microsoft Visual Studio Solution File, Format Version %s\r\n", _get_solution_verion().c_str() );
609 fprintf ( OUT
, "# Visual Studio 2005\r\n" );
610 fprintf ( OUT
, "\r\n" );
615 MSVCBackend::_generate_sln_project (
617 const Module
& module
,
618 std::string vcproj_file
,
619 std::string sln_guid
,
620 std::string vcproj_guid
,
621 const std::vector
<Dependency
*>& dependencies
)
623 vcproj_file
= DosSeparator ( std::string(".\\") + vcproj_file
);
625 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() );
627 //FIXME: only omit ProjectDependencies in VS 2005 when there are no dependencies
628 //NOTE: VS 2002 do not use ProjectSection; it uses GlobalSection instead
629 if ((configuration
.VSProjectVersion
== "7.10") || (dependencies
.size() > 0)) {
630 fprintf ( OUT
, "\tProjectSection(ProjectDependencies) = postProject\r\n" );
631 for ( size_t i
= 0; i
< dependencies
.size(); i
++ )
633 Dependency
& dependency
= *dependencies
[i
];
634 fprintf ( OUT
, "\t\t%s = %s\r\n", dependency
.module
.guid
.c_str(), dependency
.module
.guid
.c_str() );
636 fprintf ( OUT
, "\tEndProjectSection\r\n" );
639 fprintf ( OUT
, "EndProject\r\n" );
644 MSVCBackend::_generate_sln_footer ( FILE* OUT
)
646 fprintf ( OUT
, "Global\r\n" );
647 fprintf ( OUT
, "\tGlobalSection(SolutionConfiguration) = preSolution\r\n" );
648 fprintf ( OUT
, "\t\tDebug = Debug\r\n" );
649 fprintf ( OUT
, "\t\tRelease = Release\r\n" );
650 fprintf ( OUT
, "\tEndGlobalSection\r\n" );
651 fprintf ( OUT
, "\tGlobalSection(ProjectConfiguration) = postSolution\r\n" );
652 for ( size_t i
= 0; i
< ProjectNode
.modules
.size(); i
++ )
654 Module
& module
= *ProjectNode
.modules
[i
];
655 std::string guid
= module
.guid
;
656 _generate_sln_configurations ( OUT
, guid
.c_str() );
658 fprintf ( OUT
, "\tEndGlobalSection\r\n" );
659 fprintf ( OUT
, "\tGlobalSection(ExtensibilityGlobals) = postSolution\r\n" );
660 fprintf ( OUT
, "\tEndGlobalSection\r\n" );
661 fprintf ( OUT
, "\tGlobalSection(ExtensibilityAddIns) = postSolution\r\n" );
662 fprintf ( OUT
, "\tEndGlobalSection\r\n" );
664 if (configuration
.VSProjectVersion
== "7.00") {
665 fprintf ( OUT
, "\tGlobalSection(ProjectDependencies) = postSolution\r\n" );
666 //FIXME: Add dependencies for VS 2002
667 fprintf ( OUT
, "\tEndGlobalSection\r\n" );
670 if (configuration
.VSProjectVersion
== "8.00") {
671 fprintf ( OUT
, "\tGlobalSection(SolutionProperties) = preSolution\r\n" );
672 fprintf ( OUT
, "\t\tHideSolutionNode = FALSE\r\n" );
673 fprintf ( OUT
, "\tEndGlobalSection\r\n" );
676 fprintf ( OUT
, "EndGlobal\r\n" );
677 fprintf ( OUT
, "\r\n" );
682 MSVCBackend::_generate_sln_configurations ( FILE* OUT
, std::string vcproj_guid
)
684 fprintf ( OUT
, "\t\t%s.Debug.ActiveCfg = Debug|Win32\r\n", vcproj_guid
.c_str() );
685 fprintf ( OUT
, "\t\t%s.Debug.Build.0 = Debug|Win32\r\n", vcproj_guid
.c_str() );
686 fprintf ( OUT
, "\t\t%s.Debug.Release.ActiveCfg = Release|Win32\r\n", vcproj_guid
.c_str() );
687 fprintf ( OUT
, "\t\t%s.Debug.Release.Build.0 = Release|Win32\r\n", vcproj_guid
.c_str() );
691 MSVCBackend::_generate_sln ( FILE* OUT
)
693 string sln_guid
= "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}";
694 vector
<string
> guids
;
696 _generate_sln_header(OUT
);
697 // TODO FIXME - is it necessary to sort them?
698 for ( size_t i
= 0; i
< ProjectNode
.modules
.size(); i
++ )
700 Module
& module
= *ProjectNode
.modules
[i
];
702 std::string vcproj_file
= VcprojFileName ( module
);
703 _generate_sln_project ( OUT
, module
, vcproj_file
, sln_guid
, module
.guid
, module
.dependencies
);
705 _generate_sln_footer ( OUT
);