2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the qmake application of the Qt Toolkit.
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
2012-09-19 12:28:29 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-15 12:36:27 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "msvc_nmake.h"
|
|
|
|
#include "option.h"
|
2013-09-02 08:51:17 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <qregexp.h>
|
|
|
|
#include <qdir.h>
|
2014-12-22 13:54:08 +00:00
|
|
|
#include <qdiriterator.h>
|
2014-12-22 12:29:53 +00:00
|
|
|
#include <qset.h>
|
2013-09-02 08:51:17 +00:00
|
|
|
|
2016-11-18 10:42:35 +00:00
|
|
|
#include <registry_p.h>
|
2013-09-02 08:51:17 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
2013-09-02 08:51:17 +00:00
|
|
|
static QString nmakePathList(const QStringList &list)
|
|
|
|
{
|
|
|
|
QStringList pathList;
|
2016-02-01 08:49:22 +00:00
|
|
|
pathList.reserve(list.size());
|
2016-01-26 13:38:54 +00:00
|
|
|
for (const QString &path : list)
|
2013-09-02 08:51:17 +00:00
|
|
|
pathList.append(QDir::cleanPath(path));
|
|
|
|
|
|
|
|
return QDir::toNativeSeparators(pathList.join(QLatin1Char(';')))
|
2016-02-04 14:12:03 +00:00
|
|
|
.replace('#', QLatin1String("^#")).replace('$', QLatin1String("$$"));
|
2013-09-02 08:51:17 +00:00
|
|
|
}
|
|
|
|
|
2018-01-02 17:07:03 +00:00
|
|
|
NmakeMakefileGenerator::NmakeMakefileGenerator() : usePCH(false), usePCHC(false)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
NmakeMakefileGenerator::writeMakefile(QTextStream &t)
|
|
|
|
{
|
|
|
|
writeHeader(t);
|
2013-08-26 17:51:57 +00:00
|
|
|
if (writeDummyMakefile(t))
|
2011-04-27 10:05:43 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if(project->first("TEMPLATE") == "app" ||
|
2011-05-03 13:30:28 +00:00
|
|
|
project->first("TEMPLATE") == "lib" ||
|
|
|
|
project->first("TEMPLATE") == "aux") {
|
2011-04-27 10:05:43 +00:00
|
|
|
#if 0
|
|
|
|
if(Option::mkfile::do_stub_makefile)
|
|
|
|
return MakefileGenerator::writeStubMakefile(t);
|
|
|
|
#endif
|
2012-05-11 08:24:28 +00:00
|
|
|
if (!project->isHostBuild()) {
|
2018-10-15 18:20:10 +00:00
|
|
|
const QString msvcVer = project->first("MSVC_VER").toQString();
|
|
|
|
if (msvcVer.isEmpty()) {
|
|
|
|
fprintf(stderr, "Mkspec does not specify MSVC_VER. Cannot continue.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool winrtBuild = false;
|
|
|
|
bool crossPlatformDesktopBuild = false;
|
|
|
|
QString arch = project->first("VCPROJ_ARCH").toQString().toLower();
|
2016-03-09 13:59:20 +00:00
|
|
|
if (project->isActiveConfig(QStringLiteral("winrt"))) {
|
2018-10-15 18:20:10 +00:00
|
|
|
winrtBuild = true;
|
|
|
|
|
|
|
|
// Only add explicit support for arm64 cross-platform desktop builds.
|
|
|
|
} else if ((arch == QLatin1String("arm64")) && (msvcVer == QStringLiteral("15.0"))) {
|
|
|
|
crossPlatformDesktopBuild = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (winrtBuild || crossPlatformDesktopBuild) {
|
2013-09-02 08:51:17 +00:00
|
|
|
QString compiler;
|
|
|
|
QString compilerArch;
|
2018-10-15 18:20:10 +00:00
|
|
|
const ProStringList hostArch = project->values("QMAKE_TARGET.arch");
|
2016-11-22 12:14:53 +00:00
|
|
|
if (msvcVer == QStringLiteral("15.0")) {
|
2014-02-13 12:43:54 +00:00
|
|
|
if (hostArch.contains("x86_64"))
|
2016-11-22 12:14:53 +00:00
|
|
|
compiler = QStringLiteral("HostX64/");
|
2014-02-13 12:43:54 +00:00
|
|
|
else
|
2016-11-22 12:14:53 +00:00
|
|
|
compiler = QStringLiteral("HostX86/");
|
|
|
|
if (arch == QLatin1String("arm")) {
|
|
|
|
compiler += QStringLiteral("arm");
|
|
|
|
compilerArch = QStringLiteral("arm");
|
|
|
|
} else if (arch == QLatin1String("x64")) {
|
|
|
|
compiler += QStringLiteral("x64");
|
|
|
|
compilerArch = QStringLiteral("amd64");
|
2018-10-15 18:20:10 +00:00
|
|
|
} else if (arch == QLatin1String("arm64")) {
|
|
|
|
compiler += QStringLiteral("arm64");
|
|
|
|
compilerArch = QStringLiteral("arm64");
|
2016-11-22 12:14:53 +00:00
|
|
|
} else {
|
2017-05-03 05:36:06 +00:00
|
|
|
arch = QStringLiteral("x86");
|
2016-11-22 12:14:53 +00:00
|
|
|
compiler += QStringLiteral("x86");
|
|
|
|
}
|
2014-02-06 09:20:23 +00:00
|
|
|
} else {
|
2016-11-22 12:14:53 +00:00
|
|
|
if (arch == QLatin1String("arm")) {
|
|
|
|
compiler = QStringLiteral("x86_arm");
|
|
|
|
compilerArch = QStringLiteral("arm");
|
|
|
|
} else if (arch == QLatin1String("x64")) {
|
|
|
|
const ProStringList hostArch = project->values("QMAKE_TARGET.arch");
|
|
|
|
if (hostArch.contains("x86_64"))
|
|
|
|
compiler = QStringLiteral("amd64");
|
|
|
|
else
|
|
|
|
compiler = QStringLiteral("x86_amd64");
|
|
|
|
compilerArch = QStringLiteral("amd64");
|
|
|
|
} else {
|
|
|
|
arch = QStringLiteral("x86");
|
|
|
|
}
|
2013-09-02 08:51:17 +00:00
|
|
|
}
|
2013-10-24 17:14:10 +00:00
|
|
|
|
|
|
|
const QString winsdkVer = project->first("WINSDK_VER").toQString();
|
|
|
|
if (winsdkVer.isEmpty()) {
|
|
|
|
fprintf(stderr, "Mkspec does not specify WINSDK_VER. Cannot continue.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const QString targetVer = project->first("WINTARGET_VER").toQString();
|
2018-10-15 18:20:10 +00:00
|
|
|
if (targetVer.isEmpty() && winrtBuild) {
|
2013-10-24 17:14:10 +00:00
|
|
|
fprintf(stderr, "Mkspec does not specify WINTARGET_VER. Cannot continue.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-31 15:15:28 +00:00
|
|
|
#ifdef Q_OS_WIN
|
2016-11-22 12:14:53 +00:00
|
|
|
QString regKey;
|
|
|
|
if (msvcVer == QStringLiteral("15.0"))
|
|
|
|
regKey = QStringLiteral("Software\\Microsoft\\VisualStudio\\SxS\\VS7\\") + msvcVer;
|
|
|
|
else
|
|
|
|
regKey = QStringLiteral("Software\\Microsoft\\VisualStudio\\") + msvcVer + ("\\Setup\\VC\\ProductDir");
|
2015-12-05 18:09:15 +00:00
|
|
|
const QString vcInstallDir = qt_readRegistryKey(HKEY_LOCAL_MACHINE, regKey, KEY_WOW64_32KEY);
|
2013-09-02 08:51:17 +00:00
|
|
|
if (vcInstallDir.isEmpty()) {
|
2013-10-24 17:14:10 +00:00
|
|
|
fprintf(stderr, "Failed to find the Visual Studio installation directory.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-22 13:54:02 +00:00
|
|
|
const QString windowsPath = "Software\\Microsoft\\Microsoft SDKs\\Windows\\v";
|
2014-05-21 13:42:31 +00:00
|
|
|
|
2015-12-05 18:09:15 +00:00
|
|
|
regKey = windowsPath + winsdkVer + QStringLiteral("\\InstallationFolder");
|
|
|
|
const QString kitDir = qt_readRegistryKey(HKEY_LOCAL_MACHINE, regKey, KEY_WOW64_32KEY);
|
2013-10-24 17:14:10 +00:00
|
|
|
if (kitDir.isEmpty()) {
|
|
|
|
fprintf(stderr, "Failed to find the Windows Kit installation directory.\n");
|
2013-09-02 08:51:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-10-31 15:15:28 +00:00
|
|
|
#else
|
|
|
|
const QString vcInstallDir = "/fake/vc_install_dir";
|
2013-11-26 21:30:27 +00:00
|
|
|
const QString kitDir = "/fake/sdk_install_dir";
|
2013-10-31 15:15:28 +00:00
|
|
|
#endif // Q_OS_WIN
|
2013-09-02 08:51:17 +00:00
|
|
|
QStringList incDirs;
|
|
|
|
QStringList libDirs;
|
|
|
|
QStringList binDirs;
|
2016-11-22 12:14:53 +00:00
|
|
|
if (msvcVer == QStringLiteral("15.0")) {
|
|
|
|
const QString toolsInstallDir = qgetenv("VCToolsInstallDir");
|
|
|
|
if (toolsInstallDir.isEmpty()) {
|
|
|
|
fprintf(stderr, "Failed to access tools installation dir.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
binDirs << toolsInstallDir + QStringLiteral("bin/") + compiler;
|
|
|
|
if (arch == QStringLiteral("x64"))
|
|
|
|
binDirs << toolsInstallDir + QStringLiteral("bin/HostX86/X86");
|
|
|
|
binDirs << kitDir + QStringLiteral("bin/x86");
|
|
|
|
binDirs << vcInstallDir + QStringLiteral("Common7/Tools");
|
|
|
|
binDirs << vcInstallDir + QStringLiteral("Common7/ide");
|
|
|
|
binDirs << vcInstallDir + QStringLiteral("MSBuild/15.0/bin");
|
|
|
|
|
|
|
|
incDirs << toolsInstallDir + QStringLiteral("include");
|
|
|
|
incDirs << vcInstallDir + QStringLiteral("VC/Auxiliary/VS/include");
|
|
|
|
|
|
|
|
const QString crtVersion = qgetenv("UCRTVersion");
|
|
|
|
if (crtVersion.isEmpty()) {
|
|
|
|
fprintf(stderr, "Failed to access CRT version.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const QString crtInclude = kitDir + QStringLiteral("Include/") + crtVersion;
|
|
|
|
const QString crtLib = kitDir + QStringLiteral("Lib/") + crtVersion;
|
|
|
|
incDirs << crtInclude + QStringLiteral("/ucrt");
|
|
|
|
incDirs << crtInclude + QStringLiteral("/um");
|
|
|
|
incDirs << crtInclude + QStringLiteral("/shared");
|
|
|
|
incDirs << crtInclude + QStringLiteral("/winrt");
|
|
|
|
|
2018-10-15 18:20:10 +00:00
|
|
|
if (winrtBuild) {
|
|
|
|
// Only use mobile-specific headers and link against store-specific libs for
|
|
|
|
// winrt builds.
|
|
|
|
incDirs << kitDir + QStringLiteral("Extension SDKs/WindowsMobile/")
|
|
|
|
+ crtVersion + QStringLiteral("/Include/WinRT");
|
2016-11-22 12:14:53 +00:00
|
|
|
|
2018-10-15 18:20:10 +00:00
|
|
|
libDirs << toolsInstallDir + QStringLiteral("lib/") + arch + QStringLiteral("/store");
|
|
|
|
} else {
|
|
|
|
// Desktop projects may require the atl headers and libs.
|
|
|
|
incDirs << toolsInstallDir + QStringLiteral("atlmfc/include");
|
|
|
|
libDirs << toolsInstallDir + QStringLiteral("atlmfc/lib/") + compilerArch;
|
|
|
|
libDirs << toolsInstallDir + QStringLiteral("lib/") + arch;
|
|
|
|
}
|
2016-11-22 12:14:53 +00:00
|
|
|
|
|
|
|
libDirs << vcInstallDir + QStringLiteral("VC/Auxiliary/VS/lib/") + arch;
|
|
|
|
|
|
|
|
libDirs << crtLib + QStringLiteral("/ucrt/") + arch;
|
|
|
|
libDirs << crtLib + QStringLiteral("/um/") + arch;
|
|
|
|
} else if (msvcVer == QStringLiteral("14.0")) {
|
2015-04-17 09:53:28 +00:00
|
|
|
binDirs << vcInstallDir + QStringLiteral("bin/") + compiler;
|
|
|
|
binDirs << vcInstallDir + QStringLiteral("bin/"); // Maybe remove for x86 again?
|
|
|
|
binDirs << kitDir + QStringLiteral("bin/") + (arch == QStringLiteral("arm") ? QStringLiteral("x86") : arch);
|
|
|
|
binDirs << vcInstallDir + QStringLiteral("../Common7/Tools/bin");
|
|
|
|
binDirs << vcInstallDir + QStringLiteral("../Common7/Tools");
|
|
|
|
binDirs << vcInstallDir + QStringLiteral("../Common7/ide");
|
|
|
|
binDirs << kitDir + QStringLiteral("Windows Performance Toolkit/");
|
|
|
|
|
|
|
|
incDirs << vcInstallDir + QStringLiteral("include");
|
|
|
|
incDirs << vcInstallDir + QStringLiteral("atlmfc/include");
|
2015-08-04 06:18:01 +00:00
|
|
|
|
|
|
|
const QString crtVersion = qgetenv("UCRTVersion");
|
|
|
|
if (crtVersion.isEmpty()) {
|
|
|
|
fprintf(stderr, "Failed to access CRT version.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const QString crtInclude = kitDir + QStringLiteral("Include/") + crtVersion;
|
|
|
|
const QString crtLib = kitDir + QStringLiteral("Lib/") + crtVersion;
|
|
|
|
incDirs << crtInclude + QStringLiteral("/ucrt");
|
|
|
|
incDirs << crtInclude + QStringLiteral("/um");
|
|
|
|
incDirs << crtInclude + QStringLiteral("/shared");
|
|
|
|
incDirs << crtInclude + QStringLiteral("/winrt");
|
2015-04-17 09:53:28 +00:00
|
|
|
|
2016-01-13 11:57:18 +00:00
|
|
|
incDirs << kitDir + QStringLiteral("Extension SDKs/WindowsMobile/")
|
|
|
|
+ crtVersion + QStringLiteral("/Include/WinRT");
|
|
|
|
|
2015-04-17 09:53:28 +00:00
|
|
|
libDirs << vcInstallDir + QStringLiteral("lib/store/") + compilerArch;
|
|
|
|
libDirs << vcInstallDir + QStringLiteral("atlmfc/lib") + compilerArch;
|
2015-08-04 06:18:01 +00:00
|
|
|
|
|
|
|
libDirs << crtLib + QStringLiteral("/ucrt/") + arch;
|
|
|
|
libDirs << crtLib + QStringLiteral("/um/") + arch;
|
2013-09-02 08:51:17 +00:00
|
|
|
} else {
|
|
|
|
incDirs << vcInstallDir + QStringLiteral("/include");
|
2013-11-17 22:42:24 +00:00
|
|
|
libDirs << vcInstallDir + QStringLiteral("/lib/store/") + compilerArch
|
|
|
|
<< vcInstallDir + QStringLiteral("/lib/") + compilerArch;
|
2013-09-02 08:51:17 +00:00
|
|
|
binDirs << vcInstallDir + QStringLiteral("/bin/") + compiler
|
|
|
|
<< vcInstallDir + QStringLiteral("/../Common7/IDE");
|
2013-10-24 17:14:10 +00:00
|
|
|
libDirs << kitDir + QStringLiteral("/Lib/") + targetVer + ("/um/") + arch;
|
2013-09-02 08:51:17 +00:00
|
|
|
incDirs << kitDir + QStringLiteral("/include/um")
|
|
|
|
<< kitDir + QStringLiteral("/include/shared")
|
|
|
|
<< kitDir + QStringLiteral("/include/winrt");
|
|
|
|
}
|
2015-05-09 08:25:11 +00:00
|
|
|
|
|
|
|
binDirs << vcInstallDir + QStringLiteral("/bin");
|
|
|
|
|
2013-09-02 08:51:17 +00:00
|
|
|
// Inherit PATH
|
|
|
|
binDirs << QString::fromLocal8Bit(qgetenv("PATH")).split(QLatin1Char(';'));
|
|
|
|
|
|
|
|
t << "\nINCLUDE = " << nmakePathList(incDirs);
|
|
|
|
t << "\nLIB = " << nmakePathList(libDirs);
|
|
|
|
t << "\nPATH = " << nmakePathList(binDirs) << '\n';
|
|
|
|
}
|
2012-05-11 08:24:28 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
writeNmakeParts(t);
|
|
|
|
return MakefileGenerator::writeMakefile(t);
|
|
|
|
}
|
|
|
|
else if(project->first("TEMPLATE") == "subdirs") {
|
|
|
|
writeSubDirs(t);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-03 07:52:30 +00:00
|
|
|
void NmakeMakefileGenerator::writeSubMakeCall(QTextStream &t, const QString &callPrefix,
|
2012-04-25 15:12:53 +00:00
|
|
|
const QString &makeArguments)
|
2011-05-03 07:52:30 +00:00
|
|
|
{
|
|
|
|
// Pass MAKEFLAGS as environment variable to sub-make calls.
|
|
|
|
// Unlike other make tools nmake doesn't do this automatically.
|
|
|
|
t << "\n\t@set MAKEFLAGS=$(MAKEFLAGS)";
|
2012-04-25 15:12:53 +00:00
|
|
|
Win32MakefileGenerator::writeSubMakeCall(t, callPrefix, makeArguments);
|
2011-05-03 07:52:30 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QString NmakeMakefileGenerator::defaultInstall(const QString &t)
|
|
|
|
{
|
|
|
|
QString ret = Win32MakefileGenerator::defaultInstall(t);
|
2016-03-11 16:48:53 +00:00
|
|
|
if (ret.isEmpty())
|
|
|
|
return ret;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2016-01-14 12:01:39 +00:00
|
|
|
const QString root = installRoot();
|
2012-09-06 10:21:38 +00:00
|
|
|
ProStringList &uninst = project->values(ProKey(t + ".uninstall"));
|
2014-11-24 18:51:32 +00:00
|
|
|
QString targetdir = fileFixify(project->first(ProKey(t + ".path")).toQString(), FileFixifyAbsolute);
|
2011-04-27 10:05:43 +00:00
|
|
|
if(targetdir.right(1) != Option::dir_sep)
|
|
|
|
targetdir += Option::dir_sep;
|
|
|
|
|
2013-11-18 20:39:08 +00:00
|
|
|
if (project->isActiveConfig("debug_info")) {
|
2014-05-26 11:43:48 +00:00
|
|
|
if (t == "dlltarget" || project->values(ProKey(t + ".CONFIG")).indexOf("no_dll") == -1) {
|
2015-09-22 18:58:18 +00:00
|
|
|
QString pdb_target = project->first("TARGET") + project->first("TARGET_VERSION_EXT") + ".pdb";
|
2011-04-27 10:05:43 +00:00
|
|
|
QString src_targ = (project->isEmpty("DESTDIR") ? QString("$(DESTDIR)") : project->first("DESTDIR")) + pdb_target;
|
|
|
|
QString dst_targ = filePrefixRoot(root, fileFixify(targetdir + pdb_target, FileFixifyAbsolute));
|
|
|
|
if(!ret.isEmpty())
|
|
|
|
ret += "\n\t";
|
2015-02-06 14:30:02 +00:00
|
|
|
ret += QString("-$(INSTALL_FILE) ") + escapeFilePath(src_targ) + ' ' + escapeFilePath(dst_targ);
|
2011-04-27 10:05:43 +00:00
|
|
|
if(!uninst.isEmpty())
|
|
|
|
uninst.append("\n\t");
|
2015-02-06 14:30:02 +00:00
|
|
|
uninst.append("-$(DEL_FILE) " + escapeFilePath(dst_targ));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList &NmakeMakefileGenerator::findDependencies(const QString &file)
|
|
|
|
{
|
|
|
|
QStringList &aList = MakefileGenerator::findDependencies(file);
|
|
|
|
for(QStringList::Iterator it = Option::cpp_ext.begin(); it != Option::cpp_ext.end(); ++it) {
|
|
|
|
if(file.endsWith(*it)) {
|
|
|
|
if(!precompObj.isEmpty() && !aList.contains(precompObj))
|
|
|
|
aList += precompObj;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-08-22 20:26:46 +00:00
|
|
|
for (QStringList::Iterator it = Option::c_ext.begin(); it != Option::c_ext.end(); ++it) {
|
|
|
|
if (file.endsWith(*it)) {
|
|
|
|
if (!precompObjC.isEmpty() && !aList.contains(precompObjC))
|
|
|
|
aList += precompObjC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
return aList;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NmakeMakefileGenerator::writeNmakeParts(QTextStream &t)
|
|
|
|
{
|
|
|
|
writeStandardParts(t);
|
|
|
|
|
|
|
|
// precompiled header
|
|
|
|
if(usePCH) {
|
2015-02-06 14:30:02 +00:00
|
|
|
QString precompRule = QString("-c -Yc -Fp%1 -Fo%2")
|
|
|
|
.arg(escapeFilePath(precompPch), escapeFilePath(precompObj));
|
|
|
|
t << escapeDependencyPath(precompObj) << ": " << escapeDependencyPath(precompH) << ' '
|
2018-06-08 14:00:44 +00:00
|
|
|
<< finalizeDependencyPaths(findDependencies(precompH)).join(" \\\n\t\t")
|
2015-02-06 14:30:02 +00:00
|
|
|
<< "\n\t$(CXX) " + precompRule +" $(CXXFLAGS) $(INCPATH) -TP "
|
|
|
|
<< escapeFilePath(precompH) << endl << endl;
|
2018-01-02 17:07:03 +00:00
|
|
|
}
|
|
|
|
if (usePCHC) {
|
2017-08-22 20:26:46 +00:00
|
|
|
QString precompRuleC = QString("-c -Yc -Fp%1 -Fo%2")
|
|
|
|
.arg(escapeFilePath(precompPchC), escapeFilePath(precompObjC));
|
|
|
|
t << escapeDependencyPath(precompObjC) << ": " << escapeDependencyPath(precompH) << ' '
|
2018-06-08 14:00:44 +00:00
|
|
|
<< finalizeDependencyPaths(findDependencies(precompH)).join(" \\\n\t\t")
|
2017-08-22 20:26:46 +00:00
|
|
|
<< "\n\t$(CC) " + precompRuleC +" $(CFLAGS) $(INCPATH) -TC "
|
|
|
|
<< escapeFilePath(precompH) << endl << endl;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-07 19:35:18 +00:00
|
|
|
QString NmakeMakefileGenerator::var(const ProKey &value) const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2018-01-02 17:07:03 +00:00
|
|
|
if (usePCH || usePCHC) {
|
2017-08-22 20:26:46 +00:00
|
|
|
const bool isRunC = (value == "QMAKE_RUN_CC_IMP_BATCH"
|
|
|
|
|| value == "QMAKE_RUN_CC_IMP"
|
|
|
|
|| value == "QMAKE_RUN_CC");
|
2018-01-02 17:07:03 +00:00
|
|
|
const bool isRunCpp = (value == "QMAKE_RUN_CXX_IMP_BATCH"
|
|
|
|
|| value == "QMAKE_RUN_CXX_IMP"
|
|
|
|
|| value == "QMAKE_RUN_CXX");
|
|
|
|
if ((isRunCpp && usePCH) || (isRunC && usePCHC)) {
|
2011-04-27 10:05:43 +00:00
|
|
|
QFileInfo precompHInfo(fileInfo(precompH));
|
2015-02-06 14:30:02 +00:00
|
|
|
QString precompH_f = escapeFilePath(precompHInfo.fileName());
|
2011-04-27 10:05:43 +00:00
|
|
|
QString precompRule = QString("-c -FI%1 -Yu%2 -Fp%3")
|
2017-08-22 20:26:46 +00:00
|
|
|
.arg(precompH_f, precompH_f, escapeFilePath(isRunC ? precompPchC : precompPch));
|
2011-04-27 10:05:43 +00:00
|
|
|
QString p = MakefileGenerator::var(value);
|
2016-02-04 14:12:03 +00:00
|
|
|
p.replace(QLatin1String("-c"), precompRule);
|
2011-04-27 10:05:43 +00:00
|
|
|
// Cannot use -Gm with -FI & -Yu, as this gives an
|
|
|
|
// internal compiler error, on the newer compilers
|
|
|
|
// ### work-around for a VS 2003 bug. Move to some prf file or remove completely.
|
|
|
|
p.remove("-Gm");
|
|
|
|
return p;
|
|
|
|
} else if (value == "QMAKE_CXXFLAGS") {
|
|
|
|
// Remove internal compiler error option
|
|
|
|
// ### work-around for a VS 2003 bug. Move to some prf file or remove completely.
|
|
|
|
return MakefileGenerator::var(value).remove("-Gm");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Normal val
|
|
|
|
return MakefileGenerator::var(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NmakeMakefileGenerator::init()
|
|
|
|
{
|
|
|
|
/* this should probably not be here, but I'm using it to wrap the .t files */
|
|
|
|
if(project->first("TEMPLATE") == "app")
|
|
|
|
project->values("QMAKE_APP_FLAG").append("1");
|
|
|
|
else if(project->first("TEMPLATE") == "lib")
|
|
|
|
project->values("QMAKE_LIB_FLAG").append("1");
|
|
|
|
else if(project->first("TEMPLATE") == "subdirs") {
|
|
|
|
MakefileGenerator::init();
|
|
|
|
if(project->values("MAKEFILE").isEmpty())
|
|
|
|
project->values("MAKEFILE").append("Makefile");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
processVars();
|
|
|
|
|
2018-10-08 16:24:14 +00:00
|
|
|
project->values("LIBS") += project->values("RES_FILE");
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
if (!project->values("DEF_FILE").isEmpty()) {
|
2012-09-06 10:21:38 +00:00
|
|
|
QString defFileName = fileFixify(project->first("DEF_FILE").toQString());
|
2011-04-27 10:05:43 +00:00
|
|
|
project->values("QMAKE_LFLAGS").append(QString("/DEF:") + escapeFilePath(defFileName));
|
|
|
|
}
|
|
|
|
|
2015-03-31 15:34:18 +00:00
|
|
|
// set /VERSION for EXE/DLL header
|
|
|
|
ProString major_minor = project->first("VERSION_PE_HEADER");
|
|
|
|
if (major_minor.isEmpty()) {
|
|
|
|
ProString version = project->first("VERSION");
|
|
|
|
if (!version.isEmpty()) {
|
|
|
|
int firstDot = version.indexOf(".");
|
|
|
|
int secondDot = version.indexOf(".", firstDot + 1);
|
|
|
|
major_minor = version.left(secondDot);
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2015-03-31 15:34:18 +00:00
|
|
|
if (!major_minor.isEmpty())
|
|
|
|
project->values("QMAKE_LFLAGS").append("/VERSION:" + major_minor);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2013-01-30 14:58:00 +00:00
|
|
|
if (project->isEmpty("QMAKE_LINK_O_FLAG"))
|
|
|
|
project->values("QMAKE_LINK_O_FLAG").append("/OUT:");
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
// Base class init!
|
|
|
|
MakefileGenerator::init();
|
|
|
|
|
|
|
|
// Setup PCH variables
|
2012-09-06 10:21:38 +00:00
|
|
|
precompH = project->first("PRECOMPILED_HEADER").toQString();
|
2011-04-27 10:05:43 +00:00
|
|
|
usePCH = !precompH.isEmpty() && project->isActiveConfig("precompile_header");
|
2018-01-02 17:07:03 +00:00
|
|
|
usePCHC = !precompH.isEmpty() && project->isActiveConfig("precompile_header_c");
|
2011-04-27 10:05:43 +00:00
|
|
|
if (usePCH) {
|
|
|
|
// Created files
|
|
|
|
precompObj = var("PRECOMPILED_DIR") + project->first("TARGET") + "_pch" + Option::obj_ext;
|
|
|
|
precompPch = var("PRECOMPILED_DIR") + project->first("TARGET") + "_pch.pch";
|
|
|
|
// Add linking of precompObj (required for whole precompiled classes)
|
2018-01-02 17:07:03 +00:00
|
|
|
project->values("OBJECTS") += precompObj;
|
2011-04-27 10:05:43 +00:00
|
|
|
// Add pch file to cleanup
|
2018-01-02 17:07:03 +00:00
|
|
|
project->values("QMAKE_CLEAN") += precompPch;
|
2011-04-27 10:05:43 +00:00
|
|
|
// Return to variable pool
|
2012-09-06 10:21:38 +00:00
|
|
|
project->values("PRECOMPILED_OBJECT") = ProStringList(precompObj);
|
|
|
|
project->values("PRECOMPILED_PCH") = ProStringList(precompPch);
|
2018-01-02 17:07:03 +00:00
|
|
|
}
|
|
|
|
if (usePCHC) {
|
|
|
|
precompObjC = var("PRECOMPILED_DIR") + project->first("TARGET") + "_pch_c" + Option::obj_ext;
|
|
|
|
precompPchC = var("PRECOMPILED_DIR") + project->first("TARGET") + "_pch_c.pch";
|
|
|
|
project->values("OBJECTS") += precompObjC;
|
|
|
|
project->values("QMAKE_CLEAN") += precompPchC;
|
2017-08-22 20:26:46 +00:00
|
|
|
project->values("PRECOMPILED_OBJECT_C") = ProStringList(precompObjC);
|
|
|
|
project->values("PRECOMPILED_PCH_C") = ProStringList(precompPchC);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2015-06-24 15:59:55 +00:00
|
|
|
ProString tgt = project->first("DESTDIR")
|
|
|
|
+ project->first("TARGET") + project->first("TARGET_VERSION_EXT");
|
2011-04-27 10:05:43 +00:00
|
|
|
if(project->isActiveConfig("shared")) {
|
2015-06-24 15:59:55 +00:00
|
|
|
project->values("QMAKE_CLEAN").append(tgt + ".exp");
|
|
|
|
project->values("QMAKE_DISTCLEAN").append(tgt + ".lib");
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2013-11-18 20:39:08 +00:00
|
|
|
if (project->isActiveConfig("debug_info")) {
|
2016-10-28 13:38:59 +00:00
|
|
|
QString pdbfile;
|
|
|
|
QString distPdbFile = tgt + ".pdb";
|
|
|
|
if (project->isActiveConfig("staticlib")) {
|
|
|
|
// For static libraries, the compiler's pdb file and the dist pdb file are the same.
|
|
|
|
pdbfile = distPdbFile;
|
|
|
|
} else {
|
|
|
|
// Use $${TARGET}.vc.pdb in the OBJECTS_DIR for the compiler and
|
|
|
|
// $${TARGET}.pdb (the default) for the linker.
|
|
|
|
pdbfile = var("OBJECTS_DIR") + project->first("TARGET") + ".vc.pdb";
|
|
|
|
}
|
2014-02-19 11:54:34 +00:00
|
|
|
QString escapedPdbFile = escapeFilePath(pdbfile);
|
|
|
|
project->values("QMAKE_CFLAGS").append("/Fd" + escapedPdbFile);
|
|
|
|
project->values("QMAKE_CXXFLAGS").append("/Fd" + escapedPdbFile);
|
2016-06-07 14:18:49 +00:00
|
|
|
project->values("QMAKE_CLEAN").append(pdbfile);
|
2016-10-28 13:38:59 +00:00
|
|
|
project->values("QMAKE_DISTCLEAN").append(distPdbFile);
|
2013-11-18 20:39:08 +00:00
|
|
|
}
|
|
|
|
if (project->isActiveConfig("debug")) {
|
2015-06-24 15:59:55 +00:00
|
|
|
project->values("QMAKE_CLEAN").append(tgt + ".ilk");
|
|
|
|
project->values("QMAKE_CLEAN").append(tgt + ".idb");
|
2013-03-01 09:54:45 +00:00
|
|
|
} else {
|
|
|
|
ProStringList &defines = project->values("DEFINES");
|
|
|
|
if (!defines.contains("NDEBUG"))
|
|
|
|
defines.append("NDEBUG");
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2016-08-08 20:39:00 +00:00
|
|
|
|
|
|
|
if (project->values("QMAKE_APP_FLAG").isEmpty() && project->isActiveConfig("dll")) {
|
|
|
|
ProStringList &defines = project->values("DEFINES");
|
|
|
|
if (!defines.contains("_WINDLL"))
|
|
|
|
defines.append("_WINDLL");
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2014-12-22 13:54:08 +00:00
|
|
|
QStringList NmakeMakefileGenerator::sourceFilesForImplicitRulesFilter()
|
|
|
|
{
|
|
|
|
QStringList filter;
|
|
|
|
const QChar wildcard = QLatin1Char('*');
|
2016-01-26 13:38:54 +00:00
|
|
|
for (const QString &ext : qAsConst(Option::c_ext))
|
2014-12-22 13:54:08 +00:00
|
|
|
filter << wildcard + ext;
|
2016-01-26 13:38:54 +00:00
|
|
|
for (const QString &ext : qAsConst(Option::cpp_ext))
|
2014-12-22 13:54:08 +00:00
|
|
|
filter << wildcard + ext;
|
|
|
|
return filter;
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void NmakeMakefileGenerator::writeImplicitRulesPart(QTextStream &t)
|
|
|
|
{
|
2015-10-02 14:44:10 +00:00
|
|
|
t << "####### Implicit rules\n\n";
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
t << ".SUFFIXES:";
|
|
|
|
for(QStringList::Iterator cit = Option::c_ext.begin(); cit != Option::c_ext.end(); ++cit)
|
|
|
|
t << " " << (*cit);
|
|
|
|
for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit)
|
|
|
|
t << " " << (*cppit);
|
|
|
|
t << endl << endl;
|
|
|
|
|
2014-12-22 13:54:08 +00:00
|
|
|
bool useInferenceRules = !project->isActiveConfig("no_batch");
|
|
|
|
QSet<QString> source_directories;
|
|
|
|
if (useInferenceRules) {
|
2014-12-22 12:29:53 +00:00
|
|
|
source_directories.insert(".");
|
2018-08-02 22:22:24 +00:00
|
|
|
static const char * const directories[] = { "UI_SOURCES_DIR", "UI_DIR", nullptr };
|
2012-08-20 11:04:39 +00:00
|
|
|
for (int y = 0; directories[y]; y++) {
|
2012-09-06 10:21:38 +00:00
|
|
|
QString dirTemp = project->first(directories[y]).toQString();
|
2011-04-27 10:05:43 +00:00
|
|
|
if (dirTemp.endsWith("\\"))
|
|
|
|
dirTemp.truncate(dirTemp.length()-1);
|
|
|
|
if(!dirTemp.isEmpty())
|
2014-12-22 12:29:53 +00:00
|
|
|
source_directories.insert(dirTemp);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2018-08-02 22:22:24 +00:00
|
|
|
static const char * const srcs[] = { "SOURCES", "GENERATED_SOURCES", nullptr };
|
2012-08-20 11:04:39 +00:00
|
|
|
for (int x = 0; srcs[x]; x++) {
|
2012-09-06 10:21:38 +00:00
|
|
|
const ProStringList &l = project->values(srcs[x]);
|
|
|
|
for (ProStringList::ConstIterator sit = l.begin(); sit != l.end(); ++sit) {
|
2011-04-27 10:05:43 +00:00
|
|
|
QString sep = "\\";
|
|
|
|
if((*sit).indexOf(sep) == -1)
|
|
|
|
sep = "/";
|
2012-09-06 10:21:38 +00:00
|
|
|
QString dir = (*sit).toQString().section(sep, 0, -2);
|
2014-12-22 12:29:53 +00:00
|
|
|
if (!dir.isEmpty())
|
|
|
|
source_directories.insert(dir);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 13:54:08 +00:00
|
|
|
// nmake's inference rules might pick up the wrong files when encountering source files with
|
|
|
|
// the same name in different directories. In this situation, turn inference rules off.
|
|
|
|
QHash<QString, QString> fileNames;
|
|
|
|
bool duplicatesFound = false;
|
|
|
|
const QStringList sourceFilesFilter = sourceFilesForImplicitRulesFilter();
|
|
|
|
QStringList fixifiedSourceDirs = fileFixify(source_directories.toList(), FileFixifyAbsolute);
|
|
|
|
fixifiedSourceDirs.removeDuplicates();
|
2016-01-26 13:38:54 +00:00
|
|
|
for (const QString &sourceDir : qAsConst(fixifiedSourceDirs)) {
|
2014-12-22 13:54:08 +00:00
|
|
|
QDirIterator dit(sourceDir, sourceFilesFilter, QDir::Files | QDir::NoDotAndDotDot);
|
|
|
|
while (dit.hasNext()) {
|
|
|
|
dit.next();
|
2018-12-07 09:36:08 +00:00
|
|
|
const QFileInfo fi = dit.fileInfo();
|
|
|
|
QString &duplicate = fileNames[fi.completeBaseName()];
|
2014-12-22 13:54:08 +00:00
|
|
|
if (duplicate.isNull()) {
|
2018-12-07 09:36:08 +00:00
|
|
|
duplicate = fi.filePath();
|
2014-12-22 13:54:08 +00:00
|
|
|
} else {
|
|
|
|
warn_msg(WarnLogic, "%s conflicts with %s", qPrintable(duplicate),
|
2018-12-07 09:36:08 +00:00
|
|
|
qPrintable(fi.filePath()));
|
2014-12-22 13:54:08 +00:00
|
|
|
duplicatesFound = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (duplicatesFound) {
|
|
|
|
useInferenceRules = false;
|
|
|
|
warn_msg(WarnLogic, "Automatically turning off nmake's inference rules. (CONFIG += no_batch)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (useInferenceRules) {
|
|
|
|
// Batchmode doesn't use the non implicit rules QMAKE_RUN_CXX & QMAKE_RUN_CC
|
|
|
|
project->variables().remove("QMAKE_RUN_CXX");
|
|
|
|
project->variables().remove("QMAKE_RUN_CC");
|
|
|
|
|
2016-01-26 13:38:54 +00:00
|
|
|
for (const QString &sourceDir : qAsConst(source_directories)) {
|
2014-12-22 12:29:53 +00:00
|
|
|
if (sourceDir.isEmpty())
|
2011-04-27 10:05:43 +00:00
|
|
|
continue;
|
|
|
|
QString objDir = var("OBJECTS_DIR");
|
|
|
|
if (objDir == ".\\")
|
|
|
|
objDir = "";
|
|
|
|
for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit)
|
2015-02-06 14:30:02 +00:00
|
|
|
t << '{' << escapeDependencyPath(sourceDir) << '}' << (*cppit)
|
|
|
|
<< '{' << escapeDependencyPath(objDir) << '}' << Option::obj_ext << "::\n\t"
|
|
|
|
<< var("QMAKE_RUN_CXX_IMP_BATCH").replace(QRegExp("\\$@"), fileVar("OBJECTS_DIR"))
|
|
|
|
<< "\n\t$<\n<<\n\n";
|
2011-04-27 10:05:43 +00:00
|
|
|
for(QStringList::Iterator cit = Option::c_ext.begin(); cit != Option::c_ext.end(); ++cit)
|
2015-02-06 14:30:02 +00:00
|
|
|
t << '{' << escapeDependencyPath(sourceDir) << '}' << (*cit)
|
|
|
|
<< '{' << escapeDependencyPath(objDir) << '}' << Option::obj_ext << "::\n\t"
|
|
|
|
<< var("QMAKE_RUN_CC_IMP_BATCH").replace(QRegExp("\\$@"), fileVar("OBJECTS_DIR"))
|
|
|
|
<< "\n\t$<\n<<\n\n";
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit)
|
|
|
|
t << (*cppit) << Option::obj_ext << ":\n\t" << var("QMAKE_RUN_CXX_IMP") << endl << endl;
|
|
|
|
for(QStringList::Iterator cit = Option::c_ext.begin(); cit != Option::c_ext.end(); ++cit)
|
|
|
|
t << (*cit) << Option::obj_ext << ":\n\t" << var("QMAKE_RUN_CC_IMP") << endl << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void NmakeMakefileGenerator::writeBuildRulesPart(QTextStream &t)
|
|
|
|
{
|
2012-09-06 10:21:38 +00:00
|
|
|
const ProString templateName = project->first("TEMPLATE");
|
2011-05-03 13:30:28 +00:00
|
|
|
|
2013-07-04 09:25:16 +00:00
|
|
|
t << "first: all\n";
|
2015-02-06 14:30:02 +00:00
|
|
|
t << "all: " << escapeDependencyPath(fileFixify(Option::output.fileName()))
|
2018-07-10 19:04:48 +00:00
|
|
|
<< ' ' << depVar("ALL_DEPS") << ' ' << depVar("DEST_TARGET") << "\n\n";
|
|
|
|
t << depVar("DEST_TARGET") << ": "
|
|
|
|
<< depVar("PRE_TARGETDEPS") << " $(OBJECTS) " << depVar("POST_TARGETDEPS");
|
2016-11-18 18:05:54 +00:00
|
|
|
if (templateName == "aux") {
|
|
|
|
t << "\n\n";
|
|
|
|
return;
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
if(!project->isEmpty("QMAKE_PRE_LINK"))
|
|
|
|
t << "\n\t" <<var("QMAKE_PRE_LINK");
|
|
|
|
if(project->isActiveConfig("staticlib")) {
|
2017-02-08 12:20:09 +00:00
|
|
|
t << "\n\t$(LIBAPP) $(LIBFLAGS) " << var("QMAKE_LINK_O_FLAG") << "$(DESTDIR_TARGET) @<<\n\t ";
|
|
|
|
writeResponseFileFiles(t, project->values("OBJECTS"));
|
|
|
|
t << "<<";
|
2016-11-18 18:05:54 +00:00
|
|
|
} else {
|
2012-08-15 10:18:49 +00:00
|
|
|
const bool embedManifest = ((templateName == "app" && project->isActiveConfig("embed_manifest_exe"))
|
|
|
|
|| (templateName == "lib" && project->isActiveConfig("embed_manifest_dll")
|
|
|
|
&& !(project->isActiveConfig("plugin") && project->isActiveConfig("no_plugin_manifest"))
|
|
|
|
));
|
|
|
|
if (embedManifest) {
|
|
|
|
bool generateManifest = false;
|
|
|
|
const QString target = var("DEST_TARGET");
|
2012-09-06 10:21:38 +00:00
|
|
|
QString manifest = project->first("QMAKE_MANIFEST").toQString();
|
2012-08-15 10:18:49 +00:00
|
|
|
QString extraLFlags;
|
2014-03-12 17:21:52 +00:00
|
|
|
const bool linkerSupportsEmbedding = (msvcVersion() >= 1200);
|
2012-08-15 10:18:49 +00:00
|
|
|
if (manifest.isEmpty()) {
|
|
|
|
generateManifest = true;
|
2014-03-12 17:21:52 +00:00
|
|
|
if (linkerSupportsEmbedding) {
|
|
|
|
extraLFlags = "/MANIFEST:embed";
|
|
|
|
} else {
|
2015-02-06 14:30:02 +00:00
|
|
|
manifest = target + ".embed.manifest";
|
|
|
|
extraLFlags += "/MANIFEST /MANIFESTFILE:" + escapeFilePath(manifest);
|
2014-03-12 17:21:52 +00:00
|
|
|
project->values("QMAKE_CLEAN") << manifest;
|
|
|
|
}
|
2012-09-14 15:10:27 +00:00
|
|
|
} else {
|
2015-02-06 14:30:02 +00:00
|
|
|
manifest = fileFixify(manifest);
|
2018-06-12 08:56:46 +00:00
|
|
|
if (linkerSupportsEmbedding)
|
|
|
|
extraLFlags = "/MANIFEST:embed /MANIFESTINPUT:" + escapeFilePath(manifest);
|
2012-08-15 10:18:49 +00:00
|
|
|
}
|
|
|
|
|
2012-12-18 10:26:09 +00:00
|
|
|
const QString resourceId = (templateName == "app") ? "1" : "2";
|
2012-09-06 10:21:38 +00:00
|
|
|
const bool incrementalLinking = project->values("QMAKE_LFLAGS").toQStringList().filter(QRegExp("(/|-)INCREMENTAL:NO")).isEmpty();
|
2014-03-12 17:21:52 +00:00
|
|
|
if (incrementalLinking && !linkerSupportsEmbedding) {
|
2012-08-15 10:18:49 +00:00
|
|
|
// Link a resource that contains the manifest without modifying the exe/dll after linking.
|
|
|
|
|
2015-02-06 14:30:02 +00:00
|
|
|
QString manifest_rc = target + "_manifest.rc";
|
|
|
|
QString manifest_res = target + "_manifest.res";
|
2012-08-15 10:18:49 +00:00
|
|
|
project->values("QMAKE_CLEAN") << manifest_rc << manifest_res;
|
2015-02-06 14:30:02 +00:00
|
|
|
manifest_rc = escapeFilePath(manifest_rc);
|
|
|
|
manifest_res = escapeFilePath(manifest_res);
|
2012-08-15 10:18:49 +00:00
|
|
|
|
2012-12-18 10:26:09 +00:00
|
|
|
t << "\n\techo " << resourceId
|
|
|
|
<< " /* CREATEPROCESS_MANIFEST_RESOURCE_ID */ 24 /* RT_MANIFEST */ "
|
2015-02-06 14:30:02 +00:00
|
|
|
<< cQuoted(manifest) << '>' << manifest_rc;
|
2012-08-15 10:18:49 +00:00
|
|
|
|
|
|
|
if (generateManifest) {
|
2015-02-06 14:30:02 +00:00
|
|
|
manifest = escapeFilePath(manifest);
|
|
|
|
QString manifest_bak = escapeFilePath(target + "_manifest.bak");
|
2017-08-16 13:40:25 +00:00
|
|
|
project->values("QMAKE_CLEAN") << manifest_bak;
|
2013-02-14 14:32:19 +00:00
|
|
|
t << "\n\tif not exist $(DESTDIR_TARGET) if exist " << manifest
|
|
|
|
<< " del " << manifest;
|
2012-08-15 10:18:49 +00:00
|
|
|
t << "\n\tif exist " << manifest << " copy /Y " << manifest << ' ' << manifest_bak;
|
|
|
|
const QString extraInlineFileContent = "\n!IF EXIST(" + manifest_res + ")\n" + manifest_res + "\n!ENDIF";
|
|
|
|
t << "\n\t";
|
|
|
|
writeLinkCommand(t, extraLFlags, extraInlineFileContent);
|
2012-08-22 14:51:30 +00:00
|
|
|
t << "\n\tif exist " << manifest_bak << " fc /b " << manifest << ' ' << manifest_bak << " >NUL || del " << manifest_bak;
|
|
|
|
t << "\n\tif not exist " << manifest_bak << " rc.exe /fo" << manifest_res << ' ' << manifest_rc;
|
|
|
|
t << "\n\tif not exist " << manifest_bak << ' ';
|
2012-08-15 10:18:49 +00:00
|
|
|
writeLinkCommand(t, extraLFlags, manifest_res);
|
2012-08-22 14:51:30 +00:00
|
|
|
t << "\n\tif exist " << manifest_bak << " del " << manifest_bak;
|
2012-08-15 10:18:49 +00:00
|
|
|
} else {
|
2013-07-04 09:25:16 +00:00
|
|
|
t << "\n\trc.exe /fo" << manifest_res << " " << manifest_rc;
|
2012-08-15 10:18:49 +00:00
|
|
|
t << "\n\t";
|
|
|
|
writeLinkCommand(t, extraLFlags, manifest_res);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// directly embed the manifest in the executable after linking
|
|
|
|
t << "\n\t";
|
|
|
|
writeLinkCommand(t, extraLFlags);
|
2014-03-12 17:21:52 +00:00
|
|
|
if (!linkerSupportsEmbedding) {
|
2015-02-06 14:30:02 +00:00
|
|
|
t << "\n\tmt.exe /nologo /manifest " << escapeFilePath(manifest)
|
2014-03-12 17:21:52 +00:00
|
|
|
<< " /outputresource:$(DESTDIR_TARGET);" << resourceId;
|
|
|
|
}
|
2012-08-15 10:18:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
t << "\n\t";
|
|
|
|
writeLinkCommand(t);
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
if(!project->isEmpty("QMAKE_POST_LINK")) {
|
|
|
|
t << "\n\t" << var("QMAKE_POST_LINK");
|
|
|
|
}
|
|
|
|
t << endl;
|
|
|
|
}
|
|
|
|
|
2012-08-15 10:18:49 +00:00
|
|
|
void NmakeMakefileGenerator::writeLinkCommand(QTextStream &t, const QString &extraFlags, const QString &extraInlineFileContent)
|
|
|
|
{
|
2012-12-04 11:36:56 +00:00
|
|
|
t << "$(LINKER) $(LFLAGS)";
|
2012-08-15 10:18:49 +00:00
|
|
|
if (!extraFlags.isEmpty())
|
|
|
|
t << ' ' << extraFlags;
|
2017-02-08 12:20:09 +00:00
|
|
|
t << " " << var("QMAKE_LINK_O_FLAG") << "$(DESTDIR_TARGET) @<<\n";
|
|
|
|
writeResponseFileFiles(t, project->values("OBJECTS"));
|
|
|
|
t << "$(LIBS)\n";
|
2012-08-15 10:18:49 +00:00
|
|
|
if (!extraInlineFileContent.isEmpty())
|
2017-02-08 12:20:09 +00:00
|
|
|
t << extraInlineFileContent << '\n';
|
|
|
|
t << "<<";
|
|
|
|
}
|
|
|
|
|
|
|
|
void NmakeMakefileGenerator::writeResponseFileFiles(QTextStream &t, const ProStringList &files)
|
|
|
|
{
|
|
|
|
// Add line breaks in file lists in reponse files to work around LNK1170.
|
|
|
|
// The actual line length limit is 131070, but let's use a smaller limit
|
|
|
|
// in case other tools are similarly hampered.
|
|
|
|
const int maxLineLength = 1000;
|
|
|
|
int len = 0;
|
|
|
|
for (const ProString &file : files) {
|
|
|
|
const ProString escapedFilePath = escapeFilePath(file);
|
|
|
|
if (len) {
|
|
|
|
if (len + escapedFilePath.length() > maxLineLength) {
|
|
|
|
t << '\n';
|
|
|
|
len = 0;
|
|
|
|
} else {
|
|
|
|
t << ' ';
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
t << escapedFilePath;
|
|
|
|
len += escapedFilePath.length();
|
|
|
|
}
|
|
|
|
t << '\n';
|
2012-08-15 10:18:49 +00:00
|
|
|
}
|
|
|
|
|
2014-03-12 17:21:52 +00:00
|
|
|
int NmakeMakefileGenerator::msvcVersion() const
|
|
|
|
{
|
|
|
|
const int fallbackVersion = 800; // Visual Studio 2005
|
|
|
|
const QString ver = project->first(ProKey("MSVC_VER")).toQString();
|
|
|
|
bool ok;
|
|
|
|
float f = ver.toFloat(&ok);
|
|
|
|
return ok ? int(f * 100) : fallbackVersion;
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QT_END_NAMESPACE
|