source: trunk/qmake/project.h@ 282

Last change on this file since 282 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 7.3 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the qmake application of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef PROJECT_H
43#define PROJECT_H
44
45#include <qstringlist.h>
46#include <qtextstream.h>
47#include <qstring.h>
48#include <qstack.h>
49#include <qmap.h>
50#include <qmetatype.h>
51
52#ifndef QT_BUILD_QMAKE_LIBRARY
53# define QTSCRIPT_SUPPORT
54#endif
55
56#ifdef QTSCRIPT_SUPPORT
57# include <qscriptengine.h>
58#endif
59
60QT_BEGIN_NAMESPACE
61
62class QMakeProperty;
63
64struct ParsableBlock;
65struct IteratorBlock;
66struct FunctionBlock;
67
68class QMakeProject
69{
70 struct ScopeBlock
71 {
72 enum TestStatus { TestNone, TestFound, TestSeek };
73 ScopeBlock() : iterate(0), ignore(false), else_status(TestNone) { }
74 ScopeBlock(bool i) : iterate(0), ignore(i), else_status(TestNone) { }
75 ~ScopeBlock();
76 IteratorBlock *iterate;
77 uint ignore : 1, else_status : 2;
78 };
79 friend struct ParsableBlock;
80 friend struct IteratorBlock;
81 friend struct FunctionBlock;
82
83#ifdef QTSCRIPT_SUPPORT
84 QScriptEngine eng;
85#endif
86 QStack<ScopeBlock> scope_blocks;
87 QStack<FunctionBlock *> function_blocks;
88 IteratorBlock *iterator;
89 FunctionBlock *function;
90 QMap<QString, FunctionBlock*> testFunctions, replaceFunctions;
91
92 bool own_prop;
93 QString pfile, cfile;
94 QMakeProperty *prop;
95 void reset();
96 QMap<QString, QStringList> vars, base_vars, cache;
97 bool parse(const QString &text, QMap<QString, QStringList> &place, int line_count=1);
98
99 enum IncludeStatus {
100 IncludeSuccess,
101 IncludeFeatureAlreadyLoaded,
102 IncludeFailure,
103 IncludeNoExist,
104 IncludeParseFailure
105 };
106 enum IncludeFlags {
107 IncludeFlagNone = 0x00,
108 IncludeFlagFeature = 0x01,
109 IncludeFlagNewParser = 0x02,
110 IncludeFlagNewProject = 0x04
111 };
112 IncludeStatus doProjectInclude(QString file, uchar flags, QMap<QString, QStringList> &place);
113
114 bool doProjectCheckReqs(const QStringList &deps, QMap<QString, QStringList> &place);
115 bool doVariableReplace(QString &str, QMap<QString, QStringList> &place);
116 QStringList doVariableReplaceExpand(const QString &str, QMap<QString, QStringList> &place, bool *ok=0);
117 void init(QMakeProperty *, const QMap<QString, QStringList> *);
118 QStringList &values(const QString &v, QMap<QString, QStringList> &place);
119
120public:
121 QMakeProject() { init(0, 0); }
122 QMakeProject(QMakeProperty *p) { init(p, 0); }
123 QMakeProject(QMakeProject *p, const QMap<QString, QStringList> *nvars=0);
124 QMakeProject(const QMap<QString, QStringList> &nvars) { init(0, &nvars); }
125 QMakeProject(QMakeProperty *p, const QMap<QString, QStringList> &nvars) { init(p, &nvars); }
126 ~QMakeProject();
127
128 enum { ReadCache=0x01, ReadConf=0x02, ReadCmdLine=0x04, ReadProFile=0x08,
129 ReadPostFiles=0x10, ReadFeatures=0x20, ReadConfigs=0x40, ReadAll=0xFF };
130 inline bool parse(const QString &text) { return parse(text, vars); }
131 bool read(const QString &project, uchar cmd=ReadAll);
132 bool read(uchar cmd=ReadAll);
133
134 QStringList userExpandFunctions() { return replaceFunctions.keys(); }
135 QStringList userTestFunctions() { return testFunctions.keys(); }
136
137 QString projectFile();
138 QString configFile();
139 inline QMakeProperty *properties() { return prop; }
140
141 bool doProjectTest(QString str, QMap<QString, QStringList> &place);
142 bool doProjectTest(QString func, const QString &params,
143 QMap<QString, QStringList> &place);
144 bool doProjectTest(QString func, QStringList args,
145 QMap<QString, QStringList> &place);
146 bool doProjectTest(QString func, QList<QStringList> args,
147 QMap<QString, QStringList> &place);
148 QStringList doProjectExpand(QString func, const QString &params,
149 QMap<QString, QStringList> &place);
150 QStringList doProjectExpand(QString func, QStringList args,
151 QMap<QString, QStringList> &place);
152 QStringList doProjectExpand(QString func, QList<QStringList> args,
153 QMap<QString, QStringList> &place);
154
155 QStringList expand(const QString &v);
156 QStringList expand(const QString &func, const QList<QStringList> &args);
157 bool test(const QString &v);
158 bool test(const QString &func, const QList<QStringList> &args);
159 bool isActiveConfig(const QString &x, bool regex=false,
160 QMap<QString, QStringList> *place=NULL);
161
162 bool isSet(const QString &v);
163 bool isEmpty(const QString &v);
164 QStringList &values(const QString &v);
165 QString first(const QString &v);
166 QMap<QString, QStringList> &variables();
167
168protected:
169 friend class MakefileGenerator;
170 bool read(const QString &file, QMap<QString, QStringList> &place);
171 bool read(QTextStream &file, QMap<QString, QStringList> &place);
172
173};
174Q_DECLARE_METATYPE(QMakeProject*)
175
176inline QString QMakeProject::projectFile()
177{
178 if (pfile == "-")
179 return QString("(stdin)");
180 return pfile;
181}
182
183inline QString QMakeProject::configFile()
184{ return cfile; }
185
186inline QStringList &QMakeProject::values(const QString &v)
187{ return values(v, vars); }
188
189inline bool QMakeProject::isEmpty(const QString &v)
190{ return !isSet(v) || values(v).isEmpty(); }
191
192inline bool QMakeProject::isSet(const QString &v)
193{ return vars.contains(v); }
194
195inline QString QMakeProject::first(const QString &v)
196{
197 const QStringList vals = values(v);
198 if(vals.isEmpty())
199 return QString("");
200 return vals.first();
201}
202
203inline QMap<QString, QStringList> &QMakeProject::variables()
204{ return vars; }
205
206QT_END_NAMESPACE
207
208#endif // PROJECT_H
Note: See TracBrowser for help on using the repository browser.