summaryrefslogtreecommitdiffstats
path: root/qmake/option.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qmake/option.cpp')
-rw-r--r--qmake/option.cpp155
1 files changed, 56 insertions, 99 deletions
diff --git a/qmake/option.cpp b/qmake/option.cpp
index 58688ab2d6..0e2d199232 100644
--- a/qmake/option.cpp
+++ b/qmake/option.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the qmake application of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** 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
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** 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.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "option.h"
#include "cachekeys.h"
@@ -33,10 +8,13 @@
#include <qregularexpression.h>
#include <qhash.h>
#include <qdebug.h>
-#include <qlibraryinfo.h>
#include <stdlib.h>
#include <stdarg.h>
+#include <qmakelibraryinfo.h>
+#include <qtversion.h>
+#include <private/qlibraryinfo_p.h>
+
QT_BEGIN_NAMESPACE
using namespace QMakeInternal;
@@ -99,7 +77,7 @@ static Option::QMAKE_MODE default_mode(QString progname)
{
int s = progname.lastIndexOf(QDir::separator());
if(s != -1)
- progname = progname.right(progname.length() - (s + 1));
+ progname = progname.right(progname.size() - (s + 1));
if(progname == "qmakegen")
return Option::QMAKE_GENERATE_PROJECT;
else if(progname == "qt-config")
@@ -107,15 +85,18 @@ static Option::QMAKE_MODE default_mode(QString progname)
return Option::QMAKE_GENERATE_MAKEFILE;
}
-static QString detectProjectFile(const QString &path)
+static QString detectProjectFile(const QString &path, QString *singleProFileCandidate = nullptr)
{
QString ret;
QDir dir(path);
- if(dir.exists(dir.dirName() + Option::pro_ext)) {
- ret = dir.filePath(dir.dirName()) + Option::pro_ext;
+ const QString candidate = dir.filePath(dir.dirName() + Option::pro_ext);
+ if (singleProFileCandidate)
+ *singleProFileCandidate = candidate;
+ if (QFile::exists(candidate)) {
+ ret = candidate;
} else { //last try..
QStringList profiles = dir.entryList(QStringList("*" + Option::pro_ext));
- if(profiles.count() == 1)
+ if(profiles.size() == 1)
ret = dir.filePath(profiles.at(0));
}
return ret;
@@ -174,7 +155,7 @@ bool usage(const char *a0)
" -set <prop> <value> Set persistent property\n"
" -unset <prop> Unset persistent property\n"
" -query <prop> Query persistent property. Show all if <prop> is empty.\n"
- " -qtconf file Use file instead of looking for qt.conf\n"
+ " -qtconf file Use file instead of looking for qt" QT_STRINGIFY(QT_VERSION_MAJOR) ".conf, then qt.conf\n"
" -cache file Use file as cache [makefile mode only]\n"
" -spec spec Use spec as QMAKESPEC [makefile mode only]\n"
" -nocache Don't use a cache file [makefile mode only]\n"
@@ -193,7 +174,7 @@ Option::parseCommandLine(QStringList &args, QMakeCmdLineParserState &state)
{
enum { ArgNone, ArgOutput } argState = ArgNone;
int x = 0;
- while (x < args.count()) {
+ while (x < args.size()) {
switch (argState) {
case ArgOutput:
Option::output.setFileName(args.at(x--));
@@ -202,12 +183,14 @@ Option::parseCommandLine(QStringList &args, QMakeCmdLineParserState &state)
continue;
default:
QMakeGlobals::ArgumentReturn cmdRet = globals->addCommandLineArguments(state, args, &x);
- if (cmdRet == QMakeGlobals::ArgumentsOk)
- break;
if (cmdRet == QMakeGlobals::ArgumentMalformed) {
fprintf(stderr, "***Option %s requires a parameter\n", qPrintable(args.at(x - 1)));
return Option::QMAKE_CMDLINE_SHOW_USAGE | Option::QMAKE_CMDLINE_ERROR;
}
+ if (!globals->qtconf.isEmpty())
+ QLibraryInfoPrivate::setQtconfManualPath(&globals->qtconf);
+ if (cmdRet == QMakeGlobals::ArgumentsOk)
+ break;
Q_ASSERT(cmdRet == QMakeGlobals::ArgumentUnknown);
QString arg = args.at(x);
if (arg.startsWith(QLatin1Char('-'))) {
@@ -218,7 +201,9 @@ Option::parseCommandLine(QStringList &args, QMakeCmdLineParserState &state)
"QMake version %s\n"
"Using Qt version %s in %s\n",
QMAKE_VERSION_STR, QT_VERSION_STR,
- QLibraryInfo::location(QLibraryInfo::LibrariesPath).toLatin1().constData());
+ QMakeLibraryInfo::path(QLibraryInfo::LibrariesPath)
+ .toLatin1()
+ .constData());
#ifdef QMAKE_OPENSOURCE_VERSION
fprintf(stdout, "QMake is Open Source software from The Qt Company Ltd and/or its subsidiary(-ies).\n");
#endif
@@ -282,11 +267,20 @@ Option::parseCommandLine(QStringList &args, QMakeCmdLineParserState &state)
if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
Option::qmake_mode == Option::QMAKE_GENERATE_PRL) {
if(fi.isDir()) {
- QString proj = detectProjectFile(arg);
- if (!proj.isNull())
- arg = proj;
+ QString singleProFileCandidate;
+ QString proj = detectProjectFile(arg, &singleProFileCandidate);
+ if (proj.isNull()) {
+ fprintf(stderr, "***Cannot detect .pro file in directory '%s'.\n\n"
+ "QMake expects the file '%s' "
+ "or exactly one .pro file in the given directory.\n",
+ qUtf8Printable(arg),
+ qUtf8Printable(singleProFileCandidate));
+ return Option::QMAKE_CMDLINE_ERROR;
+ }
+ Option::mkfile::project_files.append(proj);
+ } else {
+ Option::mkfile::project_files.append(arg);
}
- Option::mkfile::project_files.append(arg);
} else if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT) {
Option::projfile::project_dirs.append(arg);
} else {
@@ -324,45 +318,17 @@ Option::init(int argc, char **argv)
#endif
if(Option::qmake_mode == Option::QMAKE_GENERATE_NOTHING)
Option::qmake_mode = default_mode(argv0);
- if (!argv0.isEmpty() && IoUtils::isAbsolutePath(argv0)) {
- globals->qmake_abslocation = argv0;
- } else if (argv0.contains(QLatin1Char('/'))
-#ifdef Q_OS_WIN
- || argv0.contains(QLatin1Char('\\'))
-#endif
- ) { //relative PWD
- globals->qmake_abslocation = QDir::current().absoluteFilePath(argv0);
- } else { //in the PATH
- QByteArray pEnv = qgetenv("PATH");
- QDir currentDir = QDir::current();
-#ifdef Q_OS_WIN
- QStringList paths = QString::fromLocal8Bit(pEnv).split(QLatin1String(";"));
- paths.prepend(QLatin1String("."));
-#else
- QStringList paths = QString::fromLocal8Bit(pEnv).split(QLatin1String(":"));
-#endif
- for (QStringList::const_iterator p = paths.constBegin(); p != paths.constEnd(); ++p) {
- if ((*p).isEmpty())
- continue;
- QString candidate = currentDir.absoluteFilePath(*p + QLatin1Char('/') + argv0);
- if (QFile::exists(candidate)) {
- globals->qmake_abslocation = candidate;
- break;
- }
- }
- }
+ globals->qmake_abslocation = IoUtils::binaryAbsLocation(argv0);
if (Q_UNLIKELY(globals->qmake_abslocation.isNull())) {
// This is rather unlikely to ever happen on a modern system ...
- globals->qmake_abslocation = QLibraryInfo::rawLocation(
- QLibraryInfo::HostBinariesPath,
- QLibraryInfo::EffectivePaths)
+ globals->qmake_abslocation =
+ QMakeLibraryInfo::rawLocation(QMakeLibraryInfo::HostBinariesPath,
+ QMakeLibraryInfo::EffectivePaths)
+ + "/qmake"
#ifdef Q_OS_WIN
- + "/qmake.exe";
-#else
- + "/qmake";
+ ".exe"
#endif
- } else {
- globals->qmake_abslocation = QDir::cleanPath(globals->qmake_abslocation);
+ ;
}
} else {
Option::qmake_mode = Option::QMAKE_GENERATE_MAKEFILE;
@@ -403,8 +369,9 @@ Option::init(int argc, char **argv)
for (int i = 1; i < argc; i++)
args << QString::fromLocal8Bit(argv[i]);
- while (!args.isEmpty()) {
- QString opt = args.at(0);
+ qsizetype idx = 0;
+ while (idx < args.size()) {
+ QString opt = args.at(idx);
if (opt == "-project") {
Option::recursive = true;
Option::qmake_mode = Option::QMAKE_GENERATE_PROJECT;
@@ -420,10 +387,16 @@ Option::init(int argc, char **argv)
Option::qmake_mode = Option::QMAKE_QUERY_PROPERTY;
} else if (opt == "-makefile") {
Option::qmake_mode = Option::QMAKE_GENERATE_MAKEFILE;
+ } else if (opt == "-qtconf") {
+ // Skip "-qtconf <file>" and proceed.
+ ++idx;
+ if (idx + 1 < args.size())
+ ++idx;
+ continue;
} else {
break;
}
- args.takeFirst();
+ args.takeAt(idx);
break;
}
@@ -450,12 +423,10 @@ Option::init(int argc, char **argv)
QString proj = detectProjectFile(qmake_getpwd());
if(!proj.isNull())
Option::mkfile::project_files.append(proj);
-#ifndef QT_BUILD_QMAKE_LIBRARY
if(Option::mkfile::project_files.isEmpty()) {
usage(argv[0]);
return Option::QMAKE_CMDLINE_ERROR;
}
-#endif
}
}
@@ -494,7 +465,7 @@ bool Option::postProcessProject(QMakeProject *project)
if (!project->buildRoot().isEmpty() && Option::output_dir.startsWith(project->buildRoot()))
Option::mkfile::cachefile_depth =
- Option::output_dir.mid(project->buildRoot().length()).count('/');
+ Option::output_dir.mid(project->buildRoot().size()).count('/');
return true;
}
@@ -557,7 +528,7 @@ Option::fixString(QString string, uchar flags)
if ((string.startsWith("\"") && string.endsWith("\"")) ||
(string.startsWith("\'") && string.endsWith("\'")))
- string = string.mid(1, string.length()-2);
+ string = string.mid(1, string.size()-2);
//cache
//qDebug() << "Fix" << orig_string << "->" << string;
@@ -636,7 +607,7 @@ public:
*data = nullptr;
}
};
-static QList<QMakeCacheClearItem*> cache_items;
+Q_CONSTINIT static QList<QMakeCacheClearItem*> cache_items;
void
qmakeClearCaches()
@@ -651,18 +622,4 @@ qmakeAddCacheClear(qmakeCacheClearFunc func, void **data)
cache_items.append(new QMakeCacheClearItem(func, data));
}
-QString qmake_libraryInfoFile()
-{
- if (!Option::globals->qtconf.isEmpty())
- return Option::globals->qtconf;
- if (!Option::globals->qmake_abslocation.isEmpty())
- return QDir(QFileInfo(Option::globals->qmake_abslocation).absolutePath()).filePath("qt.conf");
- return QString();
-}
-
-QString qmake_abslocation()
-{
- return Option::globals->qmake_abslocation;
-}
-
QT_END_NAMESPACE