1 /****************************************************************************
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the qmake application of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 {NET2013, "MSVC.NET 2013 (12.0)", "Software\\Wow6432Node\\Microsoft\\VisualStudio\\12.0\\Setup\\VC\\ProductDir"},
80 {NET2013, "MSVC.NET 2013 Express Edition (12.0)", "Software\\Wow6432Node\\Microsoft\\VCExpress\\12.0\\Setup\\VC\\ProductDir"},
81 {NET2012, "MSVC.NET 2012 (11.0)", "Software\\Wow6432Node\\Microsoft\\VisualStudio\\11.0\\Setup\\VC\\ProductDir"},
82 {NET2012, "MSVC.NET 2012 Express Edition (11.0)", "Software\\Wow6432Node\\Microsoft\\VCExpress\\11.0\\Setup\\VC\\ProductDir"},
83 {NET2010, "MSVC.NET 2010 (10.0)", "Software\\Wow6432Node\\Microsoft\\VisualStudio\\10.0\\Setup\\VC\\ProductDir"},
84 {NET2010, "MSVC.NET 2010 Express Edition (10.0)", "Software\\Wow6432Node\\Microsoft\\VCExpress\\10.0\\Setup\\VC\\ProductDir"},
85 {NET2008, "MSVC.NET 2008 (9.0)", "Software\\Wow6432Node\\Microsoft\\VisualStudio\\9.0\\Setup\\VC\\ProductDir"},
86 {NET2008, "MSVC.NET 2008 Express Edition (9.0)", "Software\\Wow6432Node\\Microsoft\\VCExpress\\9.0\\Setup\\VC\\ProductDir"},
87 {NET2005, "MSVC.NET 2005 (8.0)", "Software\\Wow6432Node\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir"},
88 {NET2005, "MSVC.NET 2005 Express Edition (8.0)", "Software\\Wow6432Node\\Microsoft\\VCExpress\\8.0\\Setup\\VC\\ProductDir"},
89 {NET2003, "MSVC.NET 2003 (7.1)", "Software\\Wow6432Node\\Microsoft\\VisualStudio\\7.1\\Setup\\VC\\ProductDir"},
90 {NET2002, "MSVC.NET 2002 (7.0)", "Software\\Wow6432Node\\Microsoft\\VisualStudio\\7.0\\Setup\\VC\\ProductDir"},
92 {NET2013, "MSVC.NET 2013 (12.0)", "Software\\Microsoft\\VisualStudio\\12.0\\Setup\\VC\\ProductDir"},
93 {NET2013, "MSVC.NET 2013 Express Edition (12.0)", "Software\\Microsoft\\VCExpress\\12.0\\Setup\\VC\\ProductDir"},
94 {NET2012, "MSVC.NET 2012 (11.0)", "Software\\Microsoft\\VisualStudio\\11.0\\Setup\\VC\\ProductDir"},
95 {NET2012, "MSVC.NET 2012 Express Edition (11.0)", "Software\\Microsoft\\VCExpress\\11.0\\Setup\\VC\\ProductDir"},
96 {NET2010, "MSVC.NET 2010 (10.0)", "Software\\Microsoft\\VisualStudio\\10.0\\Setup\\VC\\ProductDir"},
97 {NET2010, "MSVC.NET 2010 Express Edition (10.0)", "Software\\Microsoft\\VCExpress\\10.0\\Setup\\VC\\ProductDir"},
98 {NET2008, "MSVC.NET 2008 (9.0)", "Software\\Microsoft\\VisualStudio\\9.0\\Setup\\VC\\ProductDir"},
99 {NET2008, "MSVC.NET 2008 Express Edition (9.0)", "Software\\Microsoft\\VCExpress\\9.0\\Setup\\VC\\ProductDir"},
100 {NET2005, "MSVC.NET 2005 (8.0)", "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir"},
101 {NET2005, "MSVC.NET 2005 Express Edition (8.0)", "Software\\Microsoft\\VCExpress\\8.0\\Setup\\VC\\ProductDir"},
102 {NET2003, "MSVC.NET 2003 (7.1)", "Software\\Microsoft\\VisualStudio\\7.1\\Setup\\VC\\ProductDir"},
103 {NET2002, "MSVC.NET 2002 (7.0)", "Software\\Microsoft\\VisualStudio\\7.0\\Setup\\VC\\ProductDir"},
105 {NETUnknown, "", ""},
112 DotNET which_dotnet_version()
115 return NET2002; // Always generate 7.0 versions on other platforms
117 // Only search for the version once
118 static DotNET current_version = NETUnknown;
119 if(current_version != NETUnknown)
120 return current_version;
122 // Fallback to .NET 2002
123 current_version = NET2002;
125 QStringList warnPath;
126 QHash<DotNET, QString> installPaths;
129 for(; dotNetCombo[i].version; ++i) {
130 QString path = qt_readRegistryKey(HKEY_LOCAL_MACHINE, dotNetCombo[i].regKey);
131 if (!path.isEmpty() && installPaths.value(dotNetCombo[i].version) != path) {
132 installPaths.insert(dotNetCombo[i].version, path);
134 current_version = dotNetCombo[i].version;
135 warnPath += QString("%1").arg(dotNetCombo[i].versionStr);
140 return current_version;
142 // More than one version installed, search directory path
143 QString paths = qgetenv("PATH");
144 QStringList pathlist = paths.toLower().split(";");
147 for(; dotNetCombo[i].version; ++i) {
148 QString productPath = qt_readRegistryKey(HKEY_LOCAL_MACHINE, dotNetCombo[i].regKey).toLower();
149 if (productPath.isEmpty())
151 QStringList::iterator it;
152 for(it = pathlist.begin(); it != pathlist.end(); ++it) {
153 if((*it).contains(productPath)) {
155 current_version = dotNetCombo[i].version;
156 warnPath += QString("%1 in path").arg(dotNetCombo[i].versionStr);
165 warn_msg(WarnLogic, "Generator: MSVC.NET: Found more than one version of Visual Studio, but"
166 " none in your path! Fallback to lowest version (%s)", warnPath.join(", ").toLatin1().data());
169 warn_msg(WarnLogic, "Generator: MSVC.NET: Found more than one version of Visual Studio in"
170 " your path! Fallback to lowest version (%s)", warnPath.join(", ").toLatin1().data());
174 return current_version;
178 // Flatfile Tags ----------------------------------------------------
179 const char _slnHeader70[] = "Microsoft Visual Studio Solution File, Format Version 7.00";
180 const char _slnHeader71[] = "Microsoft Visual Studio Solution File, Format Version 8.00";
181 const char _slnHeader80[] = "Microsoft Visual Studio Solution File, Format Version 9.00"
182 "\n# Visual Studio 2005";
183 const char _slnHeader90[] = "Microsoft Visual Studio Solution File, Format Version 10.00"
184 "\n# Visual Studio 2008";
185 const char _slnHeader100[] = "Microsoft Visual Studio Solution File, Format Version 11.00"
186 "\n# Visual Studio 2010";
187 const char _slnHeader110[] = "Microsoft Visual Studio Solution File, Format Version 12.00"
188 "\n# Visual Studio 2012";
189 const char _slnHeader120[] = "Microsoft Visual Studio Solution File, Format Version 12.00"
190 "\n# Visual Studio 2013";
191 // The following UUID _may_ change for later servicepacks...
192 // If so we need to search through the registry at
193 // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.0\Projects
194 // to find the subkey that contains a "PossibleProjectExtension"
195 // containing "vcproj"...
196 // Use the hardcoded value for now so projects generated on other
197 // platforms are actually usable.
198 const char _slnMSVCvcprojGUID[] = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}";
199 const char _slnProjectBeg[] = "\nProject(\"";
200 const char _slnProjectMid[] = "\") = ";
201 const char _slnProjectEnd[] = "\nEndProject";
202 const char _slnGlobalBeg[] = "\nGlobal";
203 const char _slnGlobalEnd[] = "\nEndGlobal";
204 const char _slnSolutionConf[] = "\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution"
205 "\n\t\tDebug|Win32 = Debug|Win32"
206 "\n\t\tRelease|Win32 = Release|Win32"
207 "\n\tEndGlobalSection";
208 const char _slnProjDepBeg[] = "\n\tGlobalSection(ProjectDependencies) = postSolution";
209 const char _slnProjDepEnd[] = "\n\tEndGlobalSection";
210 const char _slnProjConfBeg[] = "\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution";
211 const char _slnProjRelConfTag1[]= ".Release|%1.ActiveCfg = Release|";
212 const char _slnProjRelConfTag2[]= ".Release|%1.Build.0 = Release|";
213 const char _slnProjDbgConfTag1[]= ".Debug|%1.ActiveCfg = Debug|";
214 const char _slnProjDbgConfTag2[]= ".Debug|%1.Build.0 = Debug|";
215 const char _slnProjConfEnd[] = "\n\tEndGlobalSection";
216 const char _slnExtSections[] = "\n\tGlobalSection(ExtensibilityGlobals) = postSolution"
217 "\n\tEndGlobalSection"
218 "\n\tGlobalSection(ExtensibilityAddIns) = postSolution"
219 "\n\tEndGlobalSection";
220 // ------------------------------------------------------------------
222 VcprojGenerator::VcprojGenerator()
223 : Win32MakefileGenerator(),
230 VcprojGenerator::~VcprojGenerator()
232 delete projectWriter;
235 bool VcprojGenerator::writeMakefile(QTextStream &t)
237 initProject(); // Fills the whole project with proper data
239 // Generate solution file
240 if(project->first("TEMPLATE") == "vcsubdirs") {
241 if (!project->isActiveConfig("build_pass")) {
242 debug_msg(1, "Generator: MSVC.NET: Writing solution file");
245 debug_msg(1, "Generator: MSVC.NET: Not writing solution file for build_pass configs");
249 // Generate single configuration project file
250 if (project->first("TEMPLATE") == "vcapp" ||
251 project->first("TEMPLATE") == "vclib") {
252 if(!project->isActiveConfig("build_pass")) {
253 debug_msg(1, "Generator: MSVC.NET: Writing single configuration project file");
255 projectWriter->write(xmlOut, vcProject);
259 return project->isActiveConfig("build_pass");
262 bool VcprojGenerator::writeProjectMakefile()
265 QTextStream t(&Option::output);
267 // Check if all requirements are fulfilled
268 if(!project->values("QMAKE_FAILED_REQUIREMENTS").isEmpty()) {
269 fprintf(stderr, "Project file not generated because all requirements not met:\n\t%s\n",
270 var("QMAKE_FAILED_REQUIREMENTS").toLatin1().constData());
274 // Generate project file
275 if(project->first("TEMPLATE") == "vcapp" ||
276 project->first("TEMPLATE") == "vclib") {
277 if (!mergedProjects.count()) {
278 warn_msg(WarnLogic, "Generator: MSVC.NET: no single configuration created, cannot output project!");
282 debug_msg(1, "Generator: MSVC.NET: Writing project file");
283 VCProject mergedProject;
284 for (int i = 0; i < mergedProjects.count(); ++i) {
285 VCProjectSingleConfig *singleProject = &(mergedProjects.at(i)->vcProject);
286 mergedProject.SingleProjects += *singleProject;
287 for (int j = 0; j < singleProject->ExtraCompilersFiles.count(); ++j) {
288 const QString &compilerName = singleProject->ExtraCompilersFiles.at(j).Name;
289 if (!mergedProject.ExtraCompilers.contains(compilerName))
290 mergedProject.ExtraCompilers += compilerName;
294 if(mergedProjects.count() > 1 &&
295 mergedProjects.at(0)->vcProject.Name ==
296 mergedProjects.at(1)->vcProject.Name)
297 mergedProjects.at(0)->writePrlFile();
298 mergedProject.Name = project->first("QMAKE_PROJECT_NAME");
299 mergedProject.Version = mergedProjects.at(0)->vcProject.Version;
300 mergedProject.ProjectGUID = project->isEmpty("QMAKE_UUID") ? getProjectUUID().toString().toUpper() : project->first("QMAKE_UUID");
301 mergedProject.Keyword = project->first("VCPROJ_KEYWORD");
302 mergedProject.SccProjectName = mergedProjects.at(0)->vcProject.SccProjectName;
303 mergedProject.SccLocalPath = mergedProjects.at(0)->vcProject.SccLocalPath;
304 mergedProject.PlatformName = mergedProjects.at(0)->vcProject.PlatformName;
307 projectWriter->write(xmlOut, mergedProject);
309 } else if(project->first("TEMPLATE") == "vcsubdirs") {
310 return writeMakefile(t);
315 struct VcsolutionDepend {
317 QString vcprojFile, orig_target, target;
319 QStringList dependencies;
322 QUuid VcprojGenerator::getProjectUUID(const QString &filename)
324 bool validUUID = true;
326 // Read GUID from variable-space
327 QUuid uuid = project->first("GUID");
329 // If none, create one based on the MD5 of absolute project path
330 if(uuid.isNull() || !filename.isEmpty()) {
331 QString abspath = Option::fixPathToLocalOS(filename.isEmpty()?project->first("QMAKE_MAKEFILE"):filename);
332 QByteArray digest = QCryptographicHash::hash(abspath.toUtf8(), QCryptographicHash::Md5);
333 memcpy((unsigned char*)(&uuid), digest.constData(), sizeof(QUuid));
334 validUUID = !uuid.isNull();
335 uuid.data4[0] = (uuid.data4[0] & 0x3F) | 0x80; // UV_DCE variant
336 uuid.data3 = (uuid.data3 & 0x0FFF) | (QUuid::Name<<12);
339 // If still not valid, generate new one, and suggest adding to .pro
340 if(uuid.isNull() || !validUUID) {
341 uuid = QUuid::createUuid();
343 "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",
344 uuid.toString().toUpper().toLatin1().constData());
347 // Store GUID in variable-space
348 project->values("GUID") = QStringList(uuid.toString().toUpper());
352 QUuid VcprojGenerator::increaseUUID(const QUuid &id)
355 qint64 dataFirst = (result.data4[0] << 24) +
356 (result.data4[1] << 16) +
357 (result.data4[2] << 8) +
359 qint64 dataLast = (result.data4[4] << 24) +
360 (result.data4[5] << 16) +
361 (result.data4[6] << 8) +
367 result.data4[0] = uchar((dataFirst >> 24) & 0xff);
368 result.data4[1] = uchar((dataFirst >> 16) & 0xff);
369 result.data4[2] = uchar((dataFirst >> 8) & 0xff);
370 result.data4[3] = uchar(dataFirst & 0xff);
371 result.data4[4] = uchar((dataLast >> 24) & 0xff);
372 result.data4[5] = uchar((dataLast >> 16) & 0xff);
373 result.data4[6] = uchar((dataLast >> 8) & 0xff);
374 result.data4[7] = uchar(dataLast & 0xff);
378 bool VcprojGenerator::isStandardSuffix(const QString &suffix) const
380 if (!project->values("QMAKE_APP_FLAG").isEmpty()) {
381 if (suffix.compare("exe", Qt::CaseInsensitive) == 0)
383 } else if (project->isActiveConfig("shared")) {
384 if (suffix.compare("dll", Qt::CaseInsensitive) == 0)
387 if (suffix.compare("lib", Qt::CaseInsensitive) == 0)
393 QStringList VcprojGenerator::collectSubDirs(QMakeProject *proj)
396 QStringList tmp_proj_subdirs = proj->variables()["SUBDIRS"];
397 for(int x = 0; x < tmp_proj_subdirs.size(); ++x) {
398 QString tmpdir = tmp_proj_subdirs.at(x);
399 if(!proj->isEmpty(tmpdir + ".file")) {
400 if(!proj->isEmpty(tmpdir + ".subdir"))
401 warn_msg(WarnLogic, "Cannot assign both file and subdir for subdir %s",
402 tmpdir.toLatin1().constData());
403 tmpdir = proj->first(tmpdir + ".file");
404 } else if(!proj->isEmpty(tmpdir + ".subdir")) {
405 tmpdir = proj->first(tmpdir + ".subdir");
412 void VcprojGenerator::writeSubDirs(QTextStream &t)
414 // Check if all requirements are fulfilled
415 if(!project->values("QMAKE_FAILED_REQUIREMENTS").isEmpty()) {
416 fprintf(stderr, "Project file not generated because all requirements not met:\n\t%s\n",
417 var("QMAKE_FAILED_REQUIREMENTS").toLatin1().constData());
421 switch(which_dotnet_version()) {
445 warn_msg(WarnLogic, "Generator: MSVC.NET: Unknown version (%d) of MSVC detected for .sln", which_dotnet_version());
449 QHash<QString, VcsolutionDepend*> solution_depends;
450 QList<VcsolutionDepend*> solution_cleanup;
452 QString oldpwd = qmake_getpwd();
454 // Make sure that all temp projects are configured
455 // for release so that the depends are created
456 // without the debug <lib>dxxx.lib name mangling
457 QStringList old_after_vars = Option::after_user_vars;
458 Option::after_user_vars.append("CONFIG+=release");
460 QStringList subdirs = collectSubDirs(project);
461 for(int i = 0; i < subdirs.size(); ++i) {
462 QString tmp = subdirs.at(i);
463 QFileInfo fi(fileInfo(Option::fixPathToLocalOS(tmp, true)));
466 QString profile = tmp;
467 if(!profile.endsWith(Option::dir_sep))
468 profile += Option::dir_sep;
469 profile += fi.baseName() + Option::pro_ext;
470 subdirs.append(profile);
472 QMakeProject tmp_proj;
473 QString dir = fi.path(), fn = fi.fileName();
475 if(!qmake_setpwd(dir))
476 fprintf(stderr, "Cannot find directory: %s\n", dir.toLatin1().constData());
478 if(tmp_proj.read(fn)) {
479 // Check if all requirements are fulfilled
480 if(!tmp_proj.variables()["QMAKE_FAILED_REQUIREMENTS"].isEmpty()) {
481 fprintf(stderr, "Project file(%s) not added to Solution because all requirements not met:\n\t%s\n",
482 fn.toLatin1().constData(), tmp_proj.values("QMAKE_FAILED_REQUIREMENTS").join(" ").toLatin1().constData());
485 if(tmp_proj.first("TEMPLATE") == "vcsubdirs") {
486 foreach(const QString &tmpdir, collectSubDirs(&tmp_proj))
487 subdirs += fileFixify(tmpdir);
488 } else if(tmp_proj.first("TEMPLATE") == "vcapp" || tmp_proj.first("TEMPLATE") == "vclib") {
489 // Initialize a 'fake' project to get the correct variables
490 // and to be able to extract all the dependencies
491 Option::QMAKE_MODE old_mode = Option::qmake_mode;
492 Option::qmake_mode = Option::QMAKE_GENERATE_NOTHING;
493 QString old_output_dir = Option::output_dir;
494 Option::output_dir = QFileInfo(fileFixify(dir, qmake_getpwd(), Option::output_dir)).canonicalFilePath();
495 VcprojGenerator tmp_vcproj;
496 tmp_vcproj.setNoIO(true);
497 tmp_vcproj.setProjectFile(&tmp_proj);
498 Option::qmake_mode = old_mode;
499 Option::output_dir = old_output_dir;
500 if(Option::debug_level) {
501 debug_msg(1, "Dumping all variables:");
502 QMap<QString, QStringList> &vars = tmp_proj.variables();
503 for(QMap<QString, QStringList>::Iterator it = vars.begin();
504 it != vars.end(); ++it) {
505 if(it.key().left(1) != "." && !it.value().isEmpty())
506 debug_msg(1, "%s: %s === %s", fn.toLatin1().constData(), it.key().toLatin1().constData(),
507 it.value().join(" :: ").toLatin1().constData());
511 // We assume project filename is [QMAKE_PROJECT_NAME].vcproj
512 QString vcproj = unescapeFilePath(tmp_vcproj.project->first("QMAKE_PROJECT_NAME") + project->first("VCPROJ_EXTENSION"));
513 QString vcprojDir = qmake_getpwd();
515 // If file doesn't exsist, then maybe the users configuration
516 // doesn't allow it to be created. Skip to next...
517 if(!exists(vcprojDir + Option::dir_sep + vcproj)) {
519 // Try to find the directory which fits relative
520 // to the output path, which represents the shadow
521 // path in case we are shadow building
522 QStringList list = fi.path().split(QLatin1Char('/'));
523 QString tmpDir = QFileInfo(Option::output).path() + Option::dir_sep;
525 for (int i = list.size() - 1; i >= 0; --i) {
527 for (int j = i; j < list.size(); ++j)
528 curr += list.at(j) + Option::dir_sep;
529 if (exists(tmpDir + curr + vcproj)) {
530 vcprojDir = QDir::cleanPath(tmpDir + curr);
536 warn_msg(WarnLogic, "Ignored (not found) '%s'", QString(vcprojDir + Option::dir_sep + vcproj).toLatin1().constData());
537 goto nextfile; // # Dirty!
541 VcsolutionDepend *newDep = new VcsolutionDepend;
542 newDep->vcprojFile = vcprojDir + Option::dir_sep + vcproj;
543 newDep->orig_target = unescapeFilePath(tmp_proj.first("QMAKE_ORIG_TARGET"));
544 newDep->target = tmp_proj.first("MSVCPROJ_TARGET").section(Option::dir_sep, -1);
545 newDep->targetType = tmp_vcproj.projectTarget;
546 newDep->uuid = tmp_proj.isEmpty("QMAKE_UUID") ? getProjectUUID(Option::fixPathToLocalOS(vcprojDir + QDir::separator() + vcproj)).toString().toUpper(): tmp_proj.first("QMAKE_UUID");
548 // We want to store it as the .lib name.
549 if(newDep->target.endsWith(".dll"))
550 newDep->target = newDep->target.left(newDep->target.length()-3) + "lib";
552 // All ActiveQt Server projects are dependent on idc.exe
553 if(tmp_proj.variables()["CONFIG"].contains("qaxserver"))
554 newDep->dependencies << "idc.exe";
556 // All extra compilers which has valid input are considered dependencies
557 const QStringList &quc = tmp_proj.variables()["QMAKE_EXTRA_COMPILERS"];
558 for(QStringList::ConstIterator it = quc.constBegin(); it != quc.constEnd(); ++it) {
559 const QStringList &invar = tmp_proj.variables().value((*it) + ".input");
560 for(QStringList::ConstIterator iit = invar.constBegin(); iit != invar.constEnd(); ++iit) {
561 const QStringList fileList = tmp_proj.variables().value(*iit);
562 if (!fileList.isEmpty()) {
563 const QStringList &cmdsParts = tmp_proj.variables().value((*it) + ".commands");
564 bool startOfLine = true;
565 foreach(QString cmd, cmdsParts) {
567 if (cmd.contains("\r"))
575 // Extra compiler commands might be defined in variables, so
576 // expand them (don't care about the in/out files)
577 cmd = tmp_vcproj.replaceExtraCompilerVariables(cmd, QStringList(), QStringList());
578 // Pull out command based on spaces and quoting, if the
579 // command starts with that
580 cmd = cmd.left(cmd.indexOf(cmd.at(0) == '"' ? '"' : ' ', 1));
581 QString dep = cmd.section('/', -1).section('\\', -1);
582 if (!newDep->dependencies.contains(dep))
583 newDep->dependencies << dep;
589 // Add all unknown libs to the deps
590 QStringList where = QStringList() << "QMAKE_LIBS" << "QMAKE_LIBS_PRIVATE";
591 if(!tmp_proj.isEmpty("QMAKE_INTERNAL_PRL_LIBS"))
592 where = tmp_proj.variables()["QMAKE_INTERNAL_PRL_LIBS"];
593 for(QStringList::iterator wit = where.begin();
594 wit != where.end(); ++wit) {
595 QStringList &l = tmp_proj.variables()[(*wit)];
596 for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
598 if(!opt.startsWith("/") && // Not a switch
599 opt != newDep->target && // Not self
600 opt != "opengl32.lib" && // We don't care about these libs
601 opt != "glu32.lib" && // to make depgen alittle faster
602 opt != "kernel32.lib" &&
603 opt != "user32.lib" &&
604 opt != "gdi32.lib" &&
605 opt != "comdlg32.lib" &&
606 opt != "advapi32.lib" &&
607 opt != "shell32.lib" &&
608 opt != "ole32.lib" &&
609 opt != "oleaut32.lib" &&
611 opt != "imm32.lib" &&
612 opt != "winmm.lib" &&
613 opt != "wsock32.lib" &&
614 opt != "ws2_32.lib" &&
615 opt != "winspool.lib" &&
616 opt != "delayimp.lib")
618 newDep->dependencies << opt.section(Option::dir_sep, -1);
622 #ifdef DEBUG_SOLUTION_GEN
623 qDebug("Deps for %20s: [%s]", newDep->target.toLatin1().constData(), newDep->dependencies.join(" :: ").toLatin1().constData());
625 solution_cleanup.append(newDep);
626 solution_depends.insert(newDep->target, newDep);
627 t << _slnProjectBeg << _slnMSVCvcprojGUID << _slnProjectMid
628 << "\"" << newDep->orig_target << "\", \"" << newDep->vcprojFile
629 << "\", \"" << newDep->uuid << "\"";
634 qmake_setpwd(oldpwd);
640 QString slnConf = _slnSolutionConf;
641 if (!project->isEmpty("CE_SDK") && !project->isEmpty("CE_ARCH")) {
642 QString slnPlatform = QString("|") + project->values("CE_SDK").join(" ") + " (" + project->first("CE_ARCH") + ")";
643 slnConf.replace(QString("|Win32"), slnPlatform);
644 } else if (is64Bit) {
645 slnConf.replace(QString("|Win32"), "|x64");
651 // Restore previous after_user_var options
652 Option::after_user_vars = old_after_vars;
654 // Figure out dependencies
655 for(QList<VcsolutionDepend*>::Iterator it = solution_cleanup.begin(); it != solution_cleanup.end(); ++it) {
657 for(QStringList::iterator dit = (*it)->dependencies.begin(); dit != (*it)->dependencies.end(); ++dit) {
658 if(VcsolutionDepend *vc = solution_depends[*dit])
659 t << "\n\t\t" << (*it)->uuid << "." << cnt++ << " = " << vc->uuid;
663 t << _slnProjConfBeg;
664 for(QList<VcsolutionDepend*>::Iterator it = solution_cleanup.begin(); it != solution_cleanup.end(); ++it) {
665 QString platform = is64Bit ? "x64" : "Win32";
666 if (!project->isEmpty("CE_SDK") && !project->isEmpty("CE_ARCH"))
667 platform = project->values("CE_SDK").join(" ") + " (" + project->first("CE_ARCH") + ")";
668 t << "\n\t\t" << (*it)->uuid << QString(_slnProjDbgConfTag1).arg(platform) << platform;
669 t << "\n\t\t" << (*it)->uuid << QString(_slnProjDbgConfTag2).arg(platform) << platform;
670 t << "\n\t\t" << (*it)->uuid << QString(_slnProjRelConfTag1).arg(platform) << platform;
671 t << "\n\t\t" << (*it)->uuid << QString(_slnProjRelConfTag2).arg(platform) << platform;
673 t << _slnProjConfEnd;
674 t << _slnExtSections;
678 while (!solution_cleanup.isEmpty())
679 delete solution_cleanup.takeFirst();
682 // ------------------------------------------------------------------------------------------------
683 // ------------------------------------------------------------------------------------------------
685 bool VcprojGenerator::hasBuiltinCompiler(const QString &file)
688 for (int i = 0; i < Option::cpp_ext.count(); ++i)
689 if (file.endsWith(Option::cpp_ext.at(i)))
691 for (int i = 0; i < Option::c_ext.count(); ++i)
692 if (file.endsWith(Option::c_ext.at(i)))
694 if (file.endsWith(".rc")
695 || file.endsWith(".idl"))
700 void VcprojGenerator::init()
705 is64Bit = (project->first("QMAKE_TARGET.arch") == "x86_64");
706 projectWriter = createProjectWriter();
708 if(project->first("TEMPLATE") == "vcsubdirs") //too much work for subdirs
711 debug_msg(1, "Generator: MSVC.NET: Initializing variables");
713 // this should probably not be here, but I'm using it to wrap the .t files
714 if (project->first("TEMPLATE") == "vcapp")
715 project->values("QMAKE_APP_FLAG").append("1");
716 else if (project->first("TEMPLATE") == "vclib")
717 project->values("QMAKE_LIB_FLAG").append("1");
718 if (project->values("QMAKESPEC").isEmpty())
719 project->values("QMAKESPEC").append(qgetenv("QMAKESPEC"));
723 project->values("QMAKE_LIBS") += escapeFilePaths(project->values("LIBS"));
724 project->values("QMAKE_LIBS_PRIVATE") += escapeFilePaths(project->values("LIBS_PRIVATE"));
726 if(!project->values("VERSION").isEmpty()) {
727 QString version = project->values("VERSION")[0];
728 int firstDot = version.indexOf(".");
729 QString major = version.left(firstDot);
730 QString minor = version.right(version.length() - firstDot - 1);
731 minor.replace(QRegExp("\\."), "");
732 project->values("QMAKE_LFLAGS").append("/VERSION:" + major + "." + minor);
735 MakefileGenerator::init();
736 initOld(); // Currently calling old DSP code to set variables. CLEAN UP!
738 // Figure out what we're trying to build
739 if(project->first("TEMPLATE") == "vcapp") {
740 projectTarget = Application;
741 } else if(project->first("TEMPLATE") == "vclib") {
742 if(project->isActiveConfig("staticlib")) {
743 if (!project->values("RES_FILE").isEmpty())
744 project->values("MSVCPROJ_LIBS") += escapeFilePaths(project->values("RES_FILE"));
745 projectTarget = StaticLib;
747 projectTarget = SharedLib;
750 // Setup PCH variables
751 precompH = project->first("PRECOMPILED_HEADER");
752 precompCPP = project->first("PRECOMPILED_SOURCE");
753 usePCH = !precompH.isEmpty() && project->isActiveConfig("precompile_header");
755 precompHFilename = fileInfo(precompH).fileName();
757 QString origTarget = unescapeFilePath(project->first("QMAKE_ORIG_TARGET"));
758 precompObj = origTarget + Option::obj_ext;
759 precompPch = origTarget + ".pch";
760 // Add PRECOMPILED_HEADER to HEADERS
761 if (!project->values("HEADERS").contains(precompH))
762 project->values("HEADERS") += precompH;
763 // Return to variable pool
764 project->values("PRECOMPILED_OBJECT") = QStringList(precompObj);
765 project->values("PRECOMPILED_PCH") = QStringList(precompPch);
767 autogenPrecompCPP = precompCPP.isEmpty() && project->isActiveConfig("autogen_precompile_source");
768 if (autogenPrecompCPP) {
769 precompCPP = precompH
770 + (Option::cpp_ext.count() ? Option::cpp_ext.at(0) : QLatin1String(".cpp"));
771 project->values("GENERATED_SOURCES") += precompCPP;
772 } else if (!precompCPP.isEmpty()) {
773 project->values("SOURCES") += precompCPP;
777 // Add all input files for a custom compiler into a map for uniqueness,
778 // unless the compiler is configure as a combined stage, then use the first one
779 const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS");
780 for(QStringList::ConstIterator it = quc.constBegin(); it != quc.constEnd(); ++it) {
781 const QStringList &invar = project->variables().value((*it) + ".input");
782 const QString compiler_out = project->first((*it) + ".output");
783 for(QStringList::ConstIterator iit = invar.constBegin(); iit != invar.constEnd(); ++iit) {
784 QStringList fileList = project->variables().value(*iit);
785 if (!fileList.isEmpty()) {
786 if (project->values((*it) + ".CONFIG").indexOf("combine") != -1)
787 fileList = QStringList(fileList.first());
788 for(QStringList::ConstIterator fit = fileList.constBegin(); fit != fileList.constEnd(); ++fit) {
789 QString file = (*fit);
790 if (verifyExtraCompiler((*it), file)) {
791 if (!hasBuiltinCompiler(file)) {
792 extraCompilerSources[file] += *it;
794 QString out = Option::fixPathToTargetOS(replaceExtraCompilerVariables(
795 compiler_out, file, QString()), false);
796 extraCompilerSources[out] += *it;
797 extraCompilerOutputs[out] = QStringList(file); // Can only have one
806 Q_FOREACH(QString aKey, extraCompilerSources.keys()) {
807 qDebug("Extracompilers for %s are (%s)", aKey.toLatin1().constData(), extraCompilerSources.value(aKey).join(", ").toLatin1().constData());
809 Q_FOREACH(QString aKey, extraCompilerOutputs.keys()) {
810 qDebug("Object mapping for %s is (%s)", aKey.toLatin1().constData(), extraCompilerOutputs.value(aKey).join(", ").toLatin1().constData());
816 bool VcprojGenerator::mergeBuildProject(MakefileGenerator *other)
818 if (!other || !other->projectFile()) {
819 warn_msg(WarnLogic, "VcprojGenerator: Cannot merge null project.");
822 if (other->projectFile()->first("MAKEFILE_GENERATOR") != project->first("MAKEFILE_GENERATOR")) {
823 warn_msg(WarnLogic, "VcprojGenerator: Cannot merge other types of projects! (ignored)");
827 VcprojGenerator *otherVC = static_cast<VcprojGenerator*>(other);
828 mergedProjects += otherVC;
832 void VcprojGenerator::initProject()
834 // Initialize XML sub elements
835 // - Do this first since project elements may need
836 // - to know of certain configuration options
841 initGeneratedFiles();
843 initTranslationFiles();
846 initExtraCompilerOutputs();
848 // Own elements -----------------------------
849 vcProject.Name = unescapeFilePath(project->first("QMAKE_ORIG_TARGET"));
850 switch(which_dotnet_version()) {
852 vcProject.Version = "13.00";
855 vcProject.Version = "12.00";
858 vcProject.Version = "10.00";
861 vcProject.Version = "9,00";
864 //### using ',' because of a bug in 2005 B2
865 //### VS uses '.' or ',' depending on the regional settings! Using ',' always works.
866 vcProject.Version = "8,00";
869 vcProject.Version = "7.10";
872 vcProject.Version = "7.00";
875 vcProject.Version = "7.00";
876 warn_msg(WarnLogic, "Generator: MSVC.NET: Unknown version (%d) of MSVC detected for .vcproj", which_dotnet_version());
880 vcProject.Keyword = project->first("VCPROJ_KEYWORD");
881 if (project->isEmpty("CE_SDK") || project->isEmpty("CE_ARCH")) {
882 vcProject.PlatformName = (is64Bit ? "x64" : "Win32");
884 vcProject.PlatformName = project->values("CE_SDK").join(" ") + " (" + project->first("CE_ARCH") + ")";
886 // These are not used by Qt, but may be used by customers
887 vcProject.SccProjectName = project->first("SCCPROJECTNAME");
888 vcProject.SccLocalPath = project->first("SCCLOCALPATH");
889 vcProject.flat_files = project->isActiveConfig("flat");
892 void VcprojGenerator::initConfiguration()
894 // Initialize XML sub elements
895 // - Do this first since main configuration elements may need
896 // - to know of certain compiler/linker options
897 VCConfiguration &conf = vcProject.Configuration;
898 conf.CompilerVersion = which_dotnet_version();
902 // Only on configuration per build
903 bool isDebug = project->isActiveConfig("debug");
905 if(projectTarget == StaticLib)
908 conf.linker.GenerateDebugInformation = isDebug ? _True : _False;
914 // Own elements -----------------------------
915 QString temp = project->first("BuildBrowserInformation");
916 switch (projectTarget) {
918 conf.ConfigurationType = typeDynamicLibrary;
921 conf.ConfigurationType = typeStaticLibrary;
925 conf.ConfigurationType = typeApplication;
929 conf.OutputDirectory = project->first("DESTDIR");
930 if (conf.OutputDirectory.isEmpty())
931 conf.OutputDirectory = ".\\";
932 if (!conf.OutputDirectory.endsWith("\\"))
933 conf.OutputDirectory += '\\';
934 if (conf.CompilerVersion >= NET2010) {
935 const QFileInfo targetInfo = fileInfo(project->first("MSVCPROJ_TARGET"));
936 conf.PrimaryOutput = targetInfo.completeBaseName();
938 const QString targetSuffix = targetInfo.suffix();
939 if (!isStandardSuffix(targetSuffix))
940 conf.PrimaryOutputExtension = '.' + targetSuffix;
943 conf.Name = project->values("BUILD_NAME").join(" ");
944 if (conf.Name.isEmpty())
945 conf.Name = isDebug ? "Debug" : "Release";
946 conf.ConfigurationName = conf.Name;
947 if (project->isEmpty("CE_SDK") || project->isEmpty("CE_ARCH")) {
948 conf.Name += (is64Bit ? "|x64" : "|Win32");
950 conf.Name += "|" + project->values("CE_SDK").join(" ") + " (" + project->first("CE_ARCH") + ")";
952 conf.ATLMinimizesCRunTimeLibraryUsage = (project->first("ATLMinimizesCRunTimeLibraryUsage").isEmpty() ? _False : _True);
953 conf.BuildBrowserInformation = triState(temp.isEmpty() ? (short)unset : temp.toShort());
954 temp = project->first("CharacterSet");
955 conf.CharacterSet = charSet(temp.isEmpty() ? (short)charSetNotSet : temp.toShort());
956 conf.DeleteExtensionsOnClean = project->first("DeleteExtensionsOnClean");
957 conf.ImportLibrary = conf.linker.ImportLibrary;
958 conf.IntermediateDirectory = project->first("OBJECTS_DIR");
959 conf.WholeProgramOptimization = conf.compiler.WholeProgramOptimization;
960 temp = project->first("UseOfATL");
962 conf.UseOfATL = useOfATL(temp.toShort());
963 temp = project->first("UseOfMfc");
965 conf.UseOfMfc = useOfMfc(temp.toShort());
967 // Configuration does not need parameters from
968 // these sub XML items;
969 initCustomBuildTool();
970 initPreBuildEventTools();
971 initPostBuildEventTools();
972 // Only deploy for CE projects
973 if (!project->isEmpty("CE_SDK") && !project->isEmpty("CE_ARCH"))
974 initDeploymentTool();
975 initPreLinkEventTools();
977 // Set definite values in both configurations
979 conf.compiler.PreprocessorDefinitions.removeAll("NDEBUG");
981 conf.compiler.PreprocessorDefinitions += "NDEBUG";
985 void VcprojGenerator::initCompilerTool()
987 QString placement = project->first("OBJECTS_DIR");
988 if(placement.isEmpty())
991 VCConfiguration &conf = vcProject.Configuration;
992 if (conf.CompilerVersion >= NET2010) {
993 // adjust compiler tool defaults for VS 2010 and above
994 conf.compiler.Optimization = optimizeDisabled;
996 conf.compiler.AssemblerListingLocation = placement ;
997 conf.compiler.ProgramDataBaseFileName = ".\\" ;
998 conf.compiler.ObjectFile = placement ;
999 conf.compiler.ExceptionHandling = ehNone;
1002 conf.compiler.UsePrecompiledHeader = pchUseUsingSpecific;
1003 conf.compiler.PrecompiledHeaderFile = "$(IntDir)\\" + precompPch;
1004 conf.compiler.PrecompiledHeaderThrough = project->first("PRECOMPILED_HEADER");
1005 conf.compiler.ForcedIncludeFiles = project->values("PRECOMPILED_HEADER");
1007 if (conf.CompilerVersion <= NET2003) {
1008 // Minimal build option triggers an Internal Compiler Error
1009 // when used in conjunction with /FI and /Yu, so remove it
1010 // ### work-around for a VS 2003 bug. Move to some prf file or remove completely.
1011 project->values("QMAKE_CFLAGS_DEBUG").removeAll("-Gm");
1012 project->values("QMAKE_CFLAGS_DEBUG").removeAll("/Gm");
1013 project->values("QMAKE_CXXFLAGS_DEBUG").removeAll("-Gm");
1014 project->values("QMAKE_CXXFLAGS_DEBUG").removeAll("/Gm");
1018 conf.compiler.parseOptions(project->values("QMAKE_CXXFLAGS"));
1020 if (project->isActiveConfig("windows"))
1021 conf.compiler.PreprocessorDefinitions += "_WINDOWS";
1022 else if (project->isActiveConfig("console"))
1023 conf.compiler.PreprocessorDefinitions += "_CONSOLE";
1025 conf.compiler.PreprocessorDefinitions += project->values("DEFINES");
1026 conf.compiler.PreprocessorDefinitions += project->values("PRL_EXPORT_DEFINES");
1027 conf.compiler.parseOptions(project->values("MSVCPROJ_INCPATH"));
1030 void VcprojGenerator::initLibrarianTool()
1032 VCConfiguration &conf = vcProject.Configuration;
1033 conf.librarian.OutputFile = "$(OutDir)\\";
1034 conf.librarian.OutputFile += project->first("MSVCPROJ_TARGET");
1035 conf.librarian.AdditionalOptions += project->values("QMAKE_LIBFLAGS");
1038 void VcprojGenerator::initLinkerTool()
1040 findLibraries(); // Need to add the highest version of the libs
1041 VCConfiguration &conf = vcProject.Configuration;
1042 conf.linker.parseOptions(project->values("QMAKE_LFLAGS"));
1044 foreach (const QString &libDir, project->values("QMAKE_LIBDIR")) {
1045 if (libDir.startsWith("/LIBPATH:"))
1046 conf.linker.AdditionalLibraryDirectories += libDir.mid(9);
1048 conf.linker.AdditionalLibraryDirectories += libDir;
1051 if (!project->values("DEF_FILE").isEmpty())
1052 conf.linker.ModuleDefinitionFile = project->first("DEF_FILE");
1054 foreach(QString libs, project->values("MSVCPROJ_LIBS")) {
1055 if (libs.left(9).toUpper() == "/LIBPATH:") {
1056 QStringList l = QStringList(libs);
1057 conf.linker.parseOptions(l);
1059 conf.linker.AdditionalDependencies += libs;
1063 conf.linker.OutputFile = "$(OutDir)\\";
1064 conf.linker.OutputFile += project->first("MSVCPROJ_TARGET");
1066 if(project->isActiveConfig("dll")){
1067 conf.linker.parseOptions(project->values("QMAKE_LFLAGS_QT_DLL"));
1071 void VcprojGenerator::initResourceTool()
1073 VCConfiguration &conf = vcProject.Configuration;
1074 conf.resource.PreprocessorDefinitions = conf.compiler.PreprocessorDefinitions;
1076 // We need to add _DEBUG for the debug version of the project, since the normal compiler defines
1077 // do not contain it. (The compiler defines this symbol automatically, which is wy we don't need
1078 // to add it for the compiler) However, the resource tool does not do this.
1079 if(project->isActiveConfig("debug"))
1080 conf.resource.PreprocessorDefinitions += "_DEBUG";
1081 if(project->isActiveConfig("staticlib"))
1082 conf.resource.ResourceOutputFileName = "$(OutDir)\\$(InputName).res";
1085 void VcprojGenerator::initIDLTool()
1089 void VcprojGenerator::initCustomBuildTool()
1093 void VcprojGenerator::initPreBuildEventTools()
1097 void VcprojGenerator::initPostBuildEventTools()
1099 VCConfiguration &conf = vcProject.Configuration;
1100 if (!project->values("QMAKE_POST_LINK").isEmpty()) {
1101 QStringList cmdline = VCToolBase::fixCommandLine(var("QMAKE_POST_LINK"));
1102 conf.postBuild.CommandLine = cmdline;
1103 conf.postBuild.Description = cmdline.join(QLatin1String("\r\n"));
1104 conf.postBuild.ExcludedFromBuild = _False;
1107 QString signature = !project->isEmpty("SIGNATURE_FILE") ? var("SIGNATURE_FILE") : var("DEFAULT_SIGNATURE");
1108 bool useSignature = !signature.isEmpty() && !project->isActiveConfig("staticlib") &&
1109 !project->isEmpty("CE_SDK") && !project->isEmpty("CE_ARCH");
1111 conf.postBuild.CommandLine.prepend(
1112 QLatin1String("signtool sign /F ") + signature + QLatin1String(" \"$(TargetPath)\""));
1113 conf.postBuild.ExcludedFromBuild = _False;
1116 if (!project->values("MSVCPROJ_COPY_DLL").isEmpty()) {
1117 conf.postBuild.Description += var("MSVCPROJ_COPY_DLL_DESC");
1118 conf.postBuild.CommandLine += var("MSVCPROJ_COPY_DLL");
1119 conf.postBuild.ExcludedFromBuild = _False;
1123 void VcprojGenerator::initDeploymentTool()
1125 VCConfiguration &conf = vcProject.Configuration;
1126 QString targetPath = project->values("deploy.path").join(" ");
1127 if (targetPath.isEmpty())
1128 targetPath = QString("%CSIDL_PROGRAM_FILES%\\") + project->first("TARGET");
1129 if (targetPath.endsWith("/") || targetPath.endsWith("\\"))
1132 // Only deploy Qt libs for shared build
1133 if (!project->values("QMAKE_QT_DLL").isEmpty()) {
1134 QStringList& arg = project->values("MSVCPROJ_LIBS");
1135 for (QStringList::ConstIterator it = arg.constBegin(); it != arg.constEnd(); ++it) {
1136 if (it->contains(project->first("QMAKE_LIBDIR"))) {
1137 QString dllName = *it;
1139 if (dllName.contains(QLatin1String("QAxContainer"))
1140 || dllName.contains(QLatin1String("qtmain"))
1141 || dllName.contains(QLatin1String("QtUiTools")))
1143 dllName.replace(QLatin1String(".lib") , QLatin1String(".dll"));
1144 QFileInfo info(dllName);
1145 conf.deployment.AdditionalFiles += info.fileName()
1146 + "|" + QDir::toNativeSeparators(info.absolutePath())
1153 // C-runtime deployment
1154 QString runtime = project->values("QT_CE_C_RUNTIME").join(QLatin1String(" "));
1155 if (!runtime.isEmpty() && (runtime != QLatin1String("no"))) {
1156 QString runtimeVersion = QLatin1String("msvcr");
1157 QString mkspec = project->first("QMAKESPEC");
1158 // If no .qmake.cache has been found, we fallback to the original mkspec
1159 if (mkspec.isEmpty())
1160 mkspec = project->first("QMAKESPEC_ORIGINAL");
1162 if (!mkspec.isEmpty()) {
1163 if (mkspec.endsWith("2008"))
1164 runtimeVersion.append("90");
1166 runtimeVersion.append("80");
1167 if (project->isActiveConfig("debug"))
1168 runtimeVersion.append("d");
1169 runtimeVersion.append(".dll");
1171 if (runtime == "yes") {
1172 // Auto-find C-runtime
1173 QString vcInstallDir = qgetenv("VCINSTALLDIR");
1174 if (!vcInstallDir.isEmpty()) {
1175 vcInstallDir += "\\ce\\dll\\";
1176 vcInstallDir += project->values("CE_ARCH").join(QLatin1String(" "));
1177 if (!QFileInfo(vcInstallDir + QDir::separator() + runtimeVersion).exists())
1180 runtime = vcInstallDir;
1185 if (!runtime.isEmpty() && runtime != QLatin1String("yes")) {
1186 conf.deployment.AdditionalFiles += runtimeVersion
1187 + "|" + QDir::toNativeSeparators(runtime)
1193 // foreach item in DEPLOYMENT
1194 foreach(QString item, project->values("DEPLOYMENT")) {
1196 QString devicePath = project->first(item + ".path");
1197 if (devicePath.isEmpty())
1198 devicePath = targetPath;
1199 // check if item.path is relative (! either /,\ or %)
1200 if (!(devicePath.at(0) == QLatin1Char('/')
1201 || devicePath.at(0) == QLatin1Char('\\')
1202 || devicePath.at(0) == QLatin1Char('%'))) {
1203 // create output path
1204 devicePath = Option::fixPathToLocalOS(QDir::cleanPath(targetPath + QLatin1Char('\\') + devicePath));
1206 // foreach d in item.sources
1207 // ### Qt 5: remove .sources, inconsistent with INSTALLS
1208 foreach(QString source, project->values(item + ".sources") + project->values(item + ".files")) {
1209 QString itemDevicePath = devicePath;
1210 source = Option::fixPathToLocalOS(source);
1212 QFileInfo info(source);
1215 nameFilter = QLatin1String("*");
1216 itemDevicePath += "\\" + info.fileName();
1217 searchPath = info.absoluteFilePath();
1219 nameFilter = source.split('\\').last();
1220 searchPath = info.absolutePath();
1223 int pathSize = searchPath.size();
1224 QDirIterator iterator(searchPath, QStringList() << nameFilter
1225 , QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks
1226 , QDirIterator::Subdirectories);
1227 // foreach dirIterator-entry in d
1228 while(iterator.hasNext()) {
1230 QString absoluteItemPath = Option::fixPathToLocalOS(QFileInfo(iterator.filePath()).absolutePath());
1231 // Identify if it is just another subdir
1232 int diffSize = absoluteItemPath.size() - pathSize;
1234 conf.deployment.AdditionalFiles += iterator.fileName()
1235 + "|" + absoluteItemPath
1236 + "|" + itemDevicePath + (diffSize ? (absoluteItemPath.right(diffSize)) : QLatin1String(""))
1243 void VcprojGenerator::initPreLinkEventTools()
1245 VCConfiguration &conf = vcProject.Configuration;
1246 if(!project->values("QMAKE_PRE_LINK").isEmpty()) {
1247 QStringList cmdline = VCToolBase::fixCommandLine(var("QMAKE_PRE_LINK"));
1248 conf.preLink.CommandLine = cmdline;
1249 conf.preLink.Description = cmdline.join(QLatin1String("\r\n"));
1250 conf.preLink.ExcludedFromBuild = _False;
1254 void VcprojGenerator::initRootFiles()
1256 // Note: Root files do _not_ have any filter name, filter nor GUID!
1257 vcProject.RootFiles.addFiles(project->values("RC_FILE"));
1259 vcProject.RootFiles.Project = this;
1260 vcProject.RootFiles.Config = &(vcProject.Configuration);
1261 vcProject.RootFiles.CustomBuild = none;
1264 void VcprojGenerator::initSourceFiles()
1266 vcProject.SourceFiles.Name = "Source Files";
1267 vcProject.SourceFiles.Filter = "cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx";
1268 vcProject.SourceFiles.Guid = _GUIDSourceFiles;
1270 vcProject.SourceFiles.addFiles(project->values("SOURCES"));
1272 vcProject.SourceFiles.Project = this;
1273 vcProject.SourceFiles.Config = &(vcProject.Configuration);
1274 vcProject.SourceFiles.CustomBuild = none;
1277 void VcprojGenerator::initHeaderFiles()
1279 vcProject.HeaderFiles.Name = "Header Files";
1280 vcProject.HeaderFiles.Filter = "h;hpp;hxx;hm;inl;inc;xsd";
1281 vcProject.HeaderFiles.Guid = _GUIDHeaderFiles;
1283 vcProject.HeaderFiles.addFiles(project->values("HEADERS"));
1284 if (usePCH) // Generated PCH cpp file
1285 vcProject.HeaderFiles.addFile(precompH);
1287 vcProject.HeaderFiles.Project = this;
1288 vcProject.HeaderFiles.Config = &(vcProject.Configuration);
1289 // vcProject.HeaderFiles.CustomBuild = mocHdr;
1290 // addMocArguments(vcProject.HeaderFiles);
1293 void VcprojGenerator::initGeneratedFiles()
1295 vcProject.GeneratedFiles.Name = "Generated Files";
1296 vcProject.GeneratedFiles.Filter = "cpp;c;cxx;moc;h;def;odl;idl;res;";
1297 vcProject.GeneratedFiles.Guid = _GUIDGeneratedFiles;
1299 // ### These cannot have CustomBuild (mocSrc)!!
1300 vcProject.GeneratedFiles.addFiles(project->values("GENERATED_SOURCES"));
1301 vcProject.GeneratedFiles.addFiles(project->values("GENERATED_FILES"));
1302 vcProject.GeneratedFiles.addFiles(project->values("IDLSOURCES"));
1303 if (project->values("RC_FILE").isEmpty())
1304 vcProject.GeneratedFiles.addFiles(project->values("RES_FILE"));
1305 vcProject.GeneratedFiles.addFiles(project->values("QMAKE_IMAGE_COLLECTION")); // compat
1306 if(!extraCompilerOutputs.isEmpty())
1307 vcProject.GeneratedFiles.addFiles(extraCompilerOutputs.keys());
1309 vcProject.GeneratedFiles.Project = this;
1310 vcProject.GeneratedFiles.Config = &(vcProject.Configuration);
1311 // vcProject.GeneratedFiles.CustomBuild = mocSrc;
1314 void VcprojGenerator::initLexYaccFiles()
1316 vcProject.LexYaccFiles.Name = "Lex / Yacc Files";
1317 vcProject.LexYaccFiles.ParseFiles = _False;
1318 vcProject.LexYaccFiles.Filter = "l;y";
1319 vcProject.LexYaccFiles.Guid = _GUIDLexYaccFiles;
1321 vcProject.LexYaccFiles.addFiles(project->values("LEXSOURCES"));
1322 vcProject.LexYaccFiles.addFiles(project->values("YACCSOURCES"));
1324 vcProject.LexYaccFiles.Project = this;
1325 vcProject.LexYaccFiles.Config = &(vcProject.Configuration);
1326 vcProject.LexYaccFiles.CustomBuild = lexyacc;
1329 void VcprojGenerator::initTranslationFiles()
1331 vcProject.TranslationFiles.Name = "Translation Files";
1332 vcProject.TranslationFiles.ParseFiles = _False;
1333 vcProject.TranslationFiles.Filter = "ts;xlf";
1334 vcProject.TranslationFiles.Guid = _GUIDTranslationFiles;
1336 vcProject.TranslationFiles.addFiles(project->values("TRANSLATIONS"));
1338 vcProject.TranslationFiles.Project = this;
1339 vcProject.TranslationFiles.Config = &(vcProject.Configuration);
1340 vcProject.TranslationFiles.CustomBuild = none;
1343 void VcprojGenerator::initFormFiles()
1345 vcProject.FormFiles.Name = "Form Files";
1346 vcProject.FormFiles.ParseFiles = _False;
1347 vcProject.FormFiles.Filter = "ui";
1348 vcProject.FormFiles.Guid = _GUIDFormFiles;
1350 vcProject.FormFiles.addFiles(project->values("FORMS"));
1351 vcProject.FormFiles.addFiles(project->values("FORMS3"));
1353 vcProject.FormFiles.Project = this;
1354 vcProject.FormFiles.Config = &(vcProject.Configuration);
1355 vcProject.FormFiles.CustomBuild = none;
1358 void VcprojGenerator::initResourceFiles()
1360 vcProject.ResourceFiles.Name = "Resource Files";
1361 vcProject.ResourceFiles.ParseFiles = _False;
1362 vcProject.ResourceFiles.Filter = "qrc;*"; //"rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;ts;xlf;qrc";
1363 vcProject.ResourceFiles.Guid = _GUIDResourceFiles;
1365 // Bad hack, please look away -------------------------------------
1366 QString rcc_dep_cmd = project->values("rcc.depend_command").join(" ");
1367 if(!rcc_dep_cmd.isEmpty()) {
1368 QStringList qrc_files = project->values("RESOURCES");
1370 if(!qrc_files.isEmpty()) {
1371 for (int i = 0; i < qrc_files.count(); ++i) {
1373 QString dep_cmd = replaceExtraCompilerVariables(rcc_dep_cmd, qrc_files.at(i),"");
1375 dep_cmd = Option::fixPathToLocalOS(dep_cmd, true, false);
1376 if(canExecute(dep_cmd)) {
1377 dep_cmd.prepend(QLatin1String("cd ")
1378 + escapeFilePath(Option::fixPathToLocalOS(Option::output_dir, false))
1379 + QLatin1String(" && "));
1380 if(FILE *proc = QT_POPEN(dep_cmd.toLatin1().constData(), "r")) {
1382 while(!feof(proc)) {
1383 int read_in = (int)fread(buff, 1, 255, proc);
1386 indeps += QByteArray(buff, read_in);
1389 if(!indeps.isEmpty())
1390 deps += fileFixify(indeps.replace('\n', ' ').simplified().split(' '),
1391 QString(), Option::output_dir);
1395 vcProject.ResourceFiles.addFiles(deps);
1398 // You may look again --------------------------------------------
1400 vcProject.ResourceFiles.addFiles(project->values("RESOURCES"));
1401 vcProject.ResourceFiles.addFiles(project->values("IMAGES"));
1403 vcProject.ResourceFiles.Project = this;
1404 vcProject.ResourceFiles.Config = &(vcProject.Configuration);
1405 vcProject.ResourceFiles.CustomBuild = none;
1408 void VcprojGenerator::initExtraCompilerOutputs()
1410 QStringList otherFilters;
1411 otherFilters << "FORMS"
1413 << "GENERATED_FILES"
1414 << "GENERATED_SOURCES"
1419 << "QMAKE_IMAGE_COLLECTION"
1426 const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS");
1427 for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) {
1428 QString extracompilerName = project->first((*it) + ".name");
1429 if (extracompilerName.isEmpty())
1430 extracompilerName = (*it);
1432 // Create an extra compiler filter and add the files
1433 VCFilter extraCompile;
1434 extraCompile.Name = extracompilerName;
1435 extraCompile.ParseFiles = _False;
1436 extraCompile.Filter = "";
1437 extraCompile.Guid = QString(_GUIDExtraCompilerFiles) + "-" + (*it);
1440 // If the extra compiler has a variable_out set the output file
1441 // is added to an other file list, and does not need its own..
1442 bool addOnInput = hasBuiltinCompiler(project->first((*it) + ".output"));
1443 QString tmp_other_out = project->first((*it) + ".variable_out");
1444 if (!tmp_other_out.isEmpty() && !addOnInput)
1448 QString tmp_out = project->first((*it) + ".output");
1449 if (project->values((*it) + ".CONFIG").indexOf("combine") != -1) {
1450 // Combined output, only one file result
1451 extraCompile.addFile(
1452 Option::fixPathToTargetOS(replaceExtraCompilerVariables(tmp_out, QString(), QString()), false));
1454 // One output file per input
1455 QStringList tmp_in = project->values(project->first((*it) + ".input"));
1456 for (int i = 0; i < tmp_in.count(); ++i) {
1457 const QString &filename = tmp_in.at(i);
1458 if (extraCompilerSources.contains(filename))
1459 extraCompile.addFile(
1460 Option::fixPathToTargetOS(replaceExtraCompilerVariables(filename, tmp_out, QString()), false));
1464 // In this case we the outputs have a built-in compiler, so we cannot add the custom
1465 // build steps there. So, we turn it around and add it to the input files instead,
1466 // provided that the input file variable is not handled already (those in otherFilters
1467 // are handled, so we avoid them).
1468 QStringList inputVars = project->values((*it) + ".input");
1469 foreach(QString inputVar, inputVars) {
1470 if (!otherFilters.contains(inputVar)) {
1471 QStringList tmp_in = project->values(inputVar);
1472 for (int i = 0; i < tmp_in.count(); ++i) {
1473 const QString &filename = tmp_in.at(i);
1474 if (extraCompilerSources.contains(filename))
1475 extraCompile.addFile(
1476 Option::fixPathToTargetOS(replaceExtraCompilerVariables(filename, QString(), QString()), false));
1481 extraCompile.Project = this;
1482 extraCompile.Config = &(vcProject.Configuration);
1483 extraCompile.CustomBuild = none;
1485 vcProject.ExtraCompilersFiles.append(extraCompile);
1489 void VcprojGenerator::initOld()
1491 // $$QMAKE.. -> $$MSVCPROJ.. -------------------------------------
1492 project->values("MSVCPROJ_LIBS") += project->values("QMAKE_LIBS");
1493 project->values("MSVCPROJ_LIBS") += project->values("QMAKE_LIBS_PRIVATE");
1494 QStringList &incs = project->values("INCLUDEPATH");
1495 for(QStringList::Iterator incit = incs.begin(); incit != incs.end(); ++incit) {
1496 QString inc = (*incit);
1497 if (!inc.startsWith('"') && !inc.endsWith('"'))
1498 inc = QString("\"%1\"").arg(inc); // Quote all paths if not quoted already
1499 project->values("MSVCPROJ_INCPATH").append("-I" + inc);
1501 project->values("MSVCPROJ_INCPATH").append("-I" + specdir());
1504 project->values("MSVCPROJ_TARGET") = QStringList(project->first("TARGET"));
1505 Option::fixPathToTargetOS(project->first("TARGET"));
1506 dest = project->first("TARGET") + project->first("TARGET_EXT");
1507 project->values("MSVCPROJ_TARGET") = QStringList(dest);
1509 // DLL COPY ------------------------------------------------------
1510 if(project->isActiveConfig("dll") && !project->values("DLLDESTDIR").isEmpty()) {
1511 QStringList dlldirs = project->values("DLLDESTDIR");
1512 QString copydll("");
1513 QStringList::Iterator dlldir;
1514 for(dlldir = dlldirs.begin(); dlldir != dlldirs.end(); ++dlldir) {
1515 if(!copydll.isEmpty())
1517 copydll += "copy \"$(TargetPath)\" \"" + *dlldir + "\"";
1520 QString deststr("Copy " + dest + " to ");
1521 for(dlldir = dlldirs.begin(); dlldir != dlldirs.end();) {
1524 if(dlldir != dlldirs.end())
1528 project->values("MSVCPROJ_COPY_DLL").append(copydll);
1529 project->values("MSVCPROJ_COPY_DLL_DESC").append(deststr);
1532 project->values("QMAKE_INTERNAL_PRL_LIBS") << "MSVCPROJ_LIBS";
1534 // Verbose output if "-d -d"...
1538 // ------------------------------------------------------------------------------------------------
1539 // ------------------------------------------------------------------------------------------------
1541 VCProjectWriter *VcprojGenerator::createProjectWriter()
1543 return new VCProjectWriter;
1546 QString VcprojGenerator::replaceExtraCompilerVariables(const QString &var, const QStringList &in, const QStringList &out)
1548 QString ret = MakefileGenerator::replaceExtraCompilerVariables(var, in, out);
1550 QStringList &defines = project->values("VCPROJ_MAKEFILE_DEFINES");
1551 if(defines.isEmpty())
1552 defines.append(varGlue("PRL_EXPORT_DEFINES"," -D"," -D","") +
1553 varGlue("DEFINES"," -D"," -D",""));
1554 ret.replace("$(DEFINES)", defines.first());
1556 QStringList &incpath = project->values("VCPROJ_MAKEFILE_INCPATH");
1557 if(incpath.isEmpty() && !this->var("MSVCPROJ_INCPATH").isEmpty())
1558 incpath.append(this->var("MSVCPROJ_INCPATH"));
1559 ret.replace("$(INCPATH)", incpath.join(" "));
1564 bool VcprojGenerator::openOutput(QFile &file, const QString &/*build*/) const
1567 if(!file.fileName().isEmpty()) {
1568 QFileInfo fi(fileInfo(file.fileName()));
1570 outdir = file.fileName() + QDir::separator();
1572 if(!outdir.isEmpty() || file.fileName().isEmpty()) {
1573 QString ext = project->first("VCPROJ_EXTENSION");
1574 if(project->first("TEMPLATE") == "vcsubdirs")
1575 ext = project->first("VCSOLUTION_EXTENSION");
1576 QString outputName = unescapeFilePath(project->first("TARGET"));
1577 if (!project->first("MAKEFILE").isEmpty())
1578 outputName = project->first("MAKEFILE");
1579 file.setFileName(outdir + outputName + ext);
1581 return Win32MakefileGenerator::openOutput(file, QString());
1584 QString VcprojGenerator::fixFilename(QString ofile) const
1586 ofile = Option::fixPathToLocalOS(ofile);
1587 int slashfind = ofile.lastIndexOf(Option::dir_sep);
1588 if(slashfind == -1) {
1589 ofile = ofile.replace('-', '_');
1591 int hyphenfind = ofile.indexOf('-', slashfind);
1592 while (hyphenfind != -1 && slashfind < hyphenfind) {
1593 ofile = ofile.replace(hyphenfind, 1, '_');
1594 hyphenfind = ofile.indexOf('-', hyphenfind + 1);
1600 QString VcprojGenerator::findTemplate(QString file)
1603 if(!exists((ret = file)) &&
1604 !exists((ret = QString(Option::mkfile::qmakespec + "/" + file))) &&
1605 !exists((ret = QString(QLibraryInfo::location(QLibraryInfo::DataPath) + "/win32-msvc.net/" + file))) &&
1606 !exists((ret = QString(QLibraryInfo::location(QLibraryInfo::DataPath) + "/win32-msvc2002/" + file))) &&
1607 !exists((ret = QString(QLibraryInfo::location(QLibraryInfo::DataPath) + "/win32-msvc2003/" + file))) &&
1608 !exists((ret = QString(QLibraryInfo::location(QLibraryInfo::DataPath) + "/win32-msvc2005/" + file))) &&
1609 !exists((ret = QString(QLibraryInfo::location(QLibraryInfo::DataPath) + "/win32-msvc2008/" + file))))
1611 debug_msg(1, "Generator: MSVC.NET: Found template \'%s\'", ret.toLatin1().constData());
1615 void VcprojGenerator::outputVariables()
1618 qDebug("Generator: MSVC.NET: List of current variables:");
1619 for(QMap<QString, QStringList>::ConstIterator it = project->variables().begin(); it != project->variables().end(); ++it)
1620 qDebug("Generator: MSVC.NET: %s => %s", qPrintable(it.key()), qPrintable(it.value().join(" | ")));