Debian Codegraph @

qmake/generators/win32/msvc_vcproj.cpp

raw
1 // Copyright (C) 2016 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4 #include "msvc_vcproj.h"
5 #include "option.h"
6 #include "xmloutput.h"
7
8 #include <ioutils.h>
9
10 #include <qdir.h>
11 #include <qdirlisting.h>
12 #include <qcryptographichash.h>
13 #include <qhash.h>
14 #include <quuid.h>
15 #include <qregularexpression.h>
16
17 #include <stdlib.h>
18 #include <tuple>
19 #include <utility>
20
21 //#define DEBUG_SOLUTION_GEN
22
23 using namespace QMakeInternal;
24 using namespace Qt::StringLiterals;
25
26 QT_BEGIN_NAMESPACE
27 // Filter GUIDs (Do NOT change these!) ------------------------------
28 const char _GUIDSourceFiles[] = "{4FC737F1-C7A5-4376-A066-2A32D752A2FF}";
29 const char _GUIDHeaderFiles[] = "{93995380-89BD-4b04-88EB-625FBE52EBFB}";
30 const char _GUIDGeneratedFiles[] = "{71ED8ED8-ACB9-4CE9-BBE1-E00B30144E11}";
31 const char _GUIDResourceFiles[] = "{D9D6E242-F8AF-46E4-B9FD-80ECBC20BA3E}";
32 const char _GUIDLexYaccFiles[] = "{E12AE0D2-192F-4d59-BD23-7D3FA58D3183}";
33 const char _GUIDTranslationFiles[] = "{639EADAA-A684-42e4-A9AD-28FC9BCB8F7C}";
34 const char _GUIDFormFiles[] = "{99349809-55BA-4b9d-BF79-8FDBB0286EB3}";
35 const char _GUIDExtraCompilerFiles[] = "{E0D8C965-CC5F-43d7-AD63-FAEF0BBC0F85}";
36 const char _GUIDDistributionFiles[] = "{B83CAF91-C7BF-462F-B76C-EA11631F866C}";
37
38 // Flatfile Tags ----------------------------------------------------
39 const char _slnHeader70[] = "Microsoft Visual Studio Solution File, Format Version 7.00";
40 const char _slnHeader71[] = "Microsoft Visual Studio Solution File, Format Version 8.00";
41 const char _slnHeader80[] = "Microsoft Visual Studio Solution File, Format Version 9.00"
42 "\n# Visual Studio 2005";
43 const char _slnHeader90[] = "Microsoft Visual Studio Solution File, Format Version 10.00"
44 "\n# Visual Studio 2008";
45 const char _slnHeader100[] = "Microsoft Visual Studio Solution File, Format Version 11.00"
46 "\n# Visual Studio 2010";
47 const char _slnHeader110[] = "Microsoft Visual Studio Solution File, Format Version 12.00"
48 "\n# Visual Studio 2012";
49 const char _slnHeader120[] = "Microsoft Visual Studio Solution File, Format Version 12.00"
50 "\n# Visual Studio 2013";
51 const char _slnHeader140[] = "Microsoft Visual Studio Solution File, Format Version 12.00"
52 "\n# Visual Studio 2015";
53 const char _slnHeader141[] = "Microsoft Visual Studio Solution File, Format Version 12.00"
54 "\n# Visual Studio 15";
55 const char _slnHeader142[] = "Microsoft Visual Studio Solution File, Format Version 12.00"
56 "\n# Visual Studio Version 16";
57 const char _slnHeader143[] = "Microsoft Visual Studio Solution File, Format Version 12.00"
58 "\n# Visual Studio Version 17";
59 const char _slnHeader145[] = "Microsoft Visual Studio Solution File, Format Version 12.00"
60 "\n# Visual Studio Version 18";
61 // The following UUID _may_ change for later servicepacks...
62 // If so we need to search through the registry at
63 // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.0\Projects
64 // to find the subkey that contains a "PossibleProjectExtension"
65 // containing "vcproj"...
66 // Use the hardcoded value for now so projects generated on other
67 // platforms are actually usable.
68 const char _slnMSVCvcprojGUID[] = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}";
69 const char _slnProjectBeg[] = "\nProject(\"";
70 const char _slnProjectMid[] = "\") = ";
71 const char _slnProjectEnd[] = "\nEndProject";
72 const char _slnGlobalBeg[] = "\nGlobal";
73 const char _slnGlobalEnd[] = "\nEndGlobal";
74 const char _slnSolutionConf[] = "\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution"
75 "\n\t\tDebug|Win32 = Debug|Win32"
76 "\n\t\tRelease|Win32 = Release|Win32"
77 "\n\tEndGlobalSection";
78
79 const char _slnProjDepBeg[] = "\n\tProjectSection(ProjectDependencies) = postProject";
80 const char _slnProjDepEnd[] = "\n\tEndProjectSection";
81 const char _slnProjConfBeg[] = "\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution";
82 const char _slnProjRelConfTag1[]= ".Release|%1.ActiveCfg = Release|";
83 const char _slnProjRelConfTag2[]= ".Release|%1.Build.0 = Release|";
84 const char _slnProjDbgConfTag1[]= ".Debug|%1.ActiveCfg = Debug|";
85 const char _slnProjDbgConfTag2[]= ".Debug|%1.Build.0 = Debug|";
86 const char _slnProjConfEnd[] = "\n\tEndGlobalSection";
87 const char _slnExtSections[] = "\n\tGlobalSection(ExtensibilityGlobals) = postSolution"
88 "\n\tEndGlobalSection"
89 "\n\tGlobalSection(ExtensibilityAddIns) = postSolution"
90 "\n\tEndGlobalSection";
91 // ------------------------------------------------------------------
92
93 VcprojGenerator::VcprojGenerator()
94 : Win32MakefileGenerator(),
95 is64Bit(false),
96 customBuildToolFilterFileSuffix(QStringLiteral(".cbt")),
97 projectWriter(nullptr)
98 {
99 }
100
101 VcprojGenerator::~VcprojGenerator()
102 {
103 delete projectWriter;
104 }
105
106 bool VcprojGenerator::writeMakefile(QTextStream &t)
107 {
108 initProject(); // Fills the whole project with proper data
109
110 // Generate solution file
111 if(project->first("TEMPLATE") == "vcsubdirs") {
112 if (!project->isActiveConfig("build_pass")) {
113 debug_msg(1, "Generator: MSVC.NET: Writing solution file");
114 writeSubDirs(t);
115 } else {
116 debug_msg(1, "Generator: MSVC.NET: Not writing solution file for build_pass configs");
117 }
118 return true;
119 } else
120 // Generate single configuration project file
121 if (project->first("TEMPLATE") == "vcapp" ||
122 project->first("TEMPLATE") == "vclib") {
123 if(!project->isActiveConfig("build_pass")) {
124 debug_msg(1, "Generator: MSVC.NET: Writing single configuration project file");
125 XmlOutput xmlOut(t);
126 projectWriter->write(xmlOut, vcProject);
127 }
128 return true;
129 }
130 return project->isActiveConfig("build_pass");
131 }
132
133 bool VcprojGenerator::writeProjectMakefile()
134 {
135 QTextStream t(&Option::output);
136
137 // Check if all requirements are fulfilled
138 if(!project->values("QMAKE_FAILED_REQUIREMENTS").isEmpty()) {
139 fprintf(stderr, "Project file not generated because all requirements not met:\n\t%s\n",
140 var("QMAKE_FAILED_REQUIREMENTS").toLatin1().constData());
141 return true;
142 }
143
144 // Generate project file
145 if(project->first("TEMPLATE") == "vcapp" ||
146 project->first("TEMPLATE") == "vclib") {
147 if (!mergedProjects.size()) {
148 warn_msg(WarnLogic, "Generator: MSVC.NET: no single configuration created, cannot output project!");
149 return false;
150 }
151
152 debug_msg(1, "Generator: MSVC.NET: Writing project file");
153 VCProject mergedProject;
154 for (int i = 0; i < mergedProjects.size(); ++i) {
155 VCProjectSingleConfig *singleProject = &(mergedProjects.at(i)->vcProject);
156 mergedProject.SingleProjects += *singleProject;
157 for (int j = 0; j < singleProject->ExtraCompilersFiles.size(); ++j) {
158 const QString &compilerName = singleProject->ExtraCompilersFiles.at(j).Name;
159 if (!mergedProject.ExtraCompilers.contains(compilerName))
160 mergedProject.ExtraCompilers += compilerName;
161 }
162 }
163
164 if(mergedProjects.size() > 1 &&
165 mergedProjects.at(0)->vcProject.Name ==
166 mergedProjects.at(1)->vcProject.Name)
167 mergedProjects.at(0)->writePrlFile();
168 mergedProject.Name = project->first("QMAKE_PROJECT_NAME").toQString();
169 mergedProject.Version = mergedProjects.at(0)->vcProject.Version;
170 mergedProject.SdkVersion = mergedProjects.at(0)->vcProject.SdkVersion;
171 mergedProject.ProjectGUID = project->isEmpty("QMAKE_UUID") ? getProjectUUID().toString().toUpper() : project->first("QMAKE_UUID").toQString();
172 mergedProject.Keyword = project->first("VCPROJ_KEYWORD").toQString();
173 mergedProject.SccProjectName = mergedProjects.at(0)->vcProject.SccProjectName;
174 mergedProject.SccLocalPath = mergedProjects.at(0)->vcProject.SccLocalPath;
175 mergedProject.PlatformName = mergedProjects.at(0)->vcProject.PlatformName;
176 mergedProject.WindowsTargetPlatformVersion =
177 project->first("WINDOWS_TARGET_PLATFORM_VERSION").toQString();
178 mergedProject.WindowsTargetPlatformMinVersion =
179 project->first("WINDOWS_TARGET_PLATFORM_MIN_VERSION").toQString();
180
181 XmlOutput xmlOut(t);
182 projectWriter->write(xmlOut, mergedProject);
183 return true;
184 } else if(project->first("TEMPLATE") == "vcsubdirs") {
185 return writeMakefile(t);
186 }
187 return false;
188 }
189
190 struct VcsolutionDepend {
191 QString uuid;
192 QString vcprojFile;
193 QString projectName;
194 QString target;
195 Target targetType;
196 QStringList dependencies;
197 };
198
199 /* Disable optimization in getProjectUUID() due to a compiler
200 * bug in MSVC 2015 that causes ASSERT: "&other != this" in the QString
201 * copy constructor for non-empty file names at:
202 * filename.isEmpty()?project->first("QMAKE_MAKEFILE"):filename */
203
204 #if defined(Q_CC_MSVC) && !defined(Q_CC_CLANG)
205 # pragma optimize( "g", off )
206 # pragma warning ( disable : 4748 )
207 #endif
208
209 QUuid VcprojGenerator::getProjectUUID(const QString &filename)
210 {
211 bool validUUID = true;
212
213 // Read GUID from variable-space
214 auto uuid = QUuid::fromString(project->first("GUID").toQStringView());
215
216 // If none, create one based on the MD5 of absolute project path
217 if(uuid.isNull() || !filename.isEmpty()) {
218 QString abspath = Option::fixPathToTargetOS(
219 filename.isEmpty() ? project->first("QMAKE_MAKEFILE").toQString() : filename);
220 QByteArray digest = QCryptographicHash::hash(abspath.toUtf8(), QCryptographicHash::Sha1);
221 memcpy((unsigned char*)(&uuid), digest.constData(), sizeof(QUuid));
222 validUUID = !uuid.isNull();
223 uuid.data4[0] = (uuid.data4[0] & 0x3F) | 0x80; // UV_DCE variant
224 uuid.data3 = (uuid.data3 & 0x0FFF) | (QUuid::Name<<12);
225 }
226
227 // If still not valid, generate new one, and suggest adding to .pro
228 if(uuid.isNull() || !validUUID) {
229 uuid = QUuid::createUuid();
230 fprintf(stderr,
231 "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",
232 uuid.toString().toUpper().toLatin1().constData());
233 }
234
235 // Store GUID in variable-space
236 project->values("GUID") = ProStringList(uuid.toString().toUpper());
237 return uuid;
238 }
239
240 #if defined(Q_CC_MSVC) && !defined(Q_CC_CLANG)
241 # pragma optimize( "g", on )
242 #endif
243
244 QUuid VcprojGenerator::increaseUUID(const QUuid &id)
245 {
246 QUuid result(id);
247 qint64 dataFirst = (result.data4[0] << 24) +
248 (result.data4[1] << 16) +
249 (result.data4[2] << 8) +
250 result.data4[3];
251 qint64 dataLast = (result.data4[4] << 24) +
252 (result.data4[5] << 16) +
253 (result.data4[6] << 8) +
254 result.data4[7];
255
256 if(!(dataLast++))
257 dataFirst++;
258
259 result.data4[0] = uchar((dataFirst >> 24) & 0xff);
260 result.data4[1] = uchar((dataFirst >> 16) & 0xff);
261 result.data4[2] = uchar((dataFirst >> 8) & 0xff);
262 result.data4[3] = uchar(dataFirst & 0xff);
263 result.data4[4] = uchar((dataLast >> 24) & 0xff);
264 result.data4[5] = uchar((dataLast >> 16) & 0xff);
265 result.data4[6] = uchar((dataLast >> 8) & 0xff);
266 result.data4[7] = uchar(dataLast & 0xff);
267 return result;
268 }
269
270 QString VcprojGenerator::retrievePlatformToolSet() const
271 {
272 // The PlatformToolset string corresponds to the name of a directory in
273 // $(VCTargetsPath)\Platforms\{Win32,x64,...}\PlatformToolsets
274 // e.g. v90, v100, v110, v110_xp, v120_CTP_Nov, v120, or WindowsSDK7.1
275
276 // This environment variable may be set by a commandline build
277 // environment such as the Windows SDK command prompt
278 QByteArray envVar = qgetenv("PlatformToolset");
279 if (!envVar.isEmpty())
280 return envVar;
281
282 return u"v"_s + project->first("MSVC_TOOLSET_VER");
283 }
284
285 bool VcprojGenerator::isStandardSuffix(const QString &suffix) const
286 {
287 if (!project->values("QMAKE_APP_FLAG").isEmpty()) {
288 if (suffix.compare("exe", Qt::CaseInsensitive) == 0)
289 return true;
290 } else if (project->isActiveConfig("shared")) {
291 if (suffix.compare("dll", Qt::CaseInsensitive) == 0)
292 return true;
293 } else {
294 if (suffix.compare("lib", Qt::CaseInsensitive) == 0)
295 return true;
296 }
297 return false;
298 }
299
300 ProString VcprojGenerator::firstInputFileName(const ProString &extraCompilerName) const
301 {
302 for (const ProString &var : project->values(ProKey(extraCompilerName + ".input"))) {
303 const ProStringList &files = project->values(var.toKey());
304 if (!files.isEmpty())
305 return files.first();
306 }
307 return ProString();
308 }
309
310 QString VcprojGenerator::firstExpandedOutputFileName(const ProString &extraCompilerName)
311 {
312 const ProString firstOutput = project->first(ProKey(extraCompilerName + ".output"));
313 return replaceExtraCompilerVariables(firstOutput.toQString(),
314 firstInputFileName(extraCompilerName).toQString(),
315 QString(), NoShell);
316 }
317
318 ProStringList VcprojGenerator::collectDependencies(QMakeProject *proj, QHash<QString, QString> &projLookup,
319 QHash<QString, QString> &projGuids,
320 QHash<VcsolutionDepend *, QStringList> &extraSubdirs,
321 QHash<QString, VcsolutionDepend*> &solution_depends,
322 QList<VcsolutionDepend*> &solution_cleanup,
323 QTextStream &t,
324 QHash<QString, ProStringList> &subdirProjectLookup,
325 const ProStringList &allDependencies)
326 {
327 QList<QPair<QString, ProStringList>> collectedSubdirs;
328 ProStringList tmp_proj_subdirs = proj->values("SUBDIRS");
329 ProStringList projectsInProject;
330 const int numSubdirs = tmp_proj_subdirs.size();
331 collectedSubdirs.reserve(numSubdirs);
332 for (int x = 0; x < numSubdirs; ++x) {
333 ProString tmpdir = tmp_proj_subdirs.at(x);
334 const ProKey tmpdirConfig(tmpdir + ".CONFIG");
335 if (!proj->isEmpty(tmpdirConfig)) {
336 const ProStringList config = proj->values(tmpdirConfig);
337 if (config.contains(QStringLiteral("no_default_target")))
338 continue; // Ignore this sub-dir
339 }
340 const ProKey fkey(tmpdir + ".file");
341 const ProKey skey(tmpdir + ".subdir");
342 if (!proj->isEmpty(fkey)) {
343 if (!proj->isEmpty(skey))
344 warn_msg(WarnLogic, "Cannot assign both file and subdir for subdir %s",
345 tmpdir.toLatin1().constData());
346 tmpdir = proj->first(fkey);
347 } else if (!proj->isEmpty(skey)) {
348 tmpdir = proj->first(skey);
349 }
350 projectsInProject.append(tmpdir);
351 collectedSubdirs.append(qMakePair(tmpdir.toQString(), proj->values(ProKey(tmp_proj_subdirs.at(x) + ".depends"))));
352 projLookup.insert(tmp_proj_subdirs.at(x).toQString(), tmpdir.toQString());
353 }
354 for (const auto &subdir : std::as_const(collectedSubdirs)) {
355 QString profile = subdir.first;
356 QFileInfo fi(fileInfo(Option::normalizePath(profile)));
357 if (fi.exists()) {
358 if (fi.isDir()) {
359 if (!profile.endsWith(Option::dir_sep))
360 profile += Option::dir_sep;
361 profile += fi.baseName() + Option::pro_ext;
362 QString profileKey = fi.absoluteFilePath();
363 fi = QFileInfo(fileInfo(Option::normalizePath(profile)));
364 if (!fi.exists())
365 continue;
366 projLookup.insert(profileKey, fi.absoluteFilePath());
367 }
368 QString oldpwd = qmake_getpwd();
369 QString oldoutpwd = Option::output_dir;
370 QMakeProject tmp_proj;
371 QString dir = fi.absolutePath(), fn = fi.fileName();
372 if (!dir.isEmpty()) {
373 if (!qmake_setpwd(dir))
374 fprintf(stderr, "Cannot find directory: %s", dir.toLatin1().constData());
375 }
376 Option::output_dir = Option::globals->shadowedPath(QDir::cleanPath(dir));
377 if (tmp_proj.read(fn)) {
378 // Check if all requirements are fulfilled
379 if (!tmp_proj.isEmpty("QMAKE_FAILED_REQUIREMENTS")) {
380 fprintf(stderr, "Project file(%s) not added to Solution because all requirements not met:\n\t%s\n",
381 fn.toLatin1().constData(),
382 tmp_proj.values("QMAKE_FAILED_REQUIREMENTS").join(' ').toLatin1().constData());
383 qmake_setpwd(oldpwd);
384 Option::output_dir = oldoutpwd;
385 continue;
386 }
387 if (tmp_proj.first("TEMPLATE") == "vcsubdirs") {
388 ProStringList tmpList = collectDependencies(&tmp_proj, projLookup, projGuids, extraSubdirs, solution_depends, solution_cleanup, t, subdirProjectLookup, subdir.second);
389 subdirProjectLookup.insert(subdir.first, tmpList);
390 } else {
391 ProStringList tmpList;
392 tmpList += subdir.second;
393 tmpList += allDependencies;
394 // Initialize a 'fake' project to get the correct variables
395 // and to be able to extract all the dependencies
396 Option::QMAKE_MODE old_mode = Option::qmake_mode;
397 Option::qmake_mode = Option::QMAKE_GENERATE_NOTHING;
398 VcprojGenerator tmp_vcproj;
399 tmp_vcproj.setNoIO(true);
400 tmp_vcproj.setProjectFile(&tmp_proj);
401 Option::qmake_mode = old_mode;
402
403 // We assume project filename is [QMAKE_PROJECT_NAME].vcproj
404 const ProString projectName = tmp_vcproj.project->first("QMAKE_PROJECT_NAME");
405 const QString vcproj = projectName + project->first("VCPROJ_EXTENSION");
406 QString vcprojDir = Option::output_dir;
407
408 // If file doesn't exsist, then maybe the users configuration
409 // doesn't allow it to be created. Skip to next...
410 if (!exists(vcprojDir + Option::dir_sep + vcproj)) {
411 warn_msg(WarnLogic, "Ignored (not found) '%s'", QString(vcprojDir + Option::dir_sep + vcproj).toLatin1().constData());
412 goto nextfile; // # Dirty!
413 }
414
415 VcsolutionDepend *newDep = new VcsolutionDepend;
416 newDep->vcprojFile = vcprojDir + Option::dir_sep + vcproj;
417 newDep->projectName = projectName.toQString();
418 newDep->target = tmp_proj.first("MSVCPROJ_TARGET").toQString().section(Option::dir_sep, -1);
419 newDep->targetType = tmp_vcproj.projectTarget;
420 newDep->uuid = tmp_proj.isEmpty("QMAKE_UUID") ? getProjectUUID(Option::fixPathToLocalOS(vcprojDir + QDir::separator() + vcproj)).toString().toUpper(): tmp_proj.first("QMAKE_UUID").toQString();
421 // We want to store it as the .lib name.
422 if (newDep->target.endsWith(".dll"))
423 newDep->target = newDep->target.left(newDep->target.size()-3) + "lib";
424 projGuids.insert(newDep->projectName, newDep->target);
425
426 if (tmpList.size()) {
427 const ProStringList depends = tmpList;
428 for (const ProString &dep : depends) {
429 QString depend = dep.toQString();
430 if (!projGuids[depend].isEmpty()) {
431 newDep->dependencies << projGuids[depend];
432 } else if (subdirProjectLookup[projLookup[depend]].size() > 0) {
433 const ProStringList tmpLst = subdirProjectLookup[projLookup[depend]];
434 for (const ProString &tDep : tmpLst) {
435 QString tmpDep = tDep.toQString();
436 newDep->dependencies << projGuids[projLookup[tmpDep]];
437 }
438 } else {
439 extraSubdirs.insert(newDep, tmpList.toQStringList());
440 newDep->dependencies.clear();
441 break;
442 }
443 }
444 }
445
446 // All ActiveQt Server projects are dependent on idc.exe
447 if (tmp_proj.values("CONFIG").contains("qaxserver"))
448 newDep->dependencies << "idc.exe";
449
450 // Add all unknown libs to the deps
451 QStringList where = QStringList() << "LIBS" << "LIBS_PRIVATE"
452 << "QMAKE_LIBS" << "QMAKE_LIBS_PRIVATE";
453 for (QStringList::ConstIterator wit = where.cbegin();
454 wit != where.cend(); ++wit) {
455 const ProStringList &l = tmp_proj.values(ProKey(*wit));
456 for (ProStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
457 const QString opt = fixLibFlag(*it).toQString();
458 if (!opt.startsWith("/") && // Not a switch
459 opt != newDep->target && // Not self
460 opt != "opengl32.lib" && // We don't care about these libs
461 opt != "glu32.lib" && // to make depgen alittle faster
462 opt != "kernel32.lib" &&
463 opt != "user32.lib" &&
464 opt != "gdi32.lib" &&
465 opt != "comdlg32.lib" &&
466 opt != "advapi32.lib" &&
467 opt != "shell32.lib" &&
468 opt != "ole32.lib" &&
469 opt != "oleaut32.lib" &&
470 opt != "uuid.lib" &&
471 opt != "imm32.lib" &&
472 opt != "winmm.lib" &&
473 opt != "wsock32.lib" &&
474 opt != "ws2_32.lib" &&
475 opt != "winspool.lib" &&
476 opt != "delayimp.lib")
477 {
478 newDep->dependencies << opt.section(Option::dir_sep, -1);
479 }
480 }
481 }
482 #ifdef DEBUG_SOLUTION_GEN
483 qDebug("Deps for %20s: [%s]", newDep->target.toLatin1().constData(), newDep->dependencies.join(" :: ").toLatin1().constData());
484 #endif
485 solution_cleanup.append(newDep);
486 solution_depends.insert(newDep->target, newDep);
487 }
488 nextfile:
489 qmake_setpwd(oldpwd);
490 Option::output_dir = oldoutpwd;
491 }
492 }
493 }
494 return projectsInProject;
495 }
496
497 void VcprojGenerator::writeSubDirs(QTextStream &t)
498 {
499 // Check if all requirements are fulfilled
500 if(!project->values("QMAKE_FAILED_REQUIREMENTS").isEmpty()) {
501 fprintf(stderr, "Project file not generated because all requirements not met:\n\t%s\n",
502 var("QMAKE_FAILED_REQUIREMENTS").toLatin1().constData());
503 return;
504 }
505
506 switch (vcProject.Configuration.CompilerVersion) {
507 case NET2026:
508 t << _slnHeader145;
509 break;
510 case NET2022:
511 t << _slnHeader143;
512 break;
513 case NET2019:
514 t << _slnHeader142;
515 break;
516 case NET2017:
517 t << _slnHeader141;
518 break;
519 case NET2015:
520 t << _slnHeader140;
521 break;
522 case NET2013:
523 t << _slnHeader120;
524 break;
525 case NET2012:
526 t << _slnHeader110;
527 break;
528 case NET2010:
529 t << _slnHeader100;
530 break;
531 case NET2008:
532 t << _slnHeader90;
533 break;
534 case NET2005:
535 t << _slnHeader80;
536 break;
537 case NET2003:
538 t << _slnHeader71;
539 break;
540 case NET2002:
541 t << _slnHeader70;
542 break;
543 default:
544 t << _slnHeader70;
545 warn_msg(WarnLogic, "Generator: MSVC.NET: Unknown version (%d) of MSVC detected for .sln",
546 vcProject.Configuration.CompilerVersion);
547 break;
548 }
549
550 QHash<QString, VcsolutionDepend*> solution_depends;
551 QList<VcsolutionDepend*> solution_cleanup;
552
553 // Make sure that all temp projects are configured
554 // for release so that the depends are created
555 // without the debug <lib>dxxx.lib name mangling
556 QString old_after_vars = Option::globals->extra_cmds[QMakeEvalAfter];
557 Option::globals->extra_cmds[QMakeEvalAfter].append("\nCONFIG+=release");
558
559 QHash<QString, QString> profileLookup;
560 QHash<QString, QString> projGuids;
561 QHash<VcsolutionDepend *, QStringList> extraSubdirs;
562 QHash<QString, ProStringList> subdirProjectLookup;
563 collectDependencies(project, profileLookup, projGuids, extraSubdirs, solution_depends, solution_cleanup, t, subdirProjectLookup);
564
565 // write out projects
566 for (QList<VcsolutionDepend*>::Iterator it = solution_cleanup.begin(); it != solution_cleanup.end(); ++it) {
567 // ### quoting rules?
568 t << _slnProjectBeg << _slnMSVCvcprojGUID << _slnProjectMid
569 << "\"" << (*it)->projectName << "\", \"" << (*it)->vcprojFile
570 << "\", \"" << (*it)->uuid << "\"";
571
572 debug_msg(1, "Project %s has dependencies: %s", (*it)->target.toLatin1().constData(), (*it)->dependencies.join(" ").toLatin1().constData());
573
574 bool hasDependency = false;
575 for (QStringList::iterator dit = (*it)->dependencies.begin(); dit != (*it)->dependencies.end(); ++dit) {
576 if (VcsolutionDepend *vc = solution_depends[*dit]) {
577 if (!hasDependency) {
578 hasDependency = true;
579 t << _slnProjDepBeg;
580 }
581 t << "\n\t\t" << vc->uuid << " = " << vc->uuid;
582 }
583 }
584 if (hasDependency)
585 t << _slnProjDepEnd;
586
587 t << _slnProjectEnd;
588 }
589
590 t << _slnGlobalBeg;
591
592 for (auto extraIt = extraSubdirs.cbegin(), end = extraSubdirs.cend(); extraIt != end; ++extraIt) {
593 for (const QString &depend : extraIt.value()) {
594 if (!projGuids[depend].isEmpty()) {
595 extraIt.key()->dependencies << projGuids[depend];
596 } else if (!profileLookup[depend].isEmpty()) {
597 if (!projGuids[profileLookup[depend]].isEmpty())
598 extraIt.key()->dependencies << projGuids[profileLookup[depend]];
599 }
600 }
601 }
602 QString slnConf = _slnSolutionConf;
603 if (!project->isEmpty("VCPROJ_ARCH")) {
604 slnConf.replace(QLatin1String("|Win32"), "|" + project->first("VCPROJ_ARCH"));
605 } else if (is64Bit) {
606 slnConf.replace(QLatin1String("|Win32"), QLatin1String("|x64"));
607 }
608 t << slnConf;
609
610 // Restore previous after_user_var options
611 Option::globals->extra_cmds[QMakeEvalAfter] = old_after_vars;
612
613 t << _slnProjConfBeg;
614 for(QList<VcsolutionDepend*>::Iterator it = solution_cleanup.begin(); it != solution_cleanup.end(); ++it) {
615 QString platform = is64Bit ? "x64" : "Win32";
616 QString xplatform = platform;
617 if (!project->isEmpty("VCPROJ_ARCH")) {
618 xplatform = project->first("VCPROJ_ARCH").toQString();
619 }
620 if (!project->isHostBuild())
621 platform = xplatform;
622 t << "\n\t\t" << (*it)->uuid << QString(_slnProjDbgConfTag1).arg(xplatform) << platform;
623 t << "\n\t\t" << (*it)->uuid << QString(_slnProjDbgConfTag2).arg(xplatform) << platform;
624 t << "\n\t\t" << (*it)->uuid << QString(_slnProjRelConfTag1).arg(xplatform) << platform;
625 t << "\n\t\t" << (*it)->uuid << QString(_slnProjRelConfTag2).arg(xplatform) << platform;
626 }
627 t << _slnProjConfEnd;
628 t << _slnExtSections;
629 t << _slnGlobalEnd;
630
631
632 while (!solution_cleanup.isEmpty())
633 delete solution_cleanup.takeFirst();
634 }
635
636 // ------------------------------------------------------------------------------------------------
637 // ------------------------------------------------------------------------------------------------
638
639 bool VcprojGenerator::hasBuiltinCompiler(const QString &file)
640 {
641 // Source files
642 for (int i = 0; i < Option::cpp_ext.size(); ++i)
643 if (file.endsWith(Option::cpp_ext.at(i)))
644 return true;
645 for (int i = 0; i < Option::c_ext.size(); ++i)
646 if (file.endsWith(Option::c_ext.at(i)))
647 return true;
648 if (file.endsWith(".rc")
649 || file.endsWith(".idl"))
650 return true;
651 return false;
652 }
653
654 void VcprojGenerator::createCustomBuildToolFakeFile(const QString &cbtFilePath,
655 const QString &realOutFilePath)
656 {
657 QFile file(fileFixify(cbtFilePath, FileFixifyFromOutdir | FileFixifyAbsolute));
658 if (file.exists())
659 return;
660 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
661 warn_msg(WarnLogic, "Cannot create '%s'.", qPrintable(file.fileName()));
662 return;
663 }
664 file.write("This is a dummy file needed to create ");
665 file.write(qPrintable(realOutFilePath));
666 file.write("\n");
667 }
668
669 void VcprojGenerator::init()
670 {
671 is64Bit = (project->first("QMAKE_TARGET.arch") == "x86_64");
672 projectWriter = createProjectWriter();
673
674 if(project->first("TEMPLATE") == "vcsubdirs") //too much work for subdirs
675 return;
676
677 debug_msg(1, "Generator: MSVC.NET: Initializing variables");
678
679 // this should probably not be here, but I'm using it to wrap the .t files
680 if (project->first("TEMPLATE") == "vcapp")
681 project->values("QMAKE_APP_FLAG").append("1");
682 else if (project->first("TEMPLATE") == "vclib")
683 project->values("QMAKE_LIB_FLAG").append("1");
684
685 processVars();
686
687 // set /VERSION for EXE/DLL header
688 ProString major_minor = project->first("VERSION_PE_HEADER");
689 if (major_minor.isEmpty()) {
690 ProString version = project->first("VERSION");
691 if (!version.isEmpty()) {
692 int firstDot = version.indexOf(".");
693 int secondDot = version.indexOf(".", firstDot + 1);
694 major_minor = version.left(secondDot);
695 }
696 }
697 if (!major_minor.isEmpty())
698 project->values("QMAKE_LFLAGS").append("/VERSION:" + major_minor);
699
700 MakefileGenerator::init();
701
702 // $$QMAKE.. -> $$MSVCPROJ.. -------------------------------------
703 const ProStringList &incs = project->values("INCLUDEPATH");
704 for (ProStringList::ConstIterator incit = incs.begin(); incit != incs.end(); ++incit) {
705 QString inc = (*incit).toQString();
706 project->values("MSVCPROJ_INCPATH").append("-I" + escapeFilePath(inc));
707 }
708
709 QString dest = Option::fixPathToTargetOS(project->first("TARGET").toQString()) + project->first("TARGET_EXT");
710 project->values("MSVCPROJ_TARGET") = ProStringList(dest);
711
712 // DLL COPY ------------------------------------------------------
713 if (project->isActiveConfig("dll") && !project->values("DLLDESTDIR").isEmpty()) {
714 const ProStringList &dlldirs = project->values("DLLDESTDIR");
715 QString copydll("");
716 ProStringList::ConstIterator dlldir;
717 for (dlldir = dlldirs.begin(); dlldir != dlldirs.end(); ++dlldir) {
718 if (!copydll.isEmpty())
719 copydll += " && ";
720 copydll += "copy \"$(TargetPath)\" " + escapeFilePath(*dlldir);
721 }
722
723 QString deststr("Copy " + dest + " to ");
724 for (dlldir = dlldirs.begin(); dlldir != dlldirs.end();) {
725 deststr += *dlldir;
726 ++dlldir;
727 if (dlldir != dlldirs.end())
728 deststr += ", ";
729 }
730
731 project->values("MSVCPROJ_COPY_DLL").append(copydll);
732 project->values("MSVCPROJ_COPY_DLL_DESC").append(deststr);
733 }
734
735 #if 0
736 // Verbose output if "-d -d"...
737 qDebug("Generator: MSVC.NET: List of current variables:");
738 for (ProValueMap::ConstIterator it = project->variables().begin(); it != project->variables().end(); ++it)
739 qDebug("Generator: MSVC.NET: %s => %s", qPrintable(it.key().toQString()), qPrintable(it.value().join(" | ")));
740 #endif
741
742 // Figure out what we're trying to build
743 if(project->first("TEMPLATE") == "vcapp") {
744 projectTarget = Application;
745 } else if(project->first("TEMPLATE") == "vclib") {
746 if(project->isActiveConfig("staticlib")) {
747 project->values("LIBS") += project->values("RES_FILE");
748 projectTarget = StaticLib;
749 } else
750 projectTarget = SharedLib;
751 }
752
753 // Setup PCH variables
754 precompH = project->first("PRECOMPILED_HEADER").toQString();
755 precompSource = project->first("PRECOMPILED_SOURCE").toQString();
756 pchIsCFile = project->isActiveConfig("precompile_header_c");
757 usePCH = !precompH.isEmpty() && (pchIsCFile || project->isActiveConfig("precompile_header"));
758 if (usePCH) {
759 precompHFilename = fileInfo(precompH).fileName();
760 // Created files
761 QString origTarget = project->first("QMAKE_ORIG_TARGET").toQString();
762 precompObj = origTarget + Option::obj_ext;
763 precompPch = origTarget + ".pch";
764 // Add PRECOMPILED_HEADER to HEADERS
765 if (!project->values("HEADERS").contains(precompH))
766 project->values("HEADERS") += precompH;
767 // Return to variable pool
768 project->values("PRECOMPILED_OBJECT") = ProStringList(precompObj);
769 project->values("PRECOMPILED_PCH") = ProStringList(precompPch);
770
771 autogenPrecompSource = precompSource.isEmpty() && project->isActiveConfig("autogen_precompile_source");
772 if (autogenPrecompSource) {
773 precompSource = precompH
774 + (pchIsCFile
775 ? (Option::c_ext.size() ? Option::c_ext.at(0) : QLatin1String(".c"))
776 : (Option::cpp_ext.size() ? Option::cpp_ext.at(0) : QLatin1String(".cpp")));
777 project->values("GENERATED_SOURCES") += precompSource;
778 } else if (!precompSource.isEmpty()) {
779 project->values("SOURCES") += precompSource;
780 }
781 }
782
783 // Helper function to create a fake file foo.cbt for the project view.
784 //
785 // This prevents VS from complaining about a circular dependency from "foo -> foo".
786 //
787 // The .cbt file is added as "source" of the Custom Build Tool. This means, in the project
788 // view, this is the file the Custom Build Tool property page is attached to.
789 //
790 // This function returns a pair with
791 // - the fully resolved output file path
792 // - the file path of the .cbt file
793 auto addExtraCompilerSourceWithCustomBuildToolFakeFile
794 = [this](const QString &compilerOutput, const ProString &extraCompiler,
795 const QStringList &inputs) -> std::pair<QString, QString>
796 {
797 QString realOut = replaceExtraCompilerVariables(compilerOutput, inputs, {}, NoShell);
798 QString out = realOut + customBuildToolFilterFileSuffix;
799 createCustomBuildToolFakeFile(out, realOut);
800 out = Option::fixPathToTargetOS(out, false);
801 extraCompilerSources[out] += extraCompiler.toQString();
802 return { realOut, out };
803 };
804
805 // Add all input files for a custom compiler into a map for uniqueness.
806 //
807 // Use .cbt files for the following cases:
808 // - CONFIG += combine
809 // - the input has a built-in compiler (e.g. C++ source file)
810 for (const ProString &quc : project->values("QMAKE_EXTRA_COMPILERS")) {
811 const ProStringList &invar = project->values(ProKey(quc + ".input"));
812 const QString compiler_out = project->first(ProKey(quc + ".output")).toQString();
813
814 QStringList inputFiles;
815 for (auto it = invar.begin(); it != invar.end(); ++it)
816 inputFiles += project->values(it->toKey()).toQStringList();
817
818 if (project->values(ProKey(quc + ".CONFIG")).contains("combine")) {
819 // Handle "CONFIG += combine" extra compilers.
820 QString realOut;
821 QString out;
822 std::tie(realOut, out)
823 = addExtraCompilerSourceWithCustomBuildToolFakeFile(compiler_out, quc, inputFiles);
824 if (hasBuiltinCompiler(realOut))
825 extraCompilerOutputs[out] = realOut;
826 } else {
827 // Handle regular 1-to-1 extra compilers.
828 for (const QString &file : inputFiles) {
829 if (verifyExtraCompiler(quc, file)) {
830 if (!hasBuiltinCompiler(file)) {
831 extraCompilerSources[file] += quc.toQString();
832 } else {
833 QString out;
834 std::tie(std::ignore, out)
835 = addExtraCompilerSourceWithCustomBuildToolFakeFile(compiler_out,
836 quc,
837 QStringList(file));
838 extraCompilerOutputs[out] = file;
839 }
840 }
841 }
842 }
843 }
844
845 #if 0 // Debugging
846 for (auto it = extraCompilerSources.cbegin(), end = extraCompilerSources.cend(); it != end; ++it)
847 qDebug("Extracompilers for %s are (%s)", it.key().toLatin1().constData(), it.value().join(", ").toLatin1().constData());
848 for (auto it = extraCompilerOutputs.cbegin(), end = extraCompilerOutputs.cend(); it != end; ++it)
849 qDebug("Object mapping for %s is (%s)", qPrintable(it.key()), qPrintable(it.value()));
850 qDebug("");
851 #endif
852 }
853
854 bool VcprojGenerator::mergeBuildProject(MakefileGenerator *other)
855 {
856 if (!other || !other->projectFile()) {
857 warn_msg(WarnLogic, "VcprojGenerator: Cannot merge null project.");
858 return false;
859 }
860 if (other->projectFile()->first("MAKEFILE_GENERATOR") != project->first("MAKEFILE_GENERATOR")) {
861 warn_msg(WarnLogic, "VcprojGenerator: Cannot merge other types of projects! (ignored)");
862 return false;
863 }
864
865 VcprojGenerator *otherVC = static_cast<VcprojGenerator*>(other);
866 mergedProjects += otherVC;
867 return true;
868 }
869
870 void VcprojGenerator::initProject()
871 {
872 // Initialize XML sub elements
873 // - Do this first since project elements may need
874 // - to know of certain configuration options
875 initConfiguration();
876 initRootFiles();
877 initSourceFiles();
878 initHeaderFiles();
879 initGeneratedFiles();
880 initLexYaccFiles();
881 initTranslationFiles();
882 initFormFiles();
883 initResourceFiles();
884 initDistributionFiles();
885 initExtraCompilerOutputs();
886
887 // Own elements -----------------------------
888 vcProject.Name = project->first("QMAKE_ORIG_TARGET").toQString();
889 switch (vcProject.Configuration.CompilerVersion) {
890 case NET2026:
891 vcProject.Version = "18.00";
892 break;
893 case NET2022:
894 vcProject.Version = "17.00";
895 break;
896 case NET2019:
897 vcProject.Version = "16.00";
898 break;
899 case NET2017:
900 vcProject.Version = "15.00";
901 break;
902 case NET2015:
903 vcProject.Version = "14.00";
904 break;
905 case NET2013:
906 vcProject.Version = "12.00";
907 break;
908 case NET2012:
909 vcProject.Version = "11.00";
910 break;
911 case NET2010:
912 vcProject.Version = "10.00";
913 break;
914 case NET2008:
915 vcProject.Version = "9,00";
916 break;
917 case NET2005:
918 //### using ',' because of a bug in 2005 B2
919 //### VS uses '.' or ',' depending on the regional settings! Using ',' always works.
920 vcProject.Version = "8,00";
921 break;
922 case NET2003:
923 vcProject.Version = "7.10";
924 break;
925 case NET2002:
926 vcProject.Version = "7.00";
927 break;
928 default:
929 vcProject.Version = "7.00";
930 warn_msg(WarnLogic, "Generator: MSVC.NET: Unknown version (%d) of MSVC detected for .vcproj", vcProject.Configuration.CompilerVersion);
931 break;
932 }
933
934 vcProject.Keyword = project->first("VCPROJ_KEYWORD").toQString();
935 if (!project->isEmpty("VCPROJ_ARCH")) {
936 vcProject.PlatformName = project->first("VCPROJ_ARCH").toQString();
937 } else {
938 vcProject.PlatformName = (is64Bit ? "x64" : "Win32");
939 }
940 vcProject.SdkVersion = project->first("WINSDK_VER").toQString();
941 // These are not used by Qt, but may be used by customers
942 vcProject.SccProjectName = project->first("SCCPROJECTNAME").toQString();
943 vcProject.SccLocalPath = project->first("SCCLOCALPATH").toQString();
944 vcProject.flat_files = project->isActiveConfig("flat");
945
946 // Set up the full target path for target conflict checking.
947 const QChar slash = QLatin1Char('/');
948 QString destdir = QDir::fromNativeSeparators(var("DESTDIR"));
949 if (!destdir.endsWith(slash))
950 destdir.append(slash);
951 project->values("DEST_TARGET") = ProStringList(destdir
952 + project->first("TARGET")
953 + project->first("TARGET_EXT"));
954 }
955
956 void VcprojGenerator::initConfiguration()
957 {
958 // Initialize XML sub elements
959 // - Do this first since main configuration elements may need
960 // - to know of certain compiler/linker options
961 VCConfiguration &conf = vcProject.Configuration;
962 conf.suppressUnknownOptionWarnings = project->isActiveConfig("suppress_vcproj_warnings");
963 conf.CompilerVersion = vsVersionFromString(project->first("MSVC_VER"));
964
965 initCompilerTool();
966
967 // Only on configuration per build
968 bool isDebug = project->isActiveConfig("debug");
969
970 if(projectTarget == StaticLib)
971 initLibrarianTool();
972 else {
973 conf.linker.GenerateDebugInformation = project->isActiveConfig("debug_info") ? _True : _False;
974 initLinkerTool();
975 }
976 initManifestTool();
977 initResourceTool();
978 initIDLTool();
979
980 // Own elements -----------------------------
981 ProString temp = project->first("BuildBrowserInformation");
982 switch (projectTarget) {
983 case SharedLib:
984 conf.ConfigurationType = typeDynamicLibrary;
985 break;
986 case StaticLib:
987 conf.ConfigurationType = typeStaticLibrary;
988 break;
989 case Application:
990 default:
991 conf.ConfigurationType = typeApplication;
992 break;
993 }
994
995 conf.OutputDirectory = project->first("DESTDIR").toQString();
996 if (conf.OutputDirectory.isEmpty())
997 conf.OutputDirectory = ".\\";
998 if (!conf.OutputDirectory.endsWith("\\"))
999 conf.OutputDirectory += '\\';
1000 if (conf.CompilerVersion >= NET2010) {
1001 conf.PlatformToolSet = retrievePlatformToolSet();
1002
1003 const QFileInfo targetInfo = fileInfo(project->first("MSVCPROJ_TARGET").toQString());
1004 conf.PrimaryOutput = targetInfo.completeBaseName();
1005
1006 const QString targetSuffix = targetInfo.suffix();
1007 if (!isStandardSuffix(targetSuffix))
1008 conf.PrimaryOutputExtension = '.' + targetSuffix;
1009 }
1010
1011 conf.Name = project->values("BUILD_NAME").join(' ');
1012 if (conf.Name.isEmpty())
1013 conf.Name = isDebug ? "Debug" : "Release";
1014 conf.ConfigurationName = conf.Name;
1015 if (!project->isEmpty("VCPROJ_ARCH")) {
1016 conf.Name += "|" + project->first("VCPROJ_ARCH");
1017 } else {
1018 conf.Name += (is64Bit ? "|x64" : "|Win32");
1019 }
1020 conf.ATLMinimizesCRunTimeLibraryUsage = (project->first("ATLMinimizesCRunTimeLibraryUsage").isEmpty() ? _False : _True);
1021 conf.BuildBrowserInformation = triState(temp.isEmpty() ? (short)unset : temp.toShort());
1022 temp = project->first("CharacterSet");
1023 conf.CharacterSet = charSet(temp.isEmpty() ? short(charSetNotSet) : temp.toShort());
1024 conf.DeleteExtensionsOnClean = project->first("DeleteExtensionsOnClean").toQString();
1025 conf.ImportLibrary = conf.linker.ImportLibrary;
1026 conf.IntermediateDirectory = project->first("OBJECTS_DIR").toQString();
1027 conf.WholeProgramOptimization = conf.compiler.WholeProgramOptimization;
1028 temp = project->first("UseOfATL");
1029 if(!temp.isEmpty())
1030 conf.UseOfATL = useOfATL(temp.toShort());
1031 temp = project->first("UseOfMfc");
1032 if(!temp.isEmpty())
1033 conf.UseOfMfc = useOfMfc(temp.toShort());
1034
1035 // Configuration does not need parameters from
1036 // these sub XML items;
1037 initCustomBuildTool();
1038 initPreBuildEventTools();
1039 initPostBuildEventTools();
1040 // Only deploy for crosscompiled projects
1041 if (!project->isHostBuild())
1042 initDeploymentTool();
1043 initWinDeployQtTool();
1044 initPreLinkEventTools();
1045 }
1046
1047 // Filter from the given QMAKE_CFLAGS the options that are relevant
1048 // for the vcxproj-global VCCLCompilerTool.
1049 static ProStringList relevantCFlags(const ProStringList &flags)
1050 {
1051 ProStringList result;
1052 static const QRegularExpression rex("^[/-]std:");
1053 for (const ProString &flag : flags) {
1054 if (rex.match(flag.toQString()).hasMatch()) {
1055 result.append(flag);
1056 }
1057 }
1058 return result;
1059 }
1060
1061 void VcprojGenerator::initCompilerTool()
1062 {
1063 QString placement = project->first("OBJECTS_DIR").toQString();
1064 if(placement.isEmpty())
1065 placement = ".\\";
1066
1067 VCConfiguration &conf = vcProject.Configuration;
1068 if (conf.CompilerVersion >= NET2010) {
1069 // adjust compiler tool defaults for VS 2010 and above
1070 conf.compiler.Optimization = optimizeDisabled;
1071 }
1072 conf.compiler.AssemblerListingLocation = placement ;
1073 conf.compiler.ObjectFile = placement ;
1074 conf.compiler.ExceptionHandling = ehNone;
1075 // PCH
1076 if (usePCH) {
1077 conf.compiler.UsePrecompiledHeader = pchUseUsingSpecific;
1078 conf.compiler.PrecompiledHeaderFile = "$(IntDir)\\" + precompPch;
1079 conf.compiler.PrecompiledHeaderThrough = project->first("PRECOMPILED_HEADER").toQString();
1080 conf.compiler.ForcedIncludeFiles = project->values("PRECOMPILED_HEADER").toQStringList();
1081 }
1082
1083 conf.compiler.parseOptions(relevantCFlags(project->values("QMAKE_CFLAGS")));
1084 conf.compiler.parseOptions(project->values("QMAKE_CXXFLAGS"));
1085
1086 if (project->isActiveConfig("windows"))
1087 conf.compiler.PreprocessorDefinitions += "_WINDOWS";
1088 else if (project->isActiveConfig("console"))
1089 conf.compiler.PreprocessorDefinitions += "_CONSOLE";
1090
1091 conf.compiler.PreprocessorDefinitions += project->values("DEFINES").toQStringList();
1092 conf.compiler.PreprocessorDefinitions += project->values("PRL_EXPORT_DEFINES").toQStringList();
1093 conf.compiler.parseOptions(project->values("MSVCPROJ_INCPATH"));
1094 }
1095
1096 void VcprojGenerator::initLibrarianTool()
1097 {
1098 VCConfiguration &conf = vcProject.Configuration;
1099 conf.librarian.OutputFile = "$(OutDir)\\";
1100 conf.librarian.OutputFile += project->first("MSVCPROJ_TARGET").toQString();
1101 conf.librarian.AdditionalOptions += project->values("QMAKE_LIBFLAGS").toQStringList();
1102 }
1103
1104 void VcprojGenerator::initManifestTool()
1105 {
1106 VCManifestTool &tool = vcProject.Configuration.manifestTool;
1107 const ProString tmplt = project->first("TEMPLATE");
1108 if ((tmplt == "vclib"
1109 && !project->isActiveConfig("embed_manifest_dll")
1110 && !project->isActiveConfig("static"))
1111 || (tmplt == "vcapp"
1112 && !project->isActiveConfig("embed_manifest_exe"))) {
1113 tool.EmbedManifest = _False;
1114 }
1115 }
1116
1117 void VcprojGenerator::initLinkerTool()
1118 {
1119 VCConfiguration &conf = vcProject.Configuration;
1120 conf.linker.parseOptions(project->values("QMAKE_LFLAGS"));
1121
1122 if (!project->values("DEF_FILE").isEmpty())
1123 conf.linker.ModuleDefinitionFile = project->first("DEF_FILE").toQString();
1124
1125 static const char * const lflags[] = { "LIBS", "LIBS_PRIVATE",
1126 "QMAKE_LIBS", "QMAKE_LIBS_PRIVATE", nullptr };
1127 for (int i = 0; lflags[i]; i++) {
1128 const auto libs = fixLibFlags(lflags[i]);
1129 for (const ProString &lib : libs) {
1130 if (lib.startsWith("/LIBPATH:"))
1131 conf.linker.AdditionalLibraryDirectories << lib.mid(9).toQString();
1132 else
1133 conf.linker.AdditionalDependencies << lib.toQString();
1134 }
1135 }
1136
1137 conf.linker.OutputFile = "$(OutDir)\\";
1138 conf.linker.OutputFile += project->first("MSVCPROJ_TARGET").toQString();
1139 }
1140
1141 void VcprojGenerator::initResourceTool()
1142 {
1143 VCConfiguration &conf = vcProject.Configuration;
1144
1145 ProStringList rcDefines = project->values("RC_DEFINES");
1146 if (rcDefines.size() > 0)
1147 conf.resource.PreprocessorDefinitions = rcDefines.toQStringList();
1148 else
1149 conf.resource.PreprocessorDefinitions = conf.compiler.PreprocessorDefinitions;
1150
1151 for (const ProString &path : project->values("RC_INCLUDEPATH")) {
1152 QString fixedPath = fileFixify(path.toQString());
1153 if (fileInfo(fixedPath).isRelative()) {
1154 if (fixedPath == QLatin1String("."))
1155 fixedPath = QStringLiteral("$(ProjectDir)");
1156 else
1157 fixedPath.prepend(QStringLiteral("$(ProjectDir)\\"));
1158 }
1159 conf.resource.AdditionalIncludeDirectories << escapeFilePath(fixedPath);
1160 }
1161
1162 // We need to add _DEBUG for the debug version of the project, since the normal compiler defines
1163 // do not contain it. (The compiler defines this symbol automatically, which is wy we don't need
1164 // to add it for the compiler) However, the resource tool does not do this.
1165 if(project->isActiveConfig("debug"))
1166 conf.resource.PreprocessorDefinitions += "_DEBUG";
1167 if (conf.CompilerVersion < NET2010 && project->isActiveConfig("staticlib"))
1168 conf.resource.ResourceOutputFileName = "$(OutDir)\\$(InputName).res";
1169 }
1170
1171 void VcprojGenerator::initIDLTool()
1172 {
1173 }
1174
1175 void VcprojGenerator::initCustomBuildTool()
1176 {
1177 }
1178
1179 void VcprojGenerator::initPreBuildEventTools()
1180 {
1181 }
1182
1183 void VcprojGenerator::initPostBuildEventTools()
1184 {
1185 VCConfiguration &conf = vcProject.Configuration;
1186 if (!project->values("QMAKE_POST_LINK").isEmpty()) {
1187 QStringList cmdline = VCToolBase::fixCommandLine(var("QMAKE_POST_LINK"));
1188 conf.postBuild.CommandLine = cmdline;
1189 conf.postBuild.Description = cmdline.join(QLatin1String("\r\n"));
1190 conf.postBuild.ExcludedFromBuild = _False;
1191 }
1192 if (!project->values("MSVCPROJ_COPY_DLL").isEmpty()) {
1193 conf.postBuild.Description += var("MSVCPROJ_COPY_DLL_DESC");
1194 conf.postBuild.CommandLine += var("MSVCPROJ_COPY_DLL");
1195 conf.postBuild.ExcludedFromBuild = _False;
1196 }
1197 }
1198
1199 void VcprojGenerator::initDeploymentTool()
1200 {
1201 VCConfiguration &conf = vcProject.Configuration;
1202 QString targetPath;
1203 targetPath = project->values("deploy.path").join(' ');
1204 if (targetPath.isEmpty())
1205 targetPath = QString("%CSIDL_PROGRAM_FILES%\\") + project->first("TARGET");
1206 if (targetPath.endsWith("/") || targetPath.endsWith("\\"))
1207 targetPath.chop(1);
1208 conf.deployment.RemoteDirectory = targetPath;
1209 const ProStringList dllPaths = project->values("QMAKE_DLL_PATHS");
1210 // Only deploy Qt libs for shared build
1211 if (!dllPaths.isEmpty()) {
1212 // FIXME: This code should actually resolve the libraries from all Qt modules.
1213 ProStringList arg = project->values("LIBS") + project->values("LIBS_PRIVATE")
1214 + project->values("QMAKE_LIBS") + project->values("QMAKE_LIBS_PRIVATE");
1215 bool qpaPluginDeployed = false;
1216 for (ProStringList::ConstIterator it = arg.constBegin(); it != arg.constEnd(); ++it) {
1217 QString dllName = (*it).toQString();
1218 dllName.replace(QLatin1Char('\\'), QLatin1Char('/'));
1219 // LIBPATH isn't relevant for deployment
1220 if (dllName.startsWith(QLatin1String("/LIBPATH:")))
1221 continue;
1222 // We want to deploy .dlls not .libs
1223 if (dllName.endsWith(QLatin1String(".lib")))
1224 dllName.replace(dllName.size() - 3, 3, QLatin1String("dll"));
1225 // Use only the file name and check in Qt's install path and LIBPATHs to check for existence
1226 dllName.remove(0, dllName.lastIndexOf(QLatin1Char('/')) + 1);
1227 QFileInfo info;
1228 for (const ProString &dllPath : dllPaths) {
1229 QString absoluteDllFilePath = dllPath.toQString();
1230 if (!absoluteDllFilePath.endsWith(QLatin1Char('/')))
1231 absoluteDllFilePath += QLatin1Char('/');
1232 absoluteDllFilePath += dllName;
1233 info = QFileInfo(absoluteDllFilePath);
1234 if (info.exists())
1235 break;
1236 }
1237
1238 if (!info.exists())
1239 continue;
1240
1241 conf.deployment.AdditionalFiles += info.fileName()
1242 + "|" + QDir::toNativeSeparators(info.absolutePath())
1243 + "|" + targetPath
1244 + "|0;";
1245 if (!qpaPluginDeployed) {
1246 QString debugInfix;
1247 bool foundGuid = dllName.contains(QLatin1String("Guid"));
1248 if (foundGuid)
1249 debugInfix = QLatin1Char('d');
1250
1251 if (foundGuid || dllName.contains(QLatin1String("Gui"))) {
1252 QFileInfo info2;
1253 for (const ProString &dllPath : dllPaths) {
1254 QString absoluteDllFilePath = dllPath.toQString();
1255 if (!absoluteDllFilePath.endsWith(QLatin1Char('/')))
1256 absoluteDllFilePath += QLatin1Char('/');
1257 absoluteDllFilePath += QLatin1String("../plugins/platforms/qwindows")
1258 + debugInfix + QLatin1String(".dll");
1259 info2 = QFileInfo(absoluteDllFilePath);
1260 if (info2.exists())
1261 break;
1262 }
1263 if (info2.exists()) {
1264 conf.deployment.AdditionalFiles += QLatin1String("qwindows") + debugInfix + QLatin1String(".dll")
1265 + QLatin1Char('|') + QDir::toNativeSeparators(info2.absolutePath())
1266 + QLatin1Char('|') + targetPath + QLatin1String("\\platforms")
1267 + QLatin1String("|0;");
1268 qpaPluginDeployed = true;
1269 }
1270 }
1271 }
1272 }
1273 }
1274
1275 for (const ProString &item : project->values("INSTALLS")) {
1276 // get item.path
1277 QString devicePath = project->first(ProKey(item + ".path")).toQString();
1278 if (devicePath.isEmpty())
1279 devicePath = targetPath;
1280 // check if item.path is relative (! either /,\ or %)
1281 if (!(devicePath.at(0) == QLatin1Char('/')
1282 || devicePath.at(0) == QLatin1Char('\\')
1283 || devicePath.at(0) == QLatin1Char('%'))) {
1284 // create output path
1285 devicePath = Option::fixPathToTargetOS(targetPath + QLatin1Char('\\') + devicePath);
1286 }
1287 // foreach d in item.files
1288 for (const ProString &src : project->values(ProKey(item + ".files"))) {
1289 QString itemDevicePath = devicePath;
1290 QString source = Option::normalizePath(src.toQString());
1291 QString nameFilter;
1292 QFileInfo info(source);
1293 QString searchPath;
1294 if (info.isDir()) {
1295 nameFilter = QLatin1String("*");
1296 itemDevicePath += "\\" + info.fileName();
1297 searchPath = info.absoluteFilePath();
1298 } else {
1299 nameFilter = info.fileName();
1300 searchPath = info.absolutePath();
1301 }
1302
1303 int pathSize = searchPath.size();
1304 using F = QDirListing::IteratorFlag;
1305 QDirListing dirList(searchPath, QStringList{nameFilter}, F::FilesOnly | F::ResolveSymlinks | F::Recursive);
1306 // foreach dirIterator-entry in d
1307 for (const auto &dirEntry : dirList) {
1308 const QString absoluteItemPath = Option::fixPathToTargetOS(dirEntry.absolutePath());
1309 // Identify if it is just another subdir
1310 int diffSize = absoluteItemPath.size() - pathSize;
1311 // write out rules
1312 conf.deployment.AdditionalFiles += dirEntry.fileName()
1313 + "|" + absoluteItemPath
1314 + "|" + itemDevicePath + (diffSize ? (absoluteItemPath.right(diffSize)) : QLatin1String(""))
1315 + "|0;";
1316 }
1317 }
1318 }
1319 }
1320
1321 void VcprojGenerator::initWinDeployQtTool()
1322 {
1323 VCConfiguration &conf = vcProject.Configuration;
1324 conf.windeployqt.ExcludedFromBuild = true;
1325 if (project->isActiveConfig("windeployqt")) {
1326 conf.windeployqt.Record = QStringLiteral("$(TargetName).windeployqt.$(Platform).$(Configuration)");
1327 const QString commandLine = MakefileGenerator::shellQuote(QDir::toNativeSeparators(project->first("QMAKE_WINDEPLOYQT").toQString()))
1328 + QLatin1Char(' ') + project->values("WINDEPLOYQT_OPTIONS").join(QLatin1Char(' '));
1329
1330 // Visual Studio copies all files to be deployed into the MSIL directory
1331 // and then invokes MDILXapCompile on it, which checks for managed code and
1332 // translates it into native code. The problem is that all entries of the
1333 // package will be copied into the MSIL directly, losing the subdirectory
1334 // structure (for instance for plugins). However, the MDILXapCompile call
1335 // itself contains the original subdirectories as parameters and hence the
1336 // call fails.
1337 // Hence the only way to get a build done is to recreate the directory
1338 // structure manually by invoking windeployqt a second time, so that
1339 // the MDILXapCompile call succeeds and deployment continues.
1340 conf.windeployqt.CommandLine += commandLine
1341 + QStringLiteral(" -list relative -dir \"$(MSBuildProjectDirectory)\" \"$(OutDir)\\$(TargetFileName)\" > ")
1342 + MakefileGenerator::shellQuote(conf.windeployqt.Record);
1343 conf.windeployqt.config = &vcProject.Configuration;
1344 conf.windeployqt.ExcludedFromBuild = false;
1345 }
1346 }
1347
1348 void VcprojGenerator::initPreLinkEventTools()
1349 {
1350 VCConfiguration &conf = vcProject.Configuration;
1351 if(!project->values("QMAKE_PRE_LINK").isEmpty()) {
1352 QStringList cmdline = VCToolBase::fixCommandLine(var("QMAKE_PRE_LINK"));
1353 conf.preLink.CommandLine = cmdline;
1354 conf.preLink.Description = cmdline.join(QLatin1String("\r\n"));
1355 conf.preLink.ExcludedFromBuild = _False;
1356 }
1357 }
1358
1359 void VcprojGenerator::initRootFiles()
1360 {
1361 // Note: Root files do _not_ have any filter name, filter nor GUID!
1362 vcProject.RootFiles.addFiles(project->values("RC_FILE"));
1363
1364 vcProject.RootFiles.Project = this;
1365 vcProject.RootFiles.Config = &(vcProject.Configuration);
1366 }
1367
1368 void VcprojGenerator::initSourceFiles()
1369 {
1370 vcProject.SourceFiles.Name = "Source Files";
1371 vcProject.SourceFiles.Filter = "cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx";
1372 vcProject.SourceFiles.Guid = _GUIDSourceFiles;
1373
1374 vcProject.SourceFiles.addFiles(project->values("SOURCES"));
1375
1376 vcProject.SourceFiles.Project = this;
1377 vcProject.SourceFiles.Config = &(vcProject.Configuration);
1378 }
1379
1380 void VcprojGenerator::initHeaderFiles()
1381 {
1382 vcProject.HeaderFiles.Name = "Header Files";
1383 vcProject.HeaderFiles.Filter = "h;hpp;hxx;hm;inl;inc;xsd";
1384 vcProject.HeaderFiles.Guid = _GUIDHeaderFiles;
1385
1386 vcProject.HeaderFiles.addFiles(project->values("HEADERS"));
1387 if (usePCH) // Generated PCH cpp file
1388 vcProject.HeaderFiles.addFile(precompH);
1389
1390 vcProject.HeaderFiles.Project = this;
1391 vcProject.HeaderFiles.Config = &(vcProject.Configuration);
1392 // vcProject.HeaderFiles.CustomBuild = mocHdr;
1393 // addMocArguments(vcProject.HeaderFiles);
1394 }
1395
1396 void VcprojGenerator::initGeneratedFiles()
1397 {
1398 vcProject.GeneratedFiles.Name = "Generated Files";
1399 vcProject.GeneratedFiles.Filter = "cpp;c;cxx;moc;h;def;odl;idl;res;";
1400 vcProject.GeneratedFiles.Guid = _GUIDGeneratedFiles;
1401
1402 // ### These cannot have CustomBuild (mocSrc)!!
1403 vcProject.GeneratedFiles.addFiles(project->values("GENERATED_SOURCES"));
1404 vcProject.GeneratedFiles.addFiles(project->values("GENERATED_FILES"));
1405 vcProject.GeneratedFiles.addFiles(project->values("IDLSOURCES"));
1406 if (project->values("RC_FILE").isEmpty())
1407 vcProject.GeneratedFiles.addFiles(project->values("RES_FILE"));
1408 if(!extraCompilerOutputs.isEmpty())
1409 vcProject.GeneratedFiles.addFiles(extraCompilerOutputs.keys());
1410
1411 vcProject.GeneratedFiles.Project = this;
1412 vcProject.GeneratedFiles.Config = &(vcProject.Configuration);
1413 // vcProject.GeneratedFiles.CustomBuild = mocSrc;
1414 }
1415
1416 void VcprojGenerator::initLexYaccFiles()
1417 {
1418 vcProject.LexYaccFiles.Name = "Lex / Yacc Files";
1419 vcProject.LexYaccFiles.ParseFiles = _False;
1420 vcProject.LexYaccFiles.Filter = "l;y";
1421 vcProject.LexYaccFiles.Guid = _GUIDLexYaccFiles;
1422
1423 vcProject.LexYaccFiles.addFiles(project->values("LEXSOURCES"));
1424 vcProject.LexYaccFiles.addFiles(project->values("YACCSOURCES"));
1425
1426 vcProject.LexYaccFiles.Project = this;
1427 vcProject.LexYaccFiles.Config = &(vcProject.Configuration);
1428 }
1429
1430 void VcprojGenerator::initTranslationFiles()
1431 {
1432 vcProject.TranslationFiles.Name = "Translation Files";
1433 vcProject.TranslationFiles.ParseFiles = _False;
1434 vcProject.TranslationFiles.Filter = "ts;xlf";
1435 vcProject.TranslationFiles.Guid = _GUIDTranslationFiles;
1436
1437 vcProject.TranslationFiles.addFiles(project->values("TRANSLATIONS"));
1438 vcProject.TranslationFiles.addFiles(project->values("EXTRA_TRANSLATIONS"));
1439
1440 vcProject.TranslationFiles.Project = this;
1441 vcProject.TranslationFiles.Config = &(vcProject.Configuration);
1442 }
1443
1444 void VcprojGenerator::initFormFiles()
1445 {
1446 vcProject.FormFiles.Name = "Form Files";
1447 vcProject.FormFiles.ParseFiles = _False;
1448 vcProject.FormFiles.Filter = "ui";
1449 vcProject.FormFiles.Guid = _GUIDFormFiles;
1450 vcProject.FormFiles.addFiles(project->values("FORMS"));
1451 vcProject.FormFiles.Project = this;
1452 vcProject.FormFiles.Config = &(vcProject.Configuration);
1453 }
1454
1455 void VcprojGenerator::initResourceFiles()
1456 {
1457 vcProject.ResourceFiles.Name = "Resource Files";
1458 vcProject.ResourceFiles.ParseFiles = _False;
1459 vcProject.ResourceFiles.Filter = "qrc;*"; //"rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;ts;xlf;qrc";
1460 vcProject.ResourceFiles.Guid = _GUIDResourceFiles;
1461
1462 // Bad hack, please look away -------------------------------------
1463 QString rcc_dep_cmd = project->values("rcc.depend_command").join(' ');
1464 if(!rcc_dep_cmd.isEmpty()) {
1465 const QStringList qrc_files = project->values("RESOURCES").toQStringList();
1466 QStringList deps;
1467 for (const QString &qrc_file : qrc_files) {
1468 callExtraCompilerDependCommand("rcc",
1469 rcc_dep_cmd,
1470 qrc_file,
1471 QString(),
1472 true, // dep_lines
1473 &deps,
1474 false, // existingDepsOnly
1475 true // checkCommandavailability
1476 );
1477 }
1478 vcProject.ResourceFiles.addFiles(deps);
1479 }
1480 // You may look again --------------------------------------------
1481
1482 vcProject.ResourceFiles.addFiles(project->values("RESOURCES"));
1483
1484 vcProject.ResourceFiles.Project = this;
1485 vcProject.ResourceFiles.Config = &(vcProject.Configuration);
1486 }
1487
1488 void VcprojGenerator::initDistributionFiles()
1489 {
1490 vcProject.DistributionFiles.Name = "Distribution Files";
1491 vcProject.DistributionFiles.ParseFiles = _False;
1492 vcProject.DistributionFiles.Filter = "*";
1493 vcProject.DistributionFiles.Guid = _GUIDDistributionFiles;
1494 vcProject.DistributionFiles.addFiles(project->values("DISTFILES"));
1495 vcProject.DistributionFiles.Project = this;
1496 vcProject.DistributionFiles.Config = &(vcProject.Configuration);
1497 }
1498
1499 QString VcprojGenerator::extraCompilerName(const ProString &extraCompiler,
1500 const QStringList &inputs,
1501 const QStringList &outputs)
1502 {
1503 QString name = project->values(ProKey(extraCompiler + ".name")).join(' ');
1504 if (name.isEmpty())
1505 name = extraCompiler.toQString();
1506 else
1507 name = replaceExtraCompilerVariables(name, inputs, outputs, NoShell);
1508 return name;
1509 }
1510
1511 void VcprojGenerator::initExtraCompilerOutputs()
1512 {
1513 ProStringList otherFilters;
1514 otherFilters << "FORMS"
1515 << "GENERATED_FILES"
1516 << "GENERATED_SOURCES"
1517 << "HEADERS"
1518 << "IDLSOURCES"
1519 << "LEXSOURCES"
1520 << "RC_FILE"
1521 << "RESOURCES"
1522 << "RES_FILE"
1523 << "SOURCES"
1524 << "TRANSLATIONS"
1525 << "YACCSOURCES";
1526 const ProStringList &quc = project->values("QMAKE_EXTRA_COMPILERS");
1527 for (ProStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) {
1528 const ProStringList &inputVars = project->values(ProKey(*it + ".input"));
1529 ProStringList inputFiles;
1530 for (auto var : inputVars)
1531 inputFiles.append(project->values(var.toKey()));
1532 const ProStringList &outputs = project->values(ProKey(*it + ".output"));
1533
1534 // Create an extra compiler filter and add the files
1535 VCFilter extraCompile;
1536 extraCompile.Name = extraCompilerName(it->toQString(), inputFiles.toQStringList(),
1537 outputs.toQStringList());
1538 extraCompile.ParseFiles = _False;
1539 extraCompile.Filter = "";
1540 extraCompile.Guid = QString(_GUIDExtraCompilerFiles) + "-" + (*it);
1541
1542 bool addOnInput = hasBuiltinCompiler(firstExpandedOutputFileName(*it));
1543 if (!addOnInput) {
1544 // If the extra compiler has a variable_out set that is already handled
1545 // some other place, ignore it.
1546 const ProString &outputVar = project->first(ProKey(*it + ".variable_out"));
1547 if (!outputVar.isEmpty() && otherFilters.contains(outputVar))
1548 continue;
1549
1550 QString tmp_out;
1551 if (!outputs.isEmpty())
1552 tmp_out = outputs.first().toQString();
1553 if (project->values(ProKey(*it + ".CONFIG")).indexOf("combine") != -1) {
1554 // Combined output, only one file result. Use .cbt file.
1555 extraCompile.addFile(Option::fixPathToTargetOS(
1556 replaceExtraCompilerVariables(tmp_out + customBuildToolFilterFileSuffix,
1557 QString(), QString(), NoShell), false));
1558 } else if (!inputVars.isEmpty()) {
1559 // One output file per input
1560 const ProStringList &tmp_in = project->values(inputVars.first().toKey());
1561 for (int i = 0; i < tmp_in.size(); ++i) {
1562 const QString &filename = tmp_in.at(i).toQString();
1563 if (extraCompilerSources.contains(filename) && !otherFiltersContain(filename))
1564 extraCompile.addFile(Option::fixPathToTargetOS(
1565 replaceExtraCompilerVariables(filename, tmp_out, QString(), NoShell), false));
1566 }
1567 }
1568 } else {
1569 // In this case we the outputs have a built-in compiler, so we cannot add the custom
1570 // build steps there. So, we turn it around and add it to the input files instead,
1571 // provided that the input file variable is not handled already (those in otherFilters
1572 // are handled, so we avoid them).
1573 for (const ProString &inputVar : inputVars) {
1574 if (!otherFilters.contains(inputVar)) {
1575 const ProStringList &tmp_in = project->values(inputVar.toKey());
1576 for (int i = 0; i < tmp_in.size(); ++i) {
1577 const QString &filename = tmp_in.at(i).toQString();
1578 if (extraCompilerSources.contains(filename) && !otherFiltersContain(filename))
1579 extraCompile.addFile(Option::fixPathToTargetOS(
1580 replaceExtraCompilerVariables(filename, QString(), QString(), NoShell), false));
1581 }
1582 }
1583 }
1584 }
1585 extraCompile.Project = this;
1586 extraCompile.Config = &(vcProject.Configuration);
1587
1588 vcProject.ExtraCompilersFiles.append(extraCompile);
1589 }
1590 }
1591
1592 bool VcprojGenerator::otherFiltersContain(const QString &fileName) const
1593 {
1594 auto filterFileMatches = [&fileName] (const VCFilterFile &ff)
1595 {
1596 return ff.file == fileName;
1597 };
1598 for (const VCFilter *filter : { &vcProject.RootFiles,
1599 &vcProject.SourceFiles,
1600 &vcProject.HeaderFiles,
1601 &vcProject.GeneratedFiles,
1602 &vcProject.LexYaccFiles,
1603 &vcProject.TranslationFiles,
1604 &vcProject.FormFiles,
1605 &vcProject.ResourceFiles,
1606 &vcProject.DeploymentFiles,
1607 &vcProject.DistributionFiles}) {
1608 if (std::any_of(filter->Files.cbegin(), filter->Files.cend(), filterFileMatches))
1609 return true;
1610 }
1611 return false;
1612 }
1613
1614 // ------------------------------------------------------------------------------------------------
1615 // ------------------------------------------------------------------------------------------------
1616
1617 VCProjectWriter *VcprojGenerator::createProjectWriter()
1618 {
1619 return new VCProjectWriter;
1620 }
1621
1622 QString VcprojGenerator::replaceExtraCompilerVariables(
1623 const QString &var, const QStringList &in, const QStringList &out, ReplaceFor forShell)
1624 {
1625 QString ret = MakefileGenerator::replaceExtraCompilerVariables(var, in, out, forShell);
1626
1627 ProStringList &defines = project->values("VCPROJ_MAKEFILE_DEFINES");
1628 if(defines.isEmpty())
1629 defines.append(varGlue("PRL_EXPORT_DEFINES"," -D"," -D","") +
1630 varGlue("DEFINES"," -D"," -D",""));
1631 ret.replace(QLatin1String("$(DEFINES)"), defines.first().toQString());
1632
1633 ProStringList &incpath = project->values("VCPROJ_MAKEFILE_INCPATH");
1634 if(incpath.isEmpty() && !this->var("MSVCPROJ_INCPATH").isEmpty())
1635 incpath.append(this->var("MSVCPROJ_INCPATH"));
1636 ret.replace(QLatin1String("$(INCPATH)"), incpath.join(' '));
1637
1638 return ret;
1639 }
1640
1641 bool VcprojGenerator::openOutput(QFile &file, const QString &/*build*/) const
1642 {
1643 ProString fileName = file.fileName();
1644 ProString extension = project->first("TEMPLATE") == "vcsubdirs"
1645 ? project->first("VCSOLUTION_EXTENSION") : project->first("VCPROJ_EXTENSION");
1646 if (!fileName.endsWith(extension)) {
1647 if (fileName.isEmpty()) {
1648 fileName = !project->first("MAKEFILE").isEmpty()
1649 ? project->first("MAKEFILE") : project->first("TARGET");
1650 }
1651 file.setFileName(fileName + extension);
1652 }
1653 return Win32MakefileGenerator::openOutput(file, QString());
1654 }
1655
1656 QT_END_NAMESPACE