unifiy initialization of QMAKE_LIBS{,_PRIVATE} among windows generators
[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     if(!project->values("VERSION").isEmpty()) {
703         QString version = project->values("VERSION")[0];
704         int firstDot = version.indexOf(".");
705         QString major = version.left(firstDot);
706         QString minor = version.right(version.length() - firstDot - 1);
707         minor.replace(QRegExp("\\."), "");
708         project->values("QMAKE_LFLAGS").append("/VERSION:" + major + "." + minor);
709     }
710
711     MakefileGenerator::init();
712     initOld();           // Currently calling old DSP code to set variables. CLEAN UP!
713
714     // Figure out what we're trying to build
715     if(project->first("TEMPLATE") == "vcapp") {
716         projectTarget = Application;
717     } else if(project->first("TEMPLATE") == "vclib") {
718         if(project->isActiveConfig("staticlib")) {
719             if (!project->values("RES_FILE").isEmpty())
720                 project->values("QMAKE_LIBS") += escapeFilePaths(project->values("RES_FILE"));
721             projectTarget = StaticLib;
722         } else
723             projectTarget = SharedLib;
724     }
725
726     // Setup PCH variables
727     precompH = project->first("PRECOMPILED_HEADER");
728     precompCPP = project->first("PRECOMPILED_SOURCE");
729     usePCH = !precompH.isEmpty() && project->isActiveConfig("precompile_header");
730     if (usePCH) {
731         precompHFilename = fileInfo(precompH).fileName();
732         // Created files
733         QString origTarget = unescapeFilePath(project->first("QMAKE_ORIG_TARGET"));
734         precompObj = origTarget + Option::obj_ext;
735         precompPch = origTarget + ".pch";
736         // Add PRECOMPILED_HEADER to HEADERS
737         if (!project->values("HEADERS").contains(precompH))
738             project->values("HEADERS") += precompH;
739         // Return to variable pool
740         project->values("PRECOMPILED_OBJECT") = QStringList(precompObj);
741         project->values("PRECOMPILED_PCH")    = QStringList(precompPch);
742
743         autogenPrecompCPP = precompCPP.isEmpty() && project->isActiveConfig("autogen_precompile_source");
744         if (autogenPrecompCPP) {
745             precompCPP = precompH
746                 + (Option::cpp_ext.count() ? Option::cpp_ext.at(0) : QLatin1String(".cpp"));
747             project->values("GENERATED_SOURCES") += precompCPP;
748         } else if (!precompCPP.isEmpty()) {
749             project->values("SOURCES") += precompCPP;
750         }
751     }
752
753     // Add all input files for a custom compiler into a map for uniqueness,
754     // unless the compiler is configure as a combined stage, then use the first one
755     const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS");
756     for(QStringList::ConstIterator it = quc.constBegin(); it != quc.constEnd(); ++it) {
757         const QStringList &invar = project->values(*it + ".input");
758         const QString compiler_out = project->first((*it) + ".output");
759         for(QStringList::ConstIterator iit = invar.constBegin(); iit != invar.constEnd(); ++iit) {
760             QStringList fileList = project->values(*iit);
761             if (!fileList.isEmpty()) {
762                 if (project->values((*it) + ".CONFIG").indexOf("combine") != -1)
763                     fileList = QStringList(fileList.first());
764                 for(QStringList::ConstIterator fit = fileList.constBegin(); fit != fileList.constEnd(); ++fit) {
765                     QString file = (*fit);
766                     if (verifyExtraCompiler((*it), file)) {
767                         if (!hasBuiltinCompiler(file)) {
768                             extraCompilerSources[file] += *it;
769                         } else {
770                             QString out = Option::fixPathToTargetOS(replaceExtraCompilerVariables(
771                                             compiler_out, file, QString()), false);
772                             extraCompilerSources[out] += *it;
773                             extraCompilerOutputs[out] = QStringList(file); // Can only have one
774                         }
775                     }
776                 }
777             }
778         }
779     }
780
781 #if 0 // Debugging
782     Q_FOREACH(QString aKey, extraCompilerSources.keys()) {
783         qDebug("Extracompilers for %s are (%s)", aKey.toLatin1().constData(), extraCompilerSources.value(aKey).join(", ").toLatin1().constData());
784     }
785     Q_FOREACH(QString aKey, extraCompilerOutputs.keys()) {
786         qDebug("Object mapping for %s is (%s)", aKey.toLatin1().constData(), extraCompilerOutputs.value(aKey).join(", ").toLatin1().constData());
787     }
788     qDebug("");
789 #endif
790 }
791
792 bool VcprojGenerator::mergeBuildProject(MakefileGenerator *other)
793 {
794     if (!other || !other->projectFile()) {
795         warn_msg(WarnLogic, "VcprojGenerator: Cannot merge null project.");
796         return false;
797     }
798     if (other->projectFile()->first("MAKEFILE_GENERATOR") != project->first("MAKEFILE_GENERATOR")) {
799         warn_msg(WarnLogic, "VcprojGenerator: Cannot merge other types of projects! (ignored)");
800         return false;
801     }
802
803     VcprojGenerator *otherVC = static_cast<VcprojGenerator*>(other);
804     mergedProjects += otherVC;
805     return true;
806 }
807
808 void VcprojGenerator::initProject()
809 {
810     // Initialize XML sub elements
811     // - Do this first since project elements may need
812     // - to know of certain configuration options
813     initConfiguration();
814     initRootFiles();
815     initSourceFiles();
816     initHeaderFiles();
817     initGeneratedFiles();
818     initLexYaccFiles();
819     initTranslationFiles();
820     initFormFiles();
821     initResourceFiles();
822     initExtraCompilerOutputs();
823
824     // Own elements -----------------------------
825     vcProject.Name = unescapeFilePath(project->first("QMAKE_ORIG_TARGET"));
826     switch(which_dotnet_version()) {
827     case NET2010:
828         vcProject.Version = "10.00";
829         break;
830     case NET2008:
831         vcProject.Version = "9,00";
832         break;
833     case NET2005:
834                 //### using ',' because of a bug in 2005 B2
835                 //### VS uses '.' or ',' depending on the regional settings! Using ',' always works.
836         vcProject.Version = "8,00";
837         break;
838     case NET2003:
839         vcProject.Version = "7.10";
840         break;
841     case NET2002:
842         vcProject.Version = "7.00";
843         break;
844     default:
845         vcProject.Version = "7.00";
846         warn_msg(WarnLogic, "Generator: MSVC.NET: Unknown version (%d) of MSVC detected for .vcproj", which_dotnet_version());
847         break;
848     }
849
850     vcProject.Keyword = project->first("VCPROJ_KEYWORD");
851     if (project->isHostBuild() || project->isEmpty("CE_SDK") || project->isEmpty("CE_ARCH")) {
852         vcProject.PlatformName = (is64Bit ? "x64" : "Win32");
853     } else {
854         vcProject.PlatformName = project->values("CE_SDK").join(" ") + " (" + project->first("CE_ARCH") + ")";
855     }
856     // These are not used by Qt, but may be used by customers
857     vcProject.SccProjectName = project->first("SCCPROJECTNAME");
858     vcProject.SccLocalPath = project->first("SCCLOCALPATH");
859     vcProject.flat_files = project->isActiveConfig("flat");
860 }
861
862 void VcprojGenerator::initConfiguration()
863 {
864     // Initialize XML sub elements
865     // - Do this first since main configuration elements may need
866     // - to know of certain compiler/linker options
867     VCConfiguration &conf = vcProject.Configuration;
868     conf.CompilerVersion = which_dotnet_version();
869
870     initCompilerTool();
871
872     // Only on configuration per build
873     bool isDebug = project->isActiveConfig("debug");
874
875     if(projectTarget == StaticLib)
876         initLibrarianTool();
877     else {
878         conf.linker.GenerateDebugInformation = isDebug ? _True : _False;
879         initLinkerTool();
880     }
881     initResourceTool();
882     initIDLTool();
883
884     // Own elements -----------------------------
885     QString temp = project->first("BuildBrowserInformation");
886     switch (projectTarget) {
887     case SharedLib:
888         conf.ConfigurationType = typeDynamicLibrary;
889         break;
890     case StaticLib:
891         conf.ConfigurationType = typeStaticLibrary;
892         break;
893     case Application:
894     default:
895         conf.ConfigurationType = typeApplication;
896         break;
897     }
898
899     conf.OutputDirectory = project->first("DESTDIR");
900     if (conf.OutputDirectory.isEmpty())
901         conf.OutputDirectory = ".\\";
902     if (!conf.OutputDirectory.endsWith("\\"))
903         conf.OutputDirectory += '\\';
904     if (conf.CompilerVersion >= NET2010) {
905         // The target name could have been changed.
906         conf.PrimaryOutput = project->first("TARGET");
907         if ( !conf.PrimaryOutput.isEmpty() && !project->first("TARGET_VERSION_EXT").isEmpty() && project->isActiveConfig("shared"))
908             conf.PrimaryOutput.append(project->first("TARGET_VERSION_EXT"));
909     }
910
911     conf.Name = project->values("BUILD_NAME").join(" ");
912     if (conf.Name.isEmpty())
913         conf.Name = isDebug ? "Debug" : "Release";
914     conf.ConfigurationName = conf.Name;
915     if (project->isHostBuild() || project->isEmpty("CE_SDK") || project->isEmpty("CE_ARCH")) {
916         conf.Name += (is64Bit ? "|x64" : "|Win32");
917     } else {
918         conf.Name += "|" + project->values("CE_SDK").join(" ") + " (" + project->first("CE_ARCH") + ")";
919     }
920     conf.ATLMinimizesCRunTimeLibraryUsage = (project->first("ATLMinimizesCRunTimeLibraryUsage").isEmpty() ? _False : _True);
921     conf.BuildBrowserInformation = triState(temp.isEmpty() ? (short)unset : temp.toShort());
922     temp = project->first("CharacterSet");
923     conf.CharacterSet = charSet(temp.isEmpty() ? (short)charSetNotSet : temp.toShort());
924     conf.DeleteExtensionsOnClean = project->first("DeleteExtensionsOnClean");
925     conf.ImportLibrary = conf.linker.ImportLibrary;
926     conf.IntermediateDirectory = project->first("OBJECTS_DIR");
927     conf.WholeProgramOptimization = conf.compiler.WholeProgramOptimization;
928     temp = project->first("UseOfATL");
929     if(!temp.isEmpty())
930         conf.UseOfATL = useOfATL(temp.toShort());
931     temp = project->first("UseOfMfc");
932     if(!temp.isEmpty())
933         conf.UseOfMfc = useOfMfc(temp.toShort());
934
935     // Configuration does not need parameters from
936     // these sub XML items;
937     initCustomBuildTool();
938     initPreBuildEventTools();
939     initPostBuildEventTools();
940     // Only deploy for CE projects
941     if (!project->isHostBuild() && !project->isEmpty("CE_SDK") && !project->isEmpty("CE_ARCH"))
942         initDeploymentTool();
943     initPreLinkEventTools();
944
945     // Set definite values in both configurations
946     if (isDebug) {
947         conf.compiler.PreprocessorDefinitions.removeAll("NDEBUG");
948     } else {
949         conf.compiler.PreprocessorDefinitions += "NDEBUG";
950     }
951 }
952
953 void VcprojGenerator::initCompilerTool()
954 {
955     QString placement = project->first("OBJECTS_DIR");
956     if(placement.isEmpty())
957         placement = ".\\";
958
959     VCConfiguration &conf = vcProject.Configuration;
960     if (conf.CompilerVersion >= NET2010) {
961         // adjust compiler tool defaults for VS 2010 and above
962         conf.compiler.Optimization = optimizeDisabled;
963     }
964     conf.compiler.AssemblerListingLocation = placement ;
965     conf.compiler.ProgramDataBaseFileName = ".\\" ;
966     conf.compiler.ObjectFile = placement ;
967     conf.compiler.ExceptionHandling = ehNone;
968     // PCH
969     if (usePCH) {
970         conf.compiler.UsePrecompiledHeader     = pchUseUsingSpecific;
971         conf.compiler.PrecompiledHeaderFile    = "$(IntDir)\\" + precompPch;
972         conf.compiler.PrecompiledHeaderThrough = project->first("PRECOMPILED_HEADER");
973         conf.compiler.ForcedIncludeFiles       = project->values("PRECOMPILED_HEADER");
974
975         if (conf.CompilerVersion <= NET2003) {
976             // Minimal build option triggers an Internal Compiler Error
977             // when used in conjunction with /FI and /Yu, so remove it
978             // ### work-around for a VS 2003 bug. Move to some prf file or remove completely.
979             project->values("QMAKE_CFLAGS_DEBUG").removeAll("-Gm");
980             project->values("QMAKE_CFLAGS_DEBUG").removeAll("/Gm");
981             project->values("QMAKE_CXXFLAGS_DEBUG").removeAll("-Gm");
982             project->values("QMAKE_CXXFLAGS_DEBUG").removeAll("/Gm");
983         }
984     }
985
986     conf.compiler.parseOptions(project->values("QMAKE_CXXFLAGS"));
987
988     if (project->isActiveConfig("windows"))
989         conf.compiler.PreprocessorDefinitions += "_WINDOWS";
990     else if (project->isActiveConfig("console"))
991         conf.compiler.PreprocessorDefinitions += "_CONSOLE";
992
993     conf.compiler.PreprocessorDefinitions += project->values("DEFINES");
994     conf.compiler.PreprocessorDefinitions += project->values("PRL_EXPORT_DEFINES");
995     conf.compiler.parseOptions(project->values("MSVCPROJ_INCPATH"));
996 }
997
998 void VcprojGenerator::initLibrarianTool()
999 {
1000     VCConfiguration &conf = vcProject.Configuration;
1001     conf.librarian.OutputFile = "$(OutDir)\\";
1002     conf.librarian.OutputFile += project->first("MSVCPROJ_TARGET");
1003     conf.librarian.AdditionalOptions += project->values("QMAKE_LIBFLAGS");
1004 }
1005
1006 void VcprojGenerator::initLinkerTool()
1007 {
1008     VCConfiguration &conf = vcProject.Configuration;
1009     conf.linker.parseOptions(project->values("QMAKE_LFLAGS"));
1010
1011     foreach (const QString &libDir, project->values("QMAKE_LIBDIR")) {
1012         if (libDir.startsWith("/LIBPATH:"))
1013             conf.linker.AdditionalLibraryDirectories += libDir.mid(9);
1014         else
1015             conf.linker.AdditionalLibraryDirectories += libDir;
1016     }
1017
1018     if (!project->values("DEF_FILE").isEmpty())
1019         conf.linker.ModuleDefinitionFile = project->first("DEF_FILE");
1020
1021     foreach (QString libs, project->values("QMAKE_LIBS") + project->values("QMAKE_LIBS_PRIVATE")) {
1022         if (libs.left(9).toUpper() == "/LIBPATH:") {
1023             QStringList l = QStringList(libs);
1024             conf.linker.parseOptions(l);
1025         } else {
1026             conf.linker.AdditionalDependencies += libs;
1027         }
1028     }
1029
1030     conf.linker.OutputFile = "$(OutDir)\\";
1031     conf.linker.OutputFile += project->first("MSVCPROJ_TARGET");
1032
1033     if(project->isActiveConfig("dll")){
1034         conf.linker.parseOptions(project->values("QMAKE_LFLAGS_QT_DLL"));
1035     }
1036 }
1037
1038 void VcprojGenerator::initResourceTool()
1039 {
1040     VCConfiguration &conf = vcProject.Configuration;
1041     conf.resource.PreprocessorDefinitions = conf.compiler.PreprocessorDefinitions;
1042
1043     // We need to add _DEBUG for the debug version of the project, since the normal compiler defines
1044     // do not contain it. (The compiler defines this symbol automatically, which is wy we don't need
1045     // to add it for the compiler) However, the resource tool does not do this.
1046     if(project->isActiveConfig("debug"))
1047         conf.resource.PreprocessorDefinitions += "_DEBUG";
1048     if(project->isActiveConfig("staticlib"))
1049         conf.resource.ResourceOutputFileName = "$(OutDir)\\$(InputName).res";
1050 }
1051
1052 void VcprojGenerator::initIDLTool()
1053 {
1054 }
1055
1056 void VcprojGenerator::initCustomBuildTool()
1057 {
1058 }
1059
1060 void VcprojGenerator::initPreBuildEventTools()
1061 {
1062 }
1063
1064 void VcprojGenerator::initPostBuildEventTools()
1065 {
1066     VCConfiguration &conf = vcProject.Configuration;
1067     if (!project->values("QMAKE_POST_LINK").isEmpty()) {
1068         QStringList cmdline = VCToolBase::fixCommandLine(var("QMAKE_POST_LINK"));
1069         conf.postBuild.CommandLine = cmdline;
1070         conf.postBuild.Description = cmdline.join(QLatin1String("\r\n"));
1071         conf.postBuild.ExcludedFromBuild = _False;
1072     }
1073
1074     QString signature = !project->isEmpty("SIGNATURE_FILE") ? var("SIGNATURE_FILE") : var("DEFAULT_SIGNATURE");
1075     bool useSignature = !signature.isEmpty() && !project->isActiveConfig("staticlib") &&
1076                         !project->isHostBuild() && !project->isEmpty("CE_SDK") && !project->isEmpty("CE_ARCH");
1077     if (useSignature) {
1078         conf.postBuild.CommandLine.prepend(
1079                 QLatin1String("signtool sign /F ") + signature + QLatin1String(" \"$(TargetPath)\""));
1080         conf.postBuild.ExcludedFromBuild = _False;
1081     }
1082
1083     if (!project->values("MSVCPROJ_COPY_DLL").isEmpty()) {
1084         conf.postBuild.Description += var("MSVCPROJ_COPY_DLL_DESC");
1085         conf.postBuild.CommandLine += var("MSVCPROJ_COPY_DLL");
1086         conf.postBuild.ExcludedFromBuild = _False;
1087     }
1088 }
1089
1090 void VcprojGenerator::initDeploymentTool()
1091 {
1092     VCConfiguration &conf = vcProject.Configuration;
1093     QString targetPath = project->values("deploy.path").join(" ");
1094     if (targetPath.isEmpty())
1095         targetPath = QString("%CSIDL_PROGRAM_FILES%\\") + project->first("TARGET");
1096     if (targetPath.endsWith("/") || targetPath.endsWith("\\"))
1097         targetPath.chop(1);
1098
1099     // Only deploy Qt libs for shared build
1100     if (!project->values("QMAKE_QT_DLL").isEmpty()) {
1101         // FIXME: This code should actually resolve the libraries from all Qt modules.
1102         const QString &qtdir = QLibraryInfo::rawLocation(QLibraryInfo::LibrariesPath,
1103                                                          QLibraryInfo::EffectivePaths);
1104         QStringList arg = project->values("QMAKE_LIBS") + project->values("QMAKE_LIBS_PRIVATE");
1105         for (QStringList::ConstIterator it = arg.constBegin(); it != arg.constEnd(); ++it) {
1106             if (it->contains(qtdir)) {
1107                 QString dllName = *it;
1108
1109                 if (dllName.contains(QLatin1String("QAxContainer"))
1110                     || dllName.contains(QLatin1String("qtmain"))
1111                     || dllName.contains(QLatin1String("QtUiTools")))
1112                     continue;
1113                 dllName.replace(QLatin1String(".lib") , QLatin1String(".dll"));
1114                 QFileInfo info(dllName);
1115                 conf.deployment.AdditionalFiles += info.fileName()
1116                                                 + "|" + QDir::toNativeSeparators(info.absolutePath())
1117                                                 + "|" + targetPath
1118                                                 + "|0;";
1119             }
1120         }
1121     }
1122
1123     // C-runtime deployment
1124     QString runtime = project->values("QT_CE_C_RUNTIME").join(QLatin1String(" "));
1125     if (!runtime.isEmpty() && (runtime != QLatin1String("no"))) {
1126         QString runtimeVersion = QLatin1String("msvcr");
1127         QString mkspec = project->first("QMAKESPEC");
1128         // If no .qmake.cache has been found, we fallback to the original mkspec
1129         if (mkspec.isEmpty())
1130             mkspec = project->first("QMAKESPEC_ORIGINAL");
1131
1132         if (!mkspec.isEmpty()) {
1133             if (mkspec.endsWith("2008"))
1134                 runtimeVersion.append("90");
1135             else
1136                 runtimeVersion.append("80");
1137             if (project->isActiveConfig("debug"))
1138                 runtimeVersion.append("d");
1139             runtimeVersion.append(".dll");
1140
1141             if (runtime == "yes") {
1142                 // Auto-find C-runtime
1143                 QString vcInstallDir = qgetenv("VCINSTALLDIR");
1144                 if (!vcInstallDir.isEmpty()) {
1145                     vcInstallDir += "\\ce\\dll\\";
1146                     vcInstallDir += project->values("CE_ARCH").join(QLatin1String(" "));
1147                     if (!QFileInfo(vcInstallDir + QDir::separator() + runtimeVersion).exists())
1148                         runtime.clear();
1149                     else
1150                         runtime = vcInstallDir;
1151                 }
1152             }
1153         }
1154
1155         if (!runtime.isEmpty() && runtime != QLatin1String("yes")) {
1156             conf.deployment.AdditionalFiles += runtimeVersion
1157                                             + "|" + QDir::toNativeSeparators(runtime)
1158                                             + "|" + targetPath
1159                                             + "|0;";
1160         }
1161     }
1162
1163     // foreach item in DEPLOYMENT
1164     foreach(QString item, project->values("DEPLOYMENT")) {
1165         // get item.path
1166         QString devicePath = project->first(item + ".path");
1167         if (devicePath.isEmpty())
1168             devicePath = targetPath;
1169         // check if item.path is relative (! either /,\ or %)
1170         if (!(devicePath.at(0) == QLatin1Char('/')
1171             || devicePath.at(0) == QLatin1Char('\\')
1172             || devicePath.at(0) == QLatin1Char('%'))) {
1173             // create output path
1174             devicePath = Option::fixPathToLocalOS(QDir::cleanPath(targetPath + QLatin1Char('\\') + devicePath));
1175         }
1176         // foreach d in item.files
1177         foreach (QString source, project->values(item + ".files")) {
1178             QString itemDevicePath = devicePath;
1179             source = Option::fixPathToLocalOS(source);
1180             QString nameFilter;
1181             QFileInfo info(source);
1182             QString searchPath;
1183             if (info.isDir()) {
1184                 nameFilter = QLatin1String("*");
1185                 itemDevicePath += "\\" + info.fileName();
1186                 searchPath = info.absoluteFilePath();
1187             } else {
1188                 nameFilter = source.split('\\').last();
1189                 searchPath = info.absolutePath();
1190             }
1191
1192             int pathSize = searchPath.size();
1193             QDirIterator iterator(searchPath, QStringList() << nameFilter
1194                                   , QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks
1195                                   , QDirIterator::Subdirectories);
1196             // foreach dirIterator-entry in d
1197             while(iterator.hasNext()) {
1198                 iterator.next();
1199                 QString absoluteItemPath = Option::fixPathToLocalOS(QFileInfo(iterator.filePath()).absolutePath());
1200                 // Identify if it is just another subdir
1201                 int diffSize = absoluteItemPath.size() - pathSize;
1202                 // write out rules
1203                 conf.deployment.AdditionalFiles += iterator.fileName()
1204                     + "|" + absoluteItemPath
1205                     + "|" + itemDevicePath + (diffSize ? (absoluteItemPath.right(diffSize)) : QLatin1String(""))
1206                     + "|0;";
1207             }
1208         }
1209     }
1210 }
1211
1212 void VcprojGenerator::initPreLinkEventTools()
1213 {
1214     VCConfiguration &conf = vcProject.Configuration;
1215     if(!project->values("QMAKE_PRE_LINK").isEmpty()) {
1216         QStringList cmdline = VCToolBase::fixCommandLine(var("QMAKE_PRE_LINK"));
1217         conf.preLink.CommandLine = cmdline;
1218         conf.preLink.Description = cmdline.join(QLatin1String("\r\n"));
1219         conf.preLink.ExcludedFromBuild = _False;
1220     }
1221 }
1222
1223 void VcprojGenerator::initRootFiles()
1224 {
1225     // Note: Root files do _not_ have any filter name, filter nor GUID!
1226     vcProject.RootFiles.addFiles(project->values("RC_FILE"));
1227
1228     vcProject.RootFiles.Project = this;
1229     vcProject.RootFiles.Config = &(vcProject.Configuration);
1230     vcProject.RootFiles.CustomBuild = none;
1231 }
1232
1233 void VcprojGenerator::initSourceFiles()
1234 {
1235     vcProject.SourceFiles.Name = "Source Files";
1236     vcProject.SourceFiles.Filter = "cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx";
1237     vcProject.SourceFiles.Guid = _GUIDSourceFiles;
1238
1239     vcProject.SourceFiles.addFiles(project->values("SOURCES"));
1240
1241     vcProject.SourceFiles.Project = this;
1242     vcProject.SourceFiles.Config = &(vcProject.Configuration);
1243     vcProject.SourceFiles.CustomBuild = none;
1244 }
1245
1246 void VcprojGenerator::initHeaderFiles()
1247 {
1248     vcProject.HeaderFiles.Name = "Header Files";
1249     vcProject.HeaderFiles.Filter = "h;hpp;hxx;hm;inl;inc;xsd";
1250     vcProject.HeaderFiles.Guid = _GUIDHeaderFiles;
1251
1252     vcProject.HeaderFiles.addFiles(project->values("HEADERS"));
1253     if (usePCH) // Generated PCH cpp file
1254         vcProject.HeaderFiles.addFile(precompH);
1255
1256     vcProject.HeaderFiles.Project = this;
1257     vcProject.HeaderFiles.Config = &(vcProject.Configuration);
1258 //    vcProject.HeaderFiles.CustomBuild = mocHdr;
1259 //    addMocArguments(vcProject.HeaderFiles);
1260 }
1261
1262 void VcprojGenerator::initGeneratedFiles()
1263 {
1264     vcProject.GeneratedFiles.Name = "Generated Files";
1265     vcProject.GeneratedFiles.Filter = "cpp;c;cxx;moc;h;def;odl;idl;res;";
1266     vcProject.GeneratedFiles.Guid = _GUIDGeneratedFiles;
1267
1268     // ### These cannot have CustomBuild (mocSrc)!!
1269     vcProject.GeneratedFiles.addFiles(project->values("GENERATED_SOURCES"));
1270     vcProject.GeneratedFiles.addFiles(project->values("GENERATED_FILES"));
1271     vcProject.GeneratedFiles.addFiles(project->values("IDLSOURCES"));
1272     vcProject.GeneratedFiles.addFiles(project->values("RES_FILE"));
1273     vcProject.GeneratedFiles.addFiles(project->values("QMAKE_IMAGE_COLLECTION"));   // compat
1274     if(!extraCompilerOutputs.isEmpty())
1275         vcProject.GeneratedFiles.addFiles(extraCompilerOutputs.keys());
1276
1277     vcProject.GeneratedFiles.Project = this;
1278     vcProject.GeneratedFiles.Config = &(vcProject.Configuration);
1279 //    vcProject.GeneratedFiles.CustomBuild = mocSrc;
1280 }
1281
1282 void VcprojGenerator::initLexYaccFiles()
1283 {
1284     vcProject.LexYaccFiles.Name = "Lex / Yacc Files";
1285     vcProject.LexYaccFiles.ParseFiles = _False;
1286     vcProject.LexYaccFiles.Filter = "l;y";
1287     vcProject.LexYaccFiles.Guid = _GUIDLexYaccFiles;
1288
1289     vcProject.LexYaccFiles.addFiles(project->values("LEXSOURCES"));
1290     vcProject.LexYaccFiles.addFiles(project->values("YACCSOURCES"));
1291
1292     vcProject.LexYaccFiles.Project = this;
1293     vcProject.LexYaccFiles.Config = &(vcProject.Configuration);
1294     vcProject.LexYaccFiles.CustomBuild = lexyacc;
1295 }
1296
1297 void VcprojGenerator::initTranslationFiles()
1298 {
1299     vcProject.TranslationFiles.Name = "Translation Files";
1300     vcProject.TranslationFiles.ParseFiles = _False;
1301     vcProject.TranslationFiles.Filter = "ts;xlf";
1302     vcProject.TranslationFiles.Guid = _GUIDTranslationFiles;
1303
1304     vcProject.TranslationFiles.addFiles(project->values("TRANSLATIONS"));
1305
1306     vcProject.TranslationFiles.Project = this;
1307     vcProject.TranslationFiles.Config = &(vcProject.Configuration);
1308     vcProject.TranslationFiles.CustomBuild = none;
1309 }
1310
1311 void VcprojGenerator::initFormFiles()
1312 {
1313     vcProject.FormFiles.Name = "Form Files";
1314     vcProject.FormFiles.ParseFiles = _False;
1315     vcProject.FormFiles.Filter = "ui";
1316     vcProject.FormFiles.Guid = _GUIDFormFiles;
1317
1318     vcProject.FormFiles.addFiles(project->values("FORMS"));
1319     vcProject.FormFiles.addFiles(project->values("FORMS3"));
1320
1321     vcProject.FormFiles.Project = this;
1322     vcProject.FormFiles.Config = &(vcProject.Configuration);
1323     vcProject.FormFiles.CustomBuild = none;
1324 }
1325
1326 void VcprojGenerator::initResourceFiles()
1327 {
1328     vcProject.ResourceFiles.Name = "Resource Files";
1329     vcProject.ResourceFiles.ParseFiles = _False;
1330     vcProject.ResourceFiles.Filter = "qrc;*"; //"rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;ts;xlf;qrc";
1331     vcProject.ResourceFiles.Guid = _GUIDResourceFiles;
1332
1333     // Bad hack, please look away -------------------------------------
1334     QString rcc_dep_cmd = project->values("rcc.depend_command").join(" ");
1335     if(!rcc_dep_cmd.isEmpty()) {
1336         QStringList qrc_files = project->values("RESOURCES");
1337         QStringList deps;
1338         if(!qrc_files.isEmpty()) {
1339             for (int i = 0; i < qrc_files.count(); ++i) {
1340                 char buff[256];
1341                 QString dep_cmd = replaceExtraCompilerVariables(rcc_dep_cmd, qrc_files.at(i),"");
1342
1343                 dep_cmd = Option::fixPathToLocalOS(dep_cmd, true, false);
1344                 if(canExecute(dep_cmd)) {
1345                     dep_cmd.prepend(QLatin1String("cd ")
1346                                     + escapeFilePath(Option::fixPathToLocalOS(Option::output_dir, false))
1347                                     + QLatin1String(" && "));
1348                     if(FILE *proc = QT_POPEN(dep_cmd.toLatin1().constData(), "r")) {
1349                         QString indeps;
1350                         while(!feof(proc)) {
1351                             int read_in = (int)fread(buff, 1, 255, proc);
1352                             if(!read_in)
1353                                 break;
1354                             indeps += QByteArray(buff, read_in);
1355                         }
1356                         QT_PCLOSE(proc);
1357                         if(!indeps.isEmpty())
1358                             deps += fileFixify(indeps.replace('\n', ' ').simplified().split(' '),
1359                                                QString(), Option::output_dir);
1360                     }
1361                 }
1362             }
1363             vcProject.ResourceFiles.addFiles(deps);
1364         }
1365     }
1366     // You may look again --------------------------------------------
1367
1368     vcProject.ResourceFiles.addFiles(project->values("RESOURCES"));
1369     vcProject.ResourceFiles.addFiles(project->values("IMAGES"));
1370
1371     vcProject.ResourceFiles.Project = this;
1372     vcProject.ResourceFiles.Config = &(vcProject.Configuration);
1373     vcProject.ResourceFiles.CustomBuild = none;
1374 }
1375
1376 void VcprojGenerator::initExtraCompilerOutputs()
1377 {
1378     QStringList otherFilters;
1379     otherFilters << "FORMS"
1380                  << "FORMS3"
1381                  << "GENERATED_FILES"
1382                  << "GENERATED_SOURCES"
1383                  << "HEADERS"
1384                  << "IDLSOURCES"
1385                  << "IMAGES"
1386                  << "LEXSOURCES"
1387                  << "QMAKE_IMAGE_COLLECTION"
1388                  << "RC_FILE"
1389                  << "RESOURCES"
1390                  << "RES_FILE"
1391                  << "SOURCES"
1392                  << "TRANSLATIONS"
1393                  << "YACCSOURCES";
1394     const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS");
1395     for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) {
1396         QString extracompilerName = project->first((*it) + ".name");
1397         if (extracompilerName.isEmpty())
1398             extracompilerName = (*it);
1399
1400         // Create an extra compiler filter and add the files
1401         VCFilter extraCompile;
1402         extraCompile.Name = extracompilerName;
1403         extraCompile.ParseFiles = _False;
1404         extraCompile.Filter = "";
1405         extraCompile.Guid = QString(_GUIDExtraCompilerFiles) + "-" + (*it);
1406
1407
1408         // If the extra compiler has a variable_out set the output file
1409         // is added to an other file list, and does not need its own..
1410         bool addOnInput = hasBuiltinCompiler(project->first((*it) + ".output"));
1411         QString tmp_other_out = project->first((*it) + ".variable_out");
1412         if (!tmp_other_out.isEmpty() && !addOnInput)
1413             continue;
1414
1415         if (!addOnInput) {
1416             QString tmp_out = project->first((*it) + ".output");
1417             if (project->values((*it) + ".CONFIG").indexOf("combine") != -1) {
1418                 // Combined output, only one file result
1419                 extraCompile.addFile(
1420                     Option::fixPathToTargetOS(replaceExtraCompilerVariables(tmp_out, QString(), QString()), false));
1421             } else {
1422                 // One output file per input
1423                 QStringList tmp_in = project->values(project->first((*it) + ".input"));
1424                 for (int i = 0; i < tmp_in.count(); ++i) {
1425                     const QString &filename = tmp_in.at(i);
1426                     if (extraCompilerSources.contains(filename))
1427                         extraCompile.addFile(
1428                             Option::fixPathToTargetOS(replaceExtraCompilerVariables(filename, tmp_out, QString()), false));
1429                 }
1430             }
1431         } else {
1432             // In this case we the outputs have a built-in compiler, so we cannot add the custom
1433             // build steps there. So, we turn it around and add it to the input files instead,
1434             // provided that the input file variable is not handled already (those in otherFilters
1435             // are handled, so we avoid them).
1436             QStringList inputVars = project->values((*it) + ".input");
1437             foreach(QString inputVar, inputVars) {
1438                 if (!otherFilters.contains(inputVar)) {
1439                     QStringList tmp_in = project->values(inputVar);
1440                     for (int i = 0; i < tmp_in.count(); ++i) {
1441                         const QString &filename = tmp_in.at(i);
1442                         if (extraCompilerSources.contains(filename))
1443                             extraCompile.addFile(
1444                                 Option::fixPathToTargetOS(replaceExtraCompilerVariables(filename, QString(), QString()), false));
1445                     }
1446                 }
1447             }
1448         }
1449         extraCompile.Project = this;
1450         extraCompile.Config = &(vcProject.Configuration);
1451         extraCompile.CustomBuild = none;
1452
1453         vcProject.ExtraCompilersFiles.append(extraCompile);
1454     }
1455 }
1456
1457 void VcprojGenerator::initOld()
1458 {
1459     // $$QMAKE.. -> $$MSVCPROJ.. -------------------------------------
1460     const QStringList &incs = project->values("INCLUDEPATH");
1461     for (QStringList::ConstIterator incit = incs.begin(); incit != incs.end(); ++incit) {
1462         QString inc = (*incit);
1463         if (!inc.startsWith('"') && !inc.endsWith('"'))
1464             inc = QString("\"%1\"").arg(inc); // Quote all paths if not quoted already
1465         project->values("MSVCPROJ_INCPATH").append("-I" + inc);
1466     }
1467     project->values("MSVCPROJ_INCPATH").append("-I" + specdir());
1468
1469     QString dest;
1470     project->values("MSVCPROJ_TARGET") = QStringList(project->first("TARGET"));
1471     Option::fixPathToTargetOS(project->first("TARGET"));
1472     dest = project->first("TARGET") + project->first("TARGET_EXT");
1473     project->values("MSVCPROJ_TARGET") = QStringList(dest);
1474
1475     // DLL COPY ------------------------------------------------------
1476     if(project->isActiveConfig("dll") && !project->values("DLLDESTDIR").isEmpty()) {
1477         QStringList dlldirs = project->values("DLLDESTDIR");
1478         QString copydll("");
1479         QStringList::Iterator dlldir;
1480         for(dlldir = dlldirs.begin(); dlldir != dlldirs.end(); ++dlldir) {
1481             if(!copydll.isEmpty())
1482                 copydll += " && ";
1483             copydll += "copy  \"$(TargetPath)\" \"" + *dlldir + "\"";
1484         }
1485
1486         QString deststr("Copy " + dest + " to ");
1487         for(dlldir = dlldirs.begin(); dlldir != dlldirs.end();) {
1488             deststr += *dlldir;
1489             ++dlldir;
1490             if(dlldir != dlldirs.end())
1491                 deststr += ", ";
1492         }
1493
1494         project->values("MSVCPROJ_COPY_DLL").append(copydll);
1495         project->values("MSVCPROJ_COPY_DLL_DESC").append(deststr);
1496     }
1497
1498     // Verbose output if "-d -d"...
1499     outputVariables();
1500 }
1501
1502 // ------------------------------------------------------------------------------------------------
1503 // ------------------------------------------------------------------------------------------------
1504
1505 VCProjectWriter *VcprojGenerator::createProjectWriter()
1506 {
1507     return new VCProjectWriter;
1508 }
1509
1510 QString VcprojGenerator::replaceExtraCompilerVariables(const QString &var, const QStringList &in, const QStringList &out)
1511 {
1512     QString ret = MakefileGenerator::replaceExtraCompilerVariables(var, in, out);
1513
1514     QStringList &defines = project->values("VCPROJ_MAKEFILE_DEFINES");
1515     if(defines.isEmpty())
1516         defines.append(varGlue("PRL_EXPORT_DEFINES"," -D"," -D","") +
1517                        varGlue("DEFINES"," -D"," -D",""));
1518     ret.replace("$(DEFINES)", defines.first());
1519
1520     QStringList &incpath = project->values("VCPROJ_MAKEFILE_INCPATH");
1521     if(incpath.isEmpty() && !this->var("MSVCPROJ_INCPATH").isEmpty())
1522         incpath.append(this->var("MSVCPROJ_INCPATH"));
1523     ret.replace("$(INCPATH)", incpath.join(" "));
1524
1525     return ret;
1526 }
1527
1528 bool VcprojGenerator::openOutput(QFile &file, const QString &/*build*/) const
1529 {
1530     QString outdir;
1531     if(!file.fileName().isEmpty()) {
1532         QFileInfo fi(fileInfo(file.fileName()));
1533         if(fi.isDir())
1534             outdir = file.fileName() + QDir::separator();
1535     }
1536     if(!outdir.isEmpty() || file.fileName().isEmpty()) {
1537         QString ext = project->first("VCPROJ_EXTENSION");
1538         if(project->first("TEMPLATE") == "vcsubdirs")
1539             ext = project->first("VCSOLUTION_EXTENSION");
1540         QString outputName = unescapeFilePath(project->first("TARGET"));
1541         if (!project->first("MAKEFILE").isEmpty())
1542             outputName = project->first("MAKEFILE");
1543         file.setFileName(outdir + outputName + ext);
1544     }
1545     return Win32MakefileGenerator::openOutput(file, QString());
1546 }
1547
1548 QString VcprojGenerator::fixFilename(QString ofile) const
1549 {
1550     ofile = Option::fixPathToLocalOS(ofile);
1551     int slashfind = ofile.lastIndexOf(Option::dir_sep);
1552     if(slashfind == -1) {
1553         ofile = ofile.replace('-', '_');
1554     } else {
1555         int hyphenfind = ofile.indexOf('-', slashfind);
1556         while (hyphenfind != -1 && slashfind < hyphenfind) {
1557             ofile = ofile.replace(hyphenfind, 1, '_');
1558             hyphenfind = ofile.indexOf('-', hyphenfind + 1);
1559         }
1560     }
1561     return ofile;
1562 }
1563
1564 void VcprojGenerator::outputVariables()
1565 {
1566 #if 0
1567     qDebug("Generator: MSVC.NET: List of current variables:");
1568     for(QHash<QString, QStringList>::ConstIterator it = project->variables().begin(); it != project->variables().end(); ++it)
1569         qDebug("Generator: MSVC.NET: %s => %s", qPrintable(it.key()), qPrintable(it.value().join(" | ")));
1570 #endif
1571 }
1572
1573 QT_END_NAMESPACE