make qlibraryinfo table-driven

switch blocks are noisy. this is nicer.

reshuffled the LibraryLocation enum to make table lookups possible and
future-safe.

using pointer-free tables to avoid adding data relocations.

Change-Id: I70ec2c2142ce02a15e67284e4b285d754d930da3
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Oswald Buddenhagen 2012-02-28 11:01:52 +01:00 committed by Qt by Nokia
parent 3b1b5be911
commit 486bde8372
4 changed files with 90 additions and 162 deletions

61
configure vendored
View File

@ -3995,36 +3995,40 @@ if [ ! -z "$QT_HOST_PREFIX" ]; then
#if defined(QT_BOOTSTRAPPED) || defined(QT_BUILD_QMAKE)
/* Installation Info */
static const char qt_configure_prefix_path_str [256 + 12] = "qt_prfxpath=$QT_HOST_PREFIX";
static const char qt_configure_documentation_path_str[256 + 12] = "qt_docspath=$QT_HOST_PREFIX/doc";
static const char qt_configure_headers_path_str [256 + 12] = "qt_hdrspath=$QT_HOST_PREFIX/include";
static const char qt_configure_libraries_path_str [256 + 12] = "qt_libspath=$QT_HOST_PREFIX/lib";
static const char qt_configure_binaries_path_str [256 + 12] = "qt_binspath=$QT_HOST_PREFIX/bin";
static const char qt_configure_plugins_path_str [256 + 12] = "qt_plugpath=$QT_HOST_PREFIX/plugins";
static const char qt_configure_imports_path_str [256 + 12] = "qt_impspath=$QT_HOST_PREFIX/IMPORTS";
static const char qt_configure_data_path_str [256 + 12] = "qt_datapath=$QT_HOST_PREFIX";
static const char qt_configure_translations_path_str [256 + 12] = "qt_trnspath=$QT_HOST_PREFIX/translations";
static const char qt_configure_prefix_path_strs[][256 + 12] = {
"qt_prfxpath=$QT_HOST_PREFIX",
"qt_docspath=$QT_HOST_PREFIX/doc",
"qt_hdrspath=$QT_HOST_PREFIX/include",
"qt_libspath=$QT_HOST_PREFIX/lib",
"qt_binspath=$QT_HOST_PREFIX/bin",
"qt_plugpath=$QT_HOST_PREFIX/plugins",
"qt_impspath=$QT_HOST_PREFIX/IMPORTS",
"qt_datapath=$QT_HOST_PREFIX",
"qt_trnspath=$QT_HOST_PREFIX/translations",
"qt_xmplpath=$QT_INSTALL_EXAMPLES",
"qt_tstspath=$QT_INSTALL_TESTS",
};
static const char qt_configure_settings_path_str[256 + 12] = "qt_stngpath=$QT_INSTALL_SETTINGS";
static const char qt_configure_examples_path_str [256 + 12] = "qt_xmplpath=$QT_INSTALL_EXAMPLES";
static const char qt_configure_tests_path_str [256 + 12] = "qt_tstspath=$QT_INSTALL_TESTS";
#else // QT_BOOTSTRAPPED
EOF
fi
cat >> "$outpath/src/corelib/global/qconfig.cpp.new" <<EOF
/* Installation Info */
static const char qt_configure_prefix_path_str [256 + 12] = "qt_prfxpath=$QT_INSTALL_PREFIX";
static const char qt_configure_documentation_path_str[256 + 12] = "qt_docspath=$QT_INSTALL_DOCS";
static const char qt_configure_headers_path_str [256 + 12] = "qt_hdrspath=$QT_INSTALL_HEADERS";
static const char qt_configure_libraries_path_str [256 + 12] = "qt_libspath=$QT_INSTALL_LIBS";
static const char qt_configure_binaries_path_str [256 + 12] = "qt_binspath=$QT_INSTALL_BINS";
static const char qt_configure_plugins_path_str [256 + 12] = "qt_plugpath=$QT_INSTALL_PLUGINS";
static const char qt_configure_imports_path_str [256 + 12] = "qt_impspath=$QT_INSTALL_IMPORTS";
static const char qt_configure_data_path_str [256 + 12] = "qt_datapath=$QT_INSTALL_DATA";
static const char qt_configure_translations_path_str [256 + 12] = "qt_trnspath=$QT_INSTALL_TRANSLATIONS";
static const char qt_configure_prefix_path_strs[][256 + 12] = {
"qt_prfxpath=$QT_INSTALL_PREFIX",
"qt_docspath=$QT_INSTALL_DOCS",
"qt_hdrspath=$QT_INSTALL_HEADERS",
"qt_libspath=$QT_INSTALL_LIBS",
"qt_binspath=$QT_INSTALL_BINS",
"qt_plugpath=$QT_INSTALL_PLUGINS",
"qt_impspath=$QT_INSTALL_IMPORTS",
"qt_datapath=$QT_INSTALL_DATA",
"qt_trnspath=$QT_INSTALL_TRANSLATIONS",
"qt_xmplpath=$QT_INSTALL_EXAMPLES",
"qt_tstspath=$QT_INSTALL_TESTS",
};
static const char qt_configure_settings_path_str[256 + 12] = "qt_stngpath=$QT_INSTALL_SETTINGS";
static const char qt_configure_examples_path_str [256 + 12] = "qt_xmplpath=$QT_INSTALL_EXAMPLES";
static const char qt_configure_tests_path_str [256 + 12] = "qt_tstspath=$QT_INSTALL_TESTS";
EOF
if [ ! -z "$QT_HOST_PREFIX" ]; then
@ -4035,21 +4039,12 @@ EOF
fi
cat >> "$outpath/src/corelib/global/qconfig.cpp.new" <<EOF
/* strlen( "qt_lcnsxxxx" ) == 12 */
#define QT_CONFIGURE_LICENSEE qt_configure_licensee_str + 12;
#define QT_CONFIGURE_LICENSED_PRODUCTS qt_configure_licensed_products_str + 12;
#define QT_CONFIGURE_PREFIX_PATH qt_configure_prefix_path_str + 12;
#define QT_CONFIGURE_DOCUMENTATION_PATH qt_configure_documentation_path_str + 12;
#define QT_CONFIGURE_HEADERS_PATH qt_configure_headers_path_str + 12;
#define QT_CONFIGURE_LIBRARIES_PATH qt_configure_libraries_path_str + 12;
#define QT_CONFIGURE_BINARIES_PATH qt_configure_binaries_path_str + 12;
#define QT_CONFIGURE_PLUGINS_PATH qt_configure_plugins_path_str + 12;
#define QT_CONFIGURE_IMPORTS_PATH qt_configure_imports_path_str + 12;
#define QT_CONFIGURE_DATA_PATH qt_configure_data_path_str + 12;
#define QT_CONFIGURE_TRANSLATIONS_PATH qt_configure_translations_path_str + 12;
#define QT_CONFIGURE_SETTINGS_PATH qt_configure_settings_path_str + 12;
#define QT_CONFIGURE_EXAMPLES_PATH qt_configure_examples_path_str + 12;
#define QT_CONFIGURE_TESTS_PATH qt_configure_tests_path_str + 12;
EOF
# avoid unecessary rebuilds by copying only if qconfig.cpp has changed

