Qt 4.8
qlibraryinfo.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module 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 "qdir.h"
43 #include "qfile.h"
44 #include "qconfig.h"
45 #include "qsettings.h"
46 #include "qlibraryinfo.h"
47 #include "qscopedpointer.h"
48 
49 #if defined(QT_BUILD_QMAKE) || defined(QT_BOOTSTRAPPED)
50 # define BOOTSTRAPPING
51 #endif
52 
53 #ifdef BOOTSTRAPPING
55 extern QString qmake_libraryInfoFile();
57 #else
58 # include "qcoreapplication.h"
59 #endif
60 
61 #ifdef Q_OS_MAC
62 # include "private/qcore_mac_p.h"
63 #endif
64 
65 #ifdef QLIBRARYINFO_EPOCROOT
66 # include "symbian/epocroot_p.h"
67 #endif
68 
69 #include "qconfig.cpp"
70 
72 
73 extern void qDumpCPUFeatures(); // in qsimd.cpp
74 
75 #ifndef QT_NO_SETTINGS
76 
78 {
81 };
82 Q_GLOBAL_STATIC(QLibrarySettings, qt_library_settings)
83 
85 {
86 public:
87  static QSettings *findConfiguration();
88  static void cleanup()
89  {
90  QLibrarySettings *ls = qt_library_settings();
91  if (ls)
92  ls->settings.reset(0);
93  }
95  {
96  QLibrarySettings *ls = qt_library_settings();
97  return ls ? ls->settings.data() : 0;
98  }
99 };
100 
102  : settings(QLibraryInfoPrivate::findConfiguration())
103 {
104 #ifndef BOOTSTRAPPING
106 #endif
107 }
108 
110 {
111  QString qtconfig = QLatin1String(":/qt/etc/qt.conf");
112 #ifdef BOOTSTRAPPING
113  if(!QFile::exists(qtconfig))
114  qtconfig = qmake_libraryInfoFile();
115 #else
116  if (!QFile::exists(qtconfig) && QCoreApplication::instance()) {
117 #ifdef Q_OS_MAC
118  CFBundleRef bundleRef = CFBundleGetMainBundle();
119  if (bundleRef) {
120  QCFType<CFURLRef> urlRef = CFBundleCopyResourceURL(bundleRef,
121  QCFString(QLatin1String("qt.conf")),
122  0,
123  0);
124  if (urlRef) {
125  QCFString path = CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle);
126  qtconfig = QDir::cleanPath(path);
127  }
128  }
129  if (qtconfig.isEmpty())
130 #endif
131  {
133  qtconfig = pwd.filePath(QLatin1String("qt.conf"));
134  }
135  }
136 #endif
137  if (QFile::exists(qtconfig))
138  return new QSettings(qtconfig, QSettings::IniFormat);
139  return 0; //no luck
140 }
141 
183 { }
184 
191 QString
193 {
194  const char *str = QT_CONFIGURE_LICENSEE;
195  return QString::fromLocal8Bit(str);
196 }
197 
204 QString
206 {
207  const char *str = QT_CONFIGURE_LICENSED_PRODUCTS;
208  return QString::fromLatin1(str);
209 }
210 
220 QString
222 {
224 }
225 
234 #ifndef QT_NO_DATESTRING
235 QDate
237 {
238  return QDate::fromString(QString::fromLatin1(qt_configure_installation + 12), Qt::ISODate);
239 }
240 #endif //QT_NO_DATESTRING
241 
247 QString
249 {
250  QString ret;
252  const char *path = 0;
253  switch (loc) {
254 #ifdef QT_CONFIGURE_PREFIX_PATH
255  case PrefixPath:
256  path = QT_CONFIGURE_PREFIX_PATH;
257  break;
258 #endif
259 #ifdef QT_CONFIGURE_DOCUMENTATION_PATH
260  case DocumentationPath:
261  path = QT_CONFIGURE_DOCUMENTATION_PATH;
262  break;
263 #endif
264 #ifdef QT_CONFIGURE_HEADERS_PATH
265  case HeadersPath:
266  path = QT_CONFIGURE_HEADERS_PATH;
267  break;
268 #endif
269 #ifdef QT_CONFIGURE_LIBRARIES_PATH
270  case LibrariesPath:
271  path = QT_CONFIGURE_LIBRARIES_PATH;
272  break;
273 #endif
274 #ifdef QT_CONFIGURE_BINARIES_PATH
275  case BinariesPath:
276  path = QT_CONFIGURE_BINARIES_PATH;
277  break;
278 #endif
279 #ifdef QT_CONFIGURE_PLUGINS_PATH
280  case PluginsPath:
281  path = QT_CONFIGURE_PLUGINS_PATH;
282  break;
283 #endif
284 #ifdef QT_CONFIGURE_IMPORTS_PATH
285  case ImportsPath:
286  path = QT_CONFIGURE_IMPORTS_PATH;
287  break;
288 #endif
289 #ifdef QT_CONFIGURE_DATA_PATH
290  case DataPath:
291  path = QT_CONFIGURE_DATA_PATH;
292  break;
293 #endif
294 #ifdef QT_CONFIGURE_TRANSLATIONS_PATH
295  case TranslationsPath:
296  path = QT_CONFIGURE_TRANSLATIONS_PATH;
297  break;
298 #endif
299 #ifdef QT_CONFIGURE_SETTINGS_PATH
300  case SettingsPath:
301  path = QT_CONFIGURE_SETTINGS_PATH;
302  break;
303 #endif
304 #ifdef QT_CONFIGURE_EXAMPLES_PATH
305  case ExamplesPath:
306  path = QT_CONFIGURE_EXAMPLES_PATH;
307  break;
308 #endif
309 #ifdef QT_CONFIGURE_DEMOS_PATH
310  case DemosPath:
311  path = QT_CONFIGURE_DEMOS_PATH;
312  break;
313 #endif
314  default:
315  break;
316  }
317 
318  if (path)
319  ret = QString::fromLocal8Bit(path);
320  } else {
321  QString key;
322  QString defaultValue;
323  switch(loc) {
324  case PrefixPath:
325  key = QLatin1String("Prefix");
326  break;
327  case DocumentationPath:
328  key = QLatin1String("Documentation");
329  defaultValue = QLatin1String("doc");
330  break;
331  case HeadersPath:
332  key = QLatin1String("Headers");
333  defaultValue = QLatin1String("include");
334  break;
335  case LibrariesPath:
336  key = QLatin1String("Libraries");
337  defaultValue = QLatin1String("lib");
338  break;
339  case BinariesPath:
340  key = QLatin1String("Binaries");
341  defaultValue = QLatin1String("bin");
342  break;
343  case PluginsPath:
344  key = QLatin1String("Plugins");
345  defaultValue = QLatin1String("plugins");
346  break;
347  case ImportsPath:
348  key = QLatin1String("Imports");
349  defaultValue = QLatin1String("imports");
350  break;
351  case DataPath:
352  key = QLatin1String("Data");
353  break;
354  case TranslationsPath:
355  key = QLatin1String("Translations");
356  defaultValue = QLatin1String("translations");
357  break;
358  case SettingsPath:
359  key = QLatin1String("Settings");
360  break;
361  case ExamplesPath:
362  key = QLatin1String("Examples");
363  break;
364  case DemosPath:
365  key = QLatin1String("Demos");
366  break;
367  default:
368  break;
369  }
370 
371  if(!key.isNull()) {
373  config->beginGroup(QLatin1String("Paths"));
374 
375  QString subKey;
376  {
377  /*
378  find the child group whose version number is closest
379  to the library version. for example and we have the
380  following groups:
381 
382  Paths
383  Paths/4.0
384  Paths/4.1.2
385  Paths/4.2.5
386  Paths/5
387 
388  if QT_VERSION is 4.0.1, then we use 'Paths/4.0'
389  if QT_VERSION is 4.1.5, then we use 'Paths/4.1.2'
390  if QT_VERSION is 4.6.3, then we use 'Paths/4.2.5'
391  if QT_VERSION is 6.0.2, then we use 'Paths/5'
392 
393  note: any of the trailing version numbers may be
394  omitted (in which case, they default to zero),
395  i.e. 4 == 4.0.0, 4.1 == 4.1.0, and so on
396  */
397  enum {
398  QT_MAJOR = ((QT_VERSION >> 16) & 0xFF),
399  QT_MINOR = ((QT_VERSION >> 8) & 0xFF),
400  QT_PATCH = (QT_VERSION & 0xFF)
401  };
402  int maj = 0, min = 0, pat = 0;
403  QStringList children = config->childGroups();
404  for(int child = 0; child < children.size(); ++child) {
405  QString cver = children.at(child);
406  QStringList cver_list = cver.split(QLatin1Char('.'));
407  if(cver_list.size() > 0 && cver_list.size() < 4) {
408  bool ok;
409  int cmaj = -1, cmin = -1, cpat = -1;
410  cmaj = cver_list[0].toInt(&ok);
411  if(!ok || cmaj < 0)
412  continue;
413  if(cver_list.size() >= 2) {
414  cmin = cver_list[1].toInt(&ok);
415  if(!ok)
416  continue;
417  if(cmin < 0)
418  cmin = -1;
419  }
420  if(cver_list.size() >= 3) {
421  cpat = cver_list[2].toInt(&ok);
422  if(!ok)
423  continue;
424  if(cpat < 0)
425  cpat = -1;
426  }
427  if((cmaj >= maj && cmaj <= QT_MAJOR) &&
428  (cmin == -1 || (cmin >= min && cmin <= QT_MINOR)) &&
429  (cpat == -1 || (cpat >= pat && cpat <= QT_PATCH)) &&
430  config->contains(cver + QLatin1Char('/') + key)) {
431  subKey = cver + QLatin1Char('/');
432  maj = cmaj;
433  min = cmin;
434  pat = cpat;
435  }
436  }
437  }
438  }
439  ret = config->value(subKey + key, defaultValue).toString();
440  // expand environment variables in the form $(ENVVAR)
441  int rep;
442  QRegExp reg_var(QLatin1String("\\$\\(.*\\)"));
443  reg_var.setMinimal(true);
444  while((rep = reg_var.indexIn(ret)) != -1) {
445  ret.replace(rep, reg_var.matchedLength(),
446  QString::fromLocal8Bit(qgetenv(ret.mid(rep + 2,
447  reg_var.matchedLength() - 3).toLatin1().constData()).constData()));
448  }
449 
450 #ifdef QLIBRARYINFO_EPOCROOT
451  // $${EPOCROOT} is a special case, resolve it similarly to qmake.
452  QRegExp epocrootMatcher(QLatin1String("\\$\\$\\{EPOCROOT\\}"));
453  if ((rep = epocrootMatcher.indexIn(ret)) != -1)
454  ret.replace(rep, epocrootMatcher.matchedLength(), qt_epocRoot());
455 #endif
456 
457  config->endGroup();
458  }
459  }
460 
461  if (QDir::isRelativePath(ret)) {
462  QString baseDir;
463  if (loc == PrefixPath) {
464  // we make the prefix path absolute to the executable's directory
465 #ifdef BOOTSTRAPPING
466  baseDir = QFileInfo(qmake_libraryInfoFile()).absolutePath();
467 #else
469 #ifdef Q_OS_MAC
470  CFBundleRef bundleRef = CFBundleGetMainBundle();
471  if (bundleRef) {
472  QCFType<CFURLRef> urlRef = CFBundleCopyBundleURL(bundleRef);
473  if (urlRef) {
474  QCFString path = CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle);
475  return QDir::cleanPath(QString(path) + QLatin1String("/Contents/") + ret);
476  }
477  }
478 #endif
480  } else {
481  baseDir = QDir::currentPath();
482  }
483 #endif
484  } else {
485  // we make any other path absolute to the prefix directory
486  baseDir = location(PrefixPath);
487  }
488  ret = QDir::cleanPath(baseDir + QLatin1Char('/') + ret);
489  }
490  return ret;
491 }
492 
520 #endif // QT_NO_SETTINGS
521 
523 
524 #if defined(Q_CC_GNU) && defined(ELF_INTERPRETER)
525 # include <stdio.h>
526 # include <stdlib.h>
527 
528 extern const char qt_core_interpreter[] __attribute__((section(".interp")))
529  = ELF_INTERPRETER;
530 
531 extern "C" void qt_core_boilerplate();
532 void qt_core_boilerplate()
533 {
534  printf("This is the QtCore library version " QT_VERSION_STR "\n"
535  "Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).\n"
536  "Contact: http://www.qt-project.org/legal\n"
537  "\n"
538  "Build key: " QT_BUILD_KEY "\n"
539  "Compat build key: "
540 #ifdef QT_BUILD_KEY_COMPAT
541  "| " QT_BUILD_KEY_COMPAT " "
542 #endif
543 #ifdef QT_BUILD_KEY_COMPAT2
544  "| " QT_BUILD_KEY_COMPAT2 " "
545 #endif
546 #ifdef QT_BUILD_KEY_COMPAT3
547  "| " QT_BUILD_KEY_COMPAT3 " "
548 #endif
549  "|\n"
550  "Build date: %s\n"
551  "Installation prefix: %s\n"
552  "Library path: %s\n"
553  "Include path: %s\n",
554  qt_configure_installation + 12,
555  qt_configure_prefix_path_str + 12,
556  qt_configure_libraries_path_str + 12,
557  qt_configure_headers_path_str + 12);
558 
560 
561 #ifdef QT_EVAL
562  extern void qt_core_eval_init(uint);
563  qt_core_eval_init(1);
564 #endif
565 
566  exit(0);
567 }
568 
569 #endif
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
Definition: qstring.cpp:4245
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns the value for setting key.
Definition: qsettings.cpp:3460
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
T * data() const
Returns the value of the pointer referenced by this object.
void qAddPostRoutine(QtCleanUpFunction p)
static QString licensee()
Returns the person to whom this build of Qt is licensed.
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
void endGroup()
Resets the group to what it was before the corresponding beginGroup() call.
Definition: qsettings.cpp:3089
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
static QSettings * configuration()
void beginGroup(const QString &prefix)
Appends prefix to the current group.
Definition: qsettings.cpp:3073
static QString licensedProducts()
Returns the products that the license for this build of Qt has access to.
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
int matchedLength() const
Returns the length of the last matched string, or -1 if there was no match.
Definition: qregexp.cpp:4193
void qDumpCPUFeatures()
Definition: qsimd.cpp:402
The QDate class provides date functions.
Definition: qdatetime.h:55
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static QString buildKey()
Returns a unique key identifying this build of Qt and its configurations.
static bool isRelativePath(const QString &path)
Returns true if path is relative; returns false if it is absolute.
Definition: qdir.cpp:2210
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString currentPath()
Returns the absolute path of the application&#39;s current directory.
Definition: qdir.cpp:1875
#define QT_BUILD_KEY
Definition: qglobal.h:1254
QStringList childGroups() const
Returns a list of all key top-level groups that contain keys that can be read using the QSettings obj...
Definition: qsettings.cpp:3288
bool exists() const
Returns true if the file specified by fileName() exists; otherwise returns false. ...
Definition: qfile.cpp:626
static QString applicationDirPath()
Returns the directory that contains the application executable.
void setMinimal(bool minimal)
Enables or disables minimal matching.
Definition: qregexp.cpp:4068
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QLibraryInfo()
You cannot create a QLibraryInfo, instead only the static functions are available to query informatio...
LibraryLocation
This enum type is used to specify a specific location specifier:
Definition: qlibraryinfo.h:67
int indexIn(const QString &str, int offset=0, CaretMode caretMode=CaretAtZero) const
Attempts to find a match in str from position offset (0 by default).
Definition: qregexp.cpp:4136
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Definition: qglobal.h:1968
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
unsigned int uint
Definition: qglobal.h:996
#define QT_VERSION_STR
This macro expands to a string that specifies Qt&#39;s version number (for example, "4.
Definition: qglobal.h:47
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
Definition: qdir.cpp:2082
static QDate buildDate()
Returns the installation date for this build of Qt.
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
static QSettings * findConfiguration()
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
static QString location(LibraryLocation)
Returns the location specified by loc.
static QTestResult::TestLocation location
Definition: qtestresult.cpp:63
int key
static void cleanup()
static QDate fromString(const QString &s, Qt::DateFormat f=Qt::TextDate)
Returns the QDate represented by the string, using the format given, or an invalid date if the string...
Definition: qdatetime.cpp:1203
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool contains(const QString &key) const
Returns true if there exists a setting called key; returns false otherwise.
Definition: qsettings.cpp:3394
QScopedPointer< QSettings > settings
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
QString filePath(const QString &fileName) const
Returns the path name of a file in the directory.
Definition: qdir.cpp:678
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
#define class
QString absolutePath() const
Returns a file&#39;s path absolute path.
Definition: qfileinfo.cpp:577
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712
#define QT_VERSION
This macro expands a numeric value of the form 0xMMNNPP (MM = major, NN = minor, PP = patch) that spe...
Definition: qglobal.h:51