2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2014-05-21 13:42:31 +00:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-09-19 12:28:29 +00:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the qmake application of the Qt Toolkit.
|
|
|
|
**
|
2014-08-21 13:51:22 +00:00
|
|
|
** $QT_BEGIN_LICENSE:LGPL21$
|
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
|
2014-08-21 13:51:22 +00:00
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
2012-09-19 12:28:29 +00:00
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-09-19 12:28:29 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-08-21 13:51:22 +00:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
2014-08-21 13:51:22 +00:00
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-04-27 10:05:43 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "msvc_nmake.h"
|
|
|
|
#include "option.h"
|
2012-05-11 08:24:28 +00:00
|
|
|
#include "cesdkhandler.h"
|
2013-09-02 08:51:17 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <qregexp.h>
|
|
|
|
#include <qhash.h>
|
|
|
|
#include <qdir.h>
|
2013-09-02 08:51:17 +00:00
|
|
|
|
|
|
|
#include <windows/registry_p.h>
|
|
|
|
|
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;
|
|
|
|
foreach (const QString &path, list)
|
|
|
|
pathList.append(QDir::cleanPath(path));
|
|
|
|
|
|
|
|
return QDir::toNativeSeparators(pathList.join(QLatin1Char(';')))
|
|
|
|
.replace('#', QStringLiteral("^#")).replace('$', QStringLiteral("$$"));
|
|
|
|
}
|
|
|
|
|
2013-03-19 10:27:31 +00:00
|
|
|
NmakeMakefileGenerator::NmakeMakefileGenerator() : Win32MakefileGenerator(), init_flag(false), usePCH(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()) {
|
2012-09-06 10:21:38 +00:00
|
|
|
const ProValueMap &variables = project->variables();
|
2013-02-12 09:04:06 +00:00
|
|
|
if (project->isActiveConfig("wince")) {
|
2012-05-11 08:24:28 +00:00
|
|
|
CeSdkHandler sdkhandler;
|
|
|
|
sdkhandler.parse();
|
2012-05-18 18:00:23 +00:00
|
|
|
const QString sdkName = variables["CE_SDK"].join(' ')
|
|
|
|
+ " (" + variables["CE_ARCH"].join(' ') + ")";
|
2012-05-11 08:24:28 +00:00
|
|
|
const QList<CeSdkInfo> sdkList = sdkhandler.listAll();
|
|
|
|
CeSdkInfo sdk;
|
|
|
|
foreach (const CeSdkInfo &info, sdkList) {
|
|
|
|
if (info.name().compare(sdkName, Qt::CaseInsensitive ) == 0) {
|
|
|
|
sdk = info;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sdk.isValid()) {
|
|
|
|
t << "\nINCLUDE = " << sdk.includePath();
|
|
|
|
t << "\nLIB = " << sdk.libPath();
|
|
|
|
t << "\nPATH = " << sdk.binPath() << "\n";
|
2012-09-21 13:12:14 +00:00
|
|
|
} else {
|
|
|
|
QStringList sdkStringList;
|
|
|
|
foreach (const CeSdkInfo &info, sdkList)
|
|
|
|
sdkStringList << info.name();
|
|
|
|
|
|
|
|
fprintf(stderr, "Failed to find Windows CE SDK matching %s, found: %s\n"
|
|
|
|
"SDK needs to be specified in mkspec (using: %s/qmake.conf)\n"
|
|
|
|
"SDK name needs to match the following format: CE_SDK (CE_ARCH)\n",
|
|
|
|
qPrintable(sdkName), qPrintable(sdkStringList.join(", ")),
|
|
|
|
qPrintable(variables["QMAKESPEC"].first().toQString()));
|
|
|
|
return false;
|
2012-05-11 08:24:28 +00:00
|
|
|
}
|
2013-10-31 15:15:28 +00:00
|
|
|
} else if (project->isActiveConfig(QStringLiteral("winrt"))) {
|
2013-09-02 08:51:17 +00:00
|
|
|
QString arch = project->first("VCPROJ_ARCH").toQString().toLower();
|
|
|
|
QString compiler;
|
|
|
|
QString compilerArch;
|
|
|
|
if (arch == QStringLiteral("arm")) {
|
|
|
|
compiler = QStringLiteral("x86_arm");
|
|
|
|
compilerArch = QStringLiteral("arm");
|
|
|
|
} else if (arch == QStringLiteral("x64")) {
|
2014-02-13 12:43:54 +00:00
|
|
|
const ProStringList hostArch = project->values("QMAKE_TARGET.arch");
|
|
|
|
if (hostArch.contains("x86_64"))
|
|
|
|
compiler = QStringLiteral("amd64");
|
|
|
|
else
|
|
|
|
compiler = QStringLiteral("x86_amd64");
|
2013-09-02 08:51:17 +00:00
|
|
|
compilerArch = QStringLiteral("amd64");
|
2014-02-06 09:20:23 +00:00
|
|
|
} else {
|
|
|
|
arch = QStringLiteral("x86");
|
2013-09-02 08:51:17 +00:00
|
|
|
}
|
2013-10-24 17:14: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;
|
|
|
|
}
|
|
|
|
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();
|
|
|
|
if (targetVer.isEmpty()) {
|
|
|
|
fprintf(stderr, "Mkspec does not specify WINTARGET_VER. Cannot continue.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-26 21:30:27 +00:00
|
|
|
const bool isPhone = project->isActiveConfig(QStringLiteral("winphone"));
|
2013-10-31 15:15:28 +00:00
|
|
|
#ifdef Q_OS_WIN
|
2013-10-24 17:14:10 +00:00
|
|
|
QString regKeyPrefix;
|
|
|
|
#if !defined(Q_OS_WIN64) && _WIN32_WINNT >= 0x0501
|
|
|
|
BOOL isWow64;
|
|
|
|
IsWow64Process(GetCurrentProcess(), &isWow64);
|
|
|
|
if (!isWow64)
|
|
|
|
regKeyPrefix = QStringLiteral("Software\\");
|
|
|
|
else
|
2013-09-02 08:51:17 +00:00
|
|
|
#endif
|
2013-10-24 17:14:10 +00:00
|
|
|
regKeyPrefix = QStringLiteral("Software\\Wow6432Node\\");
|
|
|
|
|
|
|
|
QString regKey = regKeyPrefix + QStringLiteral("Microsoft\\VisualStudio\\") + msvcVer + ("\\Setup\\VC\\ProductDir");
|
2013-09-02 08:51:17 +00:00
|
|
|
const QString vcInstallDir = qt_readRegistryKey(HKEY_LOCAL_MACHINE, regKey);
|
|
|
|
if (vcInstallDir.isEmpty()) {
|
2013-10-24 17:14:10 +00:00
|
|
|
fprintf(stderr, "Failed to find the Visual Studio installation directory.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-21 13:42:31 +00:00
|
|
|
QString windowsPath;
|
|
|
|
if (isPhone) {
|
|
|
|
if (targetVer == "WP80") // ### Windows Phone 8.0, remove in Qt 5.4
|
|
|
|
windowsPath = "Microsoft\\Microsoft SDKs\\WindowsPhone\\v";
|
|
|
|
else
|
|
|
|
windowsPath = "Microsoft\\Microsoft SDKs\\WindowsPhoneApp\\v";
|
|
|
|
} else {
|
|
|
|
windowsPath = "Microsoft\\Microsoft SDKs\\Windows\\v";
|
|
|
|
}
|
|
|
|
|
|
|
|
regKey = regKeyPrefix + windowsPath + winsdkVer + QStringLiteral("\\InstallationFolder");
|
2013-10-24 17:14:10 +00:00
|
|
|
const QString kitDir = qt_readRegistryKey(HKEY_LOCAL_MACHINE, regKey);
|
|
|
|
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;
|
|
|
|
if (isPhone) {
|
2014-05-21 13:42:31 +00:00
|
|
|
QString sdkDir = vcInstallDir;
|
|
|
|
if (targetVer == "WP80")
|
|
|
|
sdkDir += QStringLiteral("/WPSDK/") + targetVer;
|
2013-09-02 08:51:17 +00:00
|
|
|
if (!QDir(sdkDir).exists()) {
|
|
|
|
fprintf(stderr, "Failed to find the Windows Phone SDK in %s.\n"
|
|
|
|
"Check that it is properly installed.\n",
|
|
|
|
qPrintable(QDir::toNativeSeparators(sdkDir)));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
incDirs << sdkDir + QStringLiteral("/include");
|
2014-05-21 13:42:31 +00:00
|
|
|
libDirs << sdkDir + QStringLiteral("/lib/store/") + compilerArch
|
|
|
|
<< sdkDir + QStringLiteral("/lib/") + compilerArch;
|
2013-09-02 08:51:17 +00:00
|
|
|
binDirs << sdkDir + QStringLiteral("/bin/") + compiler;
|
|
|
|
libDirs << kitDir + QStringLiteral("/lib/") + arch;
|
|
|
|
incDirs << kitDir + QStringLiteral("/include")
|
|
|
|
<< kitDir + QStringLiteral("/include/abi")
|
|
|
|
<< kitDir + QStringLiteral("/include/mincore")
|
|
|
|
<< kitDir + QStringLiteral("/include/minwin");
|
|
|
|
} 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");
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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::getPdbTarget()
|
|
|
|
{
|
|
|
|
return QString(project->first("TARGET") + project->first("TARGET_VERSION_EXT") + ".pdb");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString NmakeMakefileGenerator::defaultInstall(const QString &t)
|
|
|
|
{
|
|
|
|
if((t != "target" && t != "dlltarget") ||
|
|
|
|
(t == "dlltarget" && (project->first("TEMPLATE") != "lib" || !project->isActiveConfig("shared"))) ||
|
|
|
|
project->first("TEMPLATE") == "subdirs")
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
QString ret = Win32MakefileGenerator::defaultInstall(t);
|
|
|
|
|
|
|
|
const QString root = "$(INSTALL_ROOT)";
|
2012-09-06 10:21:38 +00:00
|
|
|
ProStringList &uninst = project->values(ProKey(t + ".uninstall"));
|
|
|
|
QString targetdir = Option::fixPathToTargetOS(project->first(ProKey(t + ".path")).toQString(), false);
|
2011-04-27 10:05:43 +00:00
|
|
|
targetdir = fileFixify(targetdir, FileFixifyAbsolute);
|
|
|
|
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) {
|
2011-04-27 10:05:43 +00:00
|
|
|
QString pdb_target = getPdbTarget();
|
|
|
|
pdb_target.remove('"');
|
|
|
|
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";
|
|
|
|
ret += QString("-$(INSTALL_FILE)") + " \"" + src_targ + "\" \"" + dst_targ + "\"";
|
|
|
|
if(!uninst.isEmpty())
|
|
|
|
uninst.append("\n\t");
|
|
|
|
uninst.append("-$(DEL_FILE) \"" + dst_targ + "\"");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList &NmakeMakefileGenerator::findDependencies(const QString &file)
|
|
|
|
{
|
|
|
|
QStringList &aList = MakefileGenerator::findDependencies(file);
|
|
|
|
// Note: The QMAKE_IMAGE_COLLECTION file have all images
|
|
|
|
// as dependency, so don't add precompiled header then
|
|
|
|
if (file == project->first("QMAKE_IMAGE_COLLECTION"))
|
|
|
|
return aList;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return aList;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NmakeMakefileGenerator::writeNmakeParts(QTextStream &t)
|
|
|
|
{
|
|
|
|
writeStandardParts(t);
|
|
|
|
|
|
|
|
// precompiled header
|
|
|
|
if(usePCH) {
|
|
|
|
QString precompRule = QString("-c -Yc -Fp%1 -Fo%2").arg(precompPch).arg(precompObj);
|
2012-02-10 09:37:07 +00:00
|
|
|
t << precompObj << ": " << precompH << " " << escapeDependencyPaths(findDependencies(precompH)).join(" \\\n\t\t")
|
2013-07-04 09:25:16 +00:00
|
|
|
<< "\n\t$(CXX) " + precompRule +" $(CXXFLAGS) $(INCPATH) -TP " << 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
|
|
|
{
|
|
|
|
if (usePCH) {
|
|
|
|
if ((value == "QMAKE_RUN_CXX_IMP_BATCH"
|
|
|
|
|| value == "QMAKE_RUN_CXX_IMP"
|
|
|
|
|| value == "QMAKE_RUN_CXX")) {
|
|
|
|
QFileInfo precompHInfo(fileInfo(precompH));
|
|
|
|
QString precompRule = QString("-c -FI%1 -Yu%2 -Fp%3")
|
|
|
|
.arg(precompHInfo.fileName())
|
|
|
|
.arg(precompHInfo.fileName())
|
|
|
|
.arg(precompPch);
|
|
|
|
QString p = MakefileGenerator::var(value);
|
|
|
|
p.replace("-c", precompRule);
|
|
|
|
// 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()
|
|
|
|
{
|
|
|
|
if(init_flag)
|
|
|
|
return;
|
|
|
|
init_flag = true;
|
|
|
|
|
|
|
|
/* 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");
|
|
|
|
if(project->isEmpty("QMAKE_COPY_FILE"))
|
|
|
|
project->values("QMAKE_COPY_FILE").append("$(COPY)");
|
|
|
|
if(project->isEmpty("QMAKE_COPY_DIR"))
|
|
|
|
project->values("QMAKE_COPY_DIR").append("xcopy /s /q /y /i");
|
|
|
|
if(project->isEmpty("QMAKE_INSTALL_FILE"))
|
|
|
|
project->values("QMAKE_INSTALL_FILE").append("$(COPY_FILE)");
|
|
|
|
if(project->isEmpty("QMAKE_INSTALL_PROGRAM"))
|
|
|
|
project->values("QMAKE_INSTALL_PROGRAM").append("$(COPY_FILE)");
|
|
|
|
if(project->isEmpty("QMAKE_INSTALL_DIR"))
|
|
|
|
project->values("QMAKE_INSTALL_DIR").append("$(COPY_DIR)");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-16 12:29:48 +00:00
|
|
|
project->values("QMAKE_L_FLAG") << "/LIBPATH:";
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
processVars();
|
|
|
|
|
|
|
|
if (!project->values("RES_FILE").isEmpty()) {
|
|
|
|
project->values("QMAKE_LIBS") += escapeFilePaths(project->values("RES_FILE"));
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!project->values("VERSION").isEmpty()) {
|
2012-09-06 10:21:38 +00:00
|
|
|
ProString version = project->values("VERSION")[0];
|
2011-04-27 10:05:43 +00:00
|
|
|
int firstDot = version.indexOf(".");
|
2012-09-06 10:21:38 +00:00
|
|
|
QString major = version.left(firstDot).toQString();
|
|
|
|
QString minor = version.right(version.length() - firstDot - 1).toQString();
|
2011-04-27 10:05:43 +00:00
|
|
|
minor.replace(".", "");
|
|
|
|
project->values("QMAKE_LFLAGS").append("/VERSION:" + major + "." + minor);
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
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)
|
|
|
|
project->values("OBJECTS") += precompObj;
|
|
|
|
// Add pch file to cleanup
|
|
|
|
project->values("QMAKE_CLEAN") += precompPch;
|
|
|
|
// Return to variable pool
|
2012-09-06 10:21:38 +00:00
|
|
|
project->values("PRECOMPILED_OBJECT") = ProStringList(precompObj);
|
|
|
|
project->values("PRECOMPILED_PCH") = ProStringList(precompPch);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-09-06 10:21:38 +00:00
|
|
|
ProString version = project->first("TARGET_VERSION_EXT");
|
2011-04-27 10:05:43 +00:00
|
|
|
if(project->isActiveConfig("shared")) {
|
|
|
|
project->values("QMAKE_CLEAN").append(project->first("DESTDIR") + project->first("TARGET") + version + ".exp");
|
|
|
|
}
|
2013-11-18 20:39:08 +00:00
|
|
|
if (project->isActiveConfig("debug_info")) {
|
2013-11-18 20:39:43 +00:00
|
|
|
QString pdbfile = project->first("DESTDIR") + project->first("TARGET") + version + ".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);
|
2013-11-18 20:39:43 +00:00
|
|
|
project->values("QMAKE_DISTCLEAN").append(pdbfile);
|
2013-11-18 20:39:08 +00:00
|
|
|
}
|
|
|
|
if (project->isActiveConfig("debug")) {
|
2011-04-27 10:05:43 +00:00
|
|
|
project->values("QMAKE_CLEAN").append(project->first("DESTDIR") + project->first("TARGET") + version + ".ilk");
|
2013-11-18 20:39:43 +00:00
|
|
|
project->values("QMAKE_CLEAN").append(project->first("DESTDIR") + project->first("TARGET") + version + ".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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NmakeMakefileGenerator::writeImplicitRulesPart(QTextStream &t)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
if(!project->isActiveConfig("no_batch")) {
|
|
|
|
// 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");
|
|
|
|
|
|
|
|
QHash<QString, void*> source_directories;
|
|
|
|
source_directories.insert(".", (void*)1);
|
2012-08-20 11:04:39 +00:00
|
|
|
static const char * const directories[] = { "UI_SOURCES_DIR", "UI_DIR", 0 };
|
|
|
|
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())
|
|
|
|
source_directories.insert(dirTemp, (void*)1);
|
|
|
|
}
|
2012-08-20 11:04:39 +00:00
|
|
|
static const char * const srcs[] = { "SOURCES", "GENERATED_SOURCES", 0 };
|
|
|
|
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);
|
2011-04-27 10:05:43 +00:00
|
|
|
if(!dir.isEmpty() && !source_directories[dir])
|
|
|
|
source_directories.insert(dir, (void*)1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(QHash<QString, void*>::Iterator it(source_directories.begin()); it != source_directories.end(); ++it) {
|
|
|
|
if(it.key().isEmpty())
|
|
|
|
continue;
|
|
|
|
QString objDir = var("OBJECTS_DIR");
|
|
|
|
if (objDir == ".\\")
|
|
|
|
objDir = "";
|
|
|
|
for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit)
|
|
|
|
t << "{" << it.key() << "}" << (*cppit) << "{" << objDir << "}" << Option::obj_ext << "::\n\t"
|
2013-07-04 09:25:16 +00:00
|
|
|
<< var("QMAKE_RUN_CXX_IMP_BATCH").replace(QRegExp("\\$@"), var("OBJECTS_DIR")) << endl << "\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)
|
|
|
|
t << "{" << it.key() << "}" << (*cit) << "{" << objDir << "}" << Option::obj_ext << "::\n\t"
|
2013-07-04 09:25:16 +00:00
|
|
|
<< var("QMAKE_RUN_CC_IMP_BATCH").replace(QRegExp("\\$@"), var("OBJECTS_DIR")) << endl << "\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";
|
|
|
|
t << "all: " << fileFixify(Option::output.fileName()) << " " << varGlue("ALL_DEPS"," "," "," ") << "$(DESTDIR_TARGET)\n\n";
|
2011-04-27 10:05:43 +00:00
|
|
|
t << "$(DESTDIR_TARGET): " << var("PRE_TARGETDEPS") << " $(OBJECTS) " << var("POST_TARGETDEPS");
|
|
|
|
|
|
|
|
if(!project->isEmpty("QMAKE_PRE_LINK"))
|
|
|
|
t << "\n\t" <<var("QMAKE_PRE_LINK");
|
|
|
|
if(project->isActiveConfig("staticlib")) {
|
2013-07-04 09:25:16 +00:00
|
|
|
t << "\n\t$(LIBAPP) $(LIBFLAGS) " << var("QMAKE_LINK_O_FLAG") << "$(DESTDIR_TARGET) @<<\n\t "
|
2012-08-15 10:18:49 +00:00
|
|
|
<< "$(OBJECTS)"
|
|
|
|
<< "\n<<";
|
2012-08-15 17:42:42 +00:00
|
|
|
} else if (templateName != "aux") {
|
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 {
|
|
|
|
manifest = escapeFilePath(target + ".embed.manifest");
|
|
|
|
extraLFlags += "/MANIFEST /MANIFESTFILE:" + manifest;
|
|
|
|
project->values("QMAKE_CLEAN") << manifest;
|
|
|
|
}
|
2012-09-14 15:10:27 +00:00
|
|
|
} else {
|
|
|
|
manifest = escapeFilePath(fileFixify(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.
|
|
|
|
|
|
|
|
QString manifest_rc = escapeFilePath(target + "_manifest.rc");
|
|
|
|
QString manifest_res = escapeFilePath(target + "_manifest.res");
|
|
|
|
QString manifest_bak = escapeFilePath(target + "_manifest.bak");
|
|
|
|
project->values("QMAKE_CLEAN") << manifest_rc << manifest_res;
|
|
|
|
|
2012-12-18 10:26:09 +00:00
|
|
|
t << "\n\techo " << resourceId
|
|
|
|
<< " /* CREATEPROCESS_MANIFEST_RESOURCE_ID */ 24 /* RT_MANIFEST */ "
|
2012-09-14 15:10:27 +00:00
|
|
|
<< cQuoted(unescapeFilePath(manifest)) << ">" << manifest_rc;
|
2012-08-15 10:18:49 +00:00
|
|
|
|
|
|
|
if (generateManifest) {
|
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) {
|
|
|
|
t << "\n\tmt.exe /nologo /manifest " << manifest
|
|
|
|
<< " /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
|
|
|
}
|
|
|
|
QString signature = !project->isEmpty("SIGNATURE_FILE") ? var("SIGNATURE_FILE") : var("DEFAULT_SIGNATURE");
|
2013-03-14 23:42:15 +00:00
|
|
|
bool useSignature = !signature.isEmpty() && !project->isActiveConfig("staticlib") &&
|
2011-04-27 10:05:43 +00:00
|
|
|
!project->isEmpty("CE_SDK") && !project->isEmpty("CE_ARCH");
|
|
|
|
if(useSignature) {
|
|
|
|
t << "\n\tsigntool sign /F " << signature << " $(DESTDIR_TARGET)";
|
|
|
|
}
|
|
|
|
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;
|
2013-01-30 14:58:00 +00:00
|
|
|
t << " " << var("QMAKE_LINK_O_FLAG") << "$(DESTDIR_TARGET) @<<\n"
|
2012-08-15 10:18:49 +00:00
|
|
|
<< "$(OBJECTS) $(LIBS)";
|
|
|
|
if (!extraInlineFileContent.isEmpty())
|
|
|
|
t << ' ' << extraInlineFileContent;
|
|
|
|
t << "\n<<";
|
|
|
|
}
|
|
|
|
|
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
|