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 QMAKEGLOBALS_H
30#define QMAKEGLOBALS_H
31
32#include "qmake_global.h"
33#include "proitems.h"
34
35#ifdef QT_BUILD_QMAKE
36# include <property.h>
37#endif
38
39#include <qhash.h>
40#include <qstringlist.h>
41#ifndef QT_BOOTSTRAPPED
42# include <qprocess.h>
43#endif
44#ifdef PROEVALUATOR_THREAD_SAFE
45# include <qmutex.h>
46# include <qwaitcondition.h>
47#endif
48
49QT_BEGIN_NAMESPACE
50
51class QMakeEvaluator;
52
53enum QMakeEvalPhase { QMakeEvalEarly, QMakeEvalBefore, QMakeEvalAfter, QMakeEvalLate };
54
55class QMakeBaseKey
56{
57public:
58 QMakeBaseKey(const QString &_root, const QString &_stash, bool _hostBuild);
59
60 QString root;
61 QString stash;
62 bool hostBuild;
63};
64
65uint qHash(const QMakeBaseKey &key);
66bool operator==(const QMakeBaseKey &one, const QMakeBaseKey &two);
67
68class QMakeBaseEnv
69{
70public:
71 QMakeBaseEnv();
72 ~QMakeBaseEnv();
73
74#ifdef PROEVALUATOR_THREAD_SAFE
75 QMutex mutex;
76 QWaitCondition cond;
77 bool inProgress;
78 // The coupling of this flag to thread safety exists because for other
79 // use cases failure is immediately fatal anyway.
80 bool isOk;
81#endif
82 QMakeEvaluator *evaluator;
83};
84
85class QMAKE_EXPORT QMakeCmdLineParserState
86{
87public:
88 QMakeCmdLineParserState(const QString &_pwd) : pwd(_pwd), phase(QMakeEvalBefore) {}
89 QString pwd;
90 QStringList cmds[4], configs[4];
91 QStringList extraargs;
92 QMakeEvalPhase phase;
93
94 void flush() { phase = QMakeEvalBefore; }
95};
96
97class QMAKE_EXPORT QMakeGlobals
98{
99public:
100 QMakeGlobals();
101 ~QMakeGlobals();
102
103 bool do_cache;
104 QString dir_sep;
105 QString dirlist_sep;
106 QString cachefile;
107#ifdef PROEVALUATOR_SETENV
108 QProcessEnvironment environment;
109#endif
110 QString qmake_abslocation;
111 QStringList qmake_args, qmake_extra_args;
112
113 QString qtconf;
114 QString qmakespec, xqmakespec;
115 QString user_template, user_template_prefix;
116 QString extra_cmds[4];
117
118#ifdef PROEVALUATOR_DEBUG
119 int debugLevel;
120#endif
121
122 enum ArgumentReturn { ArgumentUnknown, ArgumentMalformed, ArgumentsOk };
123 ArgumentReturn addCommandLineArguments(QMakeCmdLineParserState &state,
124 QStringList &args, int *pos);
125 void commitCommandLineArguments(QMakeCmdLineParserState &state);
126 void setCommandLineArguments(const QString &pwd, const QStringList &args);
127 void useEnvironment();
128 void setDirectories(const QString &input_dir, const QString &output_dir);
129#ifdef QT_BUILD_QMAKE
130 void setQMakeProperty(QMakeProperty *prop) { property = prop; }
131 void reloadProperties() { property->reload(); }
132 ProString propertyValue(const ProKey &name) const { return property->value(name); }
133#else
134 static void parseProperties(const QByteArray &data, QHash<ProKey, ProString> &props);
135# ifdef PROEVALUATOR_INIT_PROPS
136 bool initProperties();
137# else
138 void setProperties(const QHash<ProKey, ProString> &props) { properties = props; }
139# endif
140 ProString propertyValue(const ProKey &name) const { return properties.value(name); }
141#endif
142
143 QString expandEnvVars(const QString &str) const;
144 QString shadowedPath(const QString &fileName) const;
145 QStringList splitPathList(const QString &value) const;
146
147private:
148 QString getEnv(const QString &) const;
149 QStringList getPathListEnv(const QString &var) const;
150
151 QString cleanSpec(QMakeCmdLineParserState &state, const QString &spec);
152
153 QString source_root, build_root;
154
155#ifdef QT_BUILD_QMAKE
156 QMakeProperty *property;
157#else
158 QHash<ProKey, ProString> properties;
159#endif
160
161#ifdef PROEVALUATOR_THREAD_SAFE
162 QMutex mutex;
163#endif
164 QHash<QMakeBaseKey, QMakeBaseEnv *> baseEnvs;
165
166 friend class QMakeEvaluator;
167};
168
169QT_END_NAMESPACE
170
171#endif // QMAKEGLOBALS_H
172