View File

@ -214,6 +214,22 @@ QLibraryInfo::isDebugBuild()
return false;
}
static const struct {
char key[14], value[13];
} qtConfEntries[] = {
{ "Prefix", "" },
{ "Documentation", "doc" },
{ "Headers", "include" },
{ "Libraries", "lib" },
{ "Binaries", "bin" },
{ "Plugins", "plugins" },
{ "Imports", "imports" },
{ "Data", "" },
{ "Translations", "translations" },
{ "Examples", "" },
{ "Tests", "tests" },
};
/*!
Returns the location specified by \a loc.
@ -225,102 +241,26 @@ QLibraryInfo::location(LibraryLocation loc)
QString ret;
if(!QLibraryInfoPrivate::configuration()) {
const char *path = 0;
switch (loc) {
case PrefixPath:
path = QT_CONFIGURE_PREFIX_PATH;
break;
case DocumentationPath:
path = QT_CONFIGURE_DOCUMENTATION_PATH;
break;
case HeadersPath:
path = QT_CONFIGURE_HEADERS_PATH;
break;
case LibrariesPath:
path = QT_CONFIGURE_LIBRARIES_PATH;
break;
case BinariesPath:
path = QT_CONFIGURE_BINARIES_PATH;
break;
case PluginsPath:
path = QT_CONFIGURE_PLUGINS_PATH;
break;
case ImportsPath:
path = QT_CONFIGURE_IMPORTS_PATH;
break;
case DataPath:
path = QT_CONFIGURE_DATA_PATH;
break;
case TranslationsPath:
path = QT_CONFIGURE_TRANSLATIONS_PATH;
break;
if (loc >= 0 && loc < sizeof(qt_configure_prefix_path_strs)/sizeof(qt_configure_prefix_path_strs[0]))
path = qt_configure_prefix_path_strs[loc] + 12;
#ifndef Q_OS_WIN // On Windows we use the registry
case SettingsPath:
else if (loc == SettingsPath)
path = QT_CONFIGURE_SETTINGS_PATH;
break;
#endif
case ExamplesPath:
path = QT_CONFIGURE_EXAMPLES_PATH;
break;
case TestsPath:
path = QT_CONFIGURE_TESTS_PATH;
break;
default:
break;
}
if (path)
ret = QString::fromLocal8Bit(path);
} else {
QString key;
QString defaultValue;
switch(loc) {
case PrefixPath:
key = QLatin1String("Prefix");
break;
case DocumentationPath:
key = QLatin1String("Documentation");
defaultValue = QLatin1String("doc");
break;
case HeadersPath:
key = QLatin1String("Headers");
defaultValue = QLatin1String("include");
break;
case LibrariesPath:
key = QLatin1String("Libraries");
defaultValue = QLatin1String("lib");
break;
case BinariesPath:
key = QLatin1String("Binaries");
defaultValue = QLatin1String("bin");
break;
case PluginsPath:
key = QLatin1String("Plugins");
defaultValue = QLatin1String("plugins");
break;
case ImportsPath:
key = QLatin1String("Imports");
defaultValue = QLatin1String("imports");
break;
case DataPath:
key = QLatin1String("Data");
break;
case TranslationsPath:
key = QLatin1String("Translations");
defaultValue = QLatin1String("translations");
break;
case SettingsPath:
key = QLatin1String("Settings");
break;
case ExamplesPath:
key = QLatin1String("Examples");
break;
case TestsPath:
key = QLatin1String("Tests");
defaultValue = QLatin1String("tests");
break;
default:
break;
if (loc >= 0 && loc < sizeof(qtConfEntries)/sizeof(qtConfEntries[0])) {
key = QLatin1String(qtConfEntries[loc].key);
defaultValue = QLatin1String(qtConfEntries[loc].value);
}
#ifndef Q_OS_WIN // On Windows we use the registry
else if (loc == SettingsPath)
key = QLatin1String("Settings");
#endif
if(!key.isNull()) {
QSettings *config = QLibraryInfoPrivate::configuration();
@ -391,9 +331,9 @@ QLibraryInfo::location(LibraryLocation loc)
\value ImportsPath The location of installed QML extensions to import.
\value DataPath The location of general Qt data.
\value TranslationsPath The location of translation information for Qt strings.
\value SettingsPath The location for Qt settings.
\value ExamplesPath The location for examples upon install.
\value TestsPath The location of installed Qt testcases.
\value SettingsPath The location for Qt settings. Not applicable on Windows.
\sa location()
*/
@ -421,9 +361,9 @@ void qt_core_boilerplate()
"Library path: %s\n"
"Include path: %s\n",
qt_configure_installation + 12,
qt_configure_prefix_path_str + 12,
qt_configure_libraries_path_str + 12,
qt_configure_headers_path_str + 12);
qt_configure_prefix_path_strs[QT_PREPEND_NAMESPACE(QLibraryInfo)::PrefixPath] + 12,
qt_configure_prefix_path_strs[QT_PREPEND_NAMESPACE(QLibraryInfo)::LibrariesPath] + 12,
qt_configure_prefix_path_strs[QT_PREPEND_NAMESPACE(QLibraryInfo)::HeadersPath] + 12);
QT_PREPEND_NAMESPACE(qDumpCPUFeatures)();

