| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the qmake application of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | #ifndef PROJECT_H |
| 30 | #define PROJECT_H |
| 31 | |
| 32 | #include <qmakeevaluator.h> |
| 33 | |
| 34 | QT_BEGIN_NAMESPACE |
| 35 | |
| 36 | class QMakeProject : private QMakeEvaluator |
| 37 | { |
| 38 | QString m_projectFile; |
| 39 | QString m_projectDir; |
| 40 | |
| 41 | public: |
| 42 | QMakeProject(); |
| 43 | QMakeProject(QMakeProject *p); |
| 44 | |
| 45 | bool read(const QString &project, LoadFlags what = LoadAll); |
| 46 | |
| 47 | QString projectFile() const { return m_projectFile; } |
| 48 | QString projectDir() const { return m_projectDir; } |
| 49 | QString sourceRoot() const { return m_sourceRoot.isEmpty() ? m_buildRoot : m_sourceRoot; } |
| 50 | QString buildRoot() const { return m_buildRoot; } |
| 51 | QString confFile() const { return m_conffile; } |
| 52 | QString cacheFile() const { return m_cachefile; } |
| 53 | QString specDir() const { return m_qmakespec; } |
| 54 | |
| 55 | ProString expand(const QString &v, const QString &file, int line); |
| 56 | QStringList expand(const ProKey &func, const QList<ProStringList> &args); |
| 57 | bool test(const QString &v, const QString &file, int line) |
| 58 | { m_current.clear(); return evaluateConditional(QStringView(v), file, line) == ReturnTrue; } |
| 59 | bool test(const ProKey &func, const QList<ProStringList> &args); |
| 60 | |
| 61 | bool isSet(const ProKey &v) const { return m_valuemapStack.front().contains(v); } |
| 62 | bool isEmpty(const ProKey &v) const; |
| 63 | ProStringList &values(const ProKey &v) { return valuesRef(v); } |
| 64 | int intValue(const ProKey &v, int defaultValue = 0) const; |
| 65 | const ProValueMap &variables() const { return m_valuemapStack.front(); } |
| 66 | ProValueMap &variables() { return m_valuemapStack.front(); } |
| 67 | bool isActiveConfig(const QString &config, bool regex = false) |
| 68 | { return QMakeEvaluator::isActiveConfig(QStringView(config), regex); } |
| 69 | |
| 70 | void dump() const; |
| 71 | |
| 72 | using QMakeEvaluator::LoadFlags; |
| 73 | using QMakeEvaluator::VisitReturn; |
| 74 | using QMakeEvaluator::setExtraVars; |
| 75 | using QMakeEvaluator::setExtraConfigs; |
| 76 | using QMakeEvaluator::loadSpec; |
| 77 | using QMakeEvaluator::evaluateFeatureFile; |
| 78 | using QMakeEvaluator::evaluateConfigFeatures; |
| 79 | using QMakeEvaluator::evaluateExpression; |
| 80 | using QMakeEvaluator::propertyValue; |
| 81 | using QMakeEvaluator::values; |
| 82 | using QMakeEvaluator::first; |
| 83 | using QMakeEvaluator::isHostBuild; |
| 84 | using QMakeEvaluator::dirSep; |
| 85 | |
| 86 | private: |
| 87 | static bool boolRet(VisitReturn vr); |
| 88 | }; |
| 89 | |
| 90 | /*! |
| 91 | * For variables that are supposed to contain a single int, |
| 92 | * this method returns the numeric value. |
| 93 | * Only the first value of the variable is taken into account. |
| 94 | * The string representation is assumed to look like a C int literal. |
| 95 | */ |
| 96 | inline int QMakeProject::intValue(const ProKey &v, int defaultValue) const |
| 97 | { |
| 98 | const ProString &str = first(v); |
| 99 | if (!str.isEmpty()) { |
| 100 | bool ok; |
| 101 | int i = str.toInt(&ok, 0); |
| 102 | if (ok) |
| 103 | return i; |
| 104 | } |
| 105 | return defaultValue; |
| 106 | } |
| 107 | |
| 108 | QT_END_NAMESPACE |
| 109 | |
| 110 | #endif // PROJECT_H |
| 111 | |