Split list in CMake instead of C++

That avoids the need for constexpr work, and therefore the need for an MSVC-specific extension
fix-osga-rotate-wildly
AnyOldName3 12 months ago
parent de107c6a98
commit 62f5c46f25

@ -43,6 +43,9 @@ list (APPEND COMPONENT_FILES "${OpenMW_BINARY_DIR}/${VERSION_CPP_FILE}")
# 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}")
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)
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}")

@ -7,6 +7,7 @@
#include <osgDB/PluginQuery>
#include <algorithm>
#include <array>
#include <filesystem>
#include <string_view>
@ -24,32 +25,14 @@ namespace Misc
namespace
{
std::string_view USED_OSG_PLUGIN_FILENAMES = "${USED_OSG_PLUGIN_FILENAMES}";
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;
auto currentStart = USED_OSG_PLUGIN_FILENAMES.begin();
while (currentStart != USED_OSG_PLUGIN_FILENAMES.end())
{
auto currentEnd = std::find(currentStart, USED_OSG_PLUGIN_FILENAMES.end(), ';');
requiredOSGPlugins.emplace_back(currentStart, currentEnd);
if (currentEnd == USED_OSG_PLUGIN_FILENAMES.end())
break;
currentStart = currentEnd + 1;
}
return requiredOSGPlugins;
}
constexpr auto USED_OSG_PLUGIN_FILENAMES = std::to_array<std::string_view>({${USED_OSG_PLUGIN_FILENAMES_FORMATTED}});
}
bool checkRequiredOSGPluginsArePresent()
{
auto availableOSGPlugins = osgDB::listAllAvailablePlugins();
auto requiredOSGPlugins = getRequiredOSGPlugins();
bool haveAllPlugins = true;
for (std::string_view plugin : requiredOSGPlugins)
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

Loading…
Cancel
Save