1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2026-01-24 05:30:54 +00:00
openmw/components/version/version.cpp.in
AnyOldName3 24d07da29c Rejig components defines
OPENMW_DOC_BASEURL is only used in a CMake-configured file, so it only needs to be a CMake variable, which it already is.
There's no benefit to making it visible to every TU in components.

MYGUI_DONT_USE_OBSOLETE should be visible in everything that transitively includes MyGUI just in case.
This should really be set up by MyGUI's CMake config or embedded in a generated MyGUI header rather than being our responsibility, but while we're forced to deal with it, it's closer to right to make it a PUBLIC define on components rather than a directory-scoped define in the components directory.
2026-01-15 18:35:12 +00:00

62 lines
1.6 KiB
C++

#include <components/version/version.hpp>
#include <filesystem>
#include <fstream>
namespace Version
{
std::string_view getVersion()
{
return "@OPENMW_VERSION@";
}
std::string_view getCommitHash()
{
return "@OPENMW_VERSION_COMMITHASH@";
}
std::string_view getTagHash()
{
return "@OPENMW_VERSION_TAGHASH@";
}
int getLuaApiRevision()
{
return @OPENMW_LUA_API_REVISION@;
}
int getPostprocessingApiRevision()
{
return @OPENMW_POSTPROCESSING_API_REVISION@;
}
std::string getOpenmwVersionDescription()
{
std::string str = "OpenMW version ";
str += getVersion();
if (!getCommitHash().empty())
{
str += "\nRevision: ";
str += getCommitHash().substr(0, 10);
}
return str;
}
bool checkResourcesVersion(const std::filesystem::path& resourcePath)
{
std::ifstream stream(resourcePath / "version");
std::string version, commitHash, tagHash;
std::getline(stream, version);
std::getline(stream, commitHash);
std::getline(stream, tagHash);
return getVersion() == version && getCommitHash() == commitHash && getTagHash() == tagHash;
}
std::string_view getDocumentationUrl()
{
if constexpr (std::string_view("@OPENMW_VERSION_COMMITHASH@") == "@OPENMW_VERSION_TAGHASH@")
return "@OPENMW_DOC_BASEURL@openmw-@OPENMW_VERSION_MAJOR@.@OPENMW_VERSION_MINOR@.@OPENMW_VERSION_RELEASE@/";
else
return "@OPENMW_DOC_BASEURL@latest/";
}
}