Mercurial > projects > qtd
annotate generator/main.h @ 382:1d56b2a2e10c
Fixes to debugging stuff. Added size_t as primitive type to workaround Qwt build failure in debug
author | Max Samukha <maxter@spambox.com> |
---|---|
date | Mon, 12 Jul 2010 20:36:07 +0300 |
parents | 347e4c7a9ba1 |
children |
rev | line source |
---|---|
1 | 1 /**************************************************************************** |
2 ** | |
3 ** Copyright (C) 1992-2008 Nokia. All rights reserved. | |
4 ** | |
5 ** This file is part of Qt Jambi. | |
6 ** | |
7 ** * Commercial Usage | |
8 * Licensees holding valid Qt Commercial licenses may use this file in | |
9 * accordance with the Qt Commercial License Agreement provided with the | |
10 * Software or, alternatively, in accordance with the terms contained in | |
11 * a written agreement between you and Nokia. | |
12 * | |
13 * | |
14 * GNU General Public License Usage | |
15 * Alternatively, this file may be used under the terms of the GNU | |
16 * General Public License versions 2.0 or 3.0 as published by the Free | |
17 * Software Foundation and appearing in the file LICENSE.GPL included in | |
18 * the packaging of this file. Please review the following information | |
19 * to ensure GNU General Public Licensing requirements will be met: | |
20 * http://www.fsf.org/licensing/licenses/info/GPLv2.html and | |
21 * http://www.gnu.org/copyleft/gpl.html. In addition, as a special | |
22 * exception, Nokia gives you certain additional rights. These rights | |
23 * are described in the Nokia Qt GPL Exception version 1.2, included in | |
24 * the file GPL_EXCEPTION.txt in this package. | |
25 * | |
26 * Qt for Windows(R) Licensees | |
27 * As a special exception, Nokia, as the sole copyright holder for Qt | |
28 * Designer, grants users of the Qt/Eclipse Integration plug-in the | |
29 * right for the Qt/Eclipse Integration to link to functionality | |
30 * provided by Qt Designer and its related libraries. | |
31 * | |
32 * | |
33 * If you are unsure which license is appropriate for your use, please | |
34 * contact the sales department at qt-sales@nokia.com. | |
35 | |
36 ** | |
37 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | |
38 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
39 ** | |
40 ****************************************************************************/ | |
41 | |
42 #ifndef MAIN_H | |
43 #define MAIN_H | |
44 | |
45 #include "pp.h" | |
46 | |
47 #include <QFile> | |
48 #include <QDir> | |
49 | |
50 struct Preprocess | |
51 { | |
4 | 52 static bool preprocess(const QString &sourceFile, const QString &targetFile, const QString &commandLineIncludes = QString(), |
53 QString qtdir = QString(), QString qtdir_inc = QString()) | |
1 | 54 { |
55 rpp::pp_environment env; | |
56 rpp::pp preprocess(env); | |
57 | |
58 rpp::pp_null_output_iterator null_out; | |
59 | |
60 const char *ppconfig = ":/trolltech/generator/parser/rpp/pp-qt-configuration"; | |
61 | |
62 QFile file(ppconfig); | |
63 if (!file.open(QFile::ReadOnly)) { | |
64 fprintf(stderr, "Preprocessor configuration file not found '%s'\n", ppconfig); | |
65 return false; | |
66 } | |
67 | |
68 QByteArray ba = file.readAll(); | |
69 file.close(); | |
70 preprocess.operator() (ba.constData(), ba.constData() + ba.size(), null_out); | |
71 | |
72 QStringList includes; | |
73 includes << QString("."); | |
74 | |
75 #if defined(Q_OS_WIN32) | |
381
347e4c7a9ba1
make QwtD compile on Windows@
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
4
diff
changeset
|
76 const char *path_splitter = "*"; |
1 | 77 #else |
78 const char *path_splitter = ":"; | |
79 #endif | |
80 // Environment INCLUDE | |
81 QString includePath = getenv("INCLUDE"); | |
82 if (!includePath.isEmpty()) | |
83 includes += includePath.split(path_splitter); | |
84 | |
85 // Includes from the command line | |
86 if (!commandLineIncludes.isEmpty()) | |
87 includes += commandLineIncludes.split(path_splitter); | |
88 | |
89 // Include Qt | |
4 | 90 if (qtdir.isEmpty()) |
91 qtdir = getenv ("QTDIR"); | |
92 if (qtdir_inc.isEmpty()) | |
93 qtdir_inc = getenv ("QTDIR_INC"); | |
1 | 94 if (qtdir.isEmpty() && qtdir_inc.isEmpty()) { |
4 | 95 qWarning("QTDIR and QTDIR_INC environment variables not set. This may cause problems with finding the necessary include files."); |
1 | 96 } else { |
97 if (qtdir_inc.isEmpty()) | |
98 qtdir_inc = qtdir + "/include"; | |
99 includes << (qtdir_inc + "/QtXml"); | |
100 includes << (qtdir_inc + "/QtNetwork"); | |
101 includes << (qtdir_inc + "/QtCore"); | |
102 includes << (qtdir_inc + "/QtGui"); | |
103 includes << (qtdir_inc + "/QtOpenGL"); | |
104 includes << qtdir_inc; | |
105 } | |
106 | |
107 foreach (QString include, includes) | |
108 preprocess.push_include_path(QDir::convertSeparators(include).toStdString()); | |
109 | |
110 QString currentDir = QDir::current().absolutePath(); | |
111 QFileInfo sourceInfo(sourceFile); | |
112 QDir::setCurrent(sourceInfo.absolutePath()); | |
113 | |
114 std::string result; | |
115 result.reserve (20 * 1024); // 20K | |
116 | |
117 result += "# 1 \"builtins\"\n"; | |
118 result += "# 1 \""; | |
119 result += sourceFile.toStdString(); | |
120 result += "\"\n"; | |
121 | |
122 preprocess.file (sourceInfo.fileName().toStdString(), | |
123 rpp::pp_output_iterator<std::string> (result)); | |
124 | |
125 QDir::setCurrent(currentDir); | |
126 | |
127 QFile f(targetFile); | |
128 if (!f.open(QIODevice::WriteOnly | QIODevice::Text)) { | |
129 fprintf(stderr, "Failed to write preprocessed file: %s\n", qPrintable(targetFile)); | |
130 } | |
131 f.write(result.c_str(), result.length()); | |
132 | |
133 return true; | |
134 } | |
135 }; | |
136 | |
137 #endif // MAIN_H |