add the boilerplate

This commit is contained in:
Green Sky 2024-05-17 22:18:41 +02:00
commit 7dfbab2d13
No known key found for this signature in database
8 changed files with 239 additions and 0 deletions

26
.gitignore vendored Normal file
View File

@ -0,0 +1,26 @@
.vs/
*.o
*.swp
~*
*~
.idea/
cmake-build-debug/
cmake-build-debugandtest/
cmake-build-release/
*.stackdump
*.coredump
compile_commands.json
/build*
/result*
.clangd
.cache
.DS_Store
.AppleDouble
.LSOverride
CMakeLists.txt.user*
CMakeCache.txt
*.tox
imgui.ini

72
CMakeLists.txt Normal file
View File

@ -0,0 +1,72 @@
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
# cmake setup begin
project(solanaceae_message_n10n)
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(SOLANACEAE_MESSAGE_N10N_STANDALONE ON)
else()
set(SOLANACEAE_MESSAGE_N10N_STANDALONE OFF)
endif()
message("II SOLANACEAE_MESSAGE_N10N_STANDALONE " ${SOLANACEAE_MESSAGE_N10N_STANDALONE})
option(SOLANACEAE_MESSAGE_N10N_BUILD_PLUGINS "Build the message_n10n plugins" ${SOLANACEAE_MESSAGE_N10N_STANDALONE})
if (SOLANACEAE_MESSAGE_N10N_STANDALONE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# defaulting to debug mode, if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()
# setup my vim ycm :D
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# more paths
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
endif()
# external libs
add_subdirectory(./external EXCLUDE_FROM_ALL) # before increasing warn levels, sad :(
if (SOLANACEAE_MESSAGE_N10N_STANDALONE)
set(CMAKE_CXX_EXTENSIONS OFF)
# bump up warning levels appropriately for clang, gcc & msvc
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
add_compile_options(
-Wall -Wextra # Reasonable and standard
-Wpedantic # Warn if non-standard C++ is used
-Wunused # Warn on anything being unused
#-Wconversion # Warn on type conversions that may lose data
#-Wsign-conversion # Warn on sign conversions
-Wshadow # Warn if a variable declaration shadows one from a parent context
)
if (NOT WIN32)
#link_libraries(-fsanitize=address)
#link_libraries(-fsanitize=address,undefined)
#link_libraries(-fsanitize-address-use-after-scope)
#link_libraries(-fsanitize=undefined)
endif()
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
if (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
endif()
endif()
# cmake setup end
add_subdirectory(./src)
if (SOLANACEAE_MESSAGE_N10N_BUILD_PLUGINS)
add_subdirectory(./plugins)
endif()

22
external/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
include(FetchContent)
if (NOT TARGET solanaceae_message3)
FetchContent_Declare(solanaceae_message3
GIT_REPOSITORY https://github.com/Green-Sky/solanaceae_message3.git
GIT_TAG master
EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable(solanaceae_message3)
endif()
if (NOT TARGET solanaceae_plugin)
FetchContent_Declare(solanaceae_plugin
GIT_REPOSITORY https://github.com/Green-Sky/solanaceae_plugin.git
GIT_TAG master
EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable(solanaceae_plugin)
endif()

11
plugins/CMakeLists.txt Normal file
View File

@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.9...3.24 FATAL_ERROR)
add_library(plugin_message_n10n SHARED
./plugin_message_n10n.cpp
)
target_link_libraries(plugin_message_n10n PUBLIC
solanaceae_plugin
solanaceae_message_n10n
)

View File

@ -0,0 +1,58 @@
#include <solanaceae/plugin/solana_plugin_v1.h>
#include "message_n10n.hpp"
#include <iostream>
static std::unique_ptr<MessageN10n> g_mn10n = nullptr;
constexpr const char* plugin_name = "MessageN10n";
extern "C" {
SOLANA_PLUGIN_EXPORT const char* solana_plugin_get_name(void) {
return plugin_name;
}
SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_get_version(void) {
return SOLANA_PLUGIN_VERSION;
}
SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api) {
std::cout << "PLUGIN " << plugin_name << " START()\n";
if (solana_api == nullptr) {
return 1;
}
try {
//auto* cr = PLUG_RESOLVE_INSTANCE_VERSIONED(Contact3Registry, "1");
auto* rmm = PLUG_RESOLVE_INSTANCE(RegistryMessageModel);
// static store, could be anywhere tho
// construct with fetched dependencies
g_mn10n = std::make_unique<MessageN10n>(*rmm);
// register types
PLUG_PROVIDE_INSTANCE(MessageN10n, plugin_name, g_mn10n.get());
} catch (const ResolveException& e) {
std::cerr << "PLUGIN " << plugin_name << " " << e.what << "\n";
return 2;
}
return 0;
}
SOLANA_PLUGIN_EXPORT void solana_plugin_stop(void) {
std::cout << "PLUGIN " << plugin_name << " STOP()\n";
g_mn10n.reset();
}
SOLANA_PLUGIN_EXPORT float solana_plugin_tick(float) {
//return g_rpbot->tick(delta);
return 1000.f;
}
} // extern C

17
src/CMakeLists.txt Normal file
View File

@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.9...3.24 FATAL_ERROR)
project(solanaceae)
add_library(solanaceae_message_n10n
./message_n10n.hpp
./message_n10n.cpp
)
target_include_directories(solanaceae_message_n10n PUBLIC .)
target_compile_features(solanaceae_message_n10n PUBLIC cxx_std_17)
target_link_libraries(solanaceae_message_n10n PUBLIC
solanaceae_message3
)
########################################

18
src/message_n10n.cpp Normal file
View File

@ -0,0 +1,18 @@
#include "./message_n10n.hpp"
#include <solanaceae/message3/components.hpp>
MessageN10n::MessageN10n(RegistryMessageModel& rmm) : _rmm(rmm) {
}
MessageN10n::~MessageN10n(void) {
}
bool MessageN10n::onEvent(const Message::Events::MessageConstruct& e) {
if (!e.e.all_of<Message::Components::MessageText>()) {
return false;
}
return false;
}

15
src/message_n10n.hpp Normal file
View File

@ -0,0 +1,15 @@
#pragma once
#include <solanaceae/message3/registry_message_model.hpp>
class MessageN10n : public RegistryMessageModelEventI {
RegistryMessageModel& _rmm;
public:
MessageN10n(RegistryMessageModel& rmm);
virtual ~MessageN10n(void);
protected: // rmm
bool onEvent(const Message::Events::MessageConstruct& e) override;
};