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#ifndef PROJECT_H
5#define PROJECT_H
6
7#include <qmakeevaluator.h>
8
9QT_BEGIN_NAMESPACE
10
11class QMakeProject : private QMakeEvaluator
12{
13 QString m_projectFile;
14 QString m_projectDir;
15
16public:
17 QMakeProject();
18 QMakeProject(QMakeProject *p);
19
20 bool read(const QString &project, LoadFlags what = LoadAll);
21
22 QString projectFile() const { return m_projectFile; }
23 QString projectDir() const { return m_projectDir; }
24 QString sourceRoot() const { return m_sourceRoot.isEmpty() ? m_buildRoot : m_sourceRoot; }
25 QString buildRoot() const { return m_buildRoot; }
26 QString confFile() const { return m_conffile; }
27 QString cacheFile() const { return m_cachefile; }
28 QString specDir() const { return m_qmakespec; }
29
30 ProString expand(const QString &v, const QString &file, int line);
31 QStringList expand(const ProKey &func, const QList<ProStringList> &args);
32 bool test(const QString &v, const QString &file, int line)
33 { m_current.clear(); return evaluateConditional(cond: QStringView(v), where: file, line) == ReturnTrue; }
34 bool test(const ProKey &func, const QList<ProStringList> &args);
35
36 bool isSet(const ProKey &v) const { return m_valuemapStack.front().contains(key: v); }
37 bool isEmpty(const ProKey &v) const;
38 ProStringList &values(const ProKey &v) { return valuesRef(variableName: v); }
39 int intValue(const ProKey &v, int defaultValue = 0) const;
40 const ProValueMap &variables() const { return m_valuemapStack.front(); }
41 ProValueMap &variables() { return m_valuemapStack.front(); }
42 bool isActiveConfig(const QString &config, bool regex = false)
43 { return QMakeEvaluator::isActiveConfig(config: QStringView(config), regex); }
44
45 void dump() const;
46
47 using QMakeEvaluator::LoadFlags;
48 using QMakeEvaluator::VisitReturn;
49 using QMakeEvaluator::setExtraVars;
50 using QMakeEvaluator::setExtraConfigs;
51 using QMakeEvaluator::loadSpec;
52 using QMakeEvaluator::evaluateFeatureFile;
53 using QMakeEvaluator::evaluateConfigFeatures;
54 using QMakeEvaluator::evaluateExpression;
55 using QMakeEvaluator::propertyValue;
56 using QMakeEvaluator::values;
57 using QMakeEvaluator::first;
58 using QMakeEvaluator::isHostBuild;
59 using QMakeEvaluator::dirSep;
60
61private:
62 static bool boolRet(VisitReturn vr);
63};
64
65/*!
66 * For variables that are supposed to contain a single int,
67 * this method returns the numeric value.
68 * Only the first value of the variable is taken into account.
69 * The string representation is assumed to look like a C int literal.
70 */
71inline int QMakeProject::intValue(const ProKey &v, int defaultValue) const
72{
73 const ProString &str = first(variableName: v);
74 if (!str.isEmpty()) {
75 bool ok;
76 int i = str.toInt(ok: &ok, base: 0);
77 if (ok)
78 return i;
79 }
80 return defaultValue;
81}
82
83QT_END_NAMESPACE
84
85#endif // PROJECT_H
86

source code of qtbase/qmake/project.h