diff --git a/.gitignore b/.gitignore index 259148f..03db9fd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ +.vscode +.idea +cmake-* +build +.cache + # Prerequisites *.d diff --git a/CMakeLists.txt b/CMakeLists.txt index d3afcab..e356bea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,10 @@ if (WIN32) target_compile_options(Plugin PRIVATE /utf-8) endif () +if (CMAKE_SYSTEM_NAME MATCHES "Linux") + target_compile_options(Plugin PRIVATE -fPIC) +endif() + target_include_directories( Plugin PUBLIC @@ -25,4 +29,42 @@ target_sources( option(SESE_PLUGIN_BUILD_TEST OFF) if (SESE_PLUGIN_BUILD_TEST) add_subdirectory(test) -endif () \ No newline at end of file +endif () + +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) +configure_package_config_file( + ${PROJECT_SOURCE_DIR}/cmake/SesePluginConfig.cmake.in + ${PROJECT_BINARY_DIR}/SesePluginConfig.cmake + INSTALL_DESTINATION lib/cmake/sese.plugin +) + +install( + TARGETS Plugin + EXPORT SesePluginTargets + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + PUBLIC_HEADER DESTINATION include +) + +install( + DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/include/sese" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" +) + +install( + FILES "${PROJECT_BINARY_DIR}/SesePluginConfig.cmake" + DESTINATION lib/cmake/sese +) + +install( + FILES "${PROJECT_BINARY_DIR}/SesePluginConfig.cmake" + DESTINATION debug/lib/cmake/sese +) + +install( + EXPORT SesePluginTargets + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/sese.plugin + NAMESPACE Sese:: +) \ No newline at end of file diff --git a/cmake/SesePluginConfig.cmake.in b/cmake/SesePluginConfig.cmake.in new file mode 100644 index 0000000..7d51118 --- /dev/null +++ b/cmake/SesePluginConfig.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/SesePluginTargets.cmake") +check_required_components("@PROJECT_NAME@") \ No newline at end of file diff --git a/include/sese/plugin/BaseClass.h b/include/sese/plugin/BaseClass.h index 91c7577..2bca073 100644 --- a/include/sese/plugin/BaseClass.h +++ b/include/sese/plugin/BaseClass.h @@ -3,6 +3,7 @@ #include namespace sese::plugin { + /// 模块基类 class BaseClass : public std::enable_shared_from_this { public: using Ptr = std::shared_ptr; diff --git a/include/sese/plugin/BaseClassFactory.h b/include/sese/plugin/BaseClassFactory.h new file mode 100644 index 0000000..bff1618 --- /dev/null +++ b/include/sese/plugin/BaseClassFactory.h @@ -0,0 +1,15 @@ +#pragma once + +#include "sese/plugin/BaseClass.h" + +#include + +namespace sese::plugin { + /// 类工厂基类 + class BaseClassFactory { + public: + /// 创建某个已注册类的实例 + /// \param id 类注册名 + virtual BaseClass::Ptr createClassWithId(const std::string &id) noexcept = 0; + }; +}// namespace sese::plugin \ No newline at end of file diff --git a/include/sese/plugin/ClassFactory.h b/include/sese/plugin/ClassFactory.h index 6941fe0..aa51887 100644 --- a/include/sese/plugin/ClassFactory.h +++ b/include/sese/plugin/ClassFactory.h @@ -1,14 +1,14 @@ #pragma once -#include "sese/plugin/BaseClass.h" +#include "sese/plugin/BaseClassFactory.h" -#include #include #include #include namespace sese::plugin { - class ClassFactory { + /// 类工厂内建实现 + class ClassFactory : public BaseClassFactory { public: using InitListType = std::pair()>>; using MapType = std::unordered_map()>>; @@ -17,7 +17,7 @@ namespace sese::plugin { ClassFactory(ClassFactory &&classFactory) = delete; ClassFactory(const ClassFactory &classFactory) = delete; - BaseClass::Ptr createClassWithId(const std::string &id) noexcept; + BaseClass::Ptr createClassWithId(const std::string &id) noexcept override; template std::shared_ptr createClassWithIdAs(const std::string &id) noexcept { diff --git a/include/sese/plugin/Marco.h b/include/sese/plugin/Marco.h index 870c506..4b60645 100644 --- a/include/sese/plugin/Marco.h +++ b/include/sese/plugin/Marco.h @@ -9,7 +9,7 @@ #endif #define DEFINE_MODULE_INFO(name, version, description) \ - SESE_EXTERN sese::plugin::ModuleInfo *getModuleInfo() { \ + SESE_EXTERN sese::plugin::ModuleInfo *getModuleInfo() { \ static sese::plugin::ModuleInfo info{name, version, description}; \ return &info; \ } @@ -22,7 +22,7 @@ } #define DEFINE_CLASS_FACTORY(...) \ - SESE_EXTERN sese::plugin::ClassFactory *getFactory() { \ + SESE_EXTERN sese::plugin::BaseClassFactory *getFactory() { \ static sese::plugin::ClassFactory factory({__VA_ARGS__}); \ return &factory; \ } \ No newline at end of file diff --git a/include/sese/plugin/ModuleInfo.h b/include/sese/plugin/ModuleInfo.h index 071cc82..c25a445 100644 --- a/include/sese/plugin/ModuleInfo.h +++ b/include/sese/plugin/ModuleInfo.h @@ -3,9 +3,13 @@ #include "sese/plugin/ClassFactory.h" namespace sese::plugin { + /// 模块基础信息 struct ModuleInfo { - const char *moduleName; - const char *versionString; - const char *description; + /// 模块名称 + const char *moduleName = nullptr; + /// 模块版本 + const char *versionString = nullptr; + /// 模块描述 + const char *description = nullptr; }; }// namespace sese::plugin