diff --git a/CMakeLists.txt b/CMakeLists.txt index da8d5d76..8a77f1aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,6 +58,9 @@ option(XEUS_CPP_USE_SHARED_XEUS "Link xcpp with the xeus shared library (instea option(XEUS_CPP_USE_SHARED_XEUS_CPP "Link xcpp with the xeus shared library (instead of the static library)" ON) option(XEUS_CPP_EMSCRIPTEN_WASM_BUILD "Build for wasm with emscripten" OFF) +# Plugin system option +option(XEUS_CPP_XPLUGIN "Enable xplugin integration" OFF) + # Test options option(XEUS_CPP_BUILD_TESTS "xeus-cpp test suite" ON) option(XEUS_CPP_ENABLE_CODE_COVERAGE "xeus-cpp test suite" OFF) @@ -108,6 +111,15 @@ endif() find_package(argparse REQUIRED) find_package(pugixml REQUIRED) +if(XEUS_CPP_XPLUGIN) + message(STATUS "xplugin integration is enabled.") + + # Find the xplugin library + find_package(xplugin REQUIRED) +else() + message(STATUS "xplugin integration is disabled.") +endif() + # Configuration # ============= @@ -367,6 +379,17 @@ macro(xeus_cpp_create_target target_name linkage output_name) target_link_libraries(${target_name} PUBLIC ${XEUS_CPP_XEUS_TARGET} clangCppInterOp pugixml argparse::argparse) endif() + if(XEUS_CPP_XPLUGIN) + # Add xplugin include directories + target_include_directories(${target_name} PRIVATE ${xplugin_INCLUDE_DIRS}) + + # Link the xplugin library + target_link_libraries(${target_name} PRIVATE xplugin) + + # Define a macro to enable plugin-related code + target_compile_definitions(${target_name} PRIVATE XEUS_CPP_XPLUGIN) + endif() + if (WIN32 OR CYGWIN) # elseif (APPLE) diff --git a/src/xinterpreter.cpp b/src/xinterpreter.cpp index 85aa07b1..6fc38944 100644 --- a/src/xinterpreter.cpp +++ b/src/xinterpreter.cpp @@ -24,6 +24,14 @@ #include "xparser.hpp" #include "xsystem.hpp" +#ifdef XEUS_CPP_XPLUGIN +#include "xplugin/xplugin_registry.hpp" +#include "xplugin/xfactory.hpp" +#include "xplugin/xshared_library.hpp" +#include "xplugin/xmagics.hpp" +#include "xplugin/os.hpp" +#endif + using Args = std::vector; void* createInterpreter(const Args &ExtraArgs = {}) { @@ -114,6 +122,18 @@ __get_cxx_version () redirect_output(); init_preamble(); init_magic(); + +#ifdef XEUS_CPP_XPLUGIN + // Initialize the xplugin registry + using base_type = plugin::PluginBase; + using factory_base_type = xp::xfactory_base; + using plugin_registry_type = xp::xplugin_registry; + + m_plugin_registry = std::make_unique(); + + // Load plugins from a directory + m_plugin_registry->load_plugins("/path/to/plugins"); +#endif } interpreter::~interpreter() @@ -367,14 +387,19 @@ __get_cxx_version () void interpreter::init_magic() { - // preamble_manager["magics"].get_cast().register_magic("executable", +// preamble_manager["magics"].get_cast().register_magic("executable", // executable(m_interpreter)); // preamble_manager["magics"].get_cast().register_magic("timeit", // timeit(&m_interpreter)); // preamble_manager["magics"].get_cast().register_magic("python", pythonexec()); preamble_manager["magics"].get_cast().register_magic("file", writefile()); + #ifndef EMSCRIPTEN preamble_manager["magics"].get_cast().register_magic("xassist", xassist()); +#endif + +#ifdef XEUS_CPP_XPLUGIN +preamble_manager["magics"].get_cast().register_magic("file", xp::writefile()); #endif } }