Skip to content

Commit

Permalink
build: Streamline definition on plugin features
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Jul 8, 2024
1 parent 39f0153 commit 03d344c
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 51 deletions.
21 changes: 17 additions & 4 deletions cmake/modules/ImHexPlugin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,23 @@ macro(add_imhex_plugin)
add_subdirectory(${IMHEX_BASE_FOLDER}/lib/external/libromfs ${CMAKE_CURRENT_BINARY_DIR}/libromfs)
target_link_libraries(${IMHEX_PLUGIN_NAME} PRIVATE ${LIBROMFS_LIBRARY})

foreach(feature ${IMHEX_PLUGIN_FEATURES})
string(TOUPPER ${feature} feature)
add_definitions(-DIMHEX_PLUGIN_${IMHEX_PLUGIN_NAME}_FEATURE_${feature}=0)
endforeach()
set(FEATURE_DEFINE_CONTENT)

if (IMHEX_PLUGIN_FEATURES)
list(LENGTH IMHEX_PLUGIN_FEATURES IMHEX_FEATURE_COUNT)
math(EXPR IMHEX_FEATURE_COUNT "${IMHEX_FEATURE_COUNT} - 1" OUTPUT_FORMAT DECIMAL)
foreach(index RANGE 0 ${IMHEX_FEATURE_COUNT} 2)
list(SUBLIST IMHEX_PLUGIN_FEATURES ${index} 2 IMHEX_PLUGIN_FEATURE)
list(GET IMHEX_PLUGIN_FEATURE 0 feature_define)
list(GET IMHEX_PLUGIN_FEATURE 1 feature_description)

string(TOUPPER ${feature_define} feature_define)
add_definitions(-DIMHEX_PLUGIN_${IMHEX_PLUGIN_NAME}_FEATURE_${feature_define}=0)
set(FEATURE_DEFINE_CONTENT "${FEATURE_DEFINE_CONTENT}{ \"${feature_description}\", IMHEX_FEATURE_ENABLED(${feature_define}) },")
endforeach()
endif()

target_compile_options(${IMHEX_PLUGIN_NAME} PRIVATE -DIMHEX_PLUGIN_FEATURES_CONTENT=${FEATURE_DEFINE_CONTENT})

# Add the new plugin to the main dependency list so it gets built by default
if (TARGET imhex_all)
Expand Down
33 changes: 18 additions & 15 deletions lib/libimhex/include/hex/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,29 @@ void* PluginSubCommandsFunctionHelper<T>::getSubCommands() {
return nullptr;
}

extern std::vector<hex::Feature> g_features;

#if defined (IMHEX_STATIC_LINK_PLUGINS)
#define IMHEX_PLUGIN_VISIBILITY_PREFIX static
#else
#define IMHEX_PLUGIN_VISIBILITY_PREFIX extern "C" [[gnu::visibility("default")]]
#endif

#define IMHEX_FEATURE_ENABLED(feature) WOLV_TOKEN_CONCAT(WOLV_TOKEN_CONCAT(WOLV_TOKEN_CONCAT(IMHEX_PLUGIN_, IMHEX_PLUGIN_NAME), _FEATURE_), feature)
#define IMHEX_DEFINE_PLUGIN_FEATURES() IMHEX_DEFINE_PLUGIN_FEATURES_IMPL()
#define IMHEX_DEFINE_PLUGIN_FEATURES_IMPL() \
extern std::vector<hex::Feature> g_features; \
template<> \
struct PluginFeatureFunctionHelper<PluginFunctionHelperInstantiation> { \
static void* getFeatures(); \
}; \
void* PluginFeatureFunctionHelper<PluginFunctionHelperInstantiation>::getFeatures() { \
return &g_features; \
} \
std::vector<hex::Feature> g_features = { IMHEX_PLUGIN_FEATURES_CONTENT }

#define IMHEX_PLUGIN_FEATURES g_features

/**
* This macro is used to define all the required entry points for a plugin.
* Name, Author and Description will be displayed in the in the plugin list on the Welcome screen.
Expand Down Expand Up @@ -85,6 +102,7 @@ void* PluginSubCommandsFunctionHelper<T>::getSubCommands() {
ImGui::SetCurrentContext(ctx); \
GImGui = ctx; \
} \
IMHEX_DEFINE_PLUGIN_FEATURES(); \
IMHEX_PLUGIN_VISIBILITY_PREFIX void* getFeatures() { \
return PluginFeatureFunctionHelper<PluginFunctionHelperInstantiation>::getFeatures(); \
} \
Expand Down Expand Up @@ -129,18 +147,3 @@ void* PluginSubCommandsFunctionHelper<T>::getSubCommands() {
return &g_subCommands; \
} \
std::vector<hex::SubCommand> g_subCommands

#define IMHEX_FEATURE_ENABLED(feature) WOLV_TOKEN_CONCAT(WOLV_TOKEN_CONCAT(WOLV_TOKEN_CONCAT(IMHEX_PLUGIN_, IMHEX_PLUGIN_NAME), _FEATURE_), feature)
#define IMHEX_DEFINE_PLUGIN_FEATURES() IMHEX_DEFINE_PLUGIN_FEATURES_IMPL()
#define IMHEX_DEFINE_PLUGIN_FEATURES_IMPL() \
extern std::vector<hex::Feature> g_features; \
template<> \
struct PluginFeatureFunctionHelper<PluginFunctionHelperInstantiation> { \
static void* getFeatures(); \
}; \
void* PluginFeatureFunctionHelper<PluginFunctionHelperInstantiation>::getFeatures() { \
return &g_features; \
} \
std::vector<hex::Feature> g_features

#define IMHEX_PLUGIN_FEATURES g_features
1 change: 0 additions & 1 deletion main/gui/source/window/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,6 @@ namespace hex {
{
int width = 0, height = 0;
glfwGetWindowSize(m_window, &width, &height);
glfwSetWindowSize(m_window, width, height);

if (initialWindowProperties.has_value()) {
width = initialWindowProperties->width;
Expand Down
10 changes: 5 additions & 5 deletions plugins/decompress/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ add_imhex_plugin(
ui
fonts
FEATURES
ZLIB
BZIP2
LIBLZMA
ZSTD
LZ4
ZLIB "ZLib support"
BZIP2 "Bzip2 support"
LIBLZMA "LZMA support"
ZSTD "zstd Support"
LZ4 "lz4 Support"
)

set(LIBLZMA_HAS_AUTO_DECODER 1)
Expand Down
7 changes: 0 additions & 7 deletions plugins/decompress/source/plugin_decompress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ namespace hex::plugin::decompress {
using namespace hex;
using namespace hex::plugin::decompress;

IMHEX_DEFINE_PLUGIN_FEATURES() {
{ "bzip2 Support", IMHEX_FEATURE_ENABLED(BZIP2) },
{ "zlib Support", IMHEX_FEATURE_ENABLED(ZLIB) },
{ "LZMA Support", IMHEX_FEATURE_ENABLED(LIBLZMA) },
{ "zstd Support", IMHEX_FEATURE_ENABLED(ZSTD) },
};

IMHEX_PLUGIN_SETUP("Decompressing", "WerWolv", "Support for decompressing data") {
hex::log::debug("Using romfs: '{}'", romfs::name());

Expand Down
30 changes: 13 additions & 17 deletions plugins/script_loader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ if (CoreClrEmbed_FOUND)
if (IMHEX_BUNDLE_DOTNET)
install(FILES ${CoreClrEmbed_SHARED_LIBRARIES} DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()

message(STATUS "Enabling .NET Scripting support!")

target_link_directories(dotnet INTERFACE ${CoreClrEmbed_FOLDER})
target_include_directories(dotnet INTERFACE ${CoreClrEmbed_INCLUDE_DIRS})
target_compile_definitions(dotnet INTERFACE IMHEX_DOTNET_SCRIPT_SUPPORT=1)
target_sources(dotnet INTERFACE
source/loaders/dotnet/dotnet_loader.cpp
)

add_subdirectory(support/dotnet)
add_dependencies(dotnet AssemblyLoader)
endif()

add_subdirectory(support/c)
Expand All @@ -44,20 +56,4 @@ add_imhex_plugin(
fonts
ui
dotnet
)



if (IMHEX_DOTNET_SCRIPT_SUPPORT)
message(STATUS "Enabling .NET Scripting support!")

target_link_directories(script_loader PRIVATE ${CoreClrEmbed_FOLDER})
target_include_directories(script_loader PRIVATE ${CoreClrEmbed_INCLUDE_DIRS})
target_compile_definitions(script_loader PRIVATE IMHEX_DOTNET_SCRIPT_SUPPORT=1)
target_sources(script_loader PRIVATE
source/loaders/dotnet/dotnet_loader.cpp
)

add_subdirectory(support/dotnet)
add_dependencies(script_loader AssemblyLoader)
endif()
)
2 changes: 0 additions & 2 deletions plugins/script_loader/source/plugin_script_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ using ScriptLoaders = std::tuple<
#endif
>;

IMHEX_DEFINE_PLUGIN_FEATURES(){ };

namespace {

ScriptLoaders s_loaders;
Expand Down

0 comments on commit 03d344c

Please sign in to comment.