source: trunk/qmake/generators/win32/msvc_vcproj.cpp@ 362

Last change on this file since 362 was 2, checked in by Dmitry A. Kuminov, 17 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

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