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 OPTION_H |
5 | #define OPTION_H |
6 | |
7 | #include <qmakeglobals.h> |
8 | #include <qmakevfs.h> |
9 | #include <qmakeparser.h> |
10 | #include <qmakeevaluator.h> |
11 | |
12 | #include <qstring.h> |
13 | #include <qstringlist.h> |
14 | #include <qfile.h> |
15 | |
16 | QT_BEGIN_NAMESPACE |
17 | |
18 | QString qmake_getpwd(); |
19 | bool qmake_setpwd(const QString &p); |
20 | |
21 | #define debug_msg if(Option::debug_level) debug_msg_internal |
22 | void debug_msg_internal(int level, const char *fmt, ...); //don't call directly, use debug_msg |
23 | enum QMakeWarn { |
24 | WarnNone = 0x00, |
25 | WarnParser = 0x01, |
26 | WarnLogic = 0x02, |
27 | WarnDeprecated = 0x04, |
28 | WarnAll = 0xFF |
29 | }; |
30 | void warn_msg(QMakeWarn t, const char *fmt, ...); |
31 | |
32 | class QMakeProject; |
33 | |
34 | class EvalHandler : public QMakeHandler { |
35 | public: |
36 | void message(int type, const QString &msg, const QString &fileName, int lineNo) override; |
37 | |
38 | void fileMessage(int type, const QString &msg) override; |
39 | |
40 | void aboutToEval(ProFile *, ProFile *, EvalFileType) override; |
41 | void doneWithEval(ProFile *) override; |
42 | }; |
43 | |
44 | struct Option |
45 | { |
46 | static EvalHandler evalHandler; |
47 | |
48 | static QMakeGlobals *globals; |
49 | static ProFileCache *proFileCache; |
50 | static QMakeVfs *vfs; |
51 | static QMakeParser *parser; |
52 | |
53 | //simply global convenience |
54 | static QString libtool_ext; |
55 | static QString pkgcfg_ext; |
56 | static QString prf_ext; |
57 | static QString prl_ext; |
58 | static QString ui_ext; |
59 | static QStringList h_ext; |
60 | static QStringList cpp_ext; |
61 | static QStringList c_ext; |
62 | static QString objc_ext; |
63 | static QString objcpp_ext; |
64 | static QString cpp_moc_ext; |
65 | static QString obj_ext; |
66 | static QString lex_ext; |
67 | static QString yacc_ext; |
68 | static QString h_moc_mod; |
69 | static QString lex_mod; |
70 | static QString yacc_mod; |
71 | static QString dir_sep; |
72 | static QString pro_ext; |
73 | static QString res_ext; |
74 | static char field_sep; |
75 | |
76 | enum CmdLineFlags { |
77 | QMAKE_CMDLINE_SUCCESS = 0x00, |
78 | QMAKE_CMDLINE_SHOW_USAGE = 0x01, |
79 | QMAKE_CMDLINE_BAIL = 0x02, |
80 | QMAKE_CMDLINE_ERROR = 0x04 |
81 | }; |
82 | |
83 | //both of these must be called.. |
84 | static int init(int argc = 0, char **argv = nullptr); //parse cmdline |
85 | static void prepareProject(const QString &pfile); |
86 | static bool postProcessProject(QMakeProject *); |
87 | |
88 | enum StringFixFlags { |
89 | FixNone = 0x00, |
90 | FixEnvVars = 0x01, |
91 | FixPathCanonicalize = 0x02, |
92 | FixPathToLocalSeparators = 0x04, |
93 | FixPathToTargetSeparators = 0x08, |
94 | FixPathToNormalSeparators = 0x10 |
95 | }; |
96 | static QString fixString(QString string, uchar flags); |
97 | |
98 | //and convenience functions |
99 | inline static QString fixPathToLocalOS(const QString &in, bool fix_env=true, bool canonical=true) |
100 | { |
101 | uchar flags = FixPathToLocalSeparators; |
102 | if(fix_env) |
103 | flags |= FixEnvVars; |
104 | if(canonical) |
105 | flags |= FixPathCanonicalize; |
106 | return fixString(string: in, flags); |
107 | } |
108 | inline static QString fixPathToTargetOS(const QString &in, bool fix_env=true, bool canonical=true) |
109 | { |
110 | uchar flags = FixPathToTargetSeparators; |
111 | if(fix_env) |
112 | flags |= FixEnvVars; |
113 | if(canonical) |
114 | flags |= FixPathCanonicalize; |
115 | return fixString(string: in, flags); |
116 | } |
117 | inline static QString normalizePath(const QString &in, bool fix_env=true, bool canonical=true) |
118 | { |
119 | uchar flags = FixPathToNormalSeparators; |
120 | if (fix_env) |
121 | flags |= FixEnvVars; |
122 | if (canonical) |
123 | flags |= FixPathCanonicalize; |
124 | return fixString(string: in, flags); |
125 | } |
126 | |
127 | inline static bool hasFileExtension(const QString &str, const QStringList &extensions) |
128 | { |
129 | for (const QString &ext : extensions) |
130 | if (str.endsWith(s: ext)) |
131 | return true; |
132 | return false; |
133 | } |
134 | |
135 | //global qmake mode, can only be in one mode per invocation! |
136 | enum QMAKE_MODE { QMAKE_GENERATE_NOTHING, |
137 | QMAKE_GENERATE_PROJECT, QMAKE_GENERATE_MAKEFILE, QMAKE_GENERATE_PRL, |
138 | QMAKE_SET_PROPERTY, QMAKE_UNSET_PROPERTY, QMAKE_QUERY_PROPERTY }; |
139 | static QMAKE_MODE qmake_mode; |
140 | |
141 | //all modes |
142 | static QFile output; |
143 | static QString output_dir; |
144 | static int debug_level; |
145 | static int warn_level; |
146 | static bool recursive; |
147 | |
148 | //QMAKE_*_PROPERTY options |
149 | struct prop { |
150 | static QStringList properties; |
151 | }; |
152 | |
153 | //QMAKE_GENERATE_PROJECT options |
154 | struct projfile { |
155 | static bool do_pwd; |
156 | static QStringList project_dirs; |
157 | }; |
158 | |
159 | //QMAKE_GENERATE_MAKEFILE options |
160 | struct mkfile { |
161 | static bool do_deps; |
162 | static bool do_mocs; |
163 | static bool do_dep_heuristics; |
164 | static bool do_preprocess; |
165 | static int cachefile_depth; |
166 | static QStringList project_files; |
167 | }; |
168 | |
169 | private: |
170 | static int parseCommandLine(QStringList &args, QMakeCmdLineParserState &state); |
171 | }; |
172 | |
173 | inline QString fixEnvVariables(const QString &x) { return Option::fixString(string: x, flags: Option::FixEnvVars); } |
174 | inline QStringList splitPathList(const QString &paths) { return paths.isEmpty() ? QStringList() : paths.split(sep: Option::globals->dirlist_sep); } |
175 | |
176 | QT_END_NAMESPACE |
177 | |
178 | #endif // OPTION_H |
179 | |