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 for ( i
= 0; i
< module
.non_if_data
.libraries
.size(); i
++ )
52 imports
.push_back ( module
.non_if_data
.libraries
[i
]->name
);
55 string module_type
= GetExtension(module
.GetTargetName());
56 bool lib
= (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'?
61 bool console
= exe
&& (module
.type
== Win32CUI
);
63 // TODO FIXME - not sure if the count here is right...
65 const char* p
= strpbrk ( vcproj_file
.c_str(), "/\\" );
69 p
= strpbrk ( p
+1, "/\\" );
71 string msvc_wine_dir
= "..";
73 msvc_wine_dir
+= "\\..";
75 string wine_include_dir
= msvc_wine_dir
+ "\\include";
77 //$progress_current++;
78 //$output->progress("$dsp_file (file $progress_current of $progress_max)");
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
);
87 // this is a define in MinGW w32api, but not Microsoft's headers
88 defines
.push_back ( "STDCALL=__stdcall" );
90 while ( ifs_list
.size() )
92 const IfableData
& data
= *ifs_list
.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
++ )
100 // TODO FIXME - do we want the full path of the file here?
101 string file
= string(".") + &files
[i
]->name
[vcproj_path
.size()];
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
);
109 const vector
<Include
*>& incs
= data
.includes
;
110 for ( i
= 0; i
< incs
.size(); i
++ )
112 // explicitly omit win32api directories
113 if ( !strncmp(incs
[i
]->directory
.c_str(), "w32api", 6 ) )
116 // explicitly omit include/wine directories
117 if ( !strncmp(incs
[i
]->directory
.c_str(), "include\\wine", 12 ) )
120 string path
= Path::RelativeFromDirectory (
122 module
.GetBasePath() );
123 includes
.push_back ( path
);
125 const vector
<Library
*>& libs
= data
.libraries
;
126 for ( i
= 0; i
< libs
.size(); i
++ )
128 libraries
.push_back ( libs
[i
]->name
+ ".lib" );
130 const vector
<Define
*>& defs
= data
.defines
;
131 for ( i
= 0; i
< defs
.size(); i
++ )
133 if ( defs
[i
]->value
[0] )
134 defines
.push_back ( defs
[i
]->name
+ "=" + defs
[i
]->value
);
136 defines
.push_back ( defs
[i
]->name
);
140 vector
<string
> header_files
;
143 bool no_msvc_headers
= true;
145 std::vector
<std::string
> cfgs
;
147 cfgs
.push_back ( "Debug" );
148 cfgs
.push_back ( "Release" );
152 std::vector
<std::string
> _cfgs
;
153 for ( i
= 0; i
< cfgs
.size(); i
++ )
155 _cfgs
.push_back ( cfgs
[i
] + " C" );
156 _cfgs
.push_back ( cfgs
[i
] + " C++" );
162 if (!no_msvc_headers
)
164 std::vector
<std::string
> _cfgs
;
165 for ( i
= 0; i
< cfgs
.size(); i
++ )
167 _cfgs
.push_back ( cfgs
[i
] + " MSVC Headers" );
168 _cfgs
.push_back ( cfgs
[i
] + " Wine Headers" );
174 string default_cfg
= cfgs
.back();
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" );
180 if (configuration
.VSProjectVersion
.empty())
181 configuration
.VSProjectVersion
= MS_VS_DEF_VERSION
;
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" );
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" );
195 std::string output_dir
;
197 fprintf ( OUT
, "\t<Configurations>\r\n" );
198 for ( size_t icfg
= 0; icfg
< cfgs
.size(); icfg
++ )
200 std::string
& cfg
= cfgs
[icfg
];
202 bool debug
= !strstr ( cfg
.c_str(), "Release" );
203 //bool msvc_headers = ( 0 != strstr ( cfg.c_str(), "MSVC Headers" ) );
205 fprintf ( OUT
, "\t\t<Configuration\r\n" );
206 fprintf ( OUT
, "\t\t\tName=\"%s|Win32\"\r\n", cfg
.c_str() );
207 fprintf ( OUT
, "\t\t\tOutputDirectory=\"%s\"\r\n", cfg
.c_str() );
208 fprintf ( OUT
, "\t\t\tIntermediateDirectory=\"%s\"\r\n", cfg
.c_str() );
209 fprintf ( OUT
, "\t\t\tConfigurationType=\"%d\"\r\n", exe
? 1 : dll
? 2 : lib
? 4 : -1 );
210 fprintf ( OUT
, "\t\t\tCharacterSet=\"2\">\r\n" );
212 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
213 fprintf ( OUT
, "\t\t\t\tName=\"VCCLCompilerTool\"\r\n" );
214 fprintf ( OUT
, "\t\t\t\tOptimization=\"%d\"\r\n", debug
? 0 : 2 );
216 fprintf ( OUT
, "\t\t\t\tAdditionalIncludeDirectories=\"" );
217 bool multiple_includes
= false;
218 fprintf ( OUT
, "./;" );
219 for ( i
= 0; i
< includes
.size(); i
++ )
221 const string
& include
= includes
[i
];
222 if ( strcmp ( include
.c_str(), "." ) )
224 if ( multiple_includes
)
225 fprintf ( OUT
, ";" );
226 fprintf ( OUT
, "%s", include
.c_str() );
227 multiple_includes
= true;
230 fprintf ( OUT
, "\"\r\n " );
234 defines
.push_back ( "_DEBUG" );
237 defines
.push_back ( "_LIB" );
241 defines
.push_back ( "_WINDOWS" );
242 defines
.push_back ( "_USRDLL" );
247 defines
.push_back ( "NDEBUG" );
250 defines
.push_back ( "_LIB" );
254 defines
.push_back ( "_WINDOWS" );
255 defines
.push_back ( "_USRDLL" );
259 fprintf ( OUT
, "\t\t\t\tPreprocessorDefinitions=\"" );
260 for ( i
= 0; i
< defines
.size(); i
++ )
263 fprintf ( OUT
, ";" );
265 defines
[i
] = _replace_str(defines
[i
], "\"",""");
266 fprintf ( OUT
, "%s", defines
[i
].c_str() );
268 fprintf ( OUT
, "\"\r\n" );
270 fprintf ( OUT
, "\t\t\t\tMinimalRebuild=\"TRUE\"\r\n" );
271 fprintf ( OUT
, "\t\t\t\tBasicRuntimeChecks=\"3\"\r\n" );
272 fprintf ( OUT
, "\t\t\t\tRuntimeLibrary=\"5\"\r\n" );
273 fprintf ( OUT
, "\t\t\t\tBufferSecurityCheck=\"%s\"\r\n", debug
? "TRUE" : "FALSE" );
274 fprintf ( OUT
, "\t\t\t\tEnableFunctionLevelLinking=\"%s\"\r\n", debug
? "TRUE" : "FALSE" );
275 fprintf ( OUT
, "\t\t\t\tUsePrecompiledHeader=\"0\"\r\n" );
276 fprintf ( OUT
, "\t\t\t\tWarningLevel=\"1\"\r\n" );
277 fprintf ( OUT
, "\t\t\t\tDetect64BitPortabilityProblems=\"TRUE\"\r\n" );
278 fprintf ( OUT
, "\t\t\t\tDebugInformationFormat=\"4\"/>\r\n" );
280 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
281 fprintf ( OUT
, "\t\t\t\tName=\"VCCustomBuildTool\"/>\r\n" );
285 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
286 fprintf ( OUT
, "\t\t\t\tName=\"VCLibrarianTool\"\r\n" );
287 fprintf ( OUT
, "\t\t\t\tOutputFile=\"$(OutDir)/%s.%s\"/>\r\n", module
.name
.c_str(), module_type
.c_str() );
291 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
292 fprintf ( OUT
, "\t\t\t\tName=\"VCLinkerTool\"\r\n" );
294 fprintf ( OUT
, "\t\t\t\tAdditionalDependencies=\"" );
295 for ( i
= 0; i
< libraries
.size(); i
++ )
298 fprintf ( OUT
, " " );
299 fprintf ( OUT
, "%s", libraries
[i
].c_str() );
301 fprintf ( OUT
, "\"\r\n" );
303 fprintf ( OUT
, "\t\t\t\tOutputFile=\"$(OutDir)/%s.%s\"\r\n", module
.name
.c_str(), module_type
.c_str() );
304 fprintf ( OUT
, "\t\t\t\tLinkIncremental=\"%d\"\r\n", debug
? 2 : 1 );
305 fprintf ( OUT
, "\t\t\t\tGenerateDebugInformation=\"TRUE\"\r\n" );
308 fprintf ( OUT
, "\t\t\t\tProgramDatabaseFile=\"$(OutDir)/%s.pdb\"\r\n", module
.name
.c_str() );
310 fprintf ( OUT
, "\t\t\t\tSubSystem=\"%d\"\r\n", console
? 1 : 2 );
311 fprintf ( OUT
, "\t\t\t\tTargetMachine=\"%d\"/>\r\n", 1 );
314 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
315 fprintf ( OUT
, "\t\t\t\tName=\"VCResourceCompilerTool\"\r\n" );
316 fprintf ( OUT
, "\t\t\t\tAdditionalIncludeDirectories=\"" );
317 multiple_includes
= false;
318 fprintf ( OUT
, "./;" );
319 for ( i
= 0; i
< includes
.size(); i
++ )
321 const string
& include
= includes
[i
];
322 if ( strcmp ( include
.c_str(), "." ) )
324 if ( multiple_includes
)
325 fprintf ( OUT
, ";" );
326 fprintf ( OUT
, "%s", include
.c_str() );
327 multiple_includes
= true;
330 fprintf ( OUT
, "\"/>\r\n " );
332 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
333 fprintf ( OUT
, "\t\t\t\tName=\"VCMIDLTool\"/>\r\n" );
334 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
335 fprintf ( OUT
, "\t\t\t\tName=\"VCPostBuildEventTool\"/>\r\n" );
336 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
337 fprintf ( OUT
, "\t\t\t\tName=\"VCPreBuildEventTool\"/>\r\n" );
338 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
339 fprintf ( OUT
, "\t\t\t\tName=\"VCPreLinkEventTool\"/>\r\n" );
340 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
341 fprintf ( OUT
, "\t\t\t\tName=\"VCWebServiceProxyGeneratorTool\"/>\r\n" );
342 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
343 fprintf ( OUT
, "\t\t\t\tName=\"VCWebDeploymentTool\"/>\r\n" );
344 fprintf ( OUT
, "\t\t</Configuration>\r\n" );
348 fprintf ( OUT
, "\t</Configurations>\r\n" );
350 fprintf ( OUT
, "\t<Files>\r\n" );
353 fprintf ( OUT
, "\t\t<Filter\r\n" );
354 fprintf ( OUT
, "\t\t\tName=\"Source Files\"\r\n" );
355 fprintf ( OUT
, "\t\t\tFilter=\"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\">\r\n" );
356 for ( size_t isrcfile
= 0; isrcfile
< source_files
.size(); isrcfile
++ )
358 const string
& source_file
= DosSeparator(source_files
[isrcfile
]);
359 fprintf ( OUT
, "\t\t\t<File\r\n" );
360 fprintf ( OUT
, "\t\t\t\tRelativePath=\"%s\">\r\n", source_file
.c_str() );
361 fprintf ( OUT
, "\t\t\t</File>\r\n" );
363 fprintf ( OUT
, "\t\t</Filter>\r\n" );
366 fprintf ( OUT
, "\t\t<Filter\r\n" );
367 fprintf ( OUT
, "\t\t\tName=\"Header Files\"\r\n" );
368 fprintf ( OUT
, "\t\t\tFilter=\"h;hpp;hxx;hm;inl\">\r\n" );
369 for ( i
= 0; i
< header_files
.size(); i
++ )
371 const string
& header_file
= header_files
[i
];
372 fprintf ( OUT
, "\t\t\t<File\r\n" );
373 fprintf ( OUT
, "\t\t\t\tRelativePath=\"%s\">\r\n", header_file
.c_str() );
374 fprintf ( OUT
, "\t\t\t</File>\r\n" );
376 fprintf ( OUT
, "\t\t</Filter>\r\n" );
379 fprintf ( OUT
, "\t\t<Filter\r\n" );
380 fprintf ( OUT
, "\t\t\tName=\"Resource Files\"\r\n" );
381 fprintf ( OUT
, "\t\t\tFilter=\"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\">\r\n" );
382 for ( i
= 0; i
< header_files
.size(); i
++ )
384 const string
& resource_file
= resource_files
[i
];
385 fprintf ( OUT
, "\t\t\t<File\r\n" );
386 fprintf ( OUT
, "\t\t\t\tRelativePath=\"%s\">\r\n", resource_file
.c_str() );
387 fprintf ( OUT
, "\t\t\t</File>\r\n" );
389 fprintf ( OUT
, "\t\t</Filter>\r\n" );
391 fprintf ( OUT
, "\t</Files>\r\n" );
392 fprintf ( OUT
, "\t<Globals>\r\n" );
393 fprintf ( OUT
, "\t</Globals>\r\n" );
394 fprintf ( OUT
, "</VisualStudioProject>\r\n" );
399 MSVCBackend::_replace_str(std::string string1
, const std::string
&find_str
, const std::string
&replace_str
)
401 std::string::size_type pos
= string1
.find(find_str
, 0);
402 int intLen
= find_str
.length();
404 while(std::string::npos
!= pos
)
406 string1
.replace(pos
, intLen
, replace_str
);
407 pos
= string1
.find(find_str
, intLen
+ pos
);
414 MSVCBackend::_generate_sln_header ( FILE* OUT
)
416 if (configuration
.VSProjectVersion
.empty())
417 configuration
.VSProjectVersion
= MS_VS_DEF_VERSION
;
421 if (configuration
.VSProjectVersion
== "7.00")
424 if (configuration
.VSProjectVersion
== "7.10")
427 if (configuration
.VSProjectVersion
== "8.00")
430 fprintf ( OUT
, "Microsoft Visual Studio Solution File, Format Version %s\r\n", version
.c_str() );
431 fprintf ( OUT
, "# Visual Studio 2005\r\n" );
432 fprintf ( OUT
, "\r\n" );
437 MSVCBackend::_generate_sln_project (
439 const Module
& module
,
440 std::string vcproj_file
,
441 std::string sln_guid
,
442 std::string vcproj_guid
,
443 const std::vector
<Dependency
*>& dependencies
)
445 vcproj_file
= DosSeparator ( std::string(".\\") + vcproj_file
);
447 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() );
449 //FIXME: only omit ProjectDependencies in VS 2005 when there are no dependencies
450 //NOTE: VS 2002 do not use ProjectSection; it uses GlobalSection instead
451 if (configuration
.VSProjectVersion
== "7.10") {
452 fprintf ( OUT
, "\tProjectSection(ProjectDependencies) = postProject\r\n" );
453 fprintf ( OUT
, "\tEndProjectSection\r\n" );
456 fprintf ( OUT
, "EndProject\r\n" );
461 MSVCBackend::_generate_sln_footer ( FILE* OUT
)
463 fprintf ( OUT
, "Global\r\n" );
464 fprintf ( OUT
, "\tGlobalSection(SolutionConfiguration) = preSolution\r\n" );
465 fprintf ( OUT
, "\t\tDebug = Debug\r\n" );
466 fprintf ( OUT
, "\t\tRelease = Release\r\n" );
467 fprintf ( OUT
, "\tEndGlobalSection\r\n" );
468 fprintf ( OUT
, "\tGlobalSection(ProjectConfiguration) = postSolution\r\n" );
469 for ( size_t i
= 0; i
< ProjectNode
.modules
.size(); i
++ )
471 Module
& module
= *ProjectNode
.modules
[i
];
472 std::string guid
= module
.guid
;
473 _generate_sln_configurations ( OUT
, guid
.c_str() );
475 fprintf ( OUT
, "\tEndGlobalSection\r\n" );
476 fprintf ( OUT
, "\tGlobalSection(ExtensibilityGlobals) = postSolution\r\n" );
477 fprintf ( OUT
, "\tEndGlobalSection\r\n" );
478 fprintf ( OUT
, "\tGlobalSection(ExtensibilityAddIns) = postSolution\r\n" );
479 fprintf ( OUT
, "\tEndGlobalSection\r\n" );
482 if (configuration
.VSProjectVersion
== "7.00") {
483 fprintf ( OUT
, "\tGlobalSection(ProjectDependencies) = postSolution\r\n" );
484 fprintf ( OUT
, "\tEndGlobalSection\r\n" );
487 if (configuration
.VSProjectVersion
== "8.00") {
488 fprintf ( OUT
, "\tGlobalSection(SolutionProperties) = preSolution\r\n" );
489 fprintf ( OUT
, "\t\tHideSolutionNode = FALSE\r\n" );
490 fprintf ( OUT
, "\tEndGlobalSection\r\n" );
493 fprintf ( OUT
, "EndGlobal\r\n" );
494 fprintf ( OUT
, "\r\n" );
499 MSVCBackend::_generate_sln_configurations ( FILE* OUT
, std::string vcproj_guid
)
501 fprintf ( OUT
, "\t\t%s.Debug.ActiveCfg = Debug|Win32\r\n", vcproj_guid
.c_str() );
502 fprintf ( OUT
, "\t\t%s.Debug.Build.0 = Debug|Win32\r\n", vcproj_guid
.c_str() );
503 fprintf ( OUT
, "\t\t%s.Debug.Release.ActiveCfg = Release|Win32\r\n", vcproj_guid
.c_str() );
504 fprintf ( OUT
, "\t\t%s.Debug.Release.Build.0 = Release|Win32\r\n", vcproj_guid
.c_str() );
508 MSVCBackend::_generate_sln ( FILE* OUT
)
510 string sln_guid
= "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}";
511 vector
<string
> guids
;
513 _generate_sln_header(OUT
);
514 // TODO FIXME - is it necessary to sort them?
515 for ( size_t i
= 0; i
< ProjectNode
.modules
.size(); i
++ )
517 Module
& module
= *ProjectNode
.modules
[i
];
519 std::string vcproj_file
= VcprojFileName ( module
);
520 _generate_sln_project ( OUT
, module
, vcproj_file
, sln_guid
, module
.guid
, module
.dependencies
);
522 _generate_sln_footer ( OUT
);