Move OpenMW version information to a textfile instead of compiling it in

Now we don't need to recompile 3 .cpp files and re-link whenever the current git HEAD changes.
sceneinput
scrawl 9 years ago
parent c783b50a83
commit f09e4620b6

1
.gitignore vendored

@ -41,7 +41,6 @@ resources
## generated objects
apps/openmw/config.hpp
components/version/version.hpp
docs/mainpage.hpp
moc_*.cxx
*.cxx_parameters

@ -366,6 +366,7 @@ IF(NOT WIN32 AND NOT APPLE)
# Install global configuration files
INSTALL(FILES "${OpenMW_BINARY_DIR}/settings-default.cfg" DESTINATION "${SYSCONFDIR}" COMPONENT "openmw")
INSTALL(FILES "${OpenMW_BINARY_DIR}/openmw.cfg.install" DESTINATION "${SYSCONFDIR}" RENAME "openmw.cfg" COMPONENT "openmw")
INSTALL(FILES "${OpenMW_BINARY_DIR}/resources/version" DESTINATION "${SYSCONFDIR}" COMPONENT "openmw")
INSTALL(FILES "${OpenMW_BINARY_DIR}/gamecontrollerdb.txt" DESTINATION "${SYSCONFDIR}" COMPONENT "openmw")
IF(BUILD_OPENCS)
@ -381,6 +382,7 @@ if(WIN32)
FILE(GLOB dll_files "${OpenMW_BINARY_DIR}/Release/*.dll")
INSTALL(FILES ${dll_files} DESTINATION ".")
INSTALL(FILES "${OpenMW_BINARY_DIR}/openmw.cfg.install" DESTINATION "." RENAME "openmw.cfg")
INSTALL(FILES "${OpenMW_BINARY_DIR}/resources/version" DESTINATION ".")
INSTALL(FILES "${OpenMW_SOURCE_DIR}/CHANGELOG.md" DESTINATION "." RENAME "CHANGELOG.txt")
INSTALL(FILES "${OpenMW_SOURCE_DIR}/README.md" DESTINATION "." RENAME "README.txt")
INSTALL(FILES

@ -57,26 +57,6 @@ Launcher::MainDialog::MainDialog(QWidget *parent)
// Remove what's this? button
setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
// Add version information to bottom of the window
QString revision(OPENMW_VERSION_COMMITHASH);
QString tag(OPENMW_VERSION_TAGHASH);
versionLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
if (!revision.isEmpty() && !tag.isEmpty())
{
if (revision == tag) {
versionLabel->setText(tr("OpenMW %1 release").arg(OPENMW_VERSION));
} else {
versionLabel->setText(tr("OpenMW development (%1)").arg(revision.left(10)));
}
// Add the compile date and time
versionLabel->setToolTip(tr("Compiled on %1 %2").arg(QLocale(QLocale::C).toDate(QString(__DATE__).simplified(),
QLatin1String("MMM d yyyy")).toString(Qt::SystemLocaleLongDate),
QLocale(QLocale::C).toTime(QString(__TIME__).simplified(),
QLatin1String("hh:mm:ss")).toString(Qt::SystemLocaleShortDate)));
}
createIcons();
}
@ -186,11 +166,38 @@ Launcher::FirstRunDialogResult Launcher::MainDialog::showFirstRunDialog()
return setup() ? FirstRunDialogResultContinue : FirstRunDialogResultFailure;
}
void Launcher::MainDialog::setVersionLabel()
{
// Add version information to bottom of the window
Version::Version v = Version::getOpenmwVersion(mGameSettings.value("resources").toUtf8().constData());
QString revision(QString::fromUtf8(v.mCommitHash.c_str()));
QString tag(QString::fromUtf8(v.mTagHash.c_str()));
versionLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
if (!revision.isEmpty() && !tag.isEmpty())
{
if (revision == tag) {
versionLabel->setText(tr("OpenMW %1 release").arg(QString::fromUtf8(v.mVersion.c_str())));
} else {
versionLabel->setText(tr("OpenMW development (%1)").arg(revision.left(10)));
}
// Add the compile date and time
versionLabel->setToolTip(tr("Compiled on %1 %2").arg(QLocale(QLocale::C).toDate(QString(__DATE__).simplified(),
QLatin1String("MMM d yyyy")).toString(Qt::SystemLocaleLongDate),
QLocale(QLocale::C).toTime(QString(__TIME__).simplified(),
QLatin1String("hh:mm:ss")).toString(Qt::SystemLocaleShortDate)));
}
}
bool Launcher::MainDialog::setup()
{
if (!setupGameSettings())
return false;
setVersionLabel();
mLauncherSettings.setContentList(mGameSettings);
if (!setupGraphicsSettings())

@ -72,6 +72,8 @@ namespace Launcher
bool setupGameSettings();
bool setupGraphicsSettings();
void setVersionLabel();
void loadSettings();
void saveSettings();

@ -27,7 +27,7 @@
#include <components/files/configurationmanager.hpp>
#include <components/translation/translation.hpp>
#include <components/esm/loadcell.hpp>
#include <components/version/version.hpp>
#include "mwinput/inputmanagerimp.hpp"
@ -493,7 +493,8 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
rootNode->addChild(guiRoot);
MWGui::WindowManager* window = new MWGui::WindowManager(mViewer, guiRoot, mResourceSystem.get(),
mCfgMgr.getLogPath().string() + std::string("/"), myguiResources,
mScriptConsoleMode, mTranslationDataStorage, mEncoding, mExportFonts, mFallbackMap);
mScriptConsoleMode, mTranslationDataStorage, mEncoding, mExportFonts, mFallbackMap,
Version::getOpenmwVersionDescription(mResDir.string()));
mEnvironment.setWindowManager (window);
// Create sound system

