1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the qmake application of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #include "msvc_vcproj.h"
44 #include "xmloutput.h"
46 #include <qdiriterator.h>
47 #include <qcryptographichash.h>
53 //#define DEBUG_SOLUTION_GEN
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}";
68 #include <qt_windows.h>
69 #include <windows/registry_p.h>
75 const char *versionStr;
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"},
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"},
104 DotNET which_dotnet_version()
107 return NET2002; // Always generate 7.0 versions on other platforms
109 // Only search for the version once
110 static DotNET current_version = NETUnknown;
111 if(current_version != NETUnknown)
112 return current_version;
114 // Fallback to .NET 2002
115 current_version = NET2002;
117 QStringList warnPath;
118 QHash<DotNET, QString> installPaths;
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);
126 current_version = dotNetCombo[i].version;
127 warnPath += QString("%1").arg(dotNetCombo[i].versionStr);
132 return current_version;
134 // More than one version installed, search directory path
135 QString paths = qgetenv("PATH");
136 QStringList pathlist = paths.toLower().split(";");
139 for(; dotNetCombo[i].version; ++i) {
140 QString productPath = qt_readRegistryKey(HKEY_LOCAL_MACHINE, dotNetCombo[i].regKey).toLower();
141 if (productPath.isEmpty())
143 QStringList::iterator it;
144 for(it = pathlist.begin(); it != pathlist.end(); ++it) {
145 if((*it).contains(productPath)) {
147 current_version = dotNetCombo[i].version;
148 warnPath += QString("%1 in path").arg(dotNetCombo[i].versionStr);
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());
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());
166 return current_version;
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 // ------------------------------------------------------------------
210 VcprojGenerator::VcprojGenerator()
211 : Win32MakefileGenerator(),
218 VcprojGenerator::~VcprojGenerator()
220 delete projectWriter;
223 bool VcprojGenerator::writeMakefile(QTextStream &t)
225 initProject(); // Fills the whole project with proper data
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");
233 debug_msg(1, "Generator: MSVC.NET: Not writing solution file for build_pass configs");
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");
243 projectWriter->write(xmlOut, vcProject);
247 return project->isActiveConfig("build_pass");
250 bool VcprojGenerator::writeProjectMakefile()
252 QTextStream t(&Option::output);
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());
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!");
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;
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;
294 projectWriter->write(xmlOut, mergedProject);
296 } else if(project->first("TEMPLATE") == "vcsubdirs") {
297 return writeMakefile(t);
302 struct VcsolutionDepend {
304 QString vcprojFile, orig_target, target;
306 QStringList dependencies;
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 */
315 # pragma optimize( "g", off )
316 # pragma warning ( disable : 4748 )
319 QUuid VcprojGenerator::getProjectUUID(const QString &filename)
321 bool validUUID = true;
323 // Read GUID from variable-space
324 QUuid uuid = project->first("GUID");
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);
336 // If still not valid, generate new one, and suggest adding to .pro
337 if(uuid.isNull() || !validUUID) {
338 uuid = QUuid::createUuid();
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());
344 // Store GUID in variable-space
345 project->values("GUID") = QStringList(uuid.toString().toUpper());
350 # pragma optimize( "g", on )
353 QUuid VcprojGenerator::increaseUUID(const QUuid &id)
356 qint64 dataFirst = (result.data4[0] << 24) +
357 (result.data4[1] << 16) +
358 (result.data4[2] << 8) +
360 qint64 dataLast = (result.data4[4] << 24) +
361 (result.data4[5] << 16) +
362 (result.data4[6] << 8) +
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);
379 QStringList VcprojGenerator::collectSubDirs(QMakeProject *proj)
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
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");
404 void VcprojGenerator::writeSubDirs(QTextStream &t)
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());
413 switch(which_dotnet_version()) {
431 warn_msg(WarnLogic, "Generator: MSVC.NET: Unknown version (%d) of MSVC detected for .sln", which_dotnet_version());
435 QHash<QString, VcsolutionDepend*> solution_depends;
436 QList<VcsolutionDepend*> solution_cleanup;
438 QString oldpwd = qmake_getpwd();
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");
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)));
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);
458 QMakeProject tmp_proj;
459 QString dir = fi.path(), fn = fi.fileName();
461 if(!qmake_setpwd(dir))
462 fprintf(stderr, "Cannot find directory: %s\n", dir.toLatin1().constData());
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());
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;
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();
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)) {
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;
501 for (int i = list.size() - 1; i >= 0; --i) {
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);
512 warn_msg(WarnLogic, "Ignored (not found) '%s'", QString(vcprojDir + Option::dir_sep + vcproj).toLatin1().constData());
513 goto nextfile; // # Dirty!
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");
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";
528 // All ActiveQt Server projects are dependent on idc.exe
529 if (tmp_proj.values("CONFIG").contains("qaxserver"))
530 newDep->dependencies << "idc.exe";
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) {
543 if (cmd.contains("\r"))
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;
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) {
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" &&
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")
594 newDep->dependencies << opt.section(Option::dir_sep, -1);
598 #ifdef DEBUG_SOLUTION_GEN
599 qDebug("Deps for %20s: [%s]", newDep->target.toLatin1().constData(), newDep->dependencies.join(" :: ").toLatin1().constData());
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 << "\"";
610 qmake_setpwd(oldpwd);
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");
627 // Restore previous after_user_var options
628 Option::after_user_vars = old_after_vars;
630 // Figure out dependencies
631 for(QList<VcsolutionDepend*>::Iterator it = solution_cleanup.begin(); it != solution_cleanup.end(); ++it) {
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;
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;
652 t << _slnProjConfEnd;
653 t << _slnExtSections;
657 while (!solution_cleanup.isEmpty())
658 delete solution_cleanup.takeFirst();
661 // ------------------------------------------------------------------------------------------------
662 // ------------------------------------------------------------------------------------------------
664 bool VcprojGenerator::hasBuiltinCompiler(const QString &file)
667 for (int i = 0; i < Option::cpp_ext.count(); ++i)
668 if (file.endsWith(Option::cpp_ext.at(i)))
670 for (int i = 0; i < Option::c_ext.count(); ++i)
671 if (file.endsWith(Option::c_ext.at(i)))
673 if (file.endsWith(".rc")
674 || file.endsWith(".idl"))
679 void VcprojGenerator::init()
684 is64Bit = (project->first("QMAKE_TARGET.arch") == "x86_64");
685 projectWriter = createProjectWriter();
687 if(project->first("TEMPLATE") == "vcsubdirs") //too much work for subdirs
690 debug_msg(1, "Generator: MSVC.NET: Initializing variables");
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"));
702 project->values("QMAKE_LIBS") += escapeFilePaths(project->values("LIBS"));
703 project->values("QMAKE_LIBS_PRIVATE") += escapeFilePaths(project->values("LIBS_PRIVATE"));
705 if(!project->values("VERSION").isEmpty()) {
706 QString version = project->values("VERSION")[0];
707 int firstDot = version.indexOf(".");
708 QString major = version.left(firstDot);
709 QString minor = version.right(version.length() - firstDot - 1);
710 minor.replace(QRegExp("\\."), "");
711 project->values("QMAKE_LFLAGS").append("/VERSION:" + major + "." + minor);
714 MakefileGenerator::init();
715 initOld(); // Currently calling old DSP code to set variables. CLEAN UP!
717 // Figure out what we're trying to build
718 if(project->first("TEMPLATE") == "vcapp") {
719 projectTarget = Application;
720 } else if(project->first("TEMPLATE") == "vclib") {
721 if(project->isActiveConfig("staticlib")) {
722 if (!project->values("RES_FILE").isEmpty())
723 project->values("QMAKE_LIBS") += escapeFilePaths(project->values("RES_FILE"));
724 projectTarget = StaticLib;
726 projectTarget = SharedLib;
729 // Setup PCH variables
730 precompH = project->first("PRECOMPILED_HEADER");
731 precompCPP = project->first("PRECOMPILED_SOURCE");
732 usePCH = !precompH.isEmpty() && project->isActiveConfig("precompile_header");
734 precompHFilename = fileInfo(precompH).fileName();
736 QString origTarget = unescapeFilePath(project->first("QMAKE_ORIG_TARGET"));
737 precompObj = origTarget + Option::obj_ext;
738 precompPch = origTarget + ".pch";
739 // Add PRECOMPILED_HEADER to HEADERS
740 if (!project->values("HEADERS").contains(precompH))
741 project->values("HEADERS") += precompH;
742 // Return to variable pool
743 project->values("PRECOMPILED_OBJECT") = QStringList(precompObj);
744 project->values("PRECOMPILED_PCH") = QStringList(precompPch);
746 autogenPrecompCPP = precompCPP.isEmpty() && project->isActiveConfig("autogen_precompile_source");
747 if (autogenPrecompCPP) {
748 precompCPP = precompH
749 + (Option::cpp_ext.count() ? Option::cpp_ext.at(0) : QLatin1String(".cpp"));
750 project->values("GENERATED_SOURCES") += precompCPP;
751 } else if (!precompCPP.isEmpty()) {
752 project->values("SOURCES") += precompCPP;
756 // Add all input files for a custom compiler into a map for uniqueness,
757 // unless the compiler is configure as a combined stage, then use the first one
758 const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS");
759 for(QStringList::ConstIterator it = quc.constBegin(); it != quc.constEnd(); ++it) {
760 const QStringList &invar = project->values(*it + ".input");
761 const QString compiler_out = project->first((*it) + ".output");
762 for(QStringList::ConstIterator iit = invar.constBegin(); iit != invar.constEnd(); ++iit) {
763 QStringList fileList = project->values(*iit);
764 if (!fileList.isEmpty()) {
765 if (project->values((*it) + ".CONFIG").indexOf("combine") != -1)
766 fileList = QStringList(fileList.first());
767 for(QStringList::ConstIterator fit = fileList.constBegin(); fit != fileList.constEnd(); ++fit) {
768 QString file = (*fit);
769 if (verifyExtraCompiler((*it), file)) {
770 if (!hasBuiltinCompiler(file)) {
771 extraCompilerSources[file] += *it;
773 QString out = Option::fixPathToTargetOS(replaceExtraCompilerVariables(
774 compiler_out, file, QString()), false);
775 extraCompilerSources[out] += *it;
776 extraCompilerOutputs[out] = QStringList(file); // Can only have one
785 Q_FOREACH(QString aKey, extraCompilerSources.keys()) {
786 qDebug("Extracompilers for %s are (%s)", aKey.toLatin1().constData(), extraCompilerSources.value(aKey).join(", ").toLatin1().constData());
788 Q_FOREACH(QString aKey, extraCompilerOutputs.keys()) {
789 qDebug("Object mapping for %s is (%s)", aKey.toLatin1().constData(), extraCompilerOutputs.value(aKey).join(", ").toLatin1().constData());
795 bool VcprojGenerator::mergeBuildProject(MakefileGenerator *other)
797 if (!other || !other->projectFile()) {
798 warn_msg(WarnLogic, "VcprojGenerator: Cannot merge null project.");
801 if (other->projectFile()->first("MAKEFILE_GENERATOR") != project->first("MAKEFILE_GENERATOR")) {
802 warn_msg(WarnLogic, "VcprojGenerator: Cannot merge other types of projects! (ignored)");
806 VcprojGenerator *otherVC = static_cast<VcprojGenerator*>(other);
807 mergedProjects += otherVC;
811 void VcprojGenerator::initProject()
813 // Initialize XML sub elements
814 // - Do this first since project elements may need
815 // - to know of certain configuration options
820 initGeneratedFiles();
822 initTranslationFiles();
825 initExtraCompilerOutputs();
827 // Own elements -----------------------------
828 vcProject.Name = unescapeFilePath(project->first("QMAKE_ORIG_TARGET"));
829 switch(which_dotnet_version()) {
831 vcProject.Version = "10.00";
834 vcProject.Version = "9,00";
837 //### using ',' because of a bug in 2005 B2
838 //### VS uses '.' or ',' depending on the regional settings! Using ',' always works.
839 vcProject.Version = "8,00";
842 vcProject.Version = "7.10";
845 vcProject.Version = "7.00";
848 vcProject.Version = "7.00";
849 warn_msg(WarnLogic, "Generator: MSVC.NET: Unknown version (%d) of MSVC detected for .vcproj", which_dotnet_version());
853 vcProject.Keyword = project->first("VCPROJ_KEYWORD");
854 if (project->isHostBuild() || project->isEmpty("CE_SDK") || project->isEmpty("CE_ARCH")) {
855 vcProject.PlatformName = (is64Bit ? "x64" : "Win32");
857 vcProject.PlatformName = project->values("CE_SDK").join(" ") + " (" + project->first("CE_ARCH") + ")";
859 // These are not used by Qt, but may be used by customers
860 vcProject.SccProjectName = project->first("SCCPROJECTNAME");
861 vcProject.SccLocalPath = project->first("SCCLOCALPATH");
862 vcProject.flat_files = project->isActiveConfig("flat");
865 void VcprojGenerator::initConfiguration()
867 // Initialize XML sub elements
868 // - Do this first since main configuration elements may need
869 // - to know of certain compiler/linker options
870 VCConfiguration &conf = vcProject.Configuration;
871 conf.CompilerVersion = which_dotnet_version();
875 // Only on configuration per build
876 bool isDebug = project->isActiveConfig("debug");
878 if(projectTarget == StaticLib)
881 conf.linker.GenerateDebugInformation = isDebug ? _True : _False;
887 // Own elements -----------------------------
888 QString temp = project->first("BuildBrowserInformation");
889 switch (projectTarget) {
891 conf.ConfigurationType = typeDynamicLibrary;
894 conf.ConfigurationType = typeStaticLibrary;
898 conf.ConfigurationType = typeApplication;
902 conf.OutputDirectory = project->first("DESTDIR");
903 if (conf.OutputDirectory.isEmpty())
904 conf.OutputDirectory = ".\\";
905 if (!conf.OutputDirectory.endsWith("\\"))
906 conf.OutputDirectory += '\\';
907 if (conf.CompilerVersion >= NET2010) {
908 // The target name could have been changed.
909 conf.PrimaryOutput = project->first("TARGET");
910 if ( !conf.PrimaryOutput.isEmpty() && !project->first("TARGET_VERSION_EXT").isEmpty() && project->isActiveConfig("shared"))
911 conf.PrimaryOutput.append(project->first("TARGET_VERSION_EXT"));
914 conf.Name = project->values("BUILD_NAME").join(" ");
915 if (conf.Name.isEmpty())
916 conf.Name = isDebug ? "Debug" : "Release";
917 conf.ConfigurationName = conf.Name;
918 if (project->isHostBuild() || project->isEmpty("CE_SDK") || project->isEmpty("CE_ARCH")) {
919 conf.Name += (is64Bit ? "|x64" : "|Win32");
921 conf.Name += "|" + project->values("CE_SDK").join(" ") + " (" + project->first("CE_ARCH") + ")";
923 conf.ATLMinimizesCRunTimeLibraryUsage = (project->first("ATLMinimizesCRunTimeLibraryUsage").isEmpty() ? _False : _True);
924 conf.BuildBrowserInformation = triState(temp.isEmpty() ? (short)unset : temp.toShort());
925 temp = project->first("CharacterSet");
926 conf.CharacterSet = charSet(temp.isEmpty() ? (short)charSetNotSet : temp.toShort());
927 conf.DeleteExtensionsOnClean = project->first("DeleteExtensionsOnClean");
928 conf.ImportLibrary = conf.linker.ImportLibrary;
929 conf.IntermediateDirectory = project->first("OBJECTS_DIR");
930 conf.WholeProgramOptimization = conf.compiler.WholeProgramOptimization;
931 temp = project->first("UseOfATL");
933 conf.UseOfATL = useOfATL(temp.toShort());
934 temp = project->first("UseOfMfc");
936 conf.UseOfMfc = useOfMfc(temp.toShort());
938 // Configuration does not need parameters from
939 // these sub XML items;
940 initCustomBuildTool();
941 initPreBuildEventTools();
942 initPostBuildEventTools();
943 // Only deploy for CE projects
944 if (!project->isHostBuild() && !project->isEmpty("CE_SDK") && !project->isEmpty("CE_ARCH"))
945 initDeploymentTool();
946 initPreLinkEventTools();
948 // Set definite values in both configurations
950 conf.compiler.PreprocessorDefinitions.removeAll("NDEBUG");
952 conf.compiler.PreprocessorDefinitions += "NDEBUG";
956 void VcprojGenerator::initCompilerTool()
958 QString placement = project->first("OBJECTS_DIR");
959 if(placement.isEmpty())
962 VCConfiguration &conf = vcProject.Configuration;
963 if (conf.CompilerVersion >= NET2010) {
964 // adjust compiler tool defaults for VS 2010 and above
965 conf.compiler.Optimization = optimizeDisabled;
967 conf.compiler.AssemblerListingLocation = placement ;
968 conf.compiler.ProgramDataBaseFileName = ".\\" ;
969 conf.compiler.ObjectFile = placement ;
970 conf.compiler.ExceptionHandling = ehNone;
973 conf.compiler.UsePrecompiledHeader = pchUseUsingSpecific;
974 conf.compiler.PrecompiledHeaderFile = "$(IntDir)\\" + precompPch;
975 conf.compiler.PrecompiledHeaderThrough = project->first("PRECOMPILED_HEADER");
976 conf.compiler.ForcedIncludeFiles = project->values("PRECOMPILED_HEADER");
978 if (conf.CompilerVersion <= NET2003) {
979 // Minimal build option triggers an Internal Compiler Error
980 // when used in conjunction with /FI and /Yu, so remove it
981 // ### work-around for a VS 2003 bug. Move to some prf file or remove completely.
982 project->values("QMAKE_CFLAGS_DEBUG").removeAll("-Gm");
983 project->values("QMAKE_CFLAGS_DEBUG").removeAll("/Gm");
984 project->values("QMAKE_CXXFLAGS_DEBUG").removeAll("-Gm");
985 project->values("QMAKE_CXXFLAGS_DEBUG").removeAll("/Gm");
989 conf.compiler.parseOptions(project->values("QMAKE_CXXFLAGS"));
991 if (project->isActiveConfig("windows"))
992 conf.compiler.PreprocessorDefinitions += "_WINDOWS";
993 else if (project->isActiveConfig("console"))
994 conf.compiler.PreprocessorDefinitions += "_CONSOLE";
996 conf.compiler.PreprocessorDefinitions += project->values("DEFINES");
997 conf.compiler.PreprocessorDefinitions += project->values("PRL_EXPORT_DEFINES");
998 conf.compiler.parseOptions(project->values("MSVCPROJ_INCPATH"));
1001 void VcprojGenerator::initLibrarianTool()
1003 VCConfiguration &conf = vcProject.Configuration;
1004 conf.librarian.OutputFile = "$(OutDir)\\";
1005 conf.librarian.OutputFile += project->first("MSVCPROJ_TARGET");
1006 conf.librarian.AdditionalOptions += project->values("QMAKE_LIBFLAGS");
1009 void VcprojGenerator::initLinkerTool()
1011 VCConfiguration &conf = vcProject.Configuration;
1012 conf.linker.parseOptions(project->values("QMAKE_LFLAGS"));
1014 foreach (const QString &libDir, project->values("QMAKE_LIBDIR")) {
1015 if (libDir.startsWith("/LIBPATH:"))
1016 conf.linker.AdditionalLibraryDirectories += libDir.mid(9);
1018 conf.linker.AdditionalLibraryDirectories += libDir;
1021 if (!project->values("DEF_FILE").isEmpty())
1022 conf.linker.ModuleDefinitionFile = project->first("DEF_FILE");
1024 foreach (QString libs, project->values("QMAKE_LIBS") + project->values("QMAKE_LIBS_PRIVATE")) {
1025 if (libs.left(9).toUpper() == "/LIBPATH:") {
1026 QStringList l = QStringList(libs);
1027 conf.linker.parseOptions(l);
1029 conf.linker.AdditionalDependencies += libs;
1033 conf.linker.OutputFile = "$(OutDir)\\";
1034 conf.linker.OutputFile += project->first("MSVCPROJ_TARGET");
1036 if(project->isActiveConfig("dll")){
1037 conf.linker.parseOptions(project->values("QMAKE_LFLAGS_QT_DLL"));
1041 void VcprojGenerator::initResourceTool()
1043 VCConfiguration &conf = vcProject.Configuration;
1044 conf.resource.PreprocessorDefinitions = conf.compiler.PreprocessorDefinitions;
1046 // We need to add _DEBUG for the debug version of the project, since the normal compiler defines
1047 // do not contain it. (The compiler defines this symbol automatically, which is wy we don't need
1048 // to add it for the compiler) However, the resource tool does not do this.
1049 if(project->isActiveConfig("debug"))
1050 conf.resource.PreprocessorDefinitions += "_DEBUG";
1051 if(project->isActiveConfig("staticlib"))
1052 conf.resource.ResourceOutputFileName = "$(OutDir)\\$(InputName).res";
1055 void VcprojGenerator::initIDLTool()
1059 void VcprojGenerator::initCustomBuildTool()
1063 void VcprojGenerator::initPreBuildEventTools()
1067 void VcprojGenerator::initPostBuildEventTools()
1069 VCConfiguration &conf = vcProject.Configuration;
1070 if (!project->values("QMAKE_POST_LINK").isEmpty()) {
1071 QStringList cmdline = VCToolBase::fixCommandLine(var("QMAKE_POST_LINK"));
1072 conf.postBuild.CommandLine = cmdline;
1073 conf.postBuild.Description = cmdline.join(QLatin1String("\r\n"));
1074 conf.postBuild.ExcludedFromBuild = _False;
1077 QString signature = !project->isEmpty("SIGNATURE_FILE") ? var("SIGNATURE_FILE") : var("DEFAULT_SIGNATURE");
1078 bool useSignature = !signature.isEmpty() && !project->isActiveConfig("staticlib") &&
1079 !project->isHostBuild() && !project->isEmpty("CE_SDK") && !project->isEmpty("CE_ARCH");
1081 conf.postBuild.CommandLine.prepend(
1082 QLatin1String("signtool sign /F ") + signature + QLatin1String(" \"$(TargetPath)\""));
1083 conf.postBuild.ExcludedFromBuild = _False;
1086 if (!project->values("MSVCPROJ_COPY_DLL").isEmpty()) {
1087 conf.postBuild.Description += var("MSVCPROJ_COPY_DLL_DESC");
1088 conf.postBuild.CommandLine += var("MSVCPROJ_COPY_DLL");
1089 conf.postBuild.ExcludedFromBuild = _False;
1093 void VcprojGenerator::initDeploymentTool()
1095 VCConfiguration &conf = vcProject.Configuration;
1096 QString targetPath = project->values("deploy.path").join(" ");
1097 if (targetPath.isEmpty())
1098 targetPath = QString("%CSIDL_PROGRAM_FILES%\\") + project->first("TARGET");
1099 if (targetPath.endsWith("/") || targetPath.endsWith("\\"))
1102 // Only deploy Qt libs for shared build
1103 if (!project->values("QMAKE_QT_DLL").isEmpty()) {
1104 // FIXME: This code should actually resolve the libraries from all Qt modules.
1105 const QString &qtdir = QLibraryInfo::rawLocation(QLibraryInfo::LibrariesPath,
1106 QLibraryInfo::EffectivePaths);
1107 QStringList arg = project->values("QMAKE_LIBS") + project->values("QMAKE_LIBS_PRIVATE");
1108 for (QStringList::ConstIterator it = arg.constBegin(); it != arg.constEnd(); ++it) {
1109 if (it->contains(qtdir)) {
1110 QString dllName = *it;
1112 if (dllName.contains(QLatin1String("QAxContainer"))
1113 || dllName.contains(QLatin1String("qtmain"))
1114 || dllName.contains(QLatin1String("QtUiTools")))
1116 dllName.replace(QLatin1String(".lib") , QLatin1String(".dll"));
1117 QFileInfo info(dllName);
1118 conf.deployment.AdditionalFiles += info.fileName()
1119 + "|" + QDir::toNativeSeparators(info.absolutePath())
1126 // C-runtime deployment
1127 QString runtime = project->values("QT_CE_C_RUNTIME").join(QLatin1String(" "));
1128 if (!runtime.isEmpty() && (runtime != QLatin1String("no"))) {
1129 QString runtimeVersion = QLatin1String("msvcr");
1130 QString mkspec = project->first("QMAKESPEC");
1131 // If no .qmake.cache has been found, we fallback to the original mkspec
1132 if (mkspec.isEmpty())
1133 mkspec = project->first("QMAKESPEC_ORIGINAL");
1135 if (!mkspec.isEmpty()) {
1136 if (mkspec.endsWith("2008"))
1137 runtimeVersion.append("90");
1139 runtimeVersion.append("80");
1140 if (project->isActiveConfig("debug"))
1141 runtimeVersion.append("d");
1142 runtimeVersion.append(".dll");
1144 if (runtime == "yes") {
1145 // Auto-find C-runtime
1146 QString vcInstallDir = qgetenv("VCINSTALLDIR");
1147 if (!vcInstallDir.isEmpty()) {
1148 vcInstallDir += "\\ce\\dll\\";
1149 vcInstallDir += project->values("CE_ARCH").join(QLatin1String(" "));
1150 if (!QFileInfo(vcInstallDir + QDir::separator() + runtimeVersion).exists())
1153 runtime = vcInstallDir;
1158 if (!runtime.isEmpty() && runtime != QLatin1String("yes")) {
1159 conf.deployment.AdditionalFiles += runtimeVersion
1160 + "|" + QDir::toNativeSeparators(runtime)
1166 // foreach item in DEPLOYMENT
1167 foreach(QString item, project->values("DEPLOYMENT")) {
1169 QString devicePath = project->first(item + ".path");
1170 if (devicePath.isEmpty())
1171 devicePath = targetPath;
1172 // check if item.path is relative (! either /,\ or %)
1173 if (!(devicePath.at(0) == QLatin1Char('/')
1174 || devicePath.at(0) == QLatin1Char('\\')
1175 || devicePath.at(0) == QLatin1Char('%'))) {
1176 // create output path
1177 devicePath = Option::fixPathToLocalOS(QDir::cleanPath(targetPath + QLatin1Char('\\') + devicePath));
1179 // foreach d in item.files
1180 foreach (QString source, project->values(item + ".files")) {
1181 QString itemDevicePath = devicePath;
1182 source = Option::fixPathToLocalOS(source);
1184 QFileInfo info(source);
1187 nameFilter = QLatin1String("*");
1188 itemDevicePath += "\\" + info.fileName();
1189 searchPath = info.absoluteFilePath();
1191 nameFilter = source.split('\\').last();
1192 searchPath = info.absolutePath();
1195 int pathSize = searchPath.size();
1196 QDirIterator iterator(searchPath, QStringList() << nameFilter
1197 , QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks
1198 , QDirIterator::Subdirectories);
1199 // foreach dirIterator-entry in d
1200 while(iterator.hasNext()) {
1202 QString absoluteItemPath = Option::fixPathToLocalOS(QFileInfo(iterator.filePath()).absolutePath());
1203 // Identify if it is just another subdir
1204 int diffSize = absoluteItemPath.size() - pathSize;
1206 conf.deployment.AdditionalFiles += iterator.fileName()
1207 + "|" + absoluteItemPath
1208 + "|" + itemDevicePath + (diffSize ? (absoluteItemPath.right(diffSize)) : QLatin1String(""))
1215 void VcprojGenerator::initPreLinkEventTools()
1217 VCConfiguration &conf = vcProject.Configuration;
1218 if(!project->values("QMAKE_PRE_LINK").isEmpty()) {
1219 QStringList cmdline = VCToolBase::fixCommandLine(var("QMAKE_PRE_LINK"));
1220 conf.preLink.CommandLine = cmdline;
1221 conf.preLink.Description = cmdline.join(QLatin1String("\r\n"));
1222 conf.preLink.ExcludedFromBuild = _False;
1226 void VcprojGenerator::initRootFiles()
1228 // Note: Root files do _not_ have any filter name, filter nor GUID!
1229 vcProject.RootFiles.addFiles(project->values("RC_FILE"));
1231 vcProject.RootFiles.Project = this;
1232 vcProject.RootFiles.Config = &(vcProject.Configuration);
1233 vcProject.RootFiles.CustomBuild = none;
1236 void VcprojGenerator::initSourceFiles()
1238 vcProject.SourceFiles.Name = "Source Files";
1239 vcProject.SourceFiles.Filter = "cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx";
1240 vcProject.SourceFiles.Guid = _GUIDSourceFiles;
1242 vcProject.SourceFiles.addFiles(project->values("SOURCES"));
1244 vcProject.SourceFiles.Project = this;
1245 vcProject.SourceFiles.Config = &(vcProject.Configuration);
1246 vcProject.SourceFiles.CustomBuild = none;
1249 void VcprojGenerator::initHeaderFiles()
1251 vcProject.HeaderFiles.Name = "Header Files";
1252 vcProject.HeaderFiles.Filter = "h;hpp;hxx;hm;inl;inc;xsd";
1253 vcProject.HeaderFiles.Guid = _GUIDHeaderFiles;
1255 vcProject.HeaderFiles.addFiles(project->values("HEADERS"));
1256 if (usePCH) // Generated PCH cpp file
1257 vcProject.HeaderFiles.addFile(precompH);
1259 vcProject.HeaderFiles.Project = this;
1260 vcProject.HeaderFiles.Config = &(vcProject.Configuration);
1261 // vcProject.HeaderFiles.CustomBuild = mocHdr;
1262 // addMocArguments(vcProject.HeaderFiles);
1265 void VcprojGenerator::initGeneratedFiles()
1267 vcProject.GeneratedFiles.Name = "Generated Files";
1268 vcProject.GeneratedFiles.Filter = "cpp;c;cxx;moc;h;def;odl;idl;res;";
1269 vcProject.GeneratedFiles.Guid = _GUIDGeneratedFiles;
1271 // ### These cannot have CustomBuild (mocSrc)!!
1272 vcProject.GeneratedFiles.addFiles(project->values("GENERATED_SOURCES"));
1273 vcProject.GeneratedFiles.addFiles(project->values("GENERATED_FILES"));
1274 vcProject.GeneratedFiles.addFiles(project->values("IDLSOURCES"));
1275 vcProject.GeneratedFiles.addFiles(project->values("RES_FILE"));
1276 vcProject.GeneratedFiles.addFiles(project->values("QMAKE_IMAGE_COLLECTION")); // compat
1277 if(!extraCompilerOutputs.isEmpty())
1278 vcProject.GeneratedFiles.addFiles(extraCompilerOutputs.keys());
1280 vcProject.GeneratedFiles.Project = this;
1281 vcProject.GeneratedFiles.Config = &(vcProject.Configuration);
1282 // vcProject.GeneratedFiles.CustomBuild = mocSrc;
1285 void VcprojGenerator::initLexYaccFiles()
1287 vcProject.LexYaccFiles.Name = "Lex / Yacc Files";
1288 vcProject.LexYaccFiles.ParseFiles = _False;
1289 vcProject.LexYaccFiles.Filter = "l;y";
1290 vcProject.LexYaccFiles.Guid = _GUIDLexYaccFiles;
1292 vcProject.LexYaccFiles.addFiles(project->values("LEXSOURCES"));
1293 vcProject.LexYaccFiles.addFiles(project->values("YACCSOURCES"));
1295 vcProject.LexYaccFiles.Project = this;
1296 vcProject.LexYaccFiles.Config = &(vcProject.Configuration);
1297 vcProject.LexYaccFiles.CustomBuild = lexyacc;
1300 void VcprojGenerator::initTranslationFiles()
1302 vcProject.TranslationFiles.Name = "Translation Files";
1303 vcProject.TranslationFiles.ParseFiles = _False;
1304 vcProject.TranslationFiles.Filter = "ts;xlf";
1305 vcProject.TranslationFiles.Guid = _GUIDTranslationFiles;
1307 vcProject.TranslationFiles.addFiles(project->values("TRANSLATIONS"));
1309 vcProject.TranslationFiles.Project = this;
1310 vcProject.TranslationFiles.Config = &(vcProject.Configuration);
1311 vcProject.TranslationFiles.CustomBuild = none;
1314 void VcprojGenerator::initFormFiles()
1316 vcProject.FormFiles.Name = "Form Files";
1317 vcProject.FormFiles.ParseFiles = _False;
1318 vcProject.FormFiles.Filter = "ui";
1319 vcProject.FormFiles.Guid = _GUIDFormFiles;
1321 vcProject.FormFiles.addFiles(project->values("FORMS"));
1322 vcProject.FormFiles.addFiles(project->values("FORMS3"));
1324 vcProject.FormFiles.Project = this;
1325 vcProject.FormFiles.Config = &(vcProject.Configuration);
1326 vcProject.FormFiles.CustomBuild = none;
1329 void VcprojGenerator::initResourceFiles()
1331 vcProject.ResourceFiles.Name = "Resource Files";
1332 vcProject.ResourceFiles.ParseFiles = _False;
1333 vcProject.ResourceFiles.Filter = "qrc;*"; //"rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;ts;xlf;qrc";
1334 vcProject.ResourceFiles.Guid = _GUIDResourceFiles;
1336 // Bad hack, please look away -------------------------------------
1337 QString rcc_dep_cmd = project->values("rcc.depend_command").join(" ");
1338 if(!rcc_dep_cmd.isEmpty()) {
1339 QStringList qrc_files = project->values("RESOURCES");
1341 if(!qrc_files.isEmpty()) {
1342 for (int i = 0; i < qrc_files.count(); ++i) {
1344 QString dep_cmd = replaceExtraCompilerVariables(rcc_dep_cmd, qrc_files.at(i),"");
1346 dep_cmd = Option::fixPathToLocalOS(dep_cmd, true, false);
1347 if(canExecute(dep_cmd)) {
1348 dep_cmd.prepend(QLatin1String("cd ")
1349 + escapeFilePath(Option::fixPathToLocalOS(Option::output_dir, false))
1350 + QLatin1String(" && "));
1351 if(FILE *proc = QT_POPEN(dep_cmd.toLatin1().constData(), "r")) {
1353 while(!feof(proc)) {
1354 int read_in = (int)fread(buff, 1, 255, proc);
1357 indeps += QByteArray(buff, read_in);
1360 if(!indeps.isEmpty())
1361 deps += fileFixify(indeps.replace('\n', ' ').simplified().split(' '),
1362 QString(), Option::output_dir);
1366 vcProject.ResourceFiles.addFiles(deps);
1369 // You may look again --------------------------------------------
1371 vcProject.ResourceFiles.addFiles(project->values("RESOURCES"));
1372 vcProject.ResourceFiles.addFiles(project->values("IMAGES"));
1374 vcProject.ResourceFiles.Project = this;
1375 vcProject.ResourceFiles.Config = &(vcProject.Configuration);
1376 vcProject.ResourceFiles.CustomBuild = none;
1379 void VcprojGenerator::initExtraCompilerOutputs()
1381 QStringList otherFilters;
1382 otherFilters << "FORMS"
1384 << "GENERATED_FILES"
1385 << "GENERATED_SOURCES"
1390 << "QMAKE_IMAGE_COLLECTION"
1397 const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS");
1398 for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) {
1399 QString extracompilerName = project->first((*it) + ".name");
1400 if (extracompilerName.isEmpty())
1401 extracompilerName = (*it);
1403 // Create an extra compiler filter and add the files
1404 VCFilter extraCompile;
1405 extraCompile.Name = extracompilerName;
1406 extraCompile.ParseFiles = _False;
1407 extraCompile.Filter = "";
1408 extraCompile.Guid = QString(_GUIDExtraCompilerFiles) + "-" + (*it);
1411 // If the extra compiler has a variable_out set the output file
1412 // is added to an other file list, and does not need its own..
1413 bool addOnInput = hasBuiltinCompiler(project->first((*it) + ".output"));
1414 QString tmp_other_out = project->first((*it) + ".variable_out");
1415 if (!tmp_other_out.isEmpty() && !addOnInput)
1419 QString tmp_out = project->first((*it) + ".output");
1420 if (project->values((*it) + ".CONFIG").indexOf("combine") != -1) {
1421 // Combined output, only one file result
1422 extraCompile.addFile(
1423 Option::fixPathToTargetOS(replaceExtraCompilerVariables(tmp_out, QString(), QString()), false));
1425 // One output file per input
1426 QStringList tmp_in = project->values(project->first((*it) + ".input"));
1427 for (int i = 0; i < tmp_in.count(); ++i) {
1428 const QString &filename = tmp_in.at(i);
1429 if (extraCompilerSources.contains(filename))
1430 extraCompile.addFile(
1431 Option::fixPathToTargetOS(replaceExtraCompilerVariables(filename, tmp_out, QString()), false));
1435 // In this case we the outputs have a built-in compiler, so we cannot add the custom
1436 // build steps there. So, we turn it around and add it to the input files instead,
1437 // provided that the input file variable is not handled already (those in otherFilters
1438 // are handled, so we avoid them).
1439 QStringList inputVars = project->values((*it) + ".input");
1440 foreach(QString inputVar, inputVars) {
1441 if (!otherFilters.contains(inputVar)) {
1442 QStringList tmp_in = project->values(inputVar);
1443 for (int i = 0; i < tmp_in.count(); ++i) {
1444 const QString &filename = tmp_in.at(i);
1445 if (extraCompilerSources.contains(filename))
1446 extraCompile.addFile(
1447 Option::fixPathToTargetOS(replaceExtraCompilerVariables(filename, QString(), QString()), false));
1452 extraCompile.Project = this;
1453 extraCompile.Config = &(vcProject.Configuration);
1454 extraCompile.CustomBuild = none;
1456 vcProject.ExtraCompilersFiles.append(extraCompile);
1460 void VcprojGenerator::initOld()
1462 // $$QMAKE.. -> $$MSVCPROJ.. -------------------------------------
1463 const QStringList &incs = project->values("INCLUDEPATH");
1464 for (QStringList::ConstIterator incit = incs.begin(); incit != incs.end(); ++incit) {
1465 QString inc = (*incit);
1466 if (!inc.startsWith('"') && !inc.endsWith('"'))
1467 inc = QString("\"%1\"").arg(inc); // Quote all paths if not quoted already
1468 project->values("MSVCPROJ_INCPATH").append("-I" + inc);
1470 project->values("MSVCPROJ_INCPATH").append("-I" + specdir());
1473 project->values("MSVCPROJ_TARGET") = QStringList(project->first("TARGET"));
1474 Option::fixPathToTargetOS(project->first("TARGET"));
1475 dest = project->first("TARGET") + project->first("TARGET_EXT");
1476 project->values("MSVCPROJ_TARGET") = QStringList(dest);
1478 // DLL COPY ------------------------------------------------------
1479 if(project->isActiveConfig("dll") && !project->values("DLLDESTDIR").isEmpty()) {
1480 QStringList dlldirs = project->values("DLLDESTDIR");
1481 QString copydll("");
1482 QStringList::Iterator dlldir;
1483 for(dlldir = dlldirs.begin(); dlldir != dlldirs.end(); ++dlldir) {
1484 if(!copydll.isEmpty())
1486 copydll += "copy \"$(TargetPath)\" \"" + *dlldir + "\"";
1489 QString deststr("Copy " + dest + " to ");
1490 for(dlldir = dlldirs.begin(); dlldir != dlldirs.end();) {
1493 if(dlldir != dlldirs.end())
1497 project->values("MSVCPROJ_COPY_DLL").append(copydll);
1498 project->values("MSVCPROJ_COPY_DLL_DESC").append(deststr);
1501 // Verbose output if "-d -d"...
1505 // ------------------------------------------------------------------------------------------------
1506 // ------------------------------------------------------------------------------------------------
1508 VCProjectWriter *VcprojGenerator::createProjectWriter()
1510 return new VCProjectWriter;
1513 QString VcprojGenerator::replaceExtraCompilerVariables(const QString &var, const QStringList &in, const QStringList &out)
1515 QString ret = MakefileGenerator::replaceExtraCompilerVariables(var, in, out);
1517 QStringList &defines = project->values("VCPROJ_MAKEFILE_DEFINES");
1518 if(defines.isEmpty())
1519 defines.append(varGlue("PRL_EXPORT_DEFINES"," -D"," -D","") +
1520 varGlue("DEFINES"," -D"," -D",""));
1521 ret.replace("$(DEFINES)", defines.first());
1523 QStringList &incpath = project->values("VCPROJ_MAKEFILE_INCPATH");
1524 if(incpath.isEmpty() && !this->var("MSVCPROJ_INCPATH").isEmpty())
1525 incpath.append(this->var("MSVCPROJ_INCPATH"));
1526 ret.replace("$(INCPATH)", incpath.join(" "));
1531 bool VcprojGenerator::openOutput(QFile &file, const QString &/*build*/) const
1534 if(!file.fileName().isEmpty()) {
1535 QFileInfo fi(fileInfo(file.fileName()));
1537 outdir = file.fileName() + QDir::separator();
1539 if(!outdir.isEmpty() || file.fileName().isEmpty()) {
1540 QString ext = project->first("VCPROJ_EXTENSION");
1541 if(project->first("TEMPLATE") == "vcsubdirs")
1542 ext = project->first("VCSOLUTION_EXTENSION");
1543 QString outputName = unescapeFilePath(project->first("TARGET"));
1544 if (!project->first("MAKEFILE").isEmpty())
1545 outputName = project->first("MAKEFILE");
1546 file.setFileName(outdir + outputName + ext);
1548 return Win32MakefileGenerator::openOutput(file, QString());
1551 QString VcprojGenerator::fixFilename(QString ofile) const
1553 ofile = Option::fixPathToLocalOS(ofile);
1554 int slashfind = ofile.lastIndexOf(Option::dir_sep);
1555 if(slashfind == -1) {
1556 ofile = ofile.replace('-', '_');
1558 int hyphenfind = ofile.indexOf('-', slashfind);
1559 while (hyphenfind != -1 && slashfind < hyphenfind) {
1560 ofile = ofile.replace(hyphenfind, 1, '_');
1561 hyphenfind = ofile.indexOf('-', hyphenfind + 1);
1567 void VcprojGenerator::outputVariables()
1570 qDebug("Generator: MSVC.NET: List of current variables:");
1571 for(QHash<QString, QStringList>::ConstIterator it = project->variables().begin(); it != project->variables().end(); ++it)
1572 qDebug("Generator: MSVC.NET: %s => %s", qPrintable(it.key()), qPrintable(it.value().join(" | ")));