From ef65f0c70d4f3659a2703003a89af236281a753e Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Sun, 7 Jan 2024 17:32:54 +0000 Subject: [PATCH] Make OSG plugin checker barely functional * Work out what module filenames should be in CMake, and give those to C++ * Compare just the module filenames instead of the full strings * Deal with OSG trying to support both UTF-8 and system-eight-bit-code-page file paths on Windows. * Add a comment complaining about the constexpr situation. * Use a stub implementation when using static OSG - apparently we don't actually support mixing and matching static and dynamic OSG plugins even though OSG itself does. --- components/CMakeLists.txt | 3 ++ components/misc/osgpluginchecker.cpp.in | 38 ++++++++++++++++++++----- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index ce4b431979..72a16c04fb 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -41,6 +41,9 @@ endif (GIT_CHECKOUT) list (APPEND COMPONENT_FILES "${OpenMW_BINARY_DIR}/${VERSION_CPP_FILE}") # OSG plugin checker +list(TRANSFORM USED_OSG_PLUGINS PREPEND "${CMAKE_SHARED_MODULE_PREFIX}" OUTPUT_VARIABLE USED_OSG_PLUGIN_FILENAMES) +list(TRANSFORM USED_OSG_PLUGIN_FILENAMES APPEND "${CMAKE_SHARED_MODULE_SUFFIX}") + set(OSG_PLUGIN_CHECKER_CPP_FILE "components/misc/osgpluginchecker.cpp") configure_file("${OpenMW_SOURCE_DIR}/${OSG_PLUGIN_CHECKER_CPP_FILE}.in" "${OpenMW_BINARY_DIR}/${OSG_PLUGIN_CHECKER_CPP_FILE}") list(APPEND COMPONENT_FILES "${OpenMW_BINARY_DIR}/${OSG_PLUGIN_CHECKER_CPP_FILE}") diff --git a/components/misc/osgpluginchecker.cpp.in b/components/misc/osgpluginchecker.cpp.in index 56a7814d33..5a7e5e92c7 100644 --- a/components/misc/osgpluginchecker.cpp.in +++ b/components/misc/osgpluginchecker.cpp.in @@ -1,27 +1,42 @@ #include "components/misc/osgpluginchecker.hpp" #include +#include +#include #include #include +#include #include namespace Misc { +#ifdef OSG_LIBRARY_STATIC + + bool checkRequiredOSGPluginsArePresent() + { + // assume they were linked in at build time and CMake would have failed if they were missing + return true; + } + +#else + namespace { - std::string_view USED_OSG_PLUGINS = "${USED_OSG_PLUGINS}"; + std::string_view USED_OSG_PLUGIN_FILENAMES = "${USED_OSG_PLUGIN_FILENAMES}"; - constexpr std::vector getRequiredOSGPlugins() + constexpr auto getRequiredOSGPlugins() { + // TODO: this is only constexpr due to an MSVC extension, so doesn't work on GCC and Clang + // I tried replacing it with std::views::split_range, but we support compilers without that bit of C++20, and it wasn't obvious how to use the result as a string_view without C++23 std::vector requiredOSGPlugins; - auto currentStart = USED_OSG_PLUGINS.begin(); - while (currentStart != USED_OSG_PLUGINS.end()) + auto currentStart = USED_OSG_PLUGIN_FILENAMES.begin(); + while (currentStart != USED_OSG_PLUGIN_FILENAMES.end()) { - auto currentEnd = std::find(currentStart, USED_OSG_PLUGINS.end(), ';'); + auto currentEnd = std::find(currentStart, USED_OSG_PLUGIN_FILENAMES.end(), ';'); requiredOSGPlugins.emplace_back(currentStart, currentEnd); - if (currentEnd == USED_OSG_PLUGINS.end()) + if (currentEnd == USED_OSG_PLUGIN_FILENAMES.end()) break; currentStart = currentEnd + 1; } @@ -36,7 +51,14 @@ namespace Misc bool haveAllPlugins = true; for (std::string_view plugin : requiredOSGPlugins) { - if (std::find(availableOSGPlugins.begin(), availableOSGPlugins.end(), plugin) == availableOSGPlugins.end()) + if (std::find_if(availableOSGPlugins.begin(), availableOSGPlugins.end(), [&](std::string availablePlugin) { +#ifdef OSG_USE_UTF8_FILENAME + std::filesystem::path pluginPath {stringToU8String(availablePlugin)}; +#else + std::filesystem::path pluginPath {availablePlugin}; +#endif + return pluginPath.filename() == plugin; + }) == availableOSGPlugins.end()) { Log(Debug::Error) << "Missing OSG plugin: " << plugin; haveAllPlugins = false; @@ -44,4 +66,6 @@ namespace Misc } return haveAllPlugins; } + +#endif }