| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
| 4 | ** All rights reserved. | 
|---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
|---|
| 6 | ** | 
|---|
| 7 | ** This file is part of the qmake application of the Qt Toolkit. | 
|---|
| 8 | ** | 
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | 
|---|
| 10 | ** Commercial Usage | 
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in | 
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the | 
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in | 
|---|
| 14 | ** a written agreement between you and Nokia. | 
|---|
| 15 | ** | 
|---|
| 16 | ** GNU Lesser General Public License Usage | 
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software | 
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | 
|---|
| 20 | ** packaging of this file.  Please review the following information to | 
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | 
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | 
|---|
| 23 | ** | 
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | 
|---|
| 25 | ** rights.  These rights are described in the Nokia Qt LGPL Exception | 
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
|---|
| 27 | ** | 
|---|
| 28 | ** GNU General Public License Usage | 
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU | 
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software | 
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the | 
|---|
| 32 | ** packaging of this file.  Please review the following information to | 
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be | 
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html. | 
|---|
| 35 | ** | 
|---|
| 36 | ** If you have questions regarding the use of this file, please contact | 
|---|
| 37 | ** Nokia at qt-info@nokia.com. | 
|---|
| 38 | ** $QT_END_LICENSE$ | 
|---|
| 39 | ** | 
|---|
| 40 | ****************************************************************************/ | 
|---|
| 41 |  | 
|---|
| 42 | #include "property.h" | 
|---|
| 43 | #include "option.h" | 
|---|
| 44 |  | 
|---|
| 45 | #include <qdir.h> | 
|---|
| 46 | #include <qmap.h> | 
|---|
| 47 | #include <qsettings.h> | 
|---|
| 48 | #include <qstringlist.h> | 
|---|
| 49 | #include <stdio.h> | 
|---|
| 50 |  | 
|---|
| 51 | QT_BEGIN_NAMESPACE | 
|---|
| 52 |  | 
|---|
| 53 | QStringList qmake_mkspec_paths(); //project.cpp | 
|---|
| 54 |  | 
|---|
| 55 | QMakeProperty::QMakeProperty() : settings(0) | 
|---|
| 56 | { | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 | QMakeProperty::~QMakeProperty() | 
|---|
| 60 | { | 
|---|
| 61 | delete settings; | 
|---|
| 62 | settings = 0; | 
|---|
| 63 | } | 
|---|
| 64 |  | 
|---|
| 65 | void QMakeProperty::initSettings() | 
|---|
| 66 | { | 
|---|
| 67 | if(!settings) { | 
|---|
| 68 | settings = new QSettings(QSettings::UserScope, "Trolltech", "QMake"); | 
|---|
| 69 | settings->setFallbacksEnabled(false); | 
|---|
| 70 | } | 
|---|
| 71 | } | 
|---|
| 72 |  | 
|---|
| 73 | QString | 
|---|
| 74 | QMakeProperty::keyBase(bool version) const | 
|---|
| 75 | { | 
|---|
| 76 | if (version) | 
|---|
| 77 | return QString(qmake_version()) + "/"; | 
|---|
| 78 | return QString(); | 
|---|
| 79 | } | 
|---|
| 80 |  | 
|---|
| 81 | QString | 
|---|
| 82 | QMakeProperty::value(QString v, bool just_check) | 
|---|
| 83 | { | 
|---|
| 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::DemosPath); | 
|---|
| 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; | 
|---|
| 115 | #endif | 
|---|
| 116 |  | 
|---|
| 117 | initSettings(); | 
|---|
| 118 | int slash = v.lastIndexOf('/'); | 
|---|
| 119 | QVariant var = settings->value(keyBase(slash == -1) + v); | 
|---|
| 120 | bool ok = var.isValid(); | 
|---|
| 121 | QString ret = var.toString(); | 
|---|
| 122 | if(!ok) { | 
|---|
| 123 | QString version = qmake_version(); | 
|---|
| 124 | if(slash != -1) { | 
|---|
| 125 | version = v.left(slash-1); | 
|---|
| 126 | v = v.mid(slash+1); | 
|---|
| 127 | } | 
|---|
| 128 | settings->beginGroup(keyBase(false)); | 
|---|
| 129 | QStringList subs = settings->childGroups(); | 
|---|
| 130 | settings->endGroup(); | 
|---|
| 131 | subs.sort(); | 
|---|
| 132 | for (int x = subs.count() - 1; x >= 0; x--) { | 
|---|
| 133 | QString s = subs[x]; | 
|---|
| 134 | if(s.isEmpty() || s > version) | 
|---|
| 135 | continue; | 
|---|
| 136 | var = settings->value(keyBase(false) + s + "/" + v); | 
|---|
| 137 | ok = var.isValid(); | 
|---|
| 138 | ret = var.toString(); | 
|---|
| 139 | if (ok) { | 
|---|
| 140 | if(!just_check) | 
|---|
| 141 | debug_msg(1, "Fell back from %s -> %s for '%s'.", version.toLatin1().constData(), | 
|---|
| 142 | s.toLatin1().constData(), v.toLatin1().constData()); | 
|---|
| 143 | return ret; | 
|---|
| 144 | } | 
|---|
| 145 | } | 
|---|
| 146 | } | 
|---|
| 147 | return ok ? ret : QString(); | 
|---|
| 148 | } | 
|---|
| 149 |  | 
|---|
| 150 | bool | 
|---|
| 151 | QMakeProperty::hasValue(QString v) | 
|---|
| 152 | { | 
|---|
| 153 | return !value(v, true).isNull(); | 
|---|
| 154 | } | 
|---|
| 155 |  | 
|---|
| 156 | void | 
|---|
| 157 | QMakeProperty::setValue(QString var, const QString &val) | 
|---|
| 158 | { | 
|---|
| 159 | initSettings(); | 
|---|
| 160 | settings->setValue(keyBase() + var, val); | 
|---|
| 161 | } | 
|---|
| 162 |  | 
|---|
| 163 | bool | 
|---|
| 164 | QMakeProperty::exec() | 
|---|
| 165 | { | 
|---|
| 166 | bool ret = true; | 
|---|
| 167 | if(Option::qmake_mode == Option::QMAKE_QUERY_PROPERTY) { | 
|---|
| 168 | if(Option::prop::properties.isEmpty()) { | 
|---|
| 169 | initSettings(); | 
|---|
| 170 | settings->beginGroup(keyBase(false)); | 
|---|
| 171 | QStringList subs = settings->childGroups(); | 
|---|
| 172 | settings->endGroup(); | 
|---|
| 173 | subs.sort(); | 
|---|
| 174 | for(int x = subs.count() - 1; x >= 0; x--) { | 
|---|
| 175 | QString s = subs[x]; | 
|---|
| 176 | if(s.isEmpty()) | 
|---|
| 177 | continue; | 
|---|
| 178 | settings->beginGroup(keyBase(false) + s); | 
|---|
| 179 | QStringList keys = settings->childKeys(); | 
|---|
| 180 | settings->endGroup(); | 
|---|
| 181 | for(QStringList::ConstIterator it2 = keys.begin(); it2 != keys.end(); it2++) { | 
|---|
| 182 | QString ret = settings->value(keyBase(false) + s + "/" + (*it2)).toString(); | 
|---|
| 183 | if(s != qmake_version()) | 
|---|
| 184 | fprintf(stdout, "%s/", s.toLatin1().constData()); | 
|---|
| 185 | fprintf(stdout, "%s:%s\n", (*it2).toLatin1().constData(), ret.toLatin1().constData()); | 
|---|
| 186 | } | 
|---|
| 187 | } | 
|---|
| 188 | QStringList specialProps; | 
|---|
| 189 | specialProps.append("QT_INSTALL_PREFIX"); | 
|---|
| 190 | specialProps.append("QT_INSTALL_DATA"); | 
|---|
| 191 | specialProps.append("QT_INSTALL_DOCS"); | 
|---|
| 192 | specialProps.append("QT_INSTALL_HEADERS"); | 
|---|
| 193 | specialProps.append("QT_INSTALL_LIBS"); | 
|---|
| 194 | specialProps.append("QT_INSTALL_BINS"); | 
|---|
| 195 | specialProps.append("QT_INSTALL_PLUGINS"); | 
|---|
| 196 | specialProps.append("QT_INSTALL_IMPORTS"); | 
|---|
| 197 | specialProps.append("QT_INSTALL_TRANSLATIONS"); | 
|---|
| 198 | specialProps.append("QT_INSTALL_CONFIGURATION"); | 
|---|
| 199 | specialProps.append("QT_INSTALL_EXAMPLES"); | 
|---|
| 200 | specialProps.append("QT_INSTALL_DEMOS"); | 
|---|
| 201 | specialProps.append("QMAKE_MKSPECS"); | 
|---|
| 202 | specialProps.append("QMAKE_VERSION"); | 
|---|
| 203 | #ifdef QT_VERSION_STR | 
|---|
| 204 | specialProps.append("QT_VERSION"); | 
|---|
| 205 | #endif | 
|---|
| 206 | foreach (QString prop, specialProps) | 
|---|
| 207 | fprintf(stdout, "%s:%s\n", prop.toLatin1().constData(), value(prop).toLatin1().constData()); | 
|---|
| 208 | return true; | 
|---|
| 209 | } | 
|---|
| 210 | for(QStringList::ConstIterator it = Option::prop::properties.begin(); | 
|---|
| 211 | it != Option::prop::properties.end(); it++) { | 
|---|
| 212 | if(Option::prop::properties.count() > 1) | 
|---|
| 213 | fprintf(stdout, "%s:", (*it).toLatin1().constData()); | 
|---|
| 214 | if(!hasValue((*it))) { | 
|---|
| 215 | ret = false; | 
|---|
| 216 | fprintf(stdout, "**Unknown**\n"); | 
|---|
| 217 | } else { | 
|---|
| 218 | fprintf(stdout, "%s\n", value((*it)).toLatin1().constData()); | 
|---|
| 219 | } | 
|---|
| 220 | } | 
|---|
| 221 | } else if(Option::qmake_mode == Option::QMAKE_SET_PROPERTY) { | 
|---|
| 222 | for(QStringList::ConstIterator it = Option::prop::properties.begin(); | 
|---|
| 223 | it != Option::prop::properties.end(); it++) { | 
|---|
| 224 | QString var = (*it); | 
|---|
| 225 | it++; | 
|---|
| 226 | if(it == Option::prop::properties.end()) { | 
|---|
| 227 | ret = false; | 
|---|
| 228 | break; | 
|---|
| 229 | } | 
|---|
| 230 | if(!var.startsWith(".")) | 
|---|
| 231 | setValue(var, (*it)); | 
|---|
| 232 | } | 
|---|
| 233 | } | 
|---|
| 234 | return ret; | 
|---|
| 235 | } | 
|---|
| 236 |  | 
|---|
| 237 | QT_END_NAMESPACE | 
|---|