mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-07 03:54:40 +00:00
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.
This commit is contained in:
parent
c2d1a4c861
commit
ef65f0c70d
@ -41,6 +41,9 @@ endif (GIT_CHECKOUT)
|
|||||||
list (APPEND COMPONENT_FILES "${OpenMW_BINARY_DIR}/${VERSION_CPP_FILE}")
|
list (APPEND COMPONENT_FILES "${OpenMW_BINARY_DIR}/${VERSION_CPP_FILE}")
|
||||||
|
|
||||||
# OSG plugin checker
|
# 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")
|
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}")
|
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}")
|
list(APPEND COMPONENT_FILES "${OpenMW_BINARY_DIR}/${OSG_PLUGIN_CHECKER_CPP_FILE}")
|
||||||
|
@ -1,27 +1,42 @@
|
|||||||
#include "components/misc/osgpluginchecker.hpp"
|
#include "components/misc/osgpluginchecker.hpp"
|
||||||
|
|
||||||
#include <components/debug/debuglog.hpp>
|
#include <components/debug/debuglog.hpp>
|
||||||
|
#include <components/misc/strings/conversion.hpp>
|
||||||
|
|
||||||
|
#include <osg/Config>
|
||||||
#include <osgDB/PluginQuery>
|
#include <osgDB/PluginQuery>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <filesystem>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
namespace Misc
|
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
|
namespace
|
||||||
{
|
{
|
||||||
std::string_view USED_OSG_PLUGINS = "${USED_OSG_PLUGINS}";
|
std::string_view USED_OSG_PLUGIN_FILENAMES = "${USED_OSG_PLUGIN_FILENAMES}";
|
||||||
|
|
||||||
constexpr std::vector<std::string_view> 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<std::string_view> requiredOSGPlugins;
|
std::vector<std::string_view> requiredOSGPlugins;
|
||||||
auto currentStart = USED_OSG_PLUGINS.begin();
|
auto currentStart = USED_OSG_PLUGIN_FILENAMES.begin();
|
||||||
while (currentStart != USED_OSG_PLUGINS.end())
|
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);
|
requiredOSGPlugins.emplace_back(currentStart, currentEnd);
|
||||||
if (currentEnd == USED_OSG_PLUGINS.end())
|
if (currentEnd == USED_OSG_PLUGIN_FILENAMES.end())
|
||||||
break;
|
break;
|
||||||
currentStart = currentEnd + 1;
|
currentStart = currentEnd + 1;
|
||||||
}
|
}
|
||||||
@ -36,7 +51,14 @@ namespace Misc
|
|||||||
bool haveAllPlugins = true;
|
bool haveAllPlugins = true;
|
||||||
for (std::string_view plugin : requiredOSGPlugins)
|
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;
|
Log(Debug::Error) << "Missing OSG plugin: " << plugin;
|
||||||
haveAllPlugins = false;
|
haveAllPlugins = false;
|
||||||
@ -44,4 +66,6 @@ namespace Misc
|
|||||||
}
|
}
|
||||||
return haveAllPlugins;
|
return haveAllPlugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user