e7ad0bc10b1fee6f7556c891ac43fec7bd5b516c
[profile/ivi/qtbase.git] / qmake / generators / win32 / msvc_vcproj.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the qmake application of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "msvc_vcproj.h"
43 #include "option.h"
44 #include "xmloutput.h"
45 #include <qdir.h>
46 #include <qdiriterator.h>
47 #include <qcryptographichash.h>
48 #include <qregexp.h>
49 #include <qhash.h>
50 #include <quuid.h>
51 #include <stdlib.h>
52
53 //#define DEBUG_SOLUTION_GEN
54
55 QT_BEGIN_NAMESPACE
56 // Filter GUIDs (Do NOT change these!) ------------------------------
57 const char _GUIDSourceFiles[]          = "{4FC737F1-C7A5-4376-A066-2A32D752A2FF}";
58 const char _GUIDHeaderFiles[]          = "{93995380-89BD-4b04-88EB-625FBE52EBFB}";
59 const char _GUIDGeneratedFiles[]       = "{71ED8ED8-ACB9-4CE9-BBE1-E00B30144E11}";
60 const char _GUIDResourceFiles[]        = "{D9D6E242-F8AF-46E4-B9FD-80ECBC20BA3E}";
61 const char _GUIDLexYaccFiles[]         = "{E12AE0D2-192F-4d59-BD23-7D3FA58D3183}";
62 const char _GUIDTranslationFiles[]     = "{639EADAA-A684-42e4-A9AD-28FC9BCB8F7C}";
63 const char _GUIDFormFiles[]            = "{99349809-55BA-4b9d-BF79-8FDBB0286EB3}";
64 const char _GUIDExtraCompilerFiles[]   = "{E0D8C965-CC5F-43d7-AD63-FAEF0BBC0F85}";
65 QT_END_NAMESPACE
66
67 #ifdef Q_OS_WIN32
68 #include <qt_windows.h>
69 #include <windows/registry_p.h>
70
71 QT_BEGIN_NAMESPACE
72
73 struct {
74     DotNET version;
75     const char *versionStr;
76     const char *regKey;
77 } dotNetCombo[] = {
78 #ifdef Q_OS_WIN64
79     {NET2010, "MSVC.NET 2010 (10.0)", "Software\\Wow6432Node\\Microsoft\\VisualStudio\\10.0\\Setup\\VC\\ProductDir"},
80     {NET2010, "MSVC.NET 2010 Express Edition (10.0)", "Software\\Wow6432Node\\Microsoft\\VCExpress\\10.0\\Setup\\VC\\ProductDir"},
81     {NET2008, "MSVC.NET 2008 (9.0)", "Software\\Wow6432Node\\Microsoft\\VisualStudio\\9.0\\Setup\\VC\\ProductDir"},
82     {NET2008, "MSVC.NET 2008 Express Edition (9.0)", "Software\\Wow6432Node\\Microsoft\\VCExpress\\9.0\\Setup\\VC\\ProductDir"},
83     {NET2005, "MSVC.NET 2005 (8.0)", "Software\\Wow6432Node\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir"},
84     {NET2005, "MSVC.NET 2005 Express Edition (8.0)", "Software\\Wow6432Node\\Microsoft\\VCExpress\\8.0\\Setup\\VC\\ProductDir"},
85     {NET2003, "MSVC.NET 2003 (7.1)", "Software\\Wow6432Node\\Microsoft\\VisualStudio\\7.1\\Setup\\VC\\ProductDir"},
86     {NET2002, "MSVC.NET 2002 (7.0)", "Software\\Wow6432Node\\Microsoft\\VisualStudio\\7.0\\Setup\\VC\\ProductDir"},
87 #else
88     {NET2010, "MSVC.NET 2010 (10.0)", "Software\\Microsoft\\VisualStudio\\10.0\\Setup\\VC\\ProductDir"},
89     {NET2010, "MSVC.NET 2010 Express Edition (10.0)", "Software\\Microsoft\\VCExpress\\10.0\\Setup\\VC\\ProductDir"},
90     {NET2008, "MSVC.NET 2008 (9.0)", "Software\\Microsoft\\VisualStudio\\9.0\\Setup\\VC\\ProductDir"},
91     {NET2008, "MSVC.NET 2008 Express Edition (9.0)", "Software\\Microsoft\\VCExpress\\9.0\\Setup\\VC\\ProductDir"},
92     {NET2005, "MSVC.NET 2005 (8.0)", "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir"},
93     {NET2005, "MSVC.NET 2005 Express Edition (8.0)", "Software\\Microsoft\\VCExpress\\8.0\\Setup\\VC\\ProductDir"},
94     {NET2003, "MSVC.NET 2003 (7.1)", "Software\\Microsoft\\VisualStudio\\7.1\\Setup\\VC\\ProductDir"},
95     {NET2002, "MSVC.NET 2002 (7.0)", "Software\\Microsoft\\VisualStudio\\7.0\\Setup\\VC\\ProductDir"},
96 #endif
97     {NETUnknown, "", ""},
98 };
99
100 QT_END_NAMESPACE
101 #endif
102
103 QT_BEGIN_NAMESPACE
104 DotNET which_dotnet_version()
105 {
106 #ifndef Q_OS_WIN32
107     return NET2002; // Always generate 7.0 versions on other platforms
108 #else
109     // Only search for the version once
110     static DotNET current_version = NETUnknown;
111     if(current_version != NETUnknown)
112         return current_version;
113
114     // Fallback to .NET 2002
115     current_version = NET2002;
116
117     QStringList warnPath;
118     QHash<DotNET, QString> installPaths;
119     int installed = 0;
120     int i = 0;
121     for(; dotNetCombo[i].version; ++i) {
122         QString path = qt_readRegistryKey(HKEY_LOCAL_MACHINE, dotNetCombo[i].regKey);
123         if (!path.isEmpty() && installPaths.value(dotNetCombo[i].version) != path) {
124             installPaths.insert(dotNetCombo[i].version, path);
125             ++installed;
126             current_version = dotNetCombo[i].version;
127                         warnPath += QString("%1").arg(dotNetCombo[i].versionStr);
128         }
129     }
130
131     if (installed < 2)
132         return current_version;
133
134     // More than one version installed, search directory path
135     QString paths = qgetenv("PATH");
136     QStringList pathlist = paths.toLower().split(";");
137
138     i = installed = 0;
139     for(; dotNetCombo[i].version; ++i) {
140         QString productPath = qt_readRegistryKey(HKEY_LOCAL_MACHINE, dotNetCombo[i].regKey).toLower();
141                 if (productPath.isEmpty())
142                         continue;
143         QStringList::iterator it;
144         for(it = pathlist.begin(); it != pathlist.end(); ++it) {
145             if((*it).contains(productPath)) {
146                 ++installed;
147                 current_version = dotNetCombo[i].version;
148                 warnPath += QString("%1 in path").arg(dotNetCombo[i].versionStr);
149                                 break;
150             }
151         }
152     }
153         switch(installed) {
154         case 1:
155                 break;
156         case 0:
157                 warn_msg(WarnLogic, "Generator: MSVC.NET: Found more than one version of Visual Studio, but"
158                                  " none in your path! Fallback to lowest version (%s)", warnPath.join(", ").toLatin1().data());
159                 break;
160         default:
161                 warn_msg(WarnLogic, "Generator: MSVC.NET: Found more than one version of Visual Studio in"
162                                  " your path! Fallback to lowest version (%s)", warnPath.join(", ").toLatin1().data());
163                 break;
164         }
165
166     return current_version;
167 #endif
168 };
169
170 // Flatfile Tags ----------------------------------------------------
171 const char _slnHeader70[]       = "Microsoft Visual Studio Solution File, Format Version 7.00";
172 const char _slnHeader71[]       = "Microsoft Visual Studio Solution File, Format Version 8.00";
173 const char _slnHeader80[]       = "Microsoft Visual Studio Solution File, Format Version 9.00"
174                                   "\n# Visual Studio 2005";
175 const char _slnHeader90[]       = "Microsoft Visual Studio Solution File, Format Version 10.00"
176                                   "\n# Visual Studio 2008";
177 const char _slnHeader100[]      = "Microsoft Visual Studio Solution File, Format Version 11.00"
178                                   "\n# Visual Studio 2010";
179                                   // The following UUID _may_ change for later servicepacks...
180                                   // If so we need to search through the registry at
181                                   // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.0\Projects
182                                   // to find the subkey that contains a "PossibleProjectExtension"
183                                   // containing "vcproj"...
184                                   // Use the hardcoded value for now so projects generated on other
185                                   // platforms are actually usable.
186 const char _slnMSVCvcprojGUID[] = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}";
187 const char _slnProjectBeg[]     = "\nProject(\"";
188 const char _slnProjectMid[]     = "\") = ";
189 const char _slnProjectEnd[]     = "\nEndProject";
190 const char _slnGlobalBeg[]      = "\nGlobal";
191 const char _slnGlobalEnd[]      = "\nEndGlobal";
192 const char _slnSolutionConf[]   = "\n\tGlobalSection(SolutionConfiguration) = preSolution"
193                                   "\n\t\tConfigName.0 = Debug|Win32"
194                                   "\n\t\tConfigName.1 = Release|Win32"
195                                   "\n\tEndGlobalSection";
196 const char _slnProjDepBeg[]     = "\n\tGlobalSection(ProjectDependencies) = postSolution";
197 const char _slnProjDepEnd[]     = "\n\tEndGlobalSection";
198 const char _slnProjConfBeg[]    = "\n\tGlobalSection(ProjectConfiguration) = postSolution";
199 const char _slnProjRelConfTag1[]= ".Release|%1.ActiveCfg = Release|";
200 const char _slnProjRelConfTag2[]= ".Release|%1.Build.0 = Release|";
201 const char _slnProjDbgConfTag1[]= ".Debug|%1.ActiveCfg = Debug|";
202 const char _slnProjDbgConfTag2[]= ".Debug|%1.Build.0 = Debug|";
203 const char _slnProjConfEnd[]    = "\n\tEndGlobalSection";
204 const char _slnExtSections[]    = "\n\tGlobalSection(ExtensibilityGlobals) = postSolution"
205                                   "\n\tEndGlobalSection"
206                                   "\n\tGlobalSection(ExtensibilityAddIns) = postSolution"
207                                   "\n\tEndGlobalSection";
208 // ------------------------------------------------------------------
209
210 VcprojGenerator::VcprojGenerator()
211     : Win32MakefileGenerator(),
212       init_flag(false),
213       is64Bit(false),
214       projectWriter(0)
215 {
216 }
217
218 VcprojGenerator::~VcprojGenerator()
219 {
220     delete projectWriter;
221 }
222
223 bool VcprojGenerator::writeMakefile(QTextStream &t)
224 {
225     initProject(); // Fills the whole project with proper data
226
227     // Generate solution file
228     if(project->first("TEMPLATE") == "vcsubdirs") {
229         if (!project->isActiveConfig("build_pass")) {
230             debug_msg(1, "Generator: MSVC.NET: Writing solution file");
231             writeSubDirs(t);
232         } else {
233             debug_msg(1, "Generator: MSVC.NET: Not writing solution file for build_pass configs");
234         }
235         return true;
236     } else
237     // Generate single configuration project file
238     if (project->first("TEMPLATE") == "vcapp" ||
239         project->first("TEMPLATE") == "vclib") {
240         if(!project->isActiveConfig("build_pass")) {
241             debug_msg(1, "Generator: MSVC.NET: Writing single configuration project file");
242             XmlOutput xmlOut(t);
243             projectWriter->write(xmlOut, vcProject);
244         }
245         return true;
246     }
247     return project->isActiveConfig("build_pass");
248 }
249
250 bool VcprojGenerator::writeProjectMakefile()
251 {
252     QTextStream t(&Option::output);
253
254     // Check if all requirements are fulfilled
255     if(!project->values("QMAKE_FAILED_REQUIREMENTS").isEmpty()) {
256         fprintf(stderr, "Project file not generated because all requirements not met:\n\t%s\n",
257                 var("QMAKE_FAILED_REQUIREMENTS").toLatin1().constData());
258         return true;
259     }
260
261     // Generate project file
262     if(project->first("TEMPLATE") == "vcapp" ||
263        project->first("TEMPLATE") == "vclib") {
264         if (!mergedProjects.count()) {
265             warn_msg(WarnLogic, "Generator: MSVC.NET: no single configuration created, cannot output project!");
266             return false;
267         }
268
269         debug_msg(1, "Generator: MSVC.NET: Writing project file");
270         VCProject mergedProject;
271         for (int i = 0; i < mergedProjects.count(); ++i) {
272             VCProjectSingleConfig *singleProject = &(mergedProjects.at(i)->vcProject);
273             mergedProject.SingleProjects += *singleProject;
274             for (int j = 0; j < singleProject->ExtraCompilersFiles.count(); ++j) {
275                 const QString &compilerName = singleProject->ExtraCompilersFiles.at(j).Name;
276                 if (!mergedProject.ExtraCompilers.contains(compilerName))
277                     mergedProject.ExtraCompilers += compilerName;
278             }
279         }
280
281         if(mergedProjects.count() > 1 &&
282            mergedProjects.at(0)->vcProject.Name ==
283            mergedProjects.at(1)->vcProject.Name)
284             mergedProjects.at(0)->writePrlFile();
285         mergedProject.Name = project->first("QMAKE_PROJECT_NAME");
286         mergedProject.Version = mergedProjects.at(0)->vcProject.Version;
287         mergedProject.ProjectGUID = project->isEmpty("QMAKE_UUID") ? getProjectUUID().toString().toUpper() : project->first("QMAKE_UUID");
288         mergedProject.Keyword = project->first("VCPROJ_KEYWORD");
289         mergedProject.SccProjectName = mergedProjects.at(0)->vcProject.SccProjectName;
290         mergedProject.SccLocalPath = mergedProjects.at(0)->vcProject.SccLocalPath;
291         mergedProject.PlatformName = mergedProjects.at(0)->vcProject.PlatformName;
292
293         XmlOutput xmlOut(t);
294         projectWriter->write(xmlOut, mergedProject);
295         return true;
296     } else if(project->first("TEMPLATE") == "vcsubdirs") {
297         return writeMakefile(t);
298     }
299     return false;
300 }
301
302 struct VcsolutionDepend {
303     QString uuid;
304     QString vcprojFile, orig_target, target;
305     Target targetType;
306     QStringList dependencies;
307 };
308
309 /* Disable optimization in getProjectUUID() due to a compiler
310  * bug in MSVC 2010 that causes ASSERT: "&other != this" in the QString
311  * copy constructor for non-empty file names at:
312  * filename.isEmpty()?project->first("QMAKE_MAKEFILE"):filename */
313
314 #ifdef Q_CC_MSVC
315 #   pragma optimize( "g", off )
316 #   pragma warning ( disable : 4748 )
317 #endif
318
319 QUuid VcprojGenerator::getProjectUUID(const QString &filename)
320 {
321     bool validUUID = true;
322
323     // Read GUID from variable-space
324     QUuid uuid = project->first("GUID");
325
326     // If none, create one based on the MD5 of absolute project path
327     if(uuid.isNull() || !filename.isEmpty()) {
328         QString abspath = Option::fixPathToLocalOS(filename.isEmpty()?project->first("QMAKE_MAKEFILE"):filename);
329         QByteArray digest = QCryptographicHash::hash(abspath.toUtf8(), QCryptographicHash::Md5);
330         memcpy((unsigned char*)(&uuid), digest.constData(), sizeof(QUuid));
331         validUUID = !uuid.isNull();
332         uuid.data4[0] = (uuid.data4[0] & 0x3F) | 0x80; // UV_DCE variant
333         uuid.data3 = (uuid.data3 & 0x0FFF) | (QUuid::Name<<12);
334     }
335
336     // If still not valid, generate new one, and suggest adding to .pro
337     if(uuid.isNull() || !validUUID) {
338         uuid = QUuid::createUuid();
339         fprintf(stderr,
340                 "qmake couldn't create a GUID based on filepath, and we couldn't\nfind a valid GUID in the .pro file (Consider adding\n'GUID = %s'  to the .pro file)\n",
341                 uuid.toString().toUpper().toLatin1().constData());
342     }
343
344     // Store GUID in variable-space
345     project->values("GUID") = QStringList(uuid.toString().toUpper());
346     return uuid;
347 }
348
349 #ifdef Q_CC_MSVC
350 #   pragma optimize( "g", on )
351 #endif
352
353 QUuid VcprojGenerator::increaseUUID(const QUuid &id)
354 {
355     QUuid result(id);
356     qint64 dataFirst = (result.data4[0] << 24) +
357                        (result.data4[1] << 16) +
358                        (result.data4[2] << 8) +
359                         result.data4[3];
360     qint64 dataLast =  (result.data4[4] << 24) +
361                        (result.data4[5] << 16) +
362                        (result.data4[6] <<  8) +
363                         result.data4[7];
364
365     if(!(dataLast++))
366         dataFirst++;
367
368     result.data4[0] = uchar((dataFirst >> 24) & 0xff);
369     result.data4[1] = uchar((dataFirst >> 16) & 0xff);
370     result.data4[2] = uchar((dataFirst >>  8) & 0xff);
371     result.data4[3] = uchar(dataFirst         & 0xff);
372     result.data4[4] = uchar((dataLast  >> 24) & 0xff);
373     result.data4[5] = uchar((dataLast  >> 16) & 0xff);
374     result.data4[6] = uchar((dataLast  >>  8) & 0xff);
375     result.data4[7] = uchar(dataLast          & 0xff);
376     return result;
377 }
378
379 QStringList VcprojGenerator::collectSubDirs(QMakeProject *proj)
380 {
381     QStringList subdirs;
382     QStringList tmp_proj_subdirs = proj->values("SUBDIRS");
383     for(int x = 0; x < tmp_proj_subdirs.size(); ++x) {
384         QString tmpdir = tmp_proj_subdirs.at(x);
385         const QString tmpdirConfig = tmpdir + QStringLiteral(".CONFIG");
386         if (!proj->isEmpty(tmpdirConfig)) {
387             const QStringList config = proj->values(tmpdirConfig);
388             if (config.contains(QStringLiteral("no_default_target")))
389                 continue; // Ignore this sub-dir
390         }
391         if(!proj->isEmpty(tmpdir + ".file")) {
392             if(!proj->isEmpty(tmpdir + ".subdir"))
393                 warn_msg(WarnLogic, "Cannot assign both file and subdir for subdir %s",
394                          tmpdir.toLatin1().constData());
395             tmpdir = proj->first(tmpdir + ".file");
396         } else if(!proj->isEmpty(tmpdir + ".subdir")) {
397             tmpdir = proj->first(tmpdir + ".subdir");
398         }
399         subdirs += tmpdir;
400     }
401     return subdirs;
402 }
403
404 void VcprojGenerator::writeSubDirs(QTextStream &t)
405 {
406     // Check if all requirements are fulfilled
407     if(!project->values("QMAKE_FAILED_REQUIREMENTS").isEmpty()) {
408         fprintf(stderr, "Project file not generated because all requirements not met:\n\t%s\n",
409                 var("QMAKE_FAILED_REQUIREMENTS").toLatin1().constData());
410         return;
411     }
412
413     switch(which_dotnet_version()) {
414     case NET2010:
415         t << _slnHeader100;
416         break;
417     case NET2008:
418         t << _slnHeader90;
419         break;
420     case NET2005:
421         t << _slnHeader80;
422         break;
423     case NET2003:
424         t << _slnHeader71;
425         break;
426     case NET2002:
427         t << _slnHeader70;
428         break;
429     default:
430         t << _slnHeader70;
431         warn_msg(WarnLogic, "Generator: MSVC.NET: Unknown version (%d) of MSVC detected for .sln", which_dotnet_version());
432         break;
433     }
434
435     QHash<QString, VcsolutionDepend*> solution_depends;
436     QList<VcsolutionDepend*> solution_cleanup;
437
438     QString oldpwd = qmake_getpwd();
439
440     // Make sure that all temp projects are configured
441     // for release so that the depends are created
442     // without the debug <lib>dxxx.lib name mangling
443     QStringList old_after_vars = Option::after_user_vars;
444     Option::after_user_vars.append("CONFIG+=release");
445
446     QStringList subdirs = collectSubDirs(project);
447     for(int i = 0; i < subdirs.size(); ++i) {
448         QString tmp = subdirs.at(i);
449         QFileInfo fi(fileInfo(Option::fixPathToLocalOS(tmp, true)));
450         if(fi.exists()) {
451             if(fi.isDir()) {
452                 QString profile = tmp;
453                 if(!profile.endsWith(Option::dir_sep))
454                     profile += Option::dir_sep;
455                 profile += fi.baseName() + Option::pro_ext;
456                 subdirs.append(profile);
457             } else {
458                 QMakeProject tmp_proj;
459                 QString dir = fi.path(), fn = fi.fileName();
460                 if(!dir.isEmpty()) {
461                     if(!qmake_setpwd(dir))
462                         fprintf(stderr, "Cannot find directory: %s\n", dir.toLatin1().constData());
463                 }
464                 if(tmp_proj.read(fn)) {
465                     // Check if all requirements are fulfilled
466                     if (!tmp_proj.isEmpty("QMAKE_FAILED_REQUIREMENTS")) {
467                         fprintf(stderr, "Project file(%s) not added to Solution because all requirements not met:\n\t%s\n",
468                                 fn.toLatin1().constData(), tmp_proj.values("QMAKE_FAILED_REQUIREMENTS").join(" ").toLatin1().constData());
469                         continue;
470                     }
471                     if(tmp_proj.first("TEMPLATE") == "vcsubdirs") {
472                         foreach(const QString &tmpdir, collectSubDirs(&tmp_proj))
473                             subdirs += fileFixify(tmpdir);
474                     } else if(tmp_proj.first("TEMPLATE") == "vcapp" || tmp_proj.first("TEMPLATE") == "vclib") {
475                         // Initialize a 'fake' project to get the correct variables
476                         // and to be able to extract all the dependencies
477                         Option::QMAKE_MODE old_mode = Option::qmake_mode;
478                         Option::qmake_mode = Option::QMAKE_GENERATE_NOTHING;
479                         QString old_output_dir = Option::output_dir;
480                         Option::output_dir = QFileInfo(fileFixify(dir, qmake_getpwd(), Option::output_dir)).canonicalFilePath();
481                         VcprojGenerator tmp_vcproj;
482                         tmp_vcproj.setNoIO(true);
483                         tmp_vcproj.setProjectFile(&tmp_proj);
484                         Option::qmake_mode = old_mode;
485                         Option::output_dir = old_output_dir;
486
487                         // We assume project filename is [QMAKE_PROJECT_NAME].vcproj
488                         QString vcproj = unescapeFilePath(tmp_vcproj.project->first("QMAKE_PROJECT_NAME") + project->first("VCPROJ_EXTENSION"));
489                         QString vcprojDir = qmake_getpwd();
490
491                         // If file doesn't exsist, then maybe the users configuration
492                         // doesn't allow it to be created. Skip to next...
493                         if(!exists(vcprojDir + Option::dir_sep + vcproj)) {
494
495                             // Try to find the directory which fits relative
496                             // to the output path, which represents the shadow
497                             // path in case we are shadow building
498                             QStringList list = fi.path().split(QLatin1Char('/'));
499                             QString tmpDir = QFileInfo(Option::output).path() + Option::dir_sep;
500                             bool found = false;
501                             for (int i = list.size() - 1; i >= 0; --i) {
502                                 QString curr;
503                                 for (int j = i; j < list.size(); ++j)
504                                     curr += list.at(j) + Option::dir_sep;
505                                 if (exists(tmpDir + curr + vcproj)) {
506                                     vcprojDir = QDir::cleanPath(tmpDir + curr);
507                                     found = true;
508                                     break;
509                                 }
510                             }
511                             if (!found) {
512                                 warn_msg(WarnLogic, "Ignored (not found) '%s'", QString(vcprojDir + Option::dir_sep + vcproj).toLatin1().constData());
513                                 goto nextfile; // # Dirty!
514                             }
515                         }
516
517                         VcsolutionDepend *newDep = new VcsolutionDepend;
518                         newDep->vcprojFile = vcprojDir + Option::dir_sep + vcproj;
519                         newDep->orig_target = unescapeFilePath(tmp_proj.first("QMAKE_ORIG_TARGET"));
520                         newDep->target = tmp_proj.first("MSVCPROJ_TARGET").section(Option::dir_sep, -1);
521                         newDep->targetType = tmp_vcproj.projectTarget;
522                         newDep->uuid = tmp_proj.isEmpty("QMAKE_UUID") ? getProjectUUID(Option::fixPathToLocalOS(vcprojDir + QDir::separator() + vcproj)).toString().toUpper(): tmp_proj.first("QMAKE_UUID");
523
524                         // We want to store it as the .lib name.
525                         if(newDep->target.endsWith(".dll"))
526                             newDep->target = newDep->target.left(newDep->target.length()-3) + "lib";
527
528                         // All ActiveQt Server projects are dependent on idc.exe
529                         if (tmp_proj.values("CONFIG").contains("qaxserver"))
530                             newDep->dependencies << "idc.exe";
531
532                         // All extra compilers which has valid input are considered dependencies
533                         const QStringList &quc = tmp_proj.values("QMAKE_EXTRA_COMPILERS");
534                         for(QStringList::ConstIterator it = quc.constBegin(); it != quc.constEnd(); ++it) {
535                             const QStringList &invar = tmp_proj.values(*it + ".input");
536                             for(QStringList::ConstIterator iit = invar.constBegin(); iit != invar.constEnd(); ++iit) {
537                                 const QStringList fileList = tmp_proj.values(*iit);
538                                 if (!fileList.isEmpty()) {
539                                     const QStringList &cmdsParts = tmp_proj.values(*it + ".commands");
540                                     bool startOfLine = true;
541                                     foreach(QString cmd, cmdsParts) {
542                                         if (!startOfLine) {
543                                             if (cmd.contains("\r"))
544                                                 startOfLine = true;
545                                             continue;
546                                         }
547                                         if (cmd.isEmpty())
548                                             continue;
549
550                                         startOfLine = false;
551                                         // Extra compiler commands might be defined in variables, so
552                                         // expand them (don't care about the in/out files)
553                                         cmd = tmp_vcproj.replaceExtraCompilerVariables(cmd, QStringList(), QStringList());
554                                         // Pull out command based on spaces and quoting, if the
555                                         // command starts with that
556                                         cmd = cmd.left(cmd.indexOf(cmd.at(0) == '"' ? '"' : ' ', 1));
557                                         QString dep = cmd.section('/', -1).section('\\', -1);
558                                         if (!newDep->dependencies.contains(dep))
559                                             newDep->dependencies << dep;
560                                     }
561                                 }
562                             }
563                         }
564
565                         // Add all unknown libs to the deps
566                         QStringList where = QStringList() << "QMAKE_LIBS" << "QMAKE_LIBS_PRIVATE";
567                         if(!tmp_proj.isEmpty("QMAKE_INTERNAL_PRL_LIBS"))
568                             where = tmp_proj.values("QMAKE_INTERNAL_PRL_LIBS");
569                         for (QStringList::ConstIterator wit = where.begin();
570                             wit != where.end(); ++wit) {
571                             const QStringList &l = tmp_proj.values(*wit);
572                             for (QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
573                                 QString opt = (*it);
574                                 if(!opt.startsWith("/") &&   // Not a switch
575                                     opt != newDep->target && // Not self
576                                     opt != "opengl32.lib" && // We don't care about these libs
577                                     opt != "glu32.lib" &&    // to make depgen alittle faster
578                                     opt != "kernel32.lib" &&
579                                     opt != "user32.lib" &&
580                                     opt != "gdi32.lib" &&
581                                     opt != "comdlg32.lib" &&
582                                     opt != "advapi32.lib" &&
583                                     opt != "shell32.lib" &&
584                                     opt != "ole32.lib" &&
585                                     opt != "oleaut32.lib" &&
586                                     opt != "uuid.lib" &&
587                                     opt != "imm32.lib" &&
588                                     opt != "winmm.lib" &&
589                                     opt != "wsock32.lib" &&
590                                     opt != "ws2_32.lib" &&
591                                     opt != "winspool.lib" &&
592                                     opt != "delayimp.lib")
593                                 {
594                                     newDep->dependencies << opt.section(Option::dir_sep, -1);
595                                 }
596                             }
597                         }
598 #ifdef DEBUG_SOLUTION_GEN
599                         qDebug("Deps for %20s: [%s]", newDep->target.toLatin1().constData(), newDep->dependencies.join(" :: ").toLatin1().constData());
600 #endif
601                         solution_cleanup.append(newDep);
602                         solution_depends.insert(newDep->target, newDep);
603                         t << _slnProjectBeg << _slnMSVCvcprojGUID << _slnProjectMid
604                             << "\"" << newDep->orig_target << "\", \"" << newDep->vcprojFile
605                             << "\", \"" << newDep->uuid << "\"";
606                         t << _slnProjectEnd;
607                     }
608                 }
609 nextfile:
610                 qmake_setpwd(oldpwd);
611             }
612         }
613     }
614     t << _slnGlobalBeg;
615
616     QString slnConf = _slnSolutionConf;
617     if (!project->isEmpty("CE_SDK") && !project->isEmpty("CE_ARCH")) {
618         QString slnPlatform = QString("|") + project->values("CE_SDK").join(" ") + " (" + project->first("CE_ARCH") + ")";
619         slnConf.replace(QString("|Win32"), slnPlatform);
620     } else if (is64Bit) {
621         slnConf.replace(QString("|Win32"), "|x64");
622     }
623     t << slnConf;
624
625     t << _slnProjDepBeg;
626
627     // Restore previous after_user_var options
628     Option::after_user_vars = old_after_vars;
629
630     // Figure out dependencies
631     for(QList<VcsolutionDepend*>::Iterator it = solution_cleanup.begin(); it != solution_cleanup.end(); ++it) {
632         int cnt = 0;
633         for(QStringList::iterator dit = (*it)->dependencies.begin();  dit != (*it)->dependencies.end(); ++dit) {
634             if(VcsolutionDepend *vc = solution_depends[*dit])
635                 t << "\n\t\t" << (*it)->uuid << "." << cnt++ << " = " << vc->uuid;
636         }
637     }
638     t << _slnProjDepEnd;
639     t << _slnProjConfBeg;
640     for(QList<VcsolutionDepend*>::Iterator it = solution_cleanup.begin(); it != solution_cleanup.end(); ++it) {
641         QString platform = is64Bit ? "x64" : "Win32";
642         QString xplatform = platform;
643         if (!project->isEmpty("CE_SDK") && !project->isEmpty("CE_ARCH"))
644             xplatform = project->values("CE_SDK").join(" ") + " (" + project->first("CE_ARCH") + ")";
645         if (!project->isHostBuild())
646             platform = xplatform;
647         t << "\n\t\t" << (*it)->uuid << QString(_slnProjDbgConfTag1).arg(xplatform) << platform;
648         t << "\n\t\t" << (*it)->uuid << QString(_slnProjDbgConfTag2).arg(xplatform) << platform;
649         t << "\n\t\t" << (*it)->uuid << QString(_slnProjRelConfTag1).arg(xplatform) << platform;
650         t << "\n\t\t" << (*it)->uuid << QString(_slnProjRelConfTag2).arg(xplatform) << platform;
651     }
652     t << _slnProjConfEnd;
653     t << _slnExtSections;
654     t << _slnGlobalEnd;
655
656
657     while (!solution_cleanup.isEmpty())
658         delete solution_cleanup.takeFirst();
659 }
660
661 // ------------------------------------------------------------------------------------------------
662 // ------------------------------------------------------------------------------------------------
663
664 bool VcprojGenerator::hasBuiltinCompiler(const QString &file)
665 {
666     // Source files
667     for (int i = 0; i < Option::cpp_ext.count(); ++i)
668         if (file.endsWith(Option::cpp_ext.at(i)))
669             return true;
670     for (int i = 0; i < Option::c_ext.count(); ++i)
671         if (file.endsWith(Option::c_ext.at(i)))
672             return true;
673     if (file.endsWith(".rc")
674         || file.endsWith(".idl"))
675         return true;
676     return false;
677 }
678
679 void VcprojGenerator::init()
680 {
681     if (init_flag)
682         return;
683     init_flag = true;
684     is64Bit = (project->first("QMAKE_TARGET.arch") == "x86_64");
685     projectWriter = createProjectWriter();
686
687     if(project->first("TEMPLATE") == "vcsubdirs") //too much work for subdirs
688         return;
689
690     debug_msg(1, "Generator: MSVC.NET: Initializing variables");
691
692     // this should probably not be here, but I'm using it to wrap the .t files
693     if (project->first("TEMPLATE") == "vcapp")
694         project->values("QMAKE_APP_FLAG").append("1");
695     else if (project->first("TEMPLATE") == "vclib")
696         project->values("QMAKE_LIB_FLAG").append("1");
697     if (project->values("QMAKESPEC").isEmpty())
698         project->values("QMAKESPEC").append(qgetenv("QMAKESPEC"));
699
700     processVars();
701
702     project->values("QMAKE_LIBS") += escapeFilePaths(project->values("LIBS"));
703     project->values("QMAKE_LIBS_PRIVATE") += escapeFilePaths(project->values("LIBS_PRIVATE"));
704
705     if(!project->values("VERSION").isEmpty()) {
706         QString version = project->values("VERSION")[0];
707         int firstDot = version.indexOf(".");
708         QString major = version.left(firstDot);
709         QString minor = version.right(version.length() - firstDot - 1);
710         minor.replace(QRegExp("\\."), "");
711         project->values("QMAKE_LFLAGS").append("/VERSION:" + major + "." + minor);
712     }
713
714     MakefileGenerator::init();
715     initOld();           // Currently calling old DSP code to set variables. CLEAN UP!
716
717     // Figure out what we're trying to build
718     if(project->first("TEMPLATE") == "vcapp") {
719         projectTarget = Application;
720     } else if(project->first("TEMPLATE") == "vclib") {
721         if(project->isActiveConfig("staticlib")) {
722             if (!project->values("RES_FILE").isEmpty())
723                 project->values("QMAKE_LIBS") += escapeFilePaths(project->values("RES_FILE"));
724             projectTarget = StaticLib;
725         } else
726             projectTarget = SharedLib;
727     }
728
729     // Setup PCH variables
730     precompH = project->first("PRECOMPILED_HEADER");
731     precompCPP = project->first("PRECOMPILED_SOURCE");
732     usePCH = !precompH.isEmpty() && project->isActiveConfig("precompile_header");
733     if (usePCH) {
734         precompHFilename = fileInfo(precompH).fileName();
735         // Created files
736         QString origTarget = unescapeFilePath(project->first("QMAKE_ORIG_TARGET"));
737         precompObj = origTarget + Option::obj_ext;
738         precompPch = origTarget + ".pch";
739         // Add PRECOMPILED_HEADER to HEADERS
740         if (!project->values("HEADERS").contains(precompH))
741             project->values("HEADERS") += precompH;
742         // Return to variable pool
743         project->values("PRECOMPILED_OBJECT") = QStringList(precompObj);
744         project->values("PRECOMPILED_PCH")    = QStringList(precompPch);
745
746         autogenPrecompCPP = precompCPP.isEmpty() && project->isActiveConfig("autogen_precompile_source");
747         if (autogenPrecompCPP) {
748             precompCPP = precompH
749                 + (Option::cpp_ext.count() ? Option::cpp_ext.at(0) : QLatin1String(".cpp"));
750             project->values("GENERATED_SOURCES") += precompCPP;
751         } else if (!precompCPP.isEmpty()) {
752             project->values("SOURCES") += precompCPP;
753         }
754     }
755
756     // Add all input files for a custom compiler into a map for uniqueness,
757     // unless the compiler is configure as a combined stage, then use the first one
758     const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS");
759     for(QStringList::ConstIterator it = quc.constBegin(); it != quc.constEnd(); ++it) {
760         const QStringList &invar = project->values(*it + ".input");
761         const QString compiler_out = project->first((*it) + ".output");
762         for(QStringList::ConstIterator iit = invar.constBegin(); iit != invar.constEnd(); ++iit) {
763             QStringList fileList = project->values(*iit);
764             if (!fileList.isEmpty()) {
765                 if (project->values((*it) + ".CONFIG").indexOf("combine") != -1)
766                     fileList = QStringList(fileList.first());
767                 for(QStringList::ConstIterator fit = fileList.constBegin(); fit != fileList.constEnd(); ++fit) {
768                     QString file = (*fit);
769                     if (verifyExtraCompiler((*it), file)) {
770                         if (!hasBuiltinCompiler(file)) {
771                             extraCompilerSources[file] += *it;
772                         } else {
773                             QString out = Option::fixPathToTargetOS(replaceExtraCompilerVariables(
774                                             compiler_out, file, QString()), false);
775                             extraCompilerSources[out] += *it;
776                             extraCompilerOutputs[out] = QStringList(file); // Can only have one
777                         }
778                     }
779                 }
780             }
781         }
782     }
783
784 #if 0 // Debugging
785     Q_FOREACH(QString aKey, extraCompilerSources.keys()) {
786         qDebug("Extracompilers for %s are (%s)", aKey.toLatin1().constData(), extraCompilerSources.value(aKey).join(", ").toLatin1().constData());
787     }
788     Q_FOREACH(QString aKey, extraCompilerOutputs.keys()) {
789         qDebug("Object mapping for %s is (%s)", aKey.toLatin1().constData(), extraCompilerOutputs.value(aKey).join(", ").toLatin1().constData());
790     }
791     qDebug("");
792 #endif
793 }
794
795 bool VcprojGenerator::mergeBuildProject(MakefileGenerator *other)
796 {
797     if (!other || !other->projectFile()) {
798         warn_msg(WarnLogic, "VcprojGenerator: Cannot merge null project.");
799         return false;
800     }
801     if (other->projectFile()->first("MAKEFILE_GENERATOR") != project->first("MAKEFILE_GENERATOR")) {
802         warn_msg(WarnLogic, "VcprojGenerator: Cannot merge other types of projects! (ignored)");
803         return false;
804     }
805
806     VcprojGenerator *otherVC = static_cast<VcprojGenerator*>(other);
807     mergedProjects += otherVC;
808     return true;
809 }
810
811 void VcprojGenerator::initProject()
812 {
813     // Initialize XML sub elements
814     // - Do this first since project elements may need
815     // - to know of certain configuration options
816     initConfiguration();
817     initRootFiles();
818     initSourceFiles();
819     initHeaderFiles();
820     initGeneratedFiles();
821     initLexYaccFiles();
822     initTranslationFiles();
823     initFormFiles();
824     initResourceFiles();
825     initExtraCompilerOutputs();
826
827     // Own elements -----------------------------
828     vcProject.Name = unescapeFilePath(project->first("QMAKE_ORIG_TARGET"));
829     switch(which_dotnet_version()) {
830     case NET2010:
831         vcProject.Version = "10.00";
832         break;
833     case NET2008:
834         vcProject.Version = "9,00";
835         break;
836     case NET2005:
837                 //### using ',' because of a bug in 2005 B2
838                 //### VS uses '.' or ',' depending on the regional settings! Using ',' always works.
839         vcProject.Version = "8,00";
840         break;
841     case NET2003:
842         vcProject.Version = "7.10";
843         break;
844     case NET2002:
845         vcProject.Version = "7.00";
846         break;
847     default:
848         vcProject.Version = "7.00";
849         warn_msg(WarnLogic, "Generator: MSVC.NET: Unknown version (%d) of MSVC detected for .vcproj", which_dotnet_version());
850         break;
851     }
852
853     vcProject.Keyword = project->first("VCPROJ_KEYWORD");
854     if (project->isHostBuild() || project->isEmpty("CE_SDK") || project->isEmpty("CE_ARCH")) {
855         vcProject.PlatformName = (is64Bit ? "x64" : "Win32");
856     } else {
857         vcProject.PlatformName = project->values("CE_SDK").join(" ") + " (" + project->first("CE_ARCH") + ")";
858     }
859     // These are not used by Qt, but may be used by customers
860     vcProject.SccProjectName = project->first("SCCPROJECTNAME");
861     vcProject.SccLocalPath = project->first("SCCLOCALPATH");
862     vcProject.flat_files = project->isActiveConfig("flat");
863 }
864
865 void VcprojGenerator::initConfiguration()
866 {
867     // Initialize XML sub elements
868     // - Do this first since main configuration elements may need
869     // - to know of certain compiler/linker options
870     VCConfiguration &conf = vcProject.Configuration;
871     conf.CompilerVersion = which_dotnet_version();
872
873     initCompilerTool();
874
875     // Only on configuration per build
876     bool isDebug = project->isActiveConfig("debug");
877
878     if(projectTarget == StaticLib)
879         initLibrarianTool();
880     else {
881         conf.linker.GenerateDebugInformation = isDebug ? _True : _False;
882         initLinkerTool();
883     }
884     initResourceTool();
885     initIDLTool();
886
887     // Own elements -----------------------------
888     QString temp = project->first("BuildBrowserInformation");
889     switch (projectTarget) {
890     case SharedLib:
891         conf.ConfigurationType = typeDynamicLibrary;
892         break;
893     case StaticLib:
894         conf.ConfigurationType = typeStaticLibrary;
895         break;
896     case Application:
897     default:
898         conf.ConfigurationType = typeApplication;
899         break;
900     }
901
902     conf.OutputDirectory = project->first("DESTDIR");
903     if (conf.OutputDirectory.isEmpty())
904         conf.OutputDirectory = ".\\";
905     if (!conf.OutputDirectory.endsWith("\\"))
906         conf.OutputDirectory += '\\';
907     if (conf.CompilerVersion >= NET2010) {
908         // The target name could have been changed.
909         conf.PrimaryOutput = project->first("TARGET");
910         if ( !conf.PrimaryOutput.isEmpty() && !project->first("TARGET_VERSION_EXT").isEmpty() && project->isActiveConfig("shared"))
911             conf.PrimaryOutput.append(project->first("TARGET_VERSION_EXT"));
912     }
913
914     conf.Name = project->values("BUILD_NAME").join(" ");
915     if (conf.Name.isEmpty())
916         conf.Name = isDebug ? "Debug" : "Release";
917     conf.ConfigurationName = conf.Name;
918     if (project->isHostBuild() || project->isEmpty("CE_SDK") || project->isEmpty("CE_ARCH")) {
919         conf.Name += (is64Bit ? "|x64" : "|Win32");
920     } else {
921         conf.Name += "|" + project->values("CE_SDK").join(" ") + " (" + project->first("CE_ARCH") + ")";
922     }
923     conf.ATLMinimizesCRunTimeLibraryUsage = (project->first("ATLMinimizesCRunTimeLibraryUsage").isEmpty() ? _False : _True);
924     conf.BuildBrowserInformation = triState(temp.isEmpty() ? (short)unset : temp.toShort());
925     temp = project->first("CharacterSet");
926     conf.CharacterSet = charSet(temp.isEmpty() ? (short)charSetNotSet : temp.toShort());
927     conf.DeleteExtensionsOnClean = project->first("DeleteExtensionsOnClean");
928     conf.ImportLibrary = conf.linker.ImportLibrary;
929     conf.IntermediateDirectory = project->first("OBJECTS_DIR");
930     conf.WholeProgramOptimization = conf.compiler.WholeProgramOptimization;
931     temp = project->first("UseOfATL");
932     if(!temp.isEmpty())
933         conf.UseOfATL = useOfATL(temp.toShort());
934     temp = project->first("UseOfMfc");
935     if(!temp.isEmpty())
936         conf.UseOfMfc = useOfMfc(temp.toShort());
937
938     // Configuration does not need parameters from
939     // these sub XML items;
940     initCustomBuildTool();
941     initPreBuildEventTools();
942     initPostBuildEventTools();
943     // Only deploy for CE projects
944     if (!project->isHostBuild() && !project->isEmpty("CE_SDK") && !project->isEmpty("CE_ARCH"))
945         initDeploymentTool();
946     initPreLinkEventTools();
947
948     // Set definite values in both configurations
949     if (isDebug) {
950         conf.compiler.PreprocessorDefinitions.removeAll("NDEBUG");
951     } else {
952         conf.compiler.PreprocessorDefinitions += "NDEBUG";
953     }
954 }
955
956 void VcprojGenerator::initCompilerTool()
957 {
958     QString placement = project->first("OBJECTS_DIR");
959     if(placement.isEmpty())
960         placement = ".\\";
961
962     VCConfiguration &conf = vcProject.Configuration;
963     if (conf.CompilerVersion >= NET2010) {
964         // adjust compiler tool defaults for VS 2010 and above
965         conf.compiler.Optimization = optimizeDisabled;
966     }
967     conf.compiler.AssemblerListingLocation = placement ;
968     conf.compiler.ProgramDataBaseFileName = ".\\" ;
969     conf.compiler.ObjectFile = placement ;
970     conf.compiler.ExceptionHandling = ehNone;
971     // PCH
972     if (usePCH) {
973         conf.compiler.UsePrecompiledHeader     = pchUseUsingSpecific;
974         conf.compiler.PrecompiledHeaderFile    = "$(IntDir)\\" + precompPch;
975         conf.compiler.PrecompiledHeaderThrough = project->first("PRECOMPILED_HEADER");
976         conf.compiler.ForcedIncludeFiles       = project->values("PRECOMPILED_HEADER");
977
978         if (conf.CompilerVersion <= NET2003) {
979             // Minimal build option triggers an Internal Compiler Error
980             // when used in conjunction with /FI and /Yu, so remove it
981             // ### work-around for a VS 2003 bug. Move to some prf file or remove completely.
982             project->values("QMAKE_CFLAGS_DEBUG").removeAll("-Gm");
983             project->values("QMAKE_CFLAGS_DEBUG").removeAll("/Gm");
984             project->values("QMAKE_CXXFLAGS_DEBUG").removeAll("-Gm");
985             project->values("QMAKE_CXXFLAGS_DEBUG").removeAll("/Gm");
986         }
987     }
988
989     conf.compiler.parseOptions(project->values("QMAKE_CXXFLAGS"));
990
991     if (project->isActiveConfig("windows"))
992         conf.compiler.PreprocessorDefinitions += "_WINDOWS";
993     else if (project->isActiveConfig("console"))
994         conf.compiler.PreprocessorDefinitions += "_CONSOLE";
995
996     conf.compiler.PreprocessorDefinitions += project->values("DEFINES");
997     conf.compiler.PreprocessorDefinitions += project->values("PRL_EXPORT_DEFINES");
998     conf.compiler.parseOptions(project->values("MSVCPROJ_INCPATH"));
999 }
1000
1001 void VcprojGenerator::initLibrarianTool()
1002 {
1003     VCConfiguration &conf = vcProject.Configuration;
1004     conf.librarian.OutputFile = "$(OutDir)\\";
1005     conf.librarian.OutputFile += project->first("MSVCPROJ_TARGET");
1006     conf.librarian.AdditionalOptions += project->values("QMAKE_LIBFLAGS");
1007 }
1008
1009 void VcprojGenerator::initLinkerTool()
1010 {
1011     VCConfiguration &conf = vcProject.Configuration;
1012     conf.linker.parseOptions(project->values("QMAKE_LFLAGS"));
1013
1014     foreach (const QString &libDir, project->values("QMAKE_LIBDIR")) {
1015         if (libDir.startsWith("/LIBPATH:"))
1016             conf.linker.AdditionalLibraryDirectories += libDir.mid(9);
1017         else
1018             conf.linker.AdditionalLibraryDirectories += libDir;
1019     }
1020
1021     if (!project->values("DEF_FILE").isEmpty())
1022         conf.linker.ModuleDefinitionFile = project->first("DEF_FILE");
1023
1024     foreach (QString libs, project->values("QMAKE_LIBS") + project->values("QMAKE_LIBS_PRIVATE")) {
1025         if (libs.left(9).toUpper() == "/LIBPATH:") {
1026             QStringList l = QStringList(libs);
1027             conf.linker.parseOptions(l);
1028         } else {
1029             conf.linker.AdditionalDependencies += libs;
1030         }
1031     }
1032
1033     conf.linker.OutputFile = "$(OutDir)\\";
1034     conf.linker.OutputFile += project->first("MSVCPROJ_TARGET");
1035
1036     if(project->isActiveConfig("dll")){
1037         conf.linker.parseOptions(project->values("QMAKE_LFLAGS_QT_DLL"));
1038     }
1039 }
1040
1041 void VcprojGenerator::initResourceTool()
1042 {
1043     VCConfiguration &conf = vcProject.Configuration;
1044     conf.resource.PreprocessorDefinitions = conf.compiler.PreprocessorDefinitions;
1045
1046     // We need to add _DEBUG for the debug version of the project, since the normal compiler defines
1047     // do not contain it. (The compiler defines this symbol automatically, which is wy we don't need
1048     // to add it for the compiler) However, the resource tool does not do this.
1049     if(project->isActiveConfig("debug"))
1050         conf.resource.PreprocessorDefinitions += "_DEBUG";
1051     if(project->isActiveConfig("staticlib"))
1052         conf.resource.ResourceOutputFileName = "$(OutDir)\\$(InputName).res";
1053 }
1054
1055 void VcprojGenerator::initIDLTool()
1056 {
1057 }
1058
1059 void VcprojGenerator::initCustomBuildTool()
1060 {
1061 }
1062
1063 void VcprojGenerator::initPreBuildEventTools()
1064 {
1065 }
1066
1067 void VcprojGenerator::initPostBuildEventTools()
1068 {
1069     VCConfiguration &conf = vcProject.Configuration;
1070     if (!project->values("QMAKE_POST_LINK").isEmpty()) {
1071         QStringList cmdline = VCToolBase::fixCommandLine(var("QMAKE_POST_LINK"));
1072         conf.postBuild.CommandLine = cmdline;
1073         conf.postBuild.Description = cmdline.join(QLatin1String("\r\n"));
1074         conf.postBuild.ExcludedFromBuild = _False;
1075     }
1076
1077     QString signature = !project->isEmpty("SIGNATURE_FILE") ? var("SIGNATURE_FILE") : var("DEFAULT_SIGNATURE");
1078     bool useSignature = !signature.isEmpty() && !project->isActiveConfig("staticlib") &&
1079                         !project->isHostBuild() && !project->isEmpty("CE_SDK") && !project->isEmpty("CE_ARCH");
1080     if (useSignature) {
1081         conf.postBuild.CommandLine.prepend(
1082                 QLatin1String("signtool sign /F ") + signature + QLatin1String(" \"$(TargetPath)\""));
1083         conf.postBuild.ExcludedFromBuild = _False;
1084     }
1085
1086     if (!project->values("MSVCPROJ_COPY_DLL").isEmpty()) {
1087         conf.postBuild.Description += var("MSVCPROJ_COPY_DLL_DESC");
1088         conf.postBuild.CommandLine += var("MSVCPROJ_COPY_DLL");
1089         conf.postBuild.ExcludedFromBuild = _False;
1090     }
1091 }
1092
1093 void VcprojGenerator::initDeploymentTool()
1094 {
1095     VCConfiguration &conf = vcProject.Configuration;
1096     QString targetPath = project->values("deploy.path").join(" ");
1097     if (targetPath.isEmpty())
1098         targetPath = QString("%CSIDL_PROGRAM_FILES%\\") + project->first("TARGET");
1099     if (targetPath.endsWith("/") || targetPath.endsWith("\\"))
1100         targetPath.chop(1);
1101
1102     // Only deploy Qt libs for shared build
1103     if (!project->values("QMAKE_QT_DLL").isEmpty()) {
1104         // FIXME: This code should actually resolve the libraries from all Qt modules.
1105         const QString &qtdir = QLibraryInfo::rawLocation(QLibraryInfo::LibrariesPath,
1106                                                          QLibraryInfo::EffectivePaths);
1107         QStringList arg = project->values("QMAKE_LIBS") + project->values("QMAKE_LIBS_PRIVATE");
1108         for (QStringList::ConstIterator it = arg.constBegin(); it != arg.constEnd(); ++it) {
1109             if (it->contains(qtdir)) {
1110                 QString dllName = *it;
1111
1112                 if (dllName.contains(QLatin1String("QAxContainer"))
1113                     || dllName.contains(QLatin1String("qtmain"))
1114                     || dllName.contains(QLatin1String("QtUiTools")))
1115                     continue;
1116                 dllName.replace(QLatin1String(".lib") , QLatin1String(".dll"));
1117                 QFileInfo info(dllName);
1118                 conf.deployment.AdditionalFiles += info.fileName()
1119                                                 + "|" + QDir::toNativeSeparators(info.absolutePath())
1120                                                 + "|" + targetPath
1121                                                 + "|0;";
1122             }
1123         }
1124     }
1125
1126     // C-runtime deployment
1127     QString runtime = project->values("QT_CE_C_RUNTIME").join(QLatin1String(" "));
1128     if (!runtime.isEmpty() && (runtime != QLatin1String("no"))) {
1129         QString runtimeVersion = QLatin1String("msvcr");
1130         QString mkspec = project->first("QMAKESPEC");
1131         // If no .qmake.cache has been found, we fallback to the original mkspec
1132         if (mkspec.isEmpty())
1133             mkspec = project->first("QMAKESPEC_ORIGINAL");
1134
1135         if (!mkspec.isEmpty()) {
1136             if (mkspec.endsWith("2008"))
1137                 runtimeVersion.append("90");
1138             else
1139                 runtimeVersion.append("80");
1140             if (project->isActiveConfig("debug"))
1141                 runtimeVersion.append("d");
1142             runtimeVersion.append(".dll");
1143
1144             if (runtime == "yes") {
1145                 // Auto-find C-runtime
1146                 QString vcInstallDir = qgetenv("VCINSTALLDIR");
1147                 if (!vcInstallDir.isEmpty()) {
1148                     vcInstallDir += "\\ce\\dll\\";
1149                     vcInstallDir += project->values("CE_ARCH").join(QLatin1String(" "));
1150                     if (!QFileInfo(vcInstallDir + QDir::separator() + runtimeVersion).exists())
1151                         runtime.clear();
1152                     else
1153                         runtime = vcInstallDir;
1154                 }
1155             }
1156         }
1157
1158         if (!runtime.isEmpty() && runtime != QLatin1String("yes")) {
1159             conf.deployment.AdditionalFiles += runtimeVersion
1160                                             + "|" + QDir::toNativeSeparators(runtime)
1161                                             + "|" + targetPath
1162                                             + "|0;";
1163         }
1164     }
1165
1166     // foreach item in DEPLOYMENT
1167     foreach(QString item, project->values("DEPLOYMENT")) {
1168         // get item.path
1169         QString devicePath = project->first(item + ".path");
1170         if (devicePath.isEmpty())
1171             devicePath = targetPath;
1172         // check if item.path is relative (! either /,\ or %)
1173         if (!(devicePath.at(0) == QLatin1Char('/')
1174             || devicePath.at(0) == QLatin1Char('\\')
1175             || devicePath.at(0) == QLatin1Char('%'))) {
1176             // create output path
1177             devicePath = Option::fixPathToLocalOS(QDir::cleanPath(targetPath + QLatin1Char('\\') + devicePath));
1178         }
1179         // foreach d in item.files
1180         foreach (QString source, project->values(item + ".files")) {
1181             QString itemDevicePath = devicePath;
1182             source = Option::fixPathToLocalOS(source);
1183             QString nameFilter;
1184             QFileInfo info(source);
1185             QString searchPath;
1186             if (info.isDir()) {
1187                 nameFilter = QLatin1String("*");
1188                 itemDevicePath += "\\" + info.fileName();
1189                 searchPath = info.absoluteFilePath();
1190             } else {
1191                 nameFilter = source.split('\\').last();
1192                 searchPath = info.absolutePath();
1193             }
1194
1195             int pathSize = searchPath.size();
1196             QDirIterator iterator(searchPath, QStringList() << nameFilter
1197                                   , QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks
1198                                   , QDirIterator::Subdirectories);
1199             // foreach dirIterator-entry in d
1200             while(iterator.hasNext()) {
1201                 iterator.next();
1202                 QString absoluteItemPath = Option::fixPathToLocalOS(QFileInfo(iterator.filePath()).absolutePath());
1203                 // Identify if it is just another subdir
1204                 int diffSize = absoluteItemPath.size() - pathSize;
1205                 // write out rules
1206                 conf.deployment.AdditionalFiles += iterator.fileName()
1207                     + "|" + absoluteItemPath
1208                     + "|" + itemDevicePath + (diffSize ? (absoluteItemPath.right(diffSize)) : QLatin1String(""))
1209                     + "|0;";
1210             }
1211         }
1212     }
1213 }
1214
1215 void VcprojGenerator::initPreLinkEventTools()
1216 {
1217     VCConfiguration &conf = vcProject.Configuration;
1218     if(!project->values("QMAKE_PRE_LINK").isEmpty()) {
1219         QStringList cmdline = VCToolBase::fixCommandLine(var("QMAKE_PRE_LINK"));
1220         conf.preLink.CommandLine = cmdline;
1221         conf.preLink.Description = cmdline.join(QLatin1String("\r\n"));
1222         conf.preLink.ExcludedFromBuild = _False;
1223     }
1224 }
1225
1226 void VcprojGenerator::initRootFiles()
1227 {
1228     // Note: Root files do _not_ have any filter name, filter nor GUID!
1229     vcProject.RootFiles.addFiles(project->values("RC_FILE"));
1230
1231     vcProject.RootFiles.Project = this;
1232     vcProject.RootFiles.Config = &(vcProject.Configuration);
1233     vcProject.RootFiles.CustomBuild = none;
1234 }
1235
1236 void VcprojGenerator::initSourceFiles()
1237 {
1238     vcProject.SourceFiles.Name = "Source Files";
1239     vcProject.SourceFiles.Filter = "cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx";
1240     vcProject.SourceFiles.Guid = _GUIDSourceFiles;
1241
1242     vcProject.SourceFiles.addFiles(project->values("SOURCES"));
1243
1244     vcProject.SourceFiles.Project = this;
1245     vcProject.SourceFiles.Config = &(vcProject.Configuration);
1246     vcProject.SourceFiles.CustomBuild = none;
1247 }
1248
1249 void VcprojGenerator::initHeaderFiles()
1250 {
1251     vcProject.HeaderFiles.Name = "Header Files";
1252     vcProject.HeaderFiles.Filter = "h;hpp;hxx;hm;inl;inc;xsd";
1253     vcProject.HeaderFiles.Guid = _GUIDHeaderFiles;
1254
1255     vcProject.HeaderFiles.addFiles(project->values("HEADERS"));
1256     if (usePCH) // Generated PCH cpp file
1257         vcProject.HeaderFiles.addFile(precompH);
1258
1259     vcProject.HeaderFiles.Project = this;
1260     vcProject.HeaderFiles.Config = &(vcProject.Configuration);
1261 //    vcProject.HeaderFiles.CustomBuild = mocHdr;
1262 //    addMocArguments(vcProject.HeaderFiles);
1263 }
1264
1265 void VcprojGenerator::initGeneratedFiles()
1266 {
1267     vcProject.GeneratedFiles.Name = "Generated Files";
1268     vcProject.GeneratedFiles.Filter = "cpp;c;cxx;moc;h;def;odl;idl;res;";
1269     vcProject.GeneratedFiles.Guid = _GUIDGeneratedFiles;
1270
1271     // ### These cannot have CustomBuild (mocSrc)!!
1272     vcProject.GeneratedFiles.addFiles(project->values("GENERATED_SOURCES"));
1273     vcProject.GeneratedFiles.addFiles(project->values("GENERATED_FILES"));
1274     vcProject.GeneratedFiles.addFiles(project->values("IDLSOURCES"));
1275     vcProject.GeneratedFiles.addFiles(project->values("RES_FILE"));
1276     vcProject.GeneratedFiles.addFiles(project->values("QMAKE_IMAGE_COLLECTION"));   // compat
1277     if(!extraCompilerOutputs.isEmpty())
1278         vcProject.GeneratedFiles.addFiles(extraCompilerOutputs.keys());
1279
1280     vcProject.GeneratedFiles.Project = this;
1281     vcProject.GeneratedFiles.Config = &(vcProject.Configuration);
1282 //    vcProject.GeneratedFiles.CustomBuild = mocSrc;
1283 }
1284
1285 void VcprojGenerator::initLexYaccFiles()
1286 {
1287     vcProject.LexYaccFiles.Name = "Lex / Yacc Files";
1288     vcProject.LexYaccFiles.ParseFiles = _False;
1289     vcProject.LexYaccFiles.Filter = "l;y";
1290     vcProject.LexYaccFiles.Guid = _GUIDLexYaccFiles;
1291
1292     vcProject.LexYaccFiles.addFiles(project->values("LEXSOURCES"));
1293     vcProject.LexYaccFiles.addFiles(project->values("YACCSOURCES"));
1294
1295     vcProject.LexYaccFiles.Project = this;
1296     vcProject.LexYaccFiles.Config = &(vcProject.Configuration);
1297     vcProject.LexYaccFiles.CustomBuild = lexyacc;
1298 }
1299
1300 void VcprojGenerator::initTranslationFiles()
1301 {
1302     vcProject.TranslationFiles.Name = "Translation Files";
1303     vcProject.TranslationFiles.ParseFiles = _False;
1304     vcProject.TranslationFiles.Filter = "ts;xlf";
1305     vcProject.TranslationFiles.Guid = _GUIDTranslationFiles;
1306
1307     vcProject.TranslationFiles.addFiles(project->values("TRANSLATIONS"));
1308
1309     vcProject.TranslationFiles.Project = this;
1310     vcProject.TranslationFiles.Config = &(vcProject.Configuration);
1311     vcProject.TranslationFiles.CustomBuild = none;
1312 }
1313
1314 void VcprojGenerator::initFormFiles()
1315 {
1316     vcProject.FormFiles.Name = "Form Files";
1317     vcProject.FormFiles.ParseFiles = _False;
1318     vcProject.FormFiles.Filter = "ui";
1319     vcProject.FormFiles.Guid = _GUIDFormFiles;
1320
1321     vcProject.FormFiles.addFiles(project->values("FORMS"));
1322     vcProject.FormFiles.addFiles(project->values("FORMS3"));
1323
1324     vcProject.FormFiles.Project = this;
1325     vcProject.FormFiles.Config = &(vcProject.Configuration);
1326     vcProject.FormFiles.CustomBuild = none;
1327 }
1328
1329 void VcprojGenerator::initResourceFiles()
1330 {
1331     vcProject.ResourceFiles.Name = "Resource Files";
1332     vcProject.ResourceFiles.ParseFiles = _False;
1333     vcProject.ResourceFiles.Filter = "qrc;*"; //"rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;ts;xlf;qrc";
1334     vcProject.ResourceFiles.Guid = _GUIDResourceFiles;
1335
1336     // Bad hack, please look away -------------------------------------
1337     QString rcc_dep_cmd = project->values("rcc.depend_command").join(" ");
1338     if(!rcc_dep_cmd.isEmpty()) {
1339         QStringList qrc_files = project->values("RESOURCES");
1340         QStringList deps;
1341         if(!qrc_files.isEmpty()) {
1342             for (int i = 0; i < qrc_files.count(); ++i) {
1343                 char buff[256];
1344                 QString dep_cmd = replaceExtraCompilerVariables(rcc_dep_cmd, qrc_files.at(i),"");
1345
1346                 dep_cmd = Option::fixPathToLocalOS(dep_cmd, true, false);
1347                 if(canExecute(dep_cmd)) {
1348                     dep_cmd.prepend(QLatin1String("cd ")
1349                                     + escapeFilePath(Option::fixPathToLocalOS(Option::output_dir, false))
1350                                     + QLatin1String(" && "));
1351                     if(FILE *proc = QT_POPEN(dep_cmd.toLatin1().constData(), "r")) {
1352                         QString indeps;
1353                         while(!feof(proc)) {
1354                             int read_in = (int)fread(buff, 1, 255, proc);
1355                             if(!read_in)
1356                                 break;
1357                             indeps += QByteArray(buff, read_in);
1358                         }
1359                         QT_PCLOSE(proc);
1360                         if(!indeps.isEmpty())
1361                             deps += fileFixify(indeps.replace('\n', ' ').simplified().split(' '),
1362                                                QString(), Option::output_dir);
1363                     }
1364                 }
1365             }
1366             vcProject.ResourceFiles.addFiles(deps);
1367         }
1368     }
1369     // You may look again --------------------------------------------
1370
1371     vcProject.ResourceFiles.addFiles(project->values("RESOURCES"));
1372     vcProject.ResourceFiles.addFiles(project->values("IMAGES"));
1373
1374     vcProject.ResourceFiles.Project = this;
1375     vcProject.ResourceFiles.Config = &(vcProject.Configuration);
1376     vcProject.ResourceFiles.CustomBuild = none;
1377 }
1378
1379 void VcprojGenerator::initExtraCompilerOutputs()
1380 {
1381     QStringList otherFilters;
1382     otherFilters << "FORMS"
1383                  << "FORMS3"
1384                  << "GENERATED_FILES"
1385                  << "GENERATED_SOURCES"
1386                  << "HEADERS"
1387                  << "IDLSOURCES"
1388                  << "IMAGES"
1389                  << "LEXSOURCES"
1390                  << "QMAKE_IMAGE_COLLECTION"
1391                  << "RC_FILE"
1392                  << "RESOURCES"
1393                  << "RES_FILE"
1394                  << "SOURCES"
1395                  << "TRANSLATIONS"
1396                  << "YACCSOURCES";
1397     const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS");
1398     for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) {
1399         QString extracompilerName = project->first((*it) + ".name");
1400         if (extracompilerName.isEmpty())
1401             extracompilerName = (*it);
1402
1403         // Create an extra compiler filter and add the files
1404         VCFilter extraCompile;
1405         extraCompile.Name = extracompilerName;
1406         extraCompile.ParseFiles = _False;
1407         extraCompile.Filter = "";
1408         extraCompile.Guid = QString(_GUIDExtraCompilerFiles) + "-" + (*it);
1409
1410
1411         // If the extra compiler has a variable_out set the output file
1412         // is added to an other file list, and does not need its own..
1413         bool addOnInput = hasBuiltinCompiler(project->first((*it) + ".output"));
1414         QString tmp_other_out = project->first((*it) + ".variable_out");
1415         if (!tmp_other_out.isEmpty() && !addOnInput)
1416             continue;
1417
1418         if (!addOnInput) {
1419             QString tmp_out = project->first((*it) + ".output");
1420             if (project->values((*it) + ".CONFIG").indexOf("combine") != -1) {
1421                 // Combined output, only one file result
1422                 extraCompile.addFile(
1423                     Option::fixPathToTargetOS(replaceExtraCompilerVariables(tmp_out, QString(), QString()), false));
1424             } else {
1425                 // One output file per input
1426                 QStringList tmp_in = project->values(project->first((*it) + ".input"));
1427                 for (int i = 0; i < tmp_in.count(); ++i) {
1428                     const QString &filename = tmp_in.at(i);
1429                     if (extraCompilerSources.contains(filename))
1430                         extraCompile.addFile(
1431                             Option::fixPathToTargetOS(replaceExtraCompilerVariables(filename, tmp_out, QString()), false));
1432                 }
1433             }
1434         } else {
1435             // In this case we the outputs have a built-in compiler, so we cannot add the custom
1436             // build steps there. So, we turn it around and add it to the input files instead,
1437             // provided that the input file variable is not handled already (those in otherFilters
1438             // are handled, so we avoid them).
1439             QStringList inputVars = project->values((*it) + ".input");
1440             foreach(QString inputVar, inputVars) {
1441                 if (!otherFilters.contains(inputVar)) {
1442                     QStringList tmp_in = project->values(inputVar);
1443                     for (int i = 0; i < tmp_in.count(); ++i) {
1444                         const QString &filename = tmp_in.at(i);
1445                         if (extraCompilerSources.contains(filename))
1446                             extraCompile.addFile(
1447                                 Option::fixPathToTargetOS(replaceExtraCompilerVariables(filename, QString(), QString()), false));
1448                     }
1449                 }
1450             }
1451         }
1452         extraCompile.Project = this;
1453         extraCompile.Config = &(vcProject.Configuration);
1454         extraCompile.CustomBuild = none;
1455
1456         vcProject.ExtraCompilersFiles.append(extraCompile);
1457     }
1458 }
1459
1460 void VcprojGenerator::initOld()
1461 {
1462     // $$QMAKE.. -> $$MSVCPROJ.. -------------------------------------
1463     const QStringList &incs = project->values("INCLUDEPATH");
1464     for (QStringList::ConstIterator incit = incs.begin(); incit != incs.end(); ++incit) {
1465         QString inc = (*incit);
1466         if (!inc.startsWith('"') && !inc.endsWith('"'))
1467             inc = QString("\"%1\"").arg(inc); // Quote all paths if not quoted already
1468         project->values("MSVCPROJ_INCPATH").append("-I" + inc);
1469     }
1470     project->values("MSVCPROJ_INCPATH").append("-I" + specdir());
1471
1472     QString dest;
1473     project->values("MSVCPROJ_TARGET") = QStringList(project->first("TARGET"));
1474     Option::fixPathToTargetOS(project->first("TARGET"));
1475     dest = project->first("TARGET") + project->first("TARGET_EXT");
1476     project->values("MSVCPROJ_TARGET") = QStringList(dest);
1477
1478     // DLL COPY ------------------------------------------------------
1479     if(project->isActiveConfig("dll") && !project->values("DLLDESTDIR").isEmpty()) {
1480         QStringList dlldirs = project->values("DLLDESTDIR");
1481         QString copydll("");
1482         QStringList::Iterator dlldir;
1483         for(dlldir = dlldirs.begin(); dlldir != dlldirs.end(); ++dlldir) {
1484             if(!copydll.isEmpty())
1485                 copydll += " && ";
1486             copydll += "copy  \"$(TargetPath)\" \"" + *dlldir + "\"";
1487         }
1488
1489         QString deststr("Copy " + dest + " to ");
1490         for(dlldir = dlldirs.begin(); dlldir != dlldirs.end();) {
1491             deststr += *dlldir;
1492             ++dlldir;
1493             if(dlldir != dlldirs.end())
1494                 deststr += ", ";
1495         }
1496
1497         project->values("MSVCPROJ_COPY_DLL").append(copydll);
1498         project->values("MSVCPROJ_COPY_DLL_DESC").append(deststr);
1499     }
1500
1501     // Verbose output if "-d -d"...
1502     outputVariables();
1503 }
1504
1505 // ------------------------------------------------------------------------------------------------
1506 // ------------------------------------------------------------------------------------------------
1507
1508 VCProjectWriter *VcprojGenerator::createProjectWriter()
1509 {
1510     return new VCProjectWriter;
1511 }
1512
1513 QString VcprojGenerator::replaceExtraCompilerVariables(const QString &var, const QStringList &in, const QStringList &out)
1514 {
1515     QString ret = MakefileGenerator::replaceExtraCompilerVariables(var, in, out);
1516
1517     QStringList &defines = project->values("VCPROJ_MAKEFILE_DEFINES");
1518     if(defines.isEmpty())
1519         defines.append(varGlue("PRL_EXPORT_DEFINES"," -D"," -D","") +
1520                        varGlue("DEFINES"," -D"," -D",""));
1521     ret.replace("$(DEFINES)", defines.first());
1522
1523     QStringList &incpath = project->values("VCPROJ_MAKEFILE_INCPATH");
1524     if(incpath.isEmpty() && !this->var("MSVCPROJ_INCPATH").isEmpty())
1525         incpath.append(this->var("MSVCPROJ_INCPATH"));
1526     ret.replace("$(INCPATH)", incpath.join(" "));
1527
1528     return ret;
1529 }
1530
1531 bool VcprojGenerator::openOutput(QFile &file, const QString &/*build*/) const
1532 {
1533     QString outdir;
1534     if(!file.fileName().isEmpty()) {
1535         QFileInfo fi(fileInfo(file.fileName()));
1536         if(fi.isDir())
1537             outdir = file.fileName() + QDir::separator();
1538     }
1539     if(!outdir.isEmpty() || file.fileName().isEmpty()) {
1540         QString ext = project->first("VCPROJ_EXTENSION");
1541         if(project->first("TEMPLATE") == "vcsubdirs")
1542             ext = project->first("VCSOLUTION_EXTENSION");
1543         QString outputName = unescapeFilePath(project->first("TARGET"));
1544         if (!project->first("MAKEFILE").isEmpty())
1545             outputName = project->first("MAKEFILE");
1546         file.setFileName(outdir + outputName + ext);
1547     }
1548     return Win32MakefileGenerator::openOutput(file, QString());
1549 }
1550
1551 QString VcprojGenerator::fixFilename(QString ofile) const
1552 {
1553     ofile = Option::fixPathToLocalOS(ofile);
1554     int slashfind = ofile.lastIndexOf(Option::dir_sep);
1555     if(slashfind == -1) {
1556         ofile = ofile.replace('-', '_');
1557     } else {
1558         int hyphenfind = ofile.indexOf('-', slashfind);
1559         while (hyphenfind != -1 && slashfind < hyphenfind) {
1560             ofile = ofile.replace(hyphenfind, 1, '_');
1561             hyphenfind = ofile.indexOf('-', hyphenfind + 1);
1562         }
1563     }
1564     return ofile;
1565 }
1566
1567 void VcprojGenerator::outputVariables()
1568 {
1569 #if 0
1570     qDebug("Generator: MSVC.NET: List of current variables:");
1571     for(QHash<QString, QStringList>::ConstIterator it = project->variables().begin(); it != project->variables().end(); ++it)
1572         qDebug("Generator: MSVC.NET: %s => %s", qPrintable(it.key()), qPrintable(it.value().join(" | ")));
1573 #endif
1574 }
1575
1576 QT_END_NAMESPACE