From 01bd3d1da0d065337e2b7f0d72e36115256b41a5 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 11 Mar 2022 05:52:26 -0500 Subject: [PATCH] add functionality to auto-load plugins --- src/PLUGIN/plugin.cpp | 18 ++++++++++++++---- src/PLUGIN/plugin.h | 1 + src/lammps.cpp | 5 +++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/PLUGIN/plugin.cpp b/src/PLUGIN/plugin.cpp index 33a252c39e..b89b042ed7 100644 --- a/src/PLUGIN/plugin.cpp +++ b/src/PLUGIN/plugin.cpp @@ -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 } diff --git a/src/PLUGIN/plugin.h b/src/PLUGIN/plugin.h index cc1a3bf2dc..483aa451a4 100644 --- a/src/PLUGIN/plugin.h +++ b/src/PLUGIN/plugin.h @@ -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 *); diff --git a/src/lammps.cpp b/src/lammps.cpp index e6ff6efb23..c74983be43 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -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 } /* ----------------------------------------------------------------------