1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the qmake application of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
46 #include <qsettings.h>
47 #include <qstringlist.h>
54 QLibraryInfo::LibraryLocation loc;
57 { "QT_SYSROOT", QLibraryInfo::SysrootPath, true },
58 { "QT_INSTALL_PREFIX", QLibraryInfo::PrefixPath, false },
59 { "QT_INSTALL_DATA", QLibraryInfo::DataPath, false },
60 { "QT_INSTALL_DOCS", QLibraryInfo::DocumentationPath, false },
61 { "QT_INSTALL_HEADERS", QLibraryInfo::HeadersPath, false },
62 { "QT_INSTALL_LIBS", QLibraryInfo::LibrariesPath, false },
63 { "QT_INSTALL_BINS", QLibraryInfo::BinariesPath, false },
64 { "QT_INSTALL_TESTS", QLibraryInfo::TestsPath, false },
65 { "QT_INSTALL_PLUGINS", QLibraryInfo::PluginsPath, false },
66 { "QT_INSTALL_IMPORTS", QLibraryInfo::ImportsPath, false },
67 { "QT_INSTALL_TRANSLATIONS", QLibraryInfo::TranslationsPath, false },
68 { "QT_INSTALL_CONFIGURATION", QLibraryInfo::SettingsPath, false },
69 { "QT_INSTALL_EXAMPLES", QLibraryInfo::ExamplesPath, false },
70 { "QT_INSTALL_DEMOS", QLibraryInfo::ExamplesPath, false }, // Just backwards compat
71 { "QT_HOST_PREFIX", QLibraryInfo::HostPrefixPath, true },
72 { "QT_HOST_DATA", QLibraryInfo::HostDataPath, true },
73 { "QT_HOST_BINS", QLibraryInfo::HostBinariesPath, true },
76 QMakeProperty::QMakeProperty() : settings(0)
78 for (int i = 0; i < sizeof(propList)/sizeof(propList[0]); i++) {
79 QString name = QString::fromLatin1(propList[i].name);
80 m_values[ProKey(name + "/get")] = QLibraryInfo::rawLocation(propList[i].loc, QLibraryInfo::EffectivePaths);
81 QString val = QLibraryInfo::rawLocation(propList[i].loc, QLibraryInfo::FinalPaths);
82 if (!propList[i].raw) {
83 m_values[ProKey(name)] = QLibraryInfo::location(propList[i].loc);
86 m_values[ProKey(name)] = val;
88 m_values["QMAKE_VERSION"] = ProString(QMAKE_VERSION_STR);
90 m_values["QT_VERSION"] = ProString(QT_VERSION_STR);
94 QMakeProperty::~QMakeProperty()
100 void QMakeProperty::initSettings()
103 settings = new QSettings(QSettings::UserScope, "Trolltech", "QMake");
104 settings->setFallbacksEnabled(false);
109 QMakeProperty::value(const ProKey &vk)
111 ProString val = m_values.value(vk);
116 QString v = vk.toQString();
117 if (!settings->contains(v))
118 return settings->value("2.01a/" + v).toString(); // Backwards compat
119 return settings->value(v).toString();
123 QMakeProperty::hasValue(const ProKey &v)
125 return !value(v).isNull();
129 QMakeProperty::setValue(QString var, const QString &val)
132 settings->setValue(var, val);
133 settings->remove("2.01a/" + var); // Backwards compat
137 QMakeProperty::remove(const QString &var)
140 settings->remove(var);
141 settings->remove("2.01a/" + var); // Backwards compat
145 QMakeProperty::exec()
148 if(Option::qmake_mode == Option::QMAKE_QUERY_PROPERTY) {
149 if(Option::prop::properties.isEmpty()) {
151 QStringList keys = settings->childKeys();
152 settings->beginGroup("2.01a");
153 keys += settings->childKeys();
154 settings->endGroup();
155 keys.removeDuplicates();
156 foreach (const QString &key, keys) {
157 QString val = settings->value(settings->contains(key) ? key : "2.01a/" + key).toString();
158 fprintf(stdout, "%s:%s\n", qPrintable(key), qPrintable(val));
160 QStringList specialProps;
161 for (int i = 0; i < sizeof(propList)/sizeof(propList[0]); i++)
162 specialProps.append(QString::fromLatin1(propList[i].name));
163 specialProps.append("QMAKE_VERSION");
164 #ifdef QT_VERSION_STR
165 specialProps.append("QT_VERSION");
167 foreach (QString prop, specialProps) {
168 ProString val = value(ProKey(prop));
169 ProString pval = value(ProKey(prop + "/raw"));
170 ProString gval = value(ProKey(prop + "/get"));
171 fprintf(stdout, "%s:%s\n", prop.toLatin1().constData(), val.toLatin1().constData());
172 if (!pval.isEmpty() && pval != val)
173 fprintf(stdout, "%s/raw:%s\n", prop.toLatin1().constData(), pval.toLatin1().constData());
174 if (!gval.isEmpty() && gval != (pval.isEmpty() ? val : pval))
175 fprintf(stdout, "%s/get:%s\n", prop.toLatin1().constData(), gval.toLatin1().constData());
179 for(QStringList::ConstIterator it = Option::prop::properties.begin();
180 it != Option::prop::properties.end(); it++) {
181 if(Option::prop::properties.count() > 1)
182 fprintf(stdout, "%s:", (*it).toLatin1().constData());
183 const ProKey pkey(*it);
184 if (!hasValue(pkey)) {
186 fprintf(stdout, "**Unknown**\n");
188 fprintf(stdout, "%s\n", value(pkey).toLatin1().constData());
191 } else if(Option::qmake_mode == Option::QMAKE_SET_PROPERTY) {
192 for(QStringList::ConstIterator it = Option::prop::properties.begin();
193 it != Option::prop::properties.end(); it++) {
196 if(it == Option::prop::properties.end()) {
200 if(!var.startsWith("."))
201 setValue(var, (*it));
203 } else if(Option::qmake_mode == Option::QMAKE_UNSET_PROPERTY) {
204 for(QStringList::ConstIterator it = Option::prop::properties.begin();
205 it != Option::prop::properties.end(); it++) {
207 if(!var.startsWith("."))