Add directwrite support to the configure script
[profile/ivi/qtbase.git] / qmake / property.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the qmake application of the Qt Toolkit.
7 **
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.
16 **
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.
24 **
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.
28 **
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.
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 static const struct {
53     const char *name;
54     QLibraryInfo::LibraryLocation loc;
55     bool raw;
56 } propList[] = {
57     { "QT_SYSROOT", QLibraryInfo::SysrootPath, true },
58     { "QT_INSTALL_PREFIX", QLibraryInfo::PrefixPath, false },
59     { "QT_INSTALL_ARCHDATA", QLibraryInfo::ArchDataPath, false },
60     { "QT_INSTALL_DATA", QLibraryInfo::DataPath, false },
61     { "QT_INSTALL_DOCS", QLibraryInfo::DocumentationPath, false },
62     { "QT_INSTALL_HEADERS", QLibraryInfo::HeadersPath, false },
63     { "QT_INSTALL_LIBS", QLibraryInfo::LibrariesPath, false },
64     { "QT_INSTALL_LIBEXECS", QLibraryInfo::LibraryExecutablesPath, 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_QML", QLibraryInfo::Qml2ImportsPath, false },
70     { "QT_INSTALL_TRANSLATIONS", QLibraryInfo::TranslationsPath, false },
71     { "QT_INSTALL_CONFIGURATION", QLibraryInfo::SettingsPath, false },
72     { "QT_INSTALL_EXAMPLES", QLibraryInfo::ExamplesPath, false },
73     { "QT_INSTALL_DEMOS", QLibraryInfo::ExamplesPath, false }, // Just backwards compat
74     { "QT_HOST_PREFIX", QLibraryInfo::HostPrefixPath, true },
75     { "QT_HOST_DATA", QLibraryInfo::HostDataPath, true },
76     { "QT_HOST_BINS", QLibraryInfo::HostBinariesPath, true },
77     { "QMAKE_SPEC", QLibraryInfo::HostSpecPath, true },
78     { "QMAKE_XSPEC", QLibraryInfo::TargetSpecPath, true },
79 };
80
81 QMakeProperty::QMakeProperty() : settings(0)
82 {
83     for (int i = 0; i < sizeof(propList)/sizeof(propList[0]); i++) {
84         QString name = QString::fromLatin1(propList[i].name);
85         m_values[ProKey(name + "/get")] = QLibraryInfo::rawLocation(propList[i].loc, QLibraryInfo::EffectivePaths);
86         QString val = QLibraryInfo::rawLocation(propList[i].loc, QLibraryInfo::FinalPaths);
87         if (!propList[i].raw) {
88             m_values[ProKey(name)] = QLibraryInfo::location(propList[i].loc);
89             name += "/raw";
90         }
91         m_values[ProKey(name)] = val;
92     }
93     m_values["QMAKE_VERSION"] = ProString(QMAKE_VERSION_STR);
94 #ifdef QT_VERSION_STR
95     m_values["QT_VERSION"] = ProString(QT_VERSION_STR);
96 #endif
97 }
98
99 QMakeProperty::~QMakeProperty()
100 {
101     delete settings;
102     settings = 0;
103 }
104
105 void QMakeProperty::initSettings()
106 {
107     if(!settings) {
108         settings = new QSettings(QSettings::UserScope, "QtProject", "QMake");
109         settings->setFallbacksEnabled(false);
110     }
111 }
112
113 ProString
114 QMakeProperty::value(const ProKey &vk)
115 {
116     ProString val = m_values.value(vk);
117     if (!val.isNull())
118         return val;
119
120     initSettings();
121     QString v = vk.toQString();
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(const ProKey &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_VERSION");
169 #ifdef QT_VERSION_STR
170             specialProps.append("QT_VERSION");
171 #endif
172             foreach (QString prop, specialProps) {
173                 ProString val = value(ProKey(prop));
174                 ProString pval = value(ProKey(prop + "/raw"));
175                 ProString gval = value(ProKey(prop + "/get"));
176                 fprintf(stdout, "%s:%s\n", prop.toLatin1().constData(), val.toLatin1().constData());
177                 if (!pval.isEmpty() && pval != val)
178                     fprintf(stdout, "%s/raw:%s\n", prop.toLatin1().constData(), pval.toLatin1().constData());
179                 if (!gval.isEmpty() && gval != (pval.isEmpty() ? val : pval))
180                     fprintf(stdout, "%s/get:%s\n", prop.toLatin1().constData(), gval.toLatin1().constData());
181             }
182             return true;
183         }
184         for(QStringList::ConstIterator it = Option::prop::properties.begin();
185             it != Option::prop::properties.end(); it++) {
186             if(Option::prop::properties.count() > 1)
187                 fprintf(stdout, "%s:", (*it).toLatin1().constData());
188             const ProKey pkey(*it);
189             if (!hasValue(pkey)) {
190                 ret = false;
191                 fprintf(stdout, "**Unknown**\n");
192             } else {
193                 fprintf(stdout, "%s\n", value(pkey).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