From 62f5c46f253f3fac78764b12a7bf8e360db8edf3 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Fri, 12 Jan 2024 20:16:53 +0000 Subject: [PATCH] Split list in CMake instead of C++ That avoids the need for constexpr work, and therefore the need for an MSVC-specific extension --- components/CMakeLists.txt | 3 +++ components/misc/osgpluginchecker.cpp.in | 23 +++-------------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 72a16c04fb..536d1098c5 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -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}") diff --git a/components/misc/osgpluginchecker.cpp.in b/components/misc/osgpluginchecker.cpp.in index 759b893d08..9bc165c5d6 100644 --- a/components/misc/osgpluginchecker.cpp.in +++ b/components/misc/osgpluginchecker.cpp.in @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -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 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({${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