Skip to content

Commit

Permalink
GeneratorRunner looks for loadable generator modules in many places.
Browse files Browse the repository at this point in the history
Besides loading generator modules given as full file paths, and placed
in the place where GeneratorRunner was installed, the modules are also
looked for in paths added via QT_PLUGIN_PATH.
  • Loading branch information
Marcelo Lira committed Jan 25, 2011
1 parent b3daa9b commit b5e32ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
3 changes: 3 additions & 0 deletions generatorrunnerconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
// generatorrunner plugin dir
#define GENERATORRUNNER_PLUGIN_DIR "@generator_plugin_DIR@"

// module extension
#define MODULE_EXTENSION "@CMAKE_SHARED_LIBRARY_SUFFIX@"

#endif
25 changes: 20 additions & 5 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,30 @@ int main(int argc, char *argv[])
if (!generatorSet.isEmpty()) {
QFileInfo generatorFile(generatorSet);

if (generatorFile.baseName() == generatorSet)
generatorFile.setFile(QDir(GENERATORRUNNER_PLUGIN_DIR), generatorSet + "_generator");
if (!generatorFile.exists()) {
QString generatorSetName(generatorSet + "_generator" + MODULE_EXTENSION);

// More library paths may be added via the QT_PLUGIN_PATH environment variable.
QCoreApplication::addLibraryPath(GENERATORRUNNER_PLUGIN_DIR);
foreach (const QString& path, QCoreApplication::libraryPaths()) {
generatorFile.setFile(QDir(path), generatorSetName);
if (generatorFile.exists())
break;
}
}

if (!generatorFile.exists()) {
std::cerr << argv[0] << ": Error loading generator-set plugin: ";
std::cerr << qPrintable(generatorFile.baseName()) << " module not found." << std::endl;
return EXIT_FAILURE;
}

QLibrary plugin(generatorFile.filePath());
getGeneratorsFunc getGenerators = (getGeneratorsFunc)plugin.resolve("getGenerators");
if (getGenerators)
if (getGenerators) {
getGenerators(&generators);
else {
std::cerr << argv[0] << ": Error loading generatorset plugin: " << qPrintable(plugin.errorString()) << std::endl;
} else {
std::cerr << argv[0] << ": Error loading generator-set plugin: " << qPrintable(plugin.errorString()) << std::endl;
return EXIT_FAILURE;
}
} else if (!args.contains("help")) {
Expand Down

0 comments on commit b5e32ea

Please sign in to comment.