mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-28 20:39:41 +00:00
Merge branch 'check-osg-plugins-but-better' into 'master'
Get OSG to tell us the plugin filenames it's going to use See merge request OpenMW/openmw!3942
This commit is contained in:
commit
6e2dbfbd74
2 changed files with 10 additions and 50 deletions
|
@ -46,17 +46,10 @@ list (APPEND COMPONENT_FILES "${OpenMW_BINARY_DIR}/${VERSION_CPP_FILE}")
|
|||
|
||||
# OSG plugin checker
|
||||
# Helpfully, OSG doesn't export this to its CMake config as it doesn't have one
|
||||
set(OSG_PLUGIN_PREFIX "")
|
||||
if (CYGWIN)
|
||||
SET(OSG_PLUGIN_PREFIX "cygwin_")
|
||||
elseif(MINGW)
|
||||
SET(OSG_PLUGIN_PREFIX "mingw_")
|
||||
endif()
|
||||
list(TRANSFORM USED_OSG_PLUGINS PREPEND "${OSG_PLUGIN_PREFIX}" OUTPUT_VARIABLE USED_OSG_PLUGIN_FILENAMES)
|
||||
list(TRANSFORM USED_OSG_PLUGIN_FILENAMES APPEND "${CMAKE_SHARED_MODULE_SUFFIX}")
|
||||
list(TRANSFORM USED_OSG_PLUGIN_FILENAMES PREPEND "\"" OUTPUT_VARIABLE USED_OSG_PLUGIN_FILENAMES_FORMATTED)
|
||||
list(TRANSFORM USED_OSG_PLUGIN_FILENAMES_FORMATTED APPEND "\"")
|
||||
list(JOIN USED_OSG_PLUGIN_FILENAMES_FORMATTED ", " USED_OSG_PLUGIN_FILENAMES_FORMATTED)
|
||||
list(TRANSFORM USED_OSG_PLUGINS REPLACE "^osgdb_" "" OUTPUT_VARIABLE USED_OSG_PLUGIN_NAMES)
|
||||
list(TRANSFORM USED_OSG_PLUGIN_NAMES PREPEND "\"" OUTPUT_VARIABLE USED_OSG_PLUGIN_NAMES_FORMATTED)
|
||||
list(TRANSFORM USED_OSG_PLUGIN_NAMES_FORMATTED APPEND "\"")
|
||||
list(JOIN USED_OSG_PLUGIN_NAMES_FORMATTED ", " USED_OSG_PLUGIN_NAMES_FORMATTED)
|
||||
|
||||
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}")
|
||||
|
|
|
@ -30,52 +30,19 @@ namespace Misc
|
|||
|
||||
namespace
|
||||
{
|
||||
constexpr auto USED_OSG_PLUGIN_FILENAMES = std::to_array<std::string_view>({${USED_OSG_PLUGIN_FILENAMES_FORMATTED}});
|
||||
constexpr auto USED_OSG_PLUGIN_NAMES = std::to_array<std::string_view>({${USED_OSG_PLUGIN_NAMES_FORMATTED}});
|
||||
}
|
||||
|
||||
bool checkRequiredOSGPluginsArePresent()
|
||||
{
|
||||
// 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
|
||||
std::filesystem::path osgPath{ StringUtils::stringToU8String(path) };
|
||||
#else
|
||||
std::filesystem::path osgPath{ path };
|
||||
#endif
|
||||
if (!osgPath.has_filename())
|
||||
osgPath = osgPath.parent_path();
|
||||
|
||||
if (osgPath.filename() == pluginDirectoryName)
|
||||
{
|
||||
osgPath = osgPath.parent_path();
|
||||
#ifdef OSG_USE_UTF8_FILENAME
|
||||
std::string extraPath = StringUtils::u8StringToString(osgPath.u8string());
|
||||
#else
|
||||
std::string extraPath = osgPath.string();
|
||||
#endif
|
||||
filepath.emplace_back(std::move(extraPath));
|
||||
}
|
||||
}
|
||||
|
||||
auto availableOSGPlugins = osgDB::listAllAvailablePlugins();
|
||||
// osgDB::listAllAvailablePlugins() lies, so don't use it
|
||||
bool haveAllPlugins = true;
|
||||
for (std::string_view plugin : USED_OSG_PLUGIN_FILENAMES)
|
||||
for (std::string_view plugin : USED_OSG_PLUGIN_NAMES)
|
||||
{
|
||||
if (std::find_if(availableOSGPlugins.begin(), availableOSGPlugins.end(),
|
||||
[&](std::string_view availablePlugin) {
|
||||
#ifdef OSG_USE_UTF8_FILENAME
|
||||
std::filesystem::path pluginPath{ StringUtils::stringToU8String(availablePlugin) };
|
||||
#else
|
||||
std::filesystem::path pluginPath {availablePlugin};
|
||||
#endif
|
||||
return pluginPath.filename() == plugin;
|
||||
})
|
||||
== availableOSGPlugins.end())
|
||||
std::string libraryName = osgDB::Registry::instance()->createLibraryNameForExtension(std::string{ plugin });
|
||||
if (osgDB::findLibraryFile(libraryName).empty())
|
||||
{
|
||||
Log(Debug::Error) << "Missing OSG plugin: " << plugin;
|
||||
Log(Debug::Error) << "Missing OSG plugin: " << libraryName;
|
||||
haveAllPlugins = false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue