Fix loading of the dbus-1 DLL built by MinGW on Windows

QLibrary does not append the version suffix on Windows by itself, since
there's no established practice on how to do this. The MinGW builds of
dbus-1 call it "libdbus-1-3.dll", so we need append the suffix
ourselves.

Unfortunately, other names like "dbus-1.dll" have been seen in the wild,
so we need to try both basenames (Windows doesn't prepend the "lib"
prefix). Both basenames work on Unix, so give "libdbus-1" on Unix since
that will result in one fewer stat.

Change-Id: I92506df5fd30c7674216568406bf86b25bf646b8
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
This commit is contained in:
Thiago Macieira 2014-12-11 13:43:14 -08:00
parent d1d3c36e87
commit cfab934186

View File

@ -84,14 +84,29 @@ bool qdbus_loadLibDBus()
triedToLoadLibrary = true;
static int majorversions[] = { 3, 2, -1 };
lib->unload();
lib->setFileName(QLatin1String("dbus-1"));
for (uint i = 0; i < sizeof(majorversions) / sizeof(majorversions[0]); ++i) {
lib->setFileNameAndVersion(lib->fileName(), majorversions[i]);
if (lib->load() && lib->resolve("dbus_connection_open_private"))
return true;
const QString baseNames[] = {
#ifdef Q_OS_WIN
QStringLiteral("dbus-1"),
#endif
QStringLiteral("libdbus-1")
};
lib->unload();
lib->unload();
for (uint i = 0; i < sizeof(majorversions) / sizeof(majorversions[0]); ++i) {
for (uint j = 0; j < sizeof(baseNames) / sizeof(baseNames[0]); ++j) {
#ifdef Q_OS_WIN
QString suffix;
if (majorversions[i] != -1)
suffix = QString::number(- majorversions[i]); // negative so it prepends the dash
lib->setFileName(baseNames[j] + suffix);
#else
lib->setFileNameAndVersion(baseNames[j], majorversions[i]);
#endif
if (lib->load() && lib->resolve("dbus_connection_open_private"))
return true;
lib->unload();
}
}
delete lib;