You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openmw/components/misc/osgpluginchecker.cpp.in

55 lines
1.5 KiB
C++

#include "components/misc/osgpluginchecker.hpp"
#include <components/debug/debuglog.hpp>
#include <components/misc/strings/conversion.hpp>
#include <osg/Config>
#include <osgDB/PluginQuery>
#include <algorithm>
#include <array>
#include <filesystem>
#include <string_view>
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
{
constexpr auto USED_OSG_PLUGIN_FILENAMES = std::to_array<std::string_view>({${USED_OSG_PLUGIN_FILENAMES_FORMATTED}});
}
bool checkRequiredOSGPluginsArePresent()
{
auto availableOSGPlugins = osgDB::listAllAvailablePlugins();
bool haveAllPlugins = true;
for (std::string_view plugin : USED_OSG_PLUGIN_FILENAMES)
{
if (std::find_if(availableOSGPlugins.begin(), availableOSGPlugins.end(), [&](std::string_view 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;
}
}
return haveAllPlugins;
}
#endif
}