diff --git a/meson.build b/meson.build index 28086b5..6ec5a5c 100644 --- a/meson.build +++ b/meson.build @@ -26,6 +26,12 @@ project_config_file = configure_file( output: 'config.h', configuration: conf ) +gitrev_config_file = vcs_tag( + command: ['git', 'rev-parse', 'HEAD'], + input: 'src/git_version.h.in', + output: 'git_version.h', + fallback: 'n/a' +) app_config_model = files('src/app_config.h.in') cxxopts_incl = include_directories('subprojects/cxxopts/include', '.') diff --git a/src/cli/main.cpp b/src/cli/main.cpp index 30e672d..fd7873c 100644 --- a/src/cli/main.cpp +++ b/src/cli/main.cpp @@ -18,6 +18,7 @@ #include "memcard.hpp" #include "config.h" #include "app_config.h" +#include "git_version.h" #include #include #include @@ -50,6 +51,7 @@ int main(int argc, char* argv[]) { if (command.count("version")) { std::cout << PROJECT_NAME << " v" << project_ver() + << (sizeof(PROJECT_GIT_SHA1) > 1 ? " git revision " PROJECT_GIT_SHA1 : "") << " built with " COMPILER_NAME " " COMPILER_VERSION << '\n'; std::cout << "Copyright (C) " COPYRIGHT_YEAR " Michele Santullo\n"; diff --git a/src/cli/meson.build b/src/cli/meson.build index f3f8142..604a897 100644 --- a/src/cli/meson.build +++ b/src/cli/meson.build @@ -13,6 +13,7 @@ executable(app_name, 'memcard.cpp', project_config_file, config_file, + gitrev_config_file, dependencies: [ memcard_dep ], diff --git a/src/git_version.h.in b/src/git_version.h.in new file mode 100644 index 0000000..1c24115 --- /dev/null +++ b/src/git_version.h.in @@ -0,0 +1,3 @@ +#pragma once + +#define PROJECT_GIT_SHA1 "@VCS_TAG@" diff --git a/src/gui/meson.build b/src/gui/meson.build index 0ad481a..5b93bd8 100644 --- a/src/gui/meson.build +++ b/src/gui/meson.build @@ -37,6 +37,7 @@ executable(app_name, 'command_line.cpp', config_file, project_config_file, + gitrev_config_file, 'run_gui.cpp', 'main_window.cpp', 'version_window.cpp', diff --git a/src/gui/version_window.cpp b/src/gui/version_window.cpp index 523da28..ec6622a 100644 --- a/src/gui/version_window.cpp +++ b/src/gui/version_window.cpp @@ -1,6 +1,7 @@ #include "version_window.hpp" #include "app_config.h" #include "config.h" +#include "git_version.h" #include namespace mc { @@ -28,6 +29,7 @@ VersionWindow::VersionWindow(nana::window owner) : nana::form(owner, nana::size{615, 505}), m_top_label(*this), m_short_desc(*this), + m_git_revision(*this), m_repo_link_1(*this), m_repo_link_2(*this), m_main_text(*this), @@ -41,6 +43,10 @@ VersionWindow::VersionWindow(nana::window owner) : m_short_desc.format(true); m_short_desc.caption(std::string("is part of " PROJECT_NAME " v") + project_ver()); + if constexpr (sizeof(PROJECT_GIT_SHA1) > 1) { + m_git_revision.caption("git revision " PROJECT_GIT_SHA1); + } + m_repo_link_1.format(true); m_repo_link_1.caption("Official source code repository is available here:"); m_repo_link_2.format(true); @@ -53,7 +59,11 @@ VersionWindow::VersionWindow(nana::window owner) : m_close.events().click([this]() { this->close(); }); this->div("< vert margin=10 <>> >"); - (*this)["top_label"] << m_top_label << m_short_desc << m_repo_link_1 << m_repo_link_2; + (*this)["top_label"] << m_top_label << m_short_desc; + if constexpr (sizeof(PROJECT_GIT_SHA1) > 1) { + (*this)["top_label"] << m_git_revision; + } + (*this)["top_label"] << m_repo_link_1 << m_repo_link_2; (*this)["main_text"] << m_main_text; (*this)["close"] << m_close; this->collocate(); diff --git a/src/gui/version_window.hpp b/src/gui/version_window.hpp index c2c09f6..7154f6b 100644 --- a/src/gui/version_window.hpp +++ b/src/gui/version_window.hpp @@ -14,6 +14,7 @@ public: private: nana::label m_top_label; nana::label m_short_desc; + nana::label m_git_revision; nana::label m_repo_link_1; nana::label m_repo_link_2; nana::textbox m_main_text;