Include git-revision based version information in binary
MODIFY
src/CMakeLists.txt
src/CMakeLists.txt
@@ -3,11 +3,11 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
file(GLOB LIB_SOURCES *.cpp graphics/*.cpp)
-file(GLOB LIB_HEADERS *.h graphics/*.h)
+file(GLOB LIB_HEADERS *.h graphics/*.h version/*.h)
file(GLOB LIB_UIS *.ui)
set(RIPES_LIB ripes_lib)
-add_library(${RIPES_LIB} ${LIB_SOURCES} ${LIB_HEADERS} ${LIB_UIS})
+add_library(${RIPES_LIB} ${LIB_SOURCES} ${LIB_HEADERS} ${LIB_UIS} ${CMAKE_CURRENT_BINARY_DIR}/version/version.cpp)
target_include_directories (${RIPES_LIB} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_features(${RIPES_LIB} PRIVATE cxx_std_17)
@@ -16,3 +16,33 @@ target_link_libraries(${RIPES_LIB} fancytabbar_lib)
target_link_libraries(${RIPES_LIB} ${VSRTL_GRAPHICS_LIB})
add_subdirectory(processors)
+
+# -----------------------------------------------------------------------------
+# Version control file
+# A file version.cpp is generated, containing information regarding the current
+# .git revision. This information is embedded into the binary for future
+# reference, ie. for issue reporting.
+#
+# Modified version of https://www.mattkeeter.com/blog/2018-01-06-versioning/
+add_custom_target(
+ version_file ALL
+ # Depend on the dummy file (which is not generated by the versioning script)
+ # to ensure that the custom command is executed each time the project is built.
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/version/_version.cpp
+ )
+
+add_dependencies(${RIPES_LIB} version_file)
+
+add_custom_command(
+ OUTPUT
+ # Actual file generated by the versioning script
+ ${CMAKE_CURRENT_BINARY_DIR}/version/version.cpp
+ # Dummy file not generated by the sript, but may be used as a dependency
+ ${CMAKE_CURRENT_BINARY_DIR}/version/_version.cpp
+ COMMAND
+ ${CMAKE_COMMAND}
+ -DRIPES_SRC_DIR=${CMAKE_SOURCE_DIR}
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/version/version.cmake)
+# Do not run AUTOMOC and AUTOUIC on the generated file (CMake warning)
+set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/version/version.cpp PROPERTY SKIP_AUTOGEN ON)
+# -----------------------------------------------------------------------------

MODIFY
src/mainwindow.cpp
src/mainwindow.cpp
#include "processortab.h"
#include "registerwidget.h"
#include "savedialog.h"
+#include "version/version.h"
#include "fancytabbar/fancytabbar.h"
@@ -76,6 +77,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), m_ui(new Ui::Main
connect(ProcessorHandler::get(), &ProcessorHandler::runFinished, m_processorTab, &ProcessorTab::runFinished);
connect(m_ui->actionOpen_wiki, &QAction::triggered, this, &MainWindow::wiki);
+ connect(m_ui->actionVersion, &QAction::triggered, this, &MainWindow::version);
}
void MainWindow::setupMenus() {
@@ -160,6 +162,12 @@ void MainWindow::wiki() {
QDesktopServices::openUrl(QUrl(QString("https://github.com/mortbopet/Ripes/wiki")));
}
+void MainWindow::version() {
+ QMessageBox aboutDialog(this);
+ aboutDialog.setText("Ripes version: " + getRipesVersion());
+ aboutDialog.exec();
+}
+
namespace {
inline QString removeFileExt(const QString& file) {
int lastPoint = file.lastIndexOf(".");

MODIFY
src/mainwindow.h
src/mainwindow.h
@@ -30,6 +30,7 @@ public:
private slots:
void exit();
void wiki();
+ void version();
void loadFileTriggered();

MODIFY
src/mainwindow.ui
src/mainwindow.ui
<string>Help</string>
</property>
<addaction name="actionOpen_wiki"/>
+ <addaction name="actionVersion"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuHelp"/>
<string>Wiki</string>
</property>
</action>
+ <action name="actionVersion">
+ <property name="text">
+ <string>Version</string>
+ </property>
+ </action>
</widget>
<customwidgets>
<customwidget>

ADD
src/version/version.cmake
+# Modified version of:
+# https://www.mattkeeter.com/blog/2018-01-06-versioning/
+
+set(ENV{GIT_DIR} ${RIPES_SRC_DIR}/.git)
+execute_process(COMMAND git describe --tags
+ OUTPUT_VARIABLE GIT_REV
+ ERROR_QUIET)
+
+# Check whether we got any revision (which isn't
+# always the case, e.g. when someone downloaded a zip
+# file from Github instead of a checkout)
+if ("${GIT_REV}" STREQUAL "")
+ set(RIPES_GIT_VERSION "N/A")
+else()
+ string(STRIP "${GIT_REV}" RIPES_GIT_VERSION)
+endif()
+
+set(VERSION "const char* RIPES_GIT_VERSION=\"${RIPES_GIT_VERSION}\";")
+
+if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp)
+ file(READ ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp VERSION_)
+else()
+ set(VERSION_ "")
+endif()
+
+if (NOT "${VERSION}" STREQUAL "${VERSION_}")
+ file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/version/version.cpp "${VERSION}")
+endif()

ADD
src/version/version.h
+#pragma once
+
+#include <QString>
+#include <QStringList>
+
+// Variables autogenerated from the current git-revision upon building the project
+extern "C" {
+extern const char* RIPES_GIT_VERSION;
+}
+
+static inline QString getRipesVersion() {
+ return QString(RIPES_GIT_VERSION);
+}

Include git-revision based version information in binary