1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the qmake application of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
46 #include <qsettings.h>
47 #include <qstringlist.h>
52 QStringList qmake_mkspec_paths(); //project.cpp
56 QLibraryInfo::LibraryLocation loc;
59 { "QT_SYSROOT", QLibraryInfo::SysrootPath, true },
60 { "QT_INSTALL_PREFIX", QLibraryInfo::PrefixPath, false },
61 { "QT_INSTALL_DATA", QLibraryInfo::DataPath, false },
62 { "QT_INSTALL_DOCS", QLibraryInfo::DocumentationPath, false },
63 { "QT_INSTALL_HEADERS", QLibraryInfo::HeadersPath, false },
64 { "QT_INSTALL_LIBS", QLibraryInfo::LibrariesPath, false },
65 { "QT_INSTALL_BINS", QLibraryInfo::BinariesPath, false },
66 { "QT_INSTALL_TESTS", QLibraryInfo::TestsPath, false },
67 { "QT_INSTALL_PLUGINS", QLibraryInfo::PluginsPath, false },
68 { "QT_INSTALL_IMPORTS", QLibraryInfo::ImportsPath, false },
69 { "QT_INSTALL_TRANSLATIONS", QLibraryInfo::TranslationsPath, false },
70 { "QT_INSTALL_CONFIGURATION", QLibraryInfo::SettingsPath, false },
71 { "QT_INSTALL_EXAMPLES", QLibraryInfo::ExamplesPath, false },
72 { "QT_INSTALL_DEMOS", QLibraryInfo::ExamplesPath, false }, // Just backwards compat
73 { "QT_HOST_PREFIX", QLibraryInfo::HostPrefixPath, true },
74 { "QT_HOST_DATA", QLibraryInfo::HostDataPath, true },
75 { "QT_HOST_BINS", QLibraryInfo::HostBinariesPath, true },
78 QMakeProperty::QMakeProperty() : settings(0)
80 for (int i = 0; i < sizeof(propList)/sizeof(propList[0]); i++) {
81 QString name = QString::fromLatin1(propList[i].name);
82 m_values[name + "/get"] = QLibraryInfo::rawLocation(propList[i].loc, QLibraryInfo::EffectivePaths);
83 QString val = QLibraryInfo::rawLocation(propList[i].loc, QLibraryInfo::FinalPaths);
84 if (!propList[i].raw) {
85 m_values[name] = QLibraryInfo::location(propList[i].loc);
92 QMakeProperty::~QMakeProperty()
98 void QMakeProperty::initSettings()
101 settings = new QSettings(QSettings::UserScope, "Trolltech", "QMake");
102 settings->setFallbacksEnabled(false);
107 QMakeProperty::value(const QString &v)
109 QString val = m_values.value(v);
112 else if(v == "QMAKE_MKSPECS")
113 return qmake_mkspec_paths().join(Option::dirlist_sep);
114 else if(v == "QMAKE_VERSION")
115 return qmake_version();
116 #ifdef QT_VERSION_STR
117 else if(v == "QT_VERSION")
118 return QT_VERSION_STR;
122 if (!settings->contains(v))
123 return settings->value("2.01a/" + v).toString(); // Backwards compat
124 return settings->value(v).toString();
128 QMakeProperty::hasValue(QString v)
130 return !value(v).isNull();
134 QMakeProperty::setValue(QString var, const QString &val)
137 settings->setValue(var, val);
138 settings->remove("2.01a/" + var); // Backwards compat
142 QMakeProperty::remove(const QString &var)
145 settings->remove(var);
146 settings->remove("2.01a/" + var); // Backwards compat
150 QMakeProperty::exec()
153 if(Option::qmake_mode == Option::QMAKE_QUERY_PROPERTY) {
154 if(Option::prop::properties.isEmpty()) {
156 QStringList keys = settings->childKeys();
157 settings->beginGroup("2.01a");
158 keys += settings->childKeys();
159 settings->endGroup();
160 keys.removeDuplicates();
161 foreach (const QString &key, keys) {
162 QString val = settings->value(settings->contains(key) ? key : "2.01a/" + key).toString();
163 fprintf(stdout, "%s:%s\n", qPrintable(key), qPrintable(val));
165 QStringList specialProps;
166 for (int i = 0; i < sizeof(propList)/sizeof(propList[0]); i++)
167 specialProps.append(QString::fromLatin1(propList[i].name));
168 specialProps.append("QMAKE_MKSPECS");
169 specialProps.append("QMAKE_VERSION");
170 #ifdef QT_VERSION_STR
171 specialProps.append("QT_VERSION");
173 foreach (QString prop, specialProps) {
174 QString val = value(prop);
175 QString pval = value(prop + "/raw");
176 QString gval = value(prop + "/get");
177 fprintf(stdout, "%s:%s\n", prop.toLatin1().constData(), val.toLatin1().constData());
178 if (!pval.isEmpty() && pval != val)
179 fprintf(stdout, "%s/raw:%s\n", prop.toLatin1().constData(), pval.toLatin1().constData());
180 if (!gval.isEmpty() && gval != (pval.isEmpty() ? val : pval))
181 fprintf(stdout, "%s/get:%s\n", prop.toLatin1().constData(), gval.toLatin1().constData());
185 for(QStringList::ConstIterator it = Option::prop::properties.begin();
186 it != Option::prop::properties.end(); it++) {
187 if(Option::prop::properties.count() > 1)
188 fprintf(stdout, "%s:", (*it).toLatin1().constData());
189 if(!hasValue((*it))) {
191 fprintf(stdout, "**Unknown**\n");
193 fprintf(stdout, "%s\n", value((*it)).toLatin1().constData());
196 } else if(Option::qmake_mode == Option::QMAKE_SET_PROPERTY) {
197 for(QStringList::ConstIterator it = Option::prop::properties.begin();
198 it != Option::prop::properties.end(); it++) {
201 if(it == Option::prop::properties.end()) {
205 if(!var.startsWith("."))
206 setValue(var, (*it));
208 } else if(Option::qmake_mode == Option::QMAKE_UNSET_PROPERTY) {
209 for(QStringList::ConstIterator it = Option::prop::properties.begin();
210 it != Option::prop::properties.end(); it++) {
212 if(!var.startsWith("."))