@ -199,18 +199,14 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
return false;
}
std::cout << "OpenMW version " << OPENMW_VERSION;
std::string rev = OPENMW_VERSION_COMMITHASH;
std::string tag = OPENMW_VERSION_TAGHASH;
if (!rev.empty() && !tag.empty())
if (variables.count ("version"))
{
rev = rev.substr(0, 10);
std::cout << " (revision " << rev << ")";
}
std::cout << std::endl;
cfgMgr.readConfiguration(variables, desc, true);
if (variables.count ("version"))
Version::Version v = Version::getOpenmwVersion(variables["resources"].as<std::string>());
std::cout << v.describe() << std::endl;
return false;
}
cfgMgr.readConfiguration(variables, desc);

@ -4,8 +4,6 @@
#include <MyGUI_Gui.h>
#include <MyGUI_RenderManager.h>
#include <components/version/version.hpp>
#include <components/widgets/imagebutton.hpp>
#include <components/settings/settings.hpp>
#include <components/vfs/manager.hpp>
@ -28,7 +26,7 @@
namespace MWGui
{
MainMenu::MainMenu(int w, int h, const VFS::Manager* vfs)
MainMenu::MainMenu(int w, int h, const VFS::Manager* vfs, const std::string& versionDescription)
: Layout("openmw_mainmenu.layout")
, mWidth (w), mHeight (h)
, mVFS(vfs), mButtonBox(0)
@ -38,20 +36,7 @@ namespace MWGui
, mSaveGameDialog(NULL)
{
getWidget(mVersionText, "VersionText");
std::stringstream sstream;
sstream << "OpenMW Version: " << OPENMW_VERSION;
// adding info about git hash if available
std::string rev = OPENMW_VERSION_COMMITHASH;
std::string tag = OPENMW_VERSION_TAGHASH;
if (!rev.empty() && !tag.empty())
{
rev = rev.substr(0,10);
sstream << "\nRevision: " << rev;
}
std::string output = sstream.str();
mVersionText->setCaption(output);
mVersionText->setCaption(versionDescription);
mHasAnimatedMenu = mVFS->exists("video/menu_background.bik");

@ -29,7 +29,7 @@ namespace MWGui
public:
MainMenu(int w, int h, const VFS::Manager* vfs);
MainMenu(int w, int h, const VFS::Manager* vfs, const std::string& versionDescription);
~MainMenu();
void onResChange(int w, int h);

@ -113,7 +113,7 @@ namespace MWGui
WindowManager::WindowManager(
osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::ResourceSystem* resourceSystem
, const std::string& logpath, const std::string& resourcePath, bool consoleOnlyScripts,
Translation::Storage& translationDataStorage, ToUTF8::FromType encoding, bool exportFonts, const std::map<std::string, std::string>& fallbackMap)
Translation::Storage& translationDataStorage, ToUTF8::FromType encoding, bool exportFonts, const std::map<std::string, std::string>& fallbackMap, const std::string& versionDescription)
: mResourceSystem(resourceSystem)
, mViewer(viewer)
, mConsoleOnlyScripts(consoleOnlyScripts)
@ -187,6 +187,7 @@ namespace MWGui
, mRestAllowed(true)
, mFPS(0.0f)
, mFallbackMap(fallbackMap)
, mVersionDescription(versionDescription)
{
float uiScale = Settings::Manager::getFloat("scaling factor", "GUI");
mGuiPlatform = new osgMyGUI::Platform(viewer, guiRoot, resourceSystem->getTextureManager(), uiScale);
@ -272,7 +273,7 @@ namespace MWGui
mDragAndDrop = new DragAndDrop();
mRecharge = new Recharge();
mMenu = new MainMenu(w, h, mResourceSystem->getVFS());
mMenu = new MainMenu(w, h, mResourceSystem->getVFS(), mVersionDescription);
mLocalMapRender = new MWRender::LocalMap(mViewer);
mMap = new MapWindow(mCustomMarkers, mDragAndDrop, mLocalMapRender);
trackWindow(mMap, "map");

@ -116,7 +116,7 @@ namespace MWGui
WindowManager(osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::ResourceSystem* resourceSystem,
const std::string& logpath, const std::string& cacheDir, bool consoleOnlyScripts,
Translation::Storage& translationDataStorage, ToUTF8::FromType encoding, bool exportFonts, const std::map<std::string,std::string>& fallbackMap);
Translation::Storage& translationDataStorage, ToUTF8::FromType encoding, bool exportFonts, const std::map<std::string,std::string>& fallbackMap, const std::string& versionDescription);
virtual ~WindowManager();
void initUI();
@ -487,6 +487,8 @@ namespace MWGui
std::map<std::string, std::string> mFallbackMap;
std::string mVersionDescription;
/**
* Called when MyGUI tries to retrieve a tag's value. Tags must be denoted in #{tag} notation and will be replaced upon setting a user visible text/property.
* Supported syntax:

@ -21,4 +21,4 @@ else (SUCCESS)
message(WARNING "Failed to get valid version information from Git")
endif (SUCCESS)
configure_file(${VERSION_HPP_IN} ${VERSION_HPP})
configure_file(${VERSION_IN_FILE} ${VERSION_FILE})

@ -1,23 +1,23 @@
project (Components)
# Version file
set (VERSION_HPP_IN ${CMAKE_CURRENT_SOURCE_DIR}/version/version.hpp.cmake)
set (VERSION_HPP ${CMAKE_CURRENT_SOURCE_DIR}/version/version.hpp)
set (VERSION_IN_FILE "${OpenMW_SOURCE_DIR}/files/version.in")
set (VERSION_FILE "${OpenMW_BINARY_DIR}/resources/version")
if (GIT_CHECKOUT)
add_custom_target (git-version
COMMAND ${CMAKE_COMMAND}
-DGIT_EXECUTABLE=${GIT_EXECUTABLE}
add_custom_target (git-version
COMMAND ${CMAKE_COMMAND}
-DGIT_EXECUTABLE=${GIT_EXECUTABLE}
-DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}
-DVERSION_HPP_IN=${VERSION_HPP_IN}
-DVERSION_HPP=${VERSION_HPP}
-DOPENMW_VERSION_MAJOR=${OPENMW_VERSION_MAJOR}
-DOPENMW_VERSION_MINOR=${OPENMW_VERSION_MINOR}
-DOPENMW_VERSION_RELEASE=${OPENMW_VERSION_RELEASE}
-DOPENMW_VERSION=${OPENMW_VERSION}
-DVERSION_IN_FILE=${VERSION_IN_FILE}
-DVERSION_FILE=${VERSION_FILE}
-DOPENMW_VERSION_MAJOR=${OPENMW_VERSION_MAJOR}
-DOPENMW_VERSION_MINOR=${OPENMW_VERSION_MINOR}
-DOPENMW_VERSION_RELEASE=${OPENMW_VERSION_RELEASE}
-DOPENMW_VERSION=${OPENMW_VERSION}
-P ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/GitVersion.cmake
VERBATIM)
VERBATIM)
else (GIT_CHECKOUT)
configure_file(${VERSION_HPP_IN} ${VERSION_HPP})
configure_file(${VERSION_IN_FILE} ${VERSION_FILE})
endif (GIT_CHECKOUT)
find_package(OpenGL REQUIRED)

@ -0,0 +1,41 @@
#include "version.hpp"
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/fstream.hpp>
namespace Version
{
Version getOpenmwVersion(const std::string &resourcePath)
{
boost::filesystem::path path (resourcePath + "/version");
boost::filesystem::ifstream stream (path);
Version v;
std::getline(stream, v.mVersion);
std::getline(stream, v.mCommitHash);
std::getline(stream, v.mTagHash);
return v;
}
std::string Version::describe()
{
std::string str = "OpenMW version " + mVersion;
std::string rev = mCommitHash;
std::string tag = mTagHash;
if (!rev.empty() && !tag.empty())
{
rev = rev.substr(0, 10);
str += "\nRevision: " + rev;
}
return str;
}
std::string getOpenmwVersionDescription(const std::string &resourcePath)
{
Version v = getOpenmwVersion(resourcePath);
return v.describe();
}
}

@ -0,0 +1,28 @@
#ifndef VERSION_HPP
#define VERSION_HPP
#include <string>
namespace Version
{
struct Version
{
std::string mVersion;
std::string mCommitHash;
std::string mTagHash;
std::string describe();
};
/// Read OpenMW version from the version file located in resourcePath.
Version getOpenmwVersion(const std::string& resourcePath);
/// Helper function to getOpenmwVersion and describe() it
std::string getOpenmwVersionDescription(const std::string& resourcePath);
}
#endif // VERSION_HPP

@ -1,13 +0,0 @@
#ifndef VERSION_HPP
#define VERSION_HPP
#define OPENMW_VERSION_MAJOR @OPENMW_VERSION_MAJOR@
#define OPENMW_VERSION_MINOR @OPENMW_VERSION_MINOR@
#define OPENMW_VERSION_RELEASE @OPENMW_VERSION_RELEASE@
#define OPENMW_VERSION "@OPENMW_VERSION@"
#define OPENMW_VERSION_COMMITHASH "@OPENMW_VERSION_COMMITHASH@"
#define OPENMW_VERSION_TAGHASH "@OPENMW_VERSION_TAGHASH@"
#endif // VERSION_HPP

@ -0,0 +1,3 @@
@OPENMW_VERSION@
@OPENMW_VERSION_COMMITHASH@
@OPENMW_VERSION_TAGHASH@
Loading…
Cancel
Save