Add the filters for extra compilers for vcxproj files
[profile/ivi/qtbase.git] / qmake / property.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the qmake application of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "property.h"
43 #include "option.h"
44
45 #include <qdir.h>
46 #include <qsettings.h>
47 #include <qstringlist.h>
48 #include <stdio.h>
49
50 QT_BEGIN_NAMESPACE
51
52 QStringList qmake_mkspec_paths(); //project.cpp
53
54 static const struct {
55     const char *name;
56     QLibraryInfo::LibraryLocation loc;
57     bool raw;
58 } propList[] = {
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 },
76 };
77
78 QMakeProperty::QMakeProperty() : settings(0)
79 {
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);
86             name += "/raw";
87         }
88         m_values[name] = val;
89     }
90 }
91
92 QMakeProperty::~QMakeProperty()
93 {
94     delete settings;
95     settings = 0;
96 }
97
98 void QMakeProperty::initSettings()
99 {
100     if(!settings) {
101         settings = new QSettings(QSettings::UserScope, "Trolltech", "QMake");
102         settings->setFallbacksEnabled(false);
103     }
104 }
105
106 QString
107 QMakeProperty::value(const QString &v)
108 {
109     QString val = m_values.value(v);
110     if (!val.isNull())
111         return val;
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;
119 #endif
120
121     initSettings();
122     if (!settings->contains(v))
123         return settings->value("2.01a/" + v).toString(); // Backwards compat
124     return settings->value(v).toString();
125 }
126
127 bool
128 QMakeProperty::hasValue(QString v)
129 {
130     return !value(v).isNull();
131 }
132
133 void
134 QMakeProperty::setValue(QString var, const QString &val)
135 {
136     initSettings();
137     settings->setValue(var, val);
138     settings->remove("2.01a/" + var); // Backwards compat
139 }
140
141 void
142 QMakeProperty::remove(const QString &var)
143 {
144     initSettings();
145     settings->remove(var);
146     settings->remove("2.01a/" + var); // Backwards compat
147 }
148
149 bool
150 QMakeProperty::exec()
151 {
152     bool ret = true;
153     if(Option::qmake_mode == Option::QMAKE_QUERY_PROPERTY) {
154         if(Option::prop::properties.isEmpty()) {
155             initSettings();
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));
164             }
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");
172 #endif
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());
182             }
183             return true;
184         }
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))) {
190                 ret = false;
191                 fprintf(stdout, "**Unknown**\n");
192             } else {
193                 fprintf(stdout, "%s\n", value((*it)).toLatin1().constData());
194             }
195         }
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++) {
199             QString var = (*it);
200             it++;
201             if(it == Option::prop::properties.end()) {
202                 ret = false;
203                 break;
204             }
205             if(!var.startsWith("."))
206                 setValue(var, (*it));
207         }
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++) {
211             QString var = (*it);
212             if(!var.startsWith("."))
213                 remove(var);
214         }
215     }
216     return ret;
217 }
218
219 QT_END_NAMESPACE