View File

@ -66,18 +66,18 @@ public:
enum LibraryLocation
{
PrefixPath,
PrefixPath = 0,
DocumentationPath,
HeadersPath,
LibrariesPath,
BinariesPath,
PluginsPath,
ImportsPath,
DataPath,
TranslationsPath,
SettingsPath,
ExamplesPath,
ImportsPath,
TestsPath
TestsPath,
SettingsPath = 100
};
static QString location(LibraryLocation); // ### Qt 5: consider renaming it to path()

View File

@ -2857,48 +2857,41 @@ void Configure::generateConfigfiles()
<< endl;
if (!dictionary[ "QT_HOST_PREFIX" ].isNull())
tmpStream << "#if !defined(QT_BOOTSTRAPPED) && !defined(QT_BUILD_QMAKE)" << endl;
tmpStream << "static const char qt_configure_prefix_path_str [512 + 12] = \"qt_prfxpath=" << escapeSeparators(dictionary["QT_INSTALL_PREFIX"]) << "\";" << endl
<< "static const char qt_configure_documentation_path_str[512 + 12] = \"qt_docspath=" << escapeSeparators(dictionary["QT_INSTALL_DOCS"]) << "\";" << endl
<< "static const char qt_configure_headers_path_str [512 + 12] = \"qt_hdrspath=" << escapeSeparators(dictionary["QT_INSTALL_HEADERS"]) << "\";" << endl
<< "static const char qt_configure_libraries_path_str [512 + 12] = \"qt_libspath=" << escapeSeparators(dictionary["QT_INSTALL_LIBS"]) << "\";" << endl
<< "static const char qt_configure_binaries_path_str [512 + 12] = \"qt_binspath=" << escapeSeparators(dictionary["QT_INSTALL_BINS"]) << "\";" << endl
<< "static const char qt_configure_plugins_path_str [512 + 12] = \"qt_plugpath=" << escapeSeparators(dictionary["QT_INSTALL_PLUGINS"]) << "\";" << endl
<< "static const char qt_configure_imports_path_str [512 + 12] = \"qt_impspath=" << escapeSeparators(dictionary["QT_INSTALL_IMPORTS"]) << "\";" << endl
<< "static const char qt_configure_data_path_str [512 + 12] = \"qt_datapath=" << escapeSeparators(dictionary["QT_INSTALL_DATA"]) << "\";" << endl
<< "static const char qt_configure_translations_path_str [512 + 12] = \"qt_trnspath=" << escapeSeparators(dictionary["QT_INSTALL_TRANSLATIONS"]) << "\";" << endl
<< "static const char qt_configure_examples_path_str [512 + 12] = \"qt_xmplpath=" << escapeSeparators(dictionary["QT_INSTALL_EXAMPLES"]) << "\";" << endl
<< "static const char qt_configure_tests_path_str [512 + 12] = \"qt_tstspath=" << escapeSeparators(dictionary["QT_INSTALL_TESTS"]) << "\";" << endl
tmpStream << "static const char qt_configure_prefix_path_strs[][12 + 512] = {" << endl
<< " \"qt_prfxpath=" << escapeSeparators(dictionary["QT_INSTALL_PREFIX"]) << "\"," << endl
<< " \"qt_docspath=" << escapeSeparators(dictionary["QT_INSTALL_DOCS"]) << "\"," << endl
<< " \"qt_hdrspath=" << escapeSeparators(dictionary["QT_INSTALL_HEADERS"]) << "\"," << endl
<< " \"qt_libspath=" << escapeSeparators(dictionary["QT_INSTALL_LIBS"]) << "\"," << endl
<< " \"qt_binspath=" << escapeSeparators(dictionary["QT_INSTALL_BINS"]) << "\"," << endl
<< " \"qt_plugpath=" << escapeSeparators(dictionary["QT_INSTALL_PLUGINS"]) << "\"," << endl
<< " \"qt_impspath=" << escapeSeparators(dictionary["QT_INSTALL_IMPORTS"]) << "\"," << endl
<< " \"qt_datapath=" << escapeSeparators(dictionary["QT_INSTALL_DATA"]) << "\"," << endl
<< " \"qt_trnspath=" << escapeSeparators(dictionary["QT_INSTALL_TRANSLATIONS"]) << "\"," << endl
<< " \"qt_xmplpath=" << escapeSeparators(dictionary["QT_INSTALL_EXAMPLES"]) << "\"," << endl
<< " \"qt_tstspath=" << escapeSeparators(dictionary["QT_INSTALL_TESTS"]) << "\"," << endl
<< "};" << endl
//<< "static const char qt_configure_settings_path_str [256] = \"qt_stngpath=" << escapeSeparators(dictionary["QT_INSTALL_SETTINGS"]) << "\";" << endl
;
if (!dictionary[ "QT_HOST_PREFIX" ].isNull()) {
tmpStream << "#else" << endl
<< "static const char qt_configure_prefix_path_str [512 + 12] = \"qt_prfxpath=" << escapeSeparators(dictionary[ "QT_HOST_PREFIX" ]) << "\";" << endl
<< "static const char qt_configure_documentation_path_str[512 + 12] = \"qt_docspath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/doc", true) <<"\";" << endl
<< "static const char qt_configure_headers_path_str [512 + 12] = \"qt_hdrspath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/include", true) <<"\";" << endl
<< "static const char qt_configure_libraries_path_str [512 + 12] = \"qt_libspath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/lib", true) <<"\";" << endl
<< "static const char qt_configure_binaries_path_str [512 + 12] = \"qt_binspath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/bin", true) <<"\";" << endl
<< "static const char qt_configure_plugins_path_str [512 + 12] = \"qt_plugpath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/plugins", true) <<"\";" << endl
<< "static const char qt_configure_imports_path_str [512 + 12] = \"qt_impspath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/imports", true) <<"\";" << endl
<< "static const char qt_configure_data_path_str [512 + 12] = \"qt_datapath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ], true) <<"\";" << endl
<< "static const char qt_configure_translations_path_str [512 + 12] = \"qt_trnspath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/translations", true) <<"\";" << endl
<< "static const char qt_configure_examples_path_str [512 + 12] = \"qt_xmplpath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/example", true) <<"\";" << endl
<< "static const char qt_configure_tests_path_str [512 + 12] = \"qt_tstspath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/tests", true) <<"\";" << endl
<< "static const char qt_configure_prefix_path_strs[][12 + 512] = {" << endl
<< " \"qt_prfxpath=" << escapeSeparators(dictionary[ "QT_HOST_PREFIX" ]) << "\";" << endl
<< " \"qt_docspath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/doc", true) <<"\"," << endl
<< " \"qt_hdrspath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/include", true) <<"\"," << endl
<< " \"qt_libspath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/lib", true) <<"\"," << endl
<< " \"qt_binspath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/bin", true) <<"\"," << endl
<< " \"qt_plugpath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/plugins", true) <<"\"," << endl
<< " \"qt_impspath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/imports", true) <<"\"," << endl
<< " \"qt_datapath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ], true) <<"\"," << endl
<< " \"qt_trnspath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/translations", true) <<"\"," << endl
<< " \"qt_xmplpath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/example", true) <<"\"," << endl
<< " \"qt_tstspath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/tests", true) <<"\"," << endl
<< "};" << endl
<< "#endif //QT_BOOTSTRAPPED" << endl;
}
tmpStream << "/* strlen( \"qt_lcnsxxxx\") == 12 */" << endl
<< "#define QT_CONFIGURE_LICENSEE qt_configure_licensee_str + 12;" << endl
<< "#define QT_CONFIGURE_LICENSED_PRODUCTS qt_configure_licensed_products_str + 12;" << endl
<< "#define QT_CONFIGURE_PREFIX_PATH qt_configure_prefix_path_str + 12;" << endl
<< "#define QT_CONFIGURE_DOCUMENTATION_PATH qt_configure_documentation_path_str + 12;" << endl
<< "#define QT_CONFIGURE_HEADERS_PATH qt_configure_headers_path_str + 12;" << endl
<< "#define QT_CONFIGURE_LIBRARIES_PATH qt_configure_libraries_path_str + 12;" << endl
<< "#define QT_CONFIGURE_BINARIES_PATH qt_configure_binaries_path_str + 12;" << endl
<< "#define QT_CONFIGURE_PLUGINS_PATH qt_configure_plugins_path_str + 12;" << endl
<< "#define QT_CONFIGURE_IMPORTS_PATH qt_configure_imports_path_str + 12;" << endl
<< "#define QT_CONFIGURE_DATA_PATH qt_configure_data_path_str + 12;" << endl
<< "#define QT_CONFIGURE_TRANSLATIONS_PATH qt_configure_translations_path_str + 12;" << endl
<< "#define QT_CONFIGURE_EXAMPLES_PATH qt_configure_examples_path_str + 12;" << endl
<< "#define QT_CONFIGURE_TESTS_PATH qt_configure_tests_path_str + 12;" << endl
//<< "#define QT_CONFIGURE_SETTINGS_PATH qt_configure_settings_path_str + 12;" << endl
<< endl;