1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtCore module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
45 #include "qsettings.h"
46 #include "qlibraryinfo.h"
47 #include "qscopedpointer.h"
49 #if defined(QT_BUILD_QMAKE) || defined(QT_BOOTSTRAPPED)
50 # define BOOTSTRAPPING
55 extern QString qmake_libraryInfoFile();
58 # include "qcoreapplication.h"
62 # include "private/qcore_mac_p.h"
65 #include "qconfig.cpp"
69 extern void qDumpCPUFeatures(); // in qsimd.cpp
71 #ifndef QT_NO_SETTINGS
73 struct QLibrarySettings
76 QScopedPointer<QSettings> settings;
78 Q_GLOBAL_STATIC(QLibrarySettings, qt_library_settings)
80 class QLibraryInfoPrivate
83 static QSettings *findConfiguration();
86 QLibrarySettings *ls = qt_library_settings();
88 ls->settings.reset(0);
90 static QSettings *configuration()
92 QLibrarySettings *ls = qt_library_settings();
93 return ls ? ls->settings.data() : 0;
97 QLibrarySettings::QLibrarySettings()
98 : settings(QLibraryInfoPrivate::findConfiguration())
100 #ifndef BOOTSTRAPPING
101 qAddPostRoutine(QLibraryInfoPrivate::cleanup);
105 QSettings *QLibraryInfoPrivate::findConfiguration()
107 QString qtconfig = QLatin1String(":/qt/etc/qt.conf");
109 if(!QFile::exists(qtconfig))
110 qtconfig = qmake_libraryInfoFile();
112 if (!QFile::exists(qtconfig) && QCoreApplication::instance()) {
114 CFBundleRef bundleRef = CFBundleGetMainBundle();
116 QCFType<CFURLRef> urlRef = CFBundleCopyResourceURL(bundleRef,
117 QCFString(QLatin1String("qt.conf")),
121 QCFString path = CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle);
122 qtconfig = QDir::cleanPath(path);
125 if (qtconfig.isEmpty())
128 QDir pwd(QCoreApplication::applicationDirPath());
129 qtconfig = pwd.filePath(QLatin1String("qt.conf"));
133 if (QFile::exists(qtconfig))
134 return new QSettings(qtconfig, QSettings::IniFormat);
140 \brief The QLibraryInfo class provides information about the Qt library.
142 Many pieces of information are established when Qt is configured and built.
143 This class provides an abstraction for accessing that information.
144 By using the static functions of this class, an application can obtain
145 information about the instance of the Qt library which the application
146 is using at run-time.
148 You can also use a \c qt.conf file to override the hard-coded paths
149 that are compiled into the Qt library. For more information, see
150 the \l {Using qt.conf} documentation.
152 \sa QSysInfo, {Using qt.conf}
157 You cannot create a QLibraryInfo, instead only the static functions are available to query
161 QLibraryInfo::QLibraryInfo()
165 Returns the person to whom this build of Qt is licensed.
167 \sa licensedProducts()
171 QLibraryInfo::licensee()
173 const char *str = QT_CONFIGURE_LICENSEE;
174 return QString::fromLocal8Bit(str);
178 Returns the products that the license for this build of Qt has access to.
184 QLibraryInfo::licensedProducts()
186 const char *str = QT_CONFIGURE_LICENSED_PRODUCTS;
187 return QString::fromLatin1(str);
192 Returns the installation date for this build of Qt. The install date will
193 usually be the last time that Qt sources were configured.
195 #ifndef QT_NO_DATESTRING
197 QLibraryInfo::buildDate()
199 return QDate::fromString(QString::fromLatin1(qt_configure_installation + 12), Qt::ISODate);
201 #endif //QT_NO_DATESTRING
205 Returns true if this build of Qt was built with debugging enabled, or
206 false if it was built in release mode.
209 QLibraryInfo::isDebugBuild()
218 Returns the location specified by \a loc.
223 QLibraryInfo::location(LibraryLocation loc)
226 if(!QLibraryInfoPrivate::configuration()) {
227 const char *path = 0;
229 #ifdef QT_CONFIGURE_PREFIX_PATH
231 path = QT_CONFIGURE_PREFIX_PATH;
234 #ifdef QT_CONFIGURE_DOCUMENTATION_PATH
235 case DocumentationPath:
236 path = QT_CONFIGURE_DOCUMENTATION_PATH;
239 #ifdef QT_CONFIGURE_HEADERS_PATH
241 path = QT_CONFIGURE_HEADERS_PATH;
244 #ifdef QT_CONFIGURE_LIBRARIES_PATH
246 path = QT_CONFIGURE_LIBRARIES_PATH;
249 #ifdef QT_CONFIGURE_BINARIES_PATH
251 path = QT_CONFIGURE_BINARIES_PATH;
254 #ifdef QT_CONFIGURE_PLUGINS_PATH
256 path = QT_CONFIGURE_PLUGINS_PATH;
259 #ifdef QT_CONFIGURE_IMPORTS_PATH
261 path = QT_CONFIGURE_IMPORTS_PATH;
264 #ifdef QT_CONFIGURE_DATA_PATH
266 path = QT_CONFIGURE_DATA_PATH;
269 #ifdef QT_CONFIGURE_TRANSLATIONS_PATH
270 case TranslationsPath:
271 path = QT_CONFIGURE_TRANSLATIONS_PATH;
274 #ifdef QT_CONFIGURE_SETTINGS_PATH
276 path = QT_CONFIGURE_SETTINGS_PATH;
279 #ifdef QT_CONFIGURE_EXAMPLES_PATH
281 path = QT_CONFIGURE_EXAMPLES_PATH;
284 #ifdef QT_CONFIGURE_TESTS_PATH
286 path = QT_CONFIGURE_TESTS_PATH;
294 ret = QString::fromLocal8Bit(path);
297 QString defaultValue;
300 key = QLatin1String("Prefix");
302 case DocumentationPath:
303 key = QLatin1String("Documentation");
304 defaultValue = QLatin1String("doc");
307 key = QLatin1String("Headers");
308 defaultValue = QLatin1String("include");
311 key = QLatin1String("Libraries");
312 defaultValue = QLatin1String("lib");
315 key = QLatin1String("Binaries");
316 defaultValue = QLatin1String("bin");
319 key = QLatin1String("Plugins");
320 defaultValue = QLatin1String("plugins");
323 key = QLatin1String("Imports");
324 defaultValue = QLatin1String("imports");
327 key = QLatin1String("Data");
329 case TranslationsPath:
330 key = QLatin1String("Translations");
331 defaultValue = QLatin1String("translations");
334 key = QLatin1String("Settings");
337 key = QLatin1String("Examples");
340 key = QLatin1String("Tests");
341 defaultValue = QLatin1String("tests");
348 QSettings *config = QLibraryInfoPrivate::configuration();
349 config->beginGroup(QLatin1String("Paths"));
354 find the child group whose version number is closest
355 to the library version. for example and we have the
364 if QT_VERSION is 4.0.1, then we use 'Paths/4.0'
365 if QT_VERSION is 4.1.5, then we use 'Paths/4.1.2'
366 if QT_VERSION is 4.6.3, then we use 'Paths/4.2.5'
367 if QT_VERSION is 6.0.2, then we use 'Paths/5'
369 note: any of the trailing version numbers may be
370 omitted (in which case, they default to zero),
371 i.e. 4 == 4.0.0, 4.1 == 4.1.0, and so on
374 QT_MAJOR = ((QT_VERSION >> 16) & 0xFF),
375 QT_MINOR = ((QT_VERSION >> 8) & 0xFF),
376 QT_PATCH = (QT_VERSION & 0xFF)
378 int maj = 0, min = 0, pat = 0;
379 QStringList children = config->childGroups();
380 for(int child = 0; child < children.size(); ++child) {
381 QString cver = children.at(child);
382 QStringList cver_list = cver.split(QLatin1Char('.'));
383 if(cver_list.size() > 0 && cver_list.size() < 4) {
385 int cmaj = -1, cmin = -1, cpat = -1;
386 cmaj = cver_list[0].toInt(&ok);
389 if(cver_list.size() >= 2) {
390 cmin = cver_list[1].toInt(&ok);
396 if(cver_list.size() >= 3) {
397 cpat = cver_list[2].toInt(&ok);
403 if((cmaj >= maj && cmaj <= QT_MAJOR) &&
404 (cmin == -1 || (cmin >= min && cmin <= QT_MINOR)) &&
405 (cpat == -1 || (cpat >= pat && cpat <= QT_PATCH)) &&
406 config->contains(cver + QLatin1Char('/') + key)) {
407 subKey = cver + QLatin1Char('/');
415 ret = config->value(subKey + key, defaultValue).toString();
416 // expand environment variables in the form $(ENVVAR)
418 QRegExp reg_var(QLatin1String("\\$\\(.*\\)"));
419 reg_var.setMinimal(true);
420 while((rep = reg_var.indexIn(ret)) != -1) {
421 ret.replace(rep, reg_var.matchedLength(),
422 QString::fromLocal8Bit(qgetenv(ret.mid(rep + 2,
423 reg_var.matchedLength() - 3).toLatin1().constData()).constData()));
430 if (QDir::isRelativePath(ret)) {
432 if (loc == PrefixPath) {
433 // we make the prefix path absolute to the executable's directory
435 baseDir = QFileInfo(qmake_libraryInfoFile()).absolutePath();
437 if (QCoreApplication::instance()) {
439 CFBundleRef bundleRef = CFBundleGetMainBundle();
441 QCFType<CFURLRef> urlRef = CFBundleCopyBundleURL(bundleRef);
443 QCFString path = CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle);
444 return QDir::cleanPath(QString(path) + QLatin1String("/Contents/") + ret);
448 baseDir = QCoreApplication::applicationDirPath();
450 baseDir = QDir::currentPath();
454 // we make any other path absolute to the prefix directory
455 baseDir = location(PrefixPath);
457 ret = QDir::cleanPath(baseDir + QLatin1Char('/') + ret);
463 \enum QLibraryInfo::LibraryLocation
465 \keyword library location
467 This enum type is used to specify a specific location
470 \value PrefixPath The default prefix for all paths.
471 \value DocumentationPath The location for documentation upon install.
472 \value HeadersPath The location for all headers.
473 \value LibrariesPath The location of installed libraries.
474 \value BinariesPath The location of installed Qt binaries (tools and applications).
475 \value PluginsPath The location of installed Qt plugins.
476 \value ImportsPath The location of installed QML extensions to import.
477 \value DataPath The location of general Qt data.
478 \value TranslationsPath The location of translation information for Qt strings.
479 \value SettingsPath The location for Qt settings.
480 \value ExamplesPath The location for examples upon install.
481 \value TestsPath The location of installed Qt testcases.
486 #endif // QT_NO_SETTINGS
490 #if defined(Q_CC_GNU) && defined(ELF_INTERPRETER)
494 extern const char qt_core_interpreter[] __attribute__((section(".interp")))
497 extern "C" void qt_core_boilerplate();
498 void qt_core_boilerplate()
500 printf("This is the QtCore library version " QT_VERSION_STR "\n"
501 "Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).\n"
502 "Contact: Nokia Corporation (qt-info@nokia.com)\n"
505 "Installation prefix: %s\n"
507 "Include path: %s\n",
508 qt_configure_installation + 12,
509 qt_configure_prefix_path_str + 12,
510 qt_configure_libraries_path_str + 12,
511 qt_configure_headers_path_str + 12);
513 QT_PREPEND_NAMESPACE(qDumpCPUFeatures)();
516 extern void qt_core_eval_init(uint);
517 qt_core_eval_init(1);