1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-01 03:21:41 +00:00
OpenMW/components/misc/osgpluginchecker.cpp.in
AnyOldName3 942eeb54c1 Yet another osgpluginchecker rewrite
It turns out that it's possible for OSG plugins to be spread across multiple directories, and OSG doesn't account for this in osgDB::listAllAvailablePlugins(), even though it works when actually loading the plugin.

Instead, use code that's much more similar to how OSG actually loads plugin, and therefore less likely to miss anything.

Incidentally make things much simpler as we don't need  awkwardness from working around osgDB::listAllAvailablePlugins()'s limitations.
2024-03-12 23:30:11 +00:00

54 lines
1.6 KiB
C++

#include "components/misc/osgpluginchecker.hpp"
#include <components/debug/debuglog.hpp>
#include <components/misc/strings/conversion.hpp>
#include <osg/Config>
#include <osg/Version>
#include <osgDB/FileUtils>
#include <osgDB/PluginQuery>
#include <algorithm>
#include <array>
#include <filesystem>
#include <string_view>
namespace Misc
{
#if defined(OSG_LIBRARY_STATIC) || defined(__APPLE__)
bool checkRequiredOSGPluginsArePresent()
{
// assume they were linked in at build time and CMake would have failed if they were missing
// true-ish for MacOS - they're copied into the package and that'd fail if they were missing,
// but if you don't actually make a MacOS package and run a local build, this won't notice.
// the workaround in the real implementation isn't powerful enough to make MacOS work, though.
return true;
}
#else
namespace
{
constexpr auto USED_OSG_PLUGIN_NAMES = std::to_array<std::string_view>({${USED_OSG_PLUGIN_NAMES_FORMATTED}});
}
bool checkRequiredOSGPluginsArePresent()
{
// osgDB::listAllAvailablePlugins() lies, so don't use it
bool haveAllPlugins = true;
for (std::string_view plugin : USED_OSG_PLUGIN_NAMES)
{
std::string libraryName = osgDB::Registry::instance()->createLibraryNameForExtension(std::string{ plugin });
if (osgDB::findLibraryFile(libraryName).empty())
{
Log(Debug::Error) << "Missing OSG plugin: " << libraryName;
haveAllPlugins = false;
}
}
return haveAllPlugins;
}
#endif
}