1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the qmake application of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
47 #include <qsettings.h>
48 #include <qstringlist.h>
53 QStringList qmake_mkspec_paths(); //project.cpp
55 QMakeProperty::QMakeProperty() : settings(0)
59 QMakeProperty::~QMakeProperty()
65 void QMakeProperty::initSettings()
68 settings = new QSettings(QSettings::UserScope, "Trolltech", "QMake");
69 settings->setFallbacksEnabled(false);
74 QMakeProperty::keyBase(bool version) const
77 return QString(qmake_version()) + "/";
82 QMakeProperty::value(QString v, bool just_check)
84 if(v == "QT_INSTALL_PREFIX")
85 return QLibraryInfo::location(QLibraryInfo::PrefixPath);
86 else if(v == "QT_INSTALL_DATA")
87 return QLibraryInfo::location(QLibraryInfo::DataPath);
88 else if(v == "QT_INSTALL_DOCS")
89 return QLibraryInfo::location(QLibraryInfo::DocumentationPath);
90 else if(v == "QT_INSTALL_HEADERS")
91 return QLibraryInfo::location(QLibraryInfo::HeadersPath);
92 else if(v == "QT_INSTALL_LIBS")
93 return QLibraryInfo::location(QLibraryInfo::LibrariesPath);
94 else if(v == "QT_INSTALL_BINS")
95 return QLibraryInfo::location(QLibraryInfo::BinariesPath);
96 else if(v == "QT_INSTALL_PLUGINS")
97 return QLibraryInfo::location(QLibraryInfo::PluginsPath);
98 else if(v == "QT_INSTALL_IMPORTS")
99 return QLibraryInfo::location(QLibraryInfo::ImportsPath);
100 else if(v == "QT_INSTALL_TRANSLATIONS")
101 return QLibraryInfo::location(QLibraryInfo::TranslationsPath);
102 else if(v == "QT_INSTALL_CONFIGURATION")
103 return QLibraryInfo::location(QLibraryInfo::SettingsPath);
104 else if(v == "QT_INSTALL_EXAMPLES")
105 return QLibraryInfo::location(QLibraryInfo::ExamplesPath);
106 else if(v == "QT_INSTALL_DEMOS")
107 return QLibraryInfo::location(QLibraryInfo::ExamplesPath);
108 else if(v == "QMAKE_MKSPECS")
109 return qmake_mkspec_paths().join(Option::dirlist_sep);
110 else if(v == "QMAKE_VERSION")
111 return qmake_version();
112 #ifdef QT_VERSION_STR
113 else if(v == "QT_VERSION")
114 return QT_VERSION_STR;
118 int slash = v.lastIndexOf('/');
119 QVariant var = settings->value(keyBase(slash == -1) + v);
120 bool ok = var.isValid();
121 QString ret = var.toString();
123 QString version = qmake_version();
125 version = v.left(slash-1);
128 settings->beginGroup(keyBase(false));
129 QStringList subs = settings->childGroups();
130 settings->endGroup();
132 for (int x = subs.count() - 1; x >= 0; x--) {
134 if(s.isEmpty() || s > version)
136 var = settings->value(keyBase(false) + s + "/" + v);
138 ret = var.toString();
141 debug_msg(1, "Fell back from %s -> %s for '%s'.", version.toLatin1().constData(),
142 s.toLatin1().constData(), v.toLatin1().constData());
147 return ok ? ret : QString();
151 QMakeProperty::hasValue(QString v)
153 return !value(v, true).isNull();
157 QMakeProperty::setValue(QString var, const QString &val)
160 settings->setValue(keyBase() + var, val);
164 QMakeProperty::remove(const QString &var)
167 settings->remove(keyBase() + var);
171 QMakeProperty::exec()
174 if(Option::qmake_mode == Option::QMAKE_QUERY_PROPERTY) {
175 if(Option::prop::properties.isEmpty()) {
177 settings->beginGroup(keyBase(false));
178 QStringList subs = settings->childGroups();
179 settings->endGroup();
181 for(int x = subs.count() - 1; x >= 0; x--) {
185 settings->beginGroup(keyBase(false) + s);
186 QStringList keys = settings->childKeys();
187 settings->endGroup();
188 for(QStringList::ConstIterator it2 = keys.begin(); it2 != keys.end(); it2++) {
189 QString ret = settings->value(keyBase(false) + s + "/" + (*it2)).toString();
190 if(s != qmake_version())
191 fprintf(stdout, "%s/", s.toLatin1().constData());
192 fprintf(stdout, "%s:%s\n", (*it2).toLatin1().constData(), ret.toLatin1().constData());
195 QStringList specialProps;
196 specialProps.append("QT_INSTALL_PREFIX");
197 specialProps.append("QT_INSTALL_DATA");
198 specialProps.append("QT_INSTALL_DOCS");
199 specialProps.append("QT_INSTALL_HEADERS");
200 specialProps.append("QT_INSTALL_LIBS");
201 specialProps.append("QT_INSTALL_BINS");
202 specialProps.append("QT_INSTALL_PLUGINS");
203 specialProps.append("QT_INSTALL_IMPORTS");
204 specialProps.append("QT_INSTALL_TRANSLATIONS");
205 specialProps.append("QT_INSTALL_CONFIGURATION");
206 specialProps.append("QT_INSTALL_EXAMPLES");
207 specialProps.append("QT_INSTALL_DEMOS");
208 specialProps.append("QMAKE_MKSPECS");
209 specialProps.append("QMAKE_VERSION");
210 #ifdef QT_VERSION_STR
211 specialProps.append("QT_VERSION");
213 foreach (QString prop, specialProps)
214 fprintf(stdout, "%s:%s\n", prop.toLatin1().constData(), value(prop).toLatin1().constData());
217 for(QStringList::ConstIterator it = Option::prop::properties.begin();
218 it != Option::prop::properties.end(); it++) {
219 if(Option::prop::properties.count() > 1)
220 fprintf(stdout, "%s:", (*it).toLatin1().constData());
221 if(!hasValue((*it))) {
223 fprintf(stdout, "**Unknown**\n");
225 fprintf(stdout, "%s\n", value((*it)).toLatin1().constData());
228 } else if(Option::qmake_mode == Option::QMAKE_SET_PROPERTY) {
229 for(QStringList::ConstIterator it = Option::prop::properties.begin();
230 it != Option::prop::properties.end(); it++) {
233 if(it == Option::prop::properties.end()) {
237 if(!var.startsWith("."))
238 setValue(var, (*it));
240 } else if(Option::qmake_mode == Option::QMAKE_UNSET_PROPERTY) {
241 for(QStringList::ConstIterator it = Option::prop::properties.begin();
242 it != Option::prop::properties.end(); it++) {
244 if(!var.startsWith("."))