Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
feat: Linux 适配
Browse files Browse the repository at this point in the history
  • Loading branch information
SHIINASAMA committed Mar 20, 2023
1 parent 92bfe2b commit 94d593b
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
.vscode
.idea
cmake-*
build
.cache

# Prerequisites
*.d

Expand Down
44 changes: 43 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,4 +29,42 @@ target_sources(
option(SESE_PLUGIN_BUILD_TEST OFF)
if (SESE_PLUGIN_BUILD_TEST)
add_subdirectory(test)
endif ()
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::
)
4 changes: 4 additions & 0 deletions cmake/SesePluginConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/SesePluginTargets.cmake")
check_required_components("@PROJECT_NAME@")
1 change: 1 addition & 0 deletions include/sese/plugin/BaseClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <memory>

namespace sese::plugin {
/// 模块基类
class BaseClass : public std::enable_shared_from_this<BaseClass> {
public:
using Ptr = std::shared_ptr<BaseClass>;
Expand Down
15 changes: 15 additions & 0 deletions include/sese/plugin/BaseClassFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include "sese/plugin/BaseClass.h"

#include <string>

namespace sese::plugin {
/// 类工厂基类
class BaseClassFactory {
public:
/// 创建某个已注册类的实例
/// \param id 类注册名
virtual BaseClass::Ptr createClassWithId(const std::string &id) noexcept = 0;
};
}// namespace sese::plugin
8 changes: 4 additions & 4 deletions include/sese/plugin/ClassFactory.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#pragma once

#include "sese/plugin/BaseClass.h"
#include "sese/plugin/BaseClassFactory.h"

#include <string>
#include <functional>
#include <initializer_list>
#include <unordered_map>

namespace sese::plugin {
class ClassFactory {
/// 类工厂内建实现
class ClassFactory : public BaseClassFactory {
public:
using InitListType = std::pair<std::string, std::function<std::shared_ptr<BaseClass>()>>;
using MapType = std::unordered_map<std::string, std::function<std::shared_ptr<BaseClass>()>>;
Expand All @@ -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<typename Class>
std::shared_ptr<Class> createClassWithIdAs(const std::string &id) noexcept {
Expand Down
4 changes: 2 additions & 2 deletions include/sese/plugin/Marco.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
}
Expand All @@ -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; \
}
10 changes: 7 additions & 3 deletions include/sese/plugin/ModuleInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 94d593b

Please # to comment.