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 QtCore module 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 ****************************************************************************/
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"));
351 ret = config->value(key, defaultValue).toString();
353 // expand environment variables in the form $(ENVVAR)
355 QRegExp reg_var(QLatin1String("\\$\\(.*\\)"));
356 reg_var.setMinimal(true);
357 while((rep = reg_var.indexIn(ret)) != -1) {
358 ret.replace(rep, reg_var.matchedLength(),
359 QString::fromLocal8Bit(qgetenv(ret.mid(rep + 2,
360 reg_var.matchedLength() - 3).toLatin1().constData()).constData()));
367 if (QDir::isRelativePath(ret)) {
369 if (loc == PrefixPath) {
370 // we make the prefix path absolute to the executable's directory
372 baseDir = QFileInfo(qmake_libraryInfoFile()).absolutePath();
374 if (QCoreApplication::instance()) {
376 CFBundleRef bundleRef = CFBundleGetMainBundle();
378 QCFType<CFURLRef> urlRef = CFBundleCopyBundleURL(bundleRef);
380 QCFString path = CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle);
381 return QDir::cleanPath(QString(path) + QLatin1String("/Contents/") + ret);
385 baseDir = QCoreApplication::applicationDirPath();
387 baseDir = QDir::currentPath();
391 // we make any other path absolute to the prefix directory
392 baseDir = location(PrefixPath);
394 ret = QDir::cleanPath(baseDir + QLatin1Char('/') + ret);
400 \enum QLibraryInfo::LibraryLocation
402 \keyword library location
404 This enum type is used to specify a specific location
407 \value PrefixPath The default prefix for all paths.
408 \value DocumentationPath The location for documentation upon install.
409 \value HeadersPath The location for all headers.
410 \value LibrariesPath The location of installed libraries.
411 \value BinariesPath The location of installed Qt binaries (tools and applications).
412 \value PluginsPath The location of installed Qt plugins.
413 \value ImportsPath The location of installed QML extensions to import.
414 \value DataPath The location of general Qt data.
415 \value TranslationsPath The location of translation information for Qt strings.
416 \value SettingsPath The location for Qt settings.
417 \value ExamplesPath The location for examples upon install.
418 \value TestsPath The location of installed Qt testcases.
423 #endif // QT_NO_SETTINGS
427 #if defined(Q_CC_GNU) && defined(ELF_INTERPRETER)
431 extern const char qt_core_interpreter[] __attribute__((section(".interp")))
434 extern "C" void qt_core_boilerplate();
435 void qt_core_boilerplate()
437 printf("This is the QtCore library version " QT_VERSION_STR "\n"
438 "Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).\n"
439 "Contact: http://www.qt-project.org/\n"
442 "Installation prefix: %s\n"
444 "Include path: %s\n",
445 qt_configure_installation + 12,
446 qt_configure_prefix_path_str + 12,
447 qt_configure_libraries_path_str + 12,
448 qt_configure_headers_path_str + 12);
450 QT_PREPEND_NAMESPACE(qDumpCPUFeatures)();
453 extern void qt_core_eval_init(uint);
454 qt_core_eval_init(1);