add functionality to auto-load plugins

This commit is contained in:
Axel Kohlmeyer
2022-03-11 05:52:26 -05:00
parent 9b989b1860
commit 01bd3d1da0
3 changed files with 20 additions and 4 deletions

View File

@ -67,10 +67,20 @@ void Plugin::command(int narg, char **arg)
}
} else
error->all(FLERR, "Illegal plugin command");
#if 0
if (comm->me == 0)
error->warning(
FLERR, "LAMMPS must be built as a shared library for it to work.");
}
// auto-load DSOs from designated folder(s)
void plugin_auto_load(LAMMPS *lmp)
{
#if defined(LMP_PLUGIN)
for (const auto &plugin_dir : platform::list_pathenv("LAMMPS_PLUGIN_PATH")) {
if (lmp->comm->me == 0)
utils::logmesg(lmp, "Looking for LAMMPS plugins in: {}\n", plugin_dir);
for (const auto &file : platform::list_directory(plugin_dir)) {
if (utils::strmatch(file, "\\plugin.so$"))
plugin_load(platform::path_join(plugin_dir, file).c_str(), lmp);
}
}
#endif
}

View File

@ -31,6 +31,7 @@ class Plugin : public Command {
void command(int, char **) override;
};
void plugin_auto_load(LAMMPS *);
void plugin_load(const char *, LAMMPS *);
void plugin_register(lammpsplugin_t *, void *);

View File

@ -824,6 +824,11 @@ void LAMMPS::create()
timer = new Timer(this);
python = new Python(this);
// auto-load plugins
#if defined(LMP_PLUGIN)
plugin_auto_load(this);
#endif
}
/* ----------------------------------------------------------------------