From 03d344c0a2a91952e6df76f74a6385292888c55e Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 8 Jul 2024 18:12:46 +0200 Subject: [PATCH] build: Streamline definition on plugin features --- cmake/modules/ImHexPlugin.cmake | 21 +++++++++--- lib/libimhex/include/hex/plugin.hpp | 33 ++++++++++--------- main/gui/source/window/window.cpp | 1 - plugins/decompress/CMakeLists.txt | 10 +++--- .../decompress/source/plugin_decompress.cpp | 7 ---- plugins/script_loader/CMakeLists.txt | 30 ++++++++--------- .../source/plugin_script_loader.cpp | 2 -- 7 files changed, 53 insertions(+), 51 deletions(-) diff --git a/cmake/modules/ImHexPlugin.cmake b/cmake/modules/ImHexPlugin.cmake index cebb13cd8..b20b0e50a 100644 --- a/cmake/modules/ImHexPlugin.cmake +++ b/cmake/modules/ImHexPlugin.cmake @@ -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) diff --git a/lib/libimhex/include/hex/plugin.hpp b/lib/libimhex/include/hex/plugin.hpp index 7f370ee20..0e842dfac 100644 --- a/lib/libimhex/include/hex/plugin.hpp +++ b/lib/libimhex/include/hex/plugin.hpp @@ -37,12 +37,29 @@ void* PluginSubCommandsFunctionHelper::getSubCommands() { return nullptr; } +extern std::vector 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 g_features; \ + template<> \ + struct PluginFeatureFunctionHelper { \ + static void* getFeatures(); \ + }; \ + void* PluginFeatureFunctionHelper::getFeatures() { \ + return &g_features; \ + } \ + std::vector 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. @@ -85,6 +102,7 @@ void* PluginSubCommandsFunctionHelper::getSubCommands() { ImGui::SetCurrentContext(ctx); \ GImGui = ctx; \ } \ + IMHEX_DEFINE_PLUGIN_FEATURES(); \ IMHEX_PLUGIN_VISIBILITY_PREFIX void* getFeatures() { \ return PluginFeatureFunctionHelper::getFeatures(); \ } \ @@ -129,18 +147,3 @@ void* PluginSubCommandsFunctionHelper::getSubCommands() { return &g_subCommands; \ } \ std::vector 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 g_features; \ - template<> \ - struct PluginFeatureFunctionHelper { \ - static void* getFeatures(); \ - }; \ - void* PluginFeatureFunctionHelper::getFeatures() { \ - return &g_features; \ - } \ - std::vector g_features - -#define IMHEX_PLUGIN_FEATURES g_features diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index 27e7e652a..78e1b877d 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -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; diff --git a/plugins/decompress/CMakeLists.txt b/plugins/decompress/CMakeLists.txt index 3da0b723d..c3e934b10 100644 --- a/plugins/decompress/CMakeLists.txt +++ b/plugins/decompress/CMakeLists.txt @@ -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) diff --git a/plugins/decompress/source/plugin_decompress.cpp b/plugins/decompress/source/plugin_decompress.cpp index a322e6c79..521d11a12 100644 --- a/plugins/decompress/source/plugin_decompress.cpp +++ b/plugins/decompress/source/plugin_decompress.cpp @@ -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()); diff --git a/plugins/script_loader/CMakeLists.txt b/plugins/script_loader/CMakeLists.txt index 7c162f88d..a1e71479d 100644 --- a/plugins/script_loader/CMakeLists.txt +++ b/plugins/script_loader/CMakeLists.txt @@ -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) @@ -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() \ No newline at end of file +) \ No newline at end of file diff --git a/plugins/script_loader/source/plugin_script_loader.cpp b/plugins/script_loader/source/plugin_script_loader.cpp index c6cf0b6f7..cab70ae17 100644 --- a/plugins/script_loader/source/plugin_script_loader.cpp +++ b/plugins/script_loader/source/plugin_script_loader.cpp @@ -21,8 +21,6 @@ using ScriptLoaders = std::tuple< #endif >; -IMHEX_DEFINE_PLUGIN_FEATURES(){ }; - namespace { ScriptLoaders s_loaders;