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 )
35 MSVCBackend::_generate_vcproj ( const Module
& module
)
38 // TODO FIXME wine hack?
39 //const bool wine = false;
41 string vcproj_file
= VcprojFileName(module
);
42 printf ( "Creating MSVC.NET project: '%s'\n", vcproj_file
.c_str() );
43 FILE* OUT
= fopen ( vcproj_file
.c_str(), "wb" );
45 vector
<string
> imports
;
46 for ( i
= 0; i
< module
.non_if_data
.libraries
.size(); i
++ )
48 imports
.push_back ( module
.non_if_data
.libraries
[i
]->name
);
51 string module_type
= GetExtension(module
.GetTargetName());
52 bool lib
= (module_type
== ".lib") || (module_type
== ".a");
53 bool dll
= (module_type
== ".dll") || (module_type
== ".cpl");
54 bool exe
= (module_type
== ".exe");
55 // TODO FIXME - need more checks here for 'sys' and possibly 'drv'?
57 bool console
= exe
&& (module
.type
== Win32CUI
);
59 // TODO FIXME - not sure if the count here is right...
61 const char* p
= strpbrk ( vcproj_file
.c_str(), "/\\" );
65 p
= strpbrk ( p
+1, "/\\" );
67 string msvc_wine_dir
= "..";
69 msvc_wine_dir
+= "\\..";
71 string wine_include_dir
= msvc_wine_dir
+ "\\include";
73 //$progress_current++;
74 //$output->progress("$dsp_file (file $progress_current of $progress_max)");
76 // TODO FIXME - what's diff. betw. 'c_srcs' and 'source_files'?
77 string vcproj_path
= module
.GetBasePath();
78 vector
<string
> c_srcs
, source_files
, resource_files
, includes
, libraries
, defines
;
79 vector
<const IfableData
*> ifs_list
;
80 ifs_list
.push_back ( &module
.project
.non_if_data
);
81 ifs_list
.push_back ( &module
.non_if_data
);
83 // this is a define in MinGW w32api, but not Microsoft's headers
84 defines
.push_back ( "STDCALL=__stdcall" );
86 while ( ifs_list
.size() )
88 const IfableData
& data
= *ifs_list
.back();
90 // TODO FIXME - refactor needed - we're discarding if conditions
91 for ( i
= 0; i
< data
.ifs
.size(); i
++ )
92 ifs_list
.push_back ( &data
.ifs
[i
]->data
);
93 const vector
<File
*>& files
= data
.files
;
94 for ( i
= 0; i
< files
.size(); i
++ )
96 // TODO FIXME - do we want the full path of the file here?
97 string file
= string(".") + &files
[i
]->name
[vcproj_path
.size()];
99 source_files
.push_back ( file
);
100 if ( !stricmp ( Right(file
,2).c_str(), ".c" ) )
101 c_srcs
.push_back ( file
);
102 if ( !stricmp ( Right(file
,3).c_str(), ".rc" ) )
103 resource_files
.push_back ( file
);
105 const vector
<Include
*>& incs
= data
.includes
;
106 for ( i
= 0; i
< incs
.size(); i
++ )
108 // explicitly omit win32api directories
109 if ( !strncmp(incs
[i
]->directory
.c_str(), "w32api", 6 ) )
112 // explicitly omit include/wine directories
113 if ( !strncmp(incs
[i
]->directory
.c_str(), "include\\wine", 12 ) )
116 string path
= Path::RelativeFromDirectory (
118 module
.GetBasePath() );
119 includes
.push_back ( path
);
121 const vector
<Library
*>& libs
= data
.libraries
;
122 for ( i
= 0; i
< libs
.size(); i
++ )
124 libraries
.push_back ( libs
[i
]->name
+ ".lib" );
126 const vector
<Define
*>& defs
= data
.defines
;
127 for ( i
= 0; i
< defs
.size(); i
++ )
129 if ( defs
[i
]->value
[0] )
130 defines
.push_back ( defs
[i
]->name
+ "=" + defs
[i
]->value
);
132 defines
.push_back ( defs
[i
]->name
);
136 vector
<string
> header_files
;
139 bool no_msvc_headers
= true;
141 std::vector
<std::string
> cfgs
;
143 cfgs
.push_back ( module
.name
+ " - Win32" );
147 std::vector
<std::string
> _cfgs
;
148 for ( i
= 0; i
< cfgs
.size(); i
++ )
150 _cfgs
.push_back ( cfgs
[i
] + " C" );
151 _cfgs
.push_back ( cfgs
[i
] + " C++" );
157 if (!no_msvc_headers
)
159 std::vector
<std::string
> _cfgs
;
160 for ( i
= 0; i
< cfgs
.size(); i
++ )
162 _cfgs
.push_back ( cfgs
[i
] + " MSVC Headers" );
163 _cfgs
.push_back ( cfgs
[i
] + " Wine Headers" );
169 string default_cfg
= cfgs
.back();
171 fprintf ( OUT
, "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\r\n" );
172 fprintf ( OUT
, "<VisualStudioProject\r\n" );
173 fprintf ( OUT
, "\tProjectType=\"Visual C++\"\r\n" );
174 fprintf ( OUT
, "\tVersion=\"7.00\"\r\n" );
175 fprintf ( OUT
, "\tName=\"%s\"\r\n", module
.name
.c_str() );
176 fprintf ( OUT
, "\tKeyword=\"Win32Proj\">\r\n" );
178 fprintf ( OUT
, "\t<Platforms>\r\n" );
179 fprintf ( OUT
, "\t\t<Platform\r\n" );
180 fprintf ( OUT
, "\t\t\tName=\"Win32\"/>\r\n" );
181 fprintf ( OUT
, "\t</Platforms>\r\n" );
185 std::string output_dir
;
187 fprintf ( OUT
, "\t<Configurations>\r\n" );
188 for ( size_t icfg
= 0; icfg
< cfgs
.size(); icfg
++ )
190 std::string
& cfg
= cfgs
[icfg
];
192 bool debug
= !strstr ( cfg
.c_str(), "Release" );
193 //bool msvc_headers = ( 0 != strstr ( cfg.c_str(), "MSVC Headers" ) );
195 fprintf ( OUT
, "\t\t<Configuration\r\n" );
196 fprintf ( OUT
, "\t\t\tName=\"%s|Win32\"\r\n", cfg
.c_str() );
197 fprintf ( OUT
, "\t\t\tOutputDirectory=\"%s\"\r\n", cfg
.c_str() );
198 fprintf ( OUT
, "\t\t\tIntermediateDirectory=\"%s\"\r\n", cfg
.c_str() );
199 fprintf ( OUT
, "\t\t\tConfigurationType=\"%d\"\r\n", exe
? 1 : dll
? 2 : lib
? 4 : -1 );
200 fprintf ( OUT
, "\t\t\tCharacterSet=\"2\">\r\n" );
202 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
203 fprintf ( OUT
, "\t\t\t\tName=\"VCCLCompilerTool\"\r\n" );
204 fprintf ( OUT
, "\t\t\t\tOptimization=\"%d\"\r\n", debug
? 0 : 2 );
206 fprintf ( OUT
, "\t\t\t\tAdditionalIncludeDirectories=\"" );
207 bool multiple_includes
= false;
208 fprintf ( OUT
, "./;" );
209 for ( i
= 0; i
< includes
.size(); i
++ )
211 const string
& include
= includes
[i
];
212 if ( strcmp ( include
.c_str(), "." ) )
214 if ( multiple_includes
)
215 fprintf ( OUT
, ";" );
216 fprintf ( OUT
, "%s", include
.c_str() );
217 multiple_includes
= true;
220 fprintf ( OUT
, "\"\r\n " );
224 defines
.push_back ( "_DEBUG" );
227 defines
.push_back ( "_LIB" );
231 defines
.push_back ( "_WINDOWS" );
232 defines
.push_back ( "_USRDLL" );
237 defines
.push_back ( "NDEBUG" );
240 defines
.push_back ( "_LIB" );
244 defines
.push_back ( "_WINDOWS" );
245 defines
.push_back ( "_USRDLL" );
249 fprintf ( OUT
, "\t\t\t\tPreprocessorDefinitions=\"" );
250 for ( i
= 0; i
< defines
.size(); i
++ )
253 fprintf ( OUT
, ";" );
254 fprintf ( OUT
, "%s", defines
[i
].c_str() );
256 fprintf ( OUT
, "\"\r\n" );
258 fprintf ( OUT
, "\t\t\t\tMinimalRebuild=\"TRUE\"\r\n" );
259 fprintf ( OUT
, "\t\t\t\tBasicRuntimeChecks=\"3\"\r\n" );
260 fprintf ( OUT
, "\t\t\t\tRuntimeLibrary=\"5\"\r\n" );
261 fprintf ( OUT
, "\t\t\t\tBufferSecurityCheck=\"%s\"\r\n", debug
? "TRUE" : "FALSE" );
262 fprintf ( OUT
, "\t\t\t\tEnableFunctionLevelLinking=\"%s\"\r\n", debug
? "TRUE" : "FALSE" );
263 fprintf ( OUT
, "\t\t\t\tUsePrecompiledHeader=\"0\"\r\n" );
264 fprintf ( OUT
, "\t\t\t\tWarningLevel=\"1\"\r\n" );
265 fprintf ( OUT
, "\t\t\t\tDetect64BitPortabilityProblems=\"TRUE\"\r\n" );
266 fprintf ( OUT
, "\t\t\t\tDebugInformationFormat=\"4\"/>\r\n" );
268 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
269 fprintf ( OUT
, "\t\t\t\tName=\"VCCustomBuildTool\"/>\r\n" );
273 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
274 fprintf ( OUT
, "\t\t\t\tName=\"VCLibrarianTool\"\r\n" );
275 fprintf ( OUT
, "\t\t\t\tOutputFile=\"$(OutDir)/%s.%s\"/>\r\n", module
.name
.c_str(), module_type
.c_str() );
279 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
280 fprintf ( OUT
, "\t\t\t\tName=\"VCLinkerTool\"\r\n" );
282 fprintf ( OUT
, "\t\t\t\tAdditionalDependencies=\"" );
283 for ( i
= 0; i
< libraries
.size(); i
++ )
286 fprintf ( OUT
, " " );
287 fprintf ( OUT
, "%s", libraries
[i
].c_str() );
289 fprintf ( OUT
, "\"\r\n" );
291 fprintf ( OUT
, "\t\t\t\tOutputFile=\"$(OutDir)/%s.%s\"\r\n", module
.name
.c_str(), module_type
.c_str() );
292 fprintf ( OUT
, "\t\t\t\tLinkIncremental=\"%d\"\r\n", debug
? 2 : 1 );
293 fprintf ( OUT
, "\t\t\t\tGenerateDebugInformation=\"TRUE\"\r\n" );
296 fprintf ( OUT
, "\t\t\t\tProgramDatabaseFile=\"$(OutDir)/%s.pdb\"\r\n", module
.name
.c_str() );
298 fprintf ( OUT
, "\t\t\t\tSubSystem=\"%d\"\r\n", console
? 1 : 2 );
299 fprintf ( OUT
, "\t\t\t\tTargetMachine=\"%d\"/>\r\n", 1 );
302 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
303 fprintf ( OUT
, "\t\t\t\tName=\"VCResourceCompilerTool\"\r\n" );
304 fprintf ( OUT
, "\t\t\t\tAdditionalIncludeDirectories=\"" );
305 multiple_includes
= false;
306 fprintf ( OUT
, "./;" );
307 for ( i
= 0; i
< includes
.size(); i
++ )
309 const string
& include
= includes
[i
];
310 if ( strcmp ( include
.c_str(), "." ) )
312 if ( multiple_includes
)
313 fprintf ( OUT
, ";" );
314 fprintf ( OUT
, "%s", include
.c_str() );
315 multiple_includes
= true;
318 fprintf ( OUT
, "\"/>\r\n " );
320 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
321 fprintf ( OUT
, "\t\t\t\tName=\"VCMIDLTool\"/>\r\n" );
322 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
323 fprintf ( OUT
, "\t\t\t\tName=\"VCPostBuildEventTool\"/>\r\n" );
324 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
325 fprintf ( OUT
, "\t\t\t\tName=\"VCPreBuildEventTool\"/>\r\n" );
326 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
327 fprintf ( OUT
, "\t\t\t\tName=\"VCPreLinkEventTool\"/>\r\n" );
328 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
329 fprintf ( OUT
, "\t\t\t\tName=\"VCWebServiceProxyGeneratorTool\"/>\r\n" );
330 fprintf ( OUT
, "\t\t\t<Tool\r\n" );
331 fprintf ( OUT
, "\t\t\t\tName=\"VCWebDeploymentTool\"/>\r\n" );
332 fprintf ( OUT
, "\t\t</Configuration>\r\n" );
336 fprintf ( OUT
, "\t</Configurations>\r\n" );
338 fprintf ( OUT
, "\t<Files>\r\n" );
341 fprintf ( OUT
, "\t\t<Filter\r\n" );
342 fprintf ( OUT
, "\t\t\tName=\"Source Files\"\r\n" );
343 fprintf ( OUT
, "\t\t\tFilter=\"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\">\r\n" );
344 for ( size_t isrcfile
= 0; isrcfile
< source_files
.size(); isrcfile
++ )
346 const string
& source_file
= DosSeparator(source_files
[isrcfile
]);
347 fprintf ( OUT
, "\t\t\t<File\r\n" );
348 fprintf ( OUT
, "\t\t\t\tRelativePath=\"%s\">\r\n", source_file
.c_str() );
349 fprintf ( OUT
, "\t\t\t</File>\r\n" );
351 fprintf ( OUT
, "\t\t</Filter>\r\n" );
354 fprintf ( OUT
, "\t\t<Filter\r\n" );
355 fprintf ( OUT
, "\t\t\tName=\"Header Files\"\r\n" );
356 fprintf ( OUT
, "\t\t\tFilter=\"h;hpp;hxx;hm;inl\">\r\n" );
357 for ( i
= 0; i
< header_files
.size(); i
++ )
359 const string
& header_file
= header_files
[i
];
360 fprintf ( OUT
, "\t\t\t<File\r\n" );
361 fprintf ( OUT
, "\t\t\t\tRelativePath=\"%s\">\r\n", header_file
.c_str() );
362 fprintf ( OUT
, "\t\t\t</File>\r\n" );
364 fprintf ( OUT
, "\t\t</Filter>\r\n" );
367 fprintf ( OUT
, "\t\t<Filter\r\n" );
368 fprintf ( OUT
, "\t\t\tName=\"Resource Files\"\r\n" );
369 fprintf ( OUT
, "\t\t\tFilter=\"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\">\r\n" );
370 for ( i
= 0; i
< header_files
.size(); i
++ )
372 const string
& resource_file
= resource_files
[i
];
373 fprintf ( OUT
, "\t\t\t<File\r\n" );
374 fprintf ( OUT
, "\t\t\t\tRelativePath=\"%s\">\r\n", resource_file
.c_str() );
375 fprintf ( OUT
, "\t\t\t</File>\r\n" );
377 fprintf ( OUT
, "\t\t</Filter>\r\n" );
379 fprintf ( OUT
, "\t</Files>\r\n" );
380 fprintf ( OUT
, "\t<Globals>\r\n" );
381 fprintf ( OUT
, "\t</Globals>\r\n" );
382 fprintf ( OUT
, "</VisualStudioProject>\r\n" );
387 MSVCBackend::_generate_sln_header ( FILE* OUT
)
389 fprintf ( OUT
, "Microsoft Visual Studio Solution File, Format Version 9.00\r\n" );
390 fprintf ( OUT
, "# Visual C++ Express 2005\r\n" );
391 fprintf ( OUT
, "\r\n" );
395 MSVCBackend::_generate_sln ( FILE* OUT
)
397 _generate_sln_header(OUT
);
398 // TODO FIXME - is it necessary to sort them?
399 for ( size_t i
= 0; i
< ProjectNode
.modules
.size(); i
++ )
401 Module
& module
= *ProjectNode
.modules
[i
];
403 std::string vcproj_file
= VcprojFileName ( module
);
404 _generate_dsw_project ( OUT
, module
, vcproj_file
, module
.dependencies
);
406 // _generate_dsw_footer ( OUT );
412 m_devFile << "Microsoft Visual Studio Solution File, Format Version 9.00" << endl;
413 m_devFile << "# Visual C++ Express 2005" << endl;
415 m_devFile << "# FIXME Project listings here" << endl;
416 m_devFile << "EndProject" << endl;
417 m_devFile << "Global" << endl;
418 m_devFile << " GlobalSection(SolutionConfigurationPlatforms) = preSolution" << endl;
419 m_devFile << " Debug|Win32 = Debug|Win32" << endl;
420 m_devFile << " Release|Win32 = Release|Win32" << endl;
421 m_devFile << " EndGlobalSection" << endl;
422 m_devFile << " GlobalSection(ProjectConfigurationPlatforms) = postSolution" << endl;
423 m_devFile << " #FIXME Project Listings Here" << endl;
424 m_devFile << " EndGlobalSection" << endl;
425 m_devFile << " GlobalSection(SolutionProperties) = preSolution" << endl;
426 m_devFile << " HideSolutionNode = FALSE" << endl;
427 m_devFile << " EndGlobalSection" << endl;
428 m_devFile << "EndGlobal" << endl;
430 m_devFile << endl << endl;