2024-01-07 01:18:15 +00:00
|
|
|
#include "components/misc/osgpluginchecker.hpp"
|
|
|
|
|
|
|
|
#include <components/debug/debuglog.hpp>
|
2024-01-07 17:32:54 +00:00
|
|
|
#include <components/misc/strings/conversion.hpp>
|
2024-01-07 01:18:15 +00:00
|
|
|
|
2024-01-07 17:32:54 +00:00
|
|
|
#include <osg/Config>
|
2024-02-19 23:16:50 +00:00
|
|
|
#include <osg/Version>
|
|
|
|
#include <osgDB/FileUtils>
|
2024-01-07 01:18:15 +00:00
|
|
|
#include <osgDB/PluginQuery>
|
|
|
|
|
|
|
|
#include <algorithm>
|
2024-01-12 20:16:53 +00:00
|
|
|
#include <array>
|
2024-01-07 17:32:54 +00:00
|
|
|
#include <filesystem>
|
2024-01-07 01:18:15 +00:00
|
|
|
#include <string_view>
|
|
|
|
|
|
|
|
namespace Misc
|
|
|
|
{
|
2024-02-22 00:24:44 +00:00
|
|
|
#if defined(OSG_LIBRARY_STATIC) || defined(__APPLE__)
|
2024-01-07 17:32:54 +00:00
|
|
|
|
|
|
|
bool checkRequiredOSGPluginsArePresent()
|
|
|
|
{
|
|
|
|
// assume they were linked in at build time and CMake would have failed if they were missing
|
2024-02-22 00:24:44 +00:00
|
|
|
// 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.
|
2024-01-07 17:32:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2024-01-07 01:18:15 +00:00
|
|
|
namespace
|
|
|
|
{
|
2024-01-12 20:16:53 +00:00
|
|
|
constexpr auto USED_OSG_PLUGIN_FILENAMES = std::to_array<std::string_view>({${USED_OSG_PLUGIN_FILENAMES_FORMATTED}});
|
2024-01-07 01:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool checkRequiredOSGPluginsArePresent()
|
|
|
|
{
|
2024-02-19 23:16:50 +00:00
|
|
|
// work around osgDB::listAllAvailablePlugins() not working on some platforms due to a suspected OSG bug
|
|
|
|
std::filesystem::path pluginDirectoryName = std::string("osgPlugins-") + std::string(osgGetVersion());
|
|
|
|
osgDB::FilePathList& filepath = osgDB::getLibraryFilePathList();
|
|
|
|
for (const auto& path : filepath)
|
|
|
|
{
|
|
|
|
#ifdef OSG_USE_UTF8_FILENAME
|
2024-03-06 19:51:48 +00:00
|
|
|
std::filesystem::path osgPath{ StringUtils::stringToU8String(path) };
|
2024-02-19 23:16:50 +00:00
|
|
|
#else
|
2024-02-25 23:01:52 +00:00
|
|
|
std::filesystem::path osgPath{ path };
|
2024-02-19 23:16:50 +00:00
|
|
|
#endif
|
|
|
|
if (!osgPath.has_filename())
|
|
|
|
osgPath = osgPath.parent_path();
|
2024-02-25 23:01:52 +00:00
|
|
|
|
2024-02-19 23:16:50 +00:00
|
|
|
if (osgPath.filename() == pluginDirectoryName)
|
|
|
|
{
|
|
|
|
osgPath = osgPath.parent_path();
|
|
|
|
#ifdef OSG_USE_UTF8_FILENAME
|
2024-03-06 19:51:48 +00:00
|
|
|
std::string extraPath = StringUtils::u8StringToString(osgPath.u8string());
|
2024-02-19 23:16:50 +00:00
|
|
|
#else
|
|
|
|
std::string extraPath = osgPath.string();
|
|
|
|
#endif
|
|
|
|
filepath.emplace_back(std::move(extraPath));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-07 01:18:15 +00:00
|
|
|
auto availableOSGPlugins = osgDB::listAllAvailablePlugins();
|
|
|
|
bool haveAllPlugins = true;
|
2024-01-12 20:16:53 +00:00
|
|
|
for (std::string_view plugin : USED_OSG_PLUGIN_FILENAMES)
|
2024-01-07 01:18:15 +00:00
|
|
|
{
|
2024-02-25 23:01:52 +00:00
|
|
|
if (std::find_if(availableOSGPlugins.begin(), availableOSGPlugins.end(),
|
|
|
|
[&](std::string_view availablePlugin) {
|
2024-01-07 17:32:54 +00:00
|
|
|
#ifdef OSG_USE_UTF8_FILENAME
|
2024-03-06 19:51:48 +00:00
|
|
|
std::filesystem::path pluginPath{ StringUtils::stringToU8String(availablePlugin) };
|
2024-01-07 17:32:54 +00:00
|
|
|
#else
|
|
|
|
std::filesystem::path pluginPath {availablePlugin};
|
|
|
|
#endif
|
2024-02-25 23:01:52 +00:00
|
|
|
return pluginPath.filename() == plugin;
|
|
|
|
})
|
|
|
|
== availableOSGPlugins.end())
|
2024-01-07 01:18:15 +00:00
|
|
|
{
|
|
|
|
Log(Debug::Error) << "Missing OSG plugin: " << plugin;
|
|
|
|
haveAllPlugins = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return haveAllPlugins;
|
|
|
|
}
|
2024-01-07 17:32:54 +00:00
|
|
|
|
|
|
|
#endif
|
2024-01-07 01:18:15 +00:00
|
|
|
}
|