From d34df838e6bec1b97db07c3793a9e2db0650cbe8 Mon Sep 17 00:00:00 2001 From: Jussi Kuokkanen Date: Sun, 5 Nov 2023 15:42:15 +0200 Subject: [PATCH] add command line option to show version --- src/meson.build | 8 +++++++- src/tuxclocker-qt/main.cpp | 6 ++++++ src/tuxclocker-qt/meson.build | 2 +- src/tuxclockerd/main.cpp | 6 ++++++ src/tuxclockerd/meson.build | 2 +- 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/meson.build b/src/meson.build index 8522135..b01fa97 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,4 +1,9 @@ -# Define libtuxclocker target here since others depend on it +# Version information +tuxclocker_version = '1.3.0-rc.1' +git_commit = run_command('git', 'describe', '--always', '--dirty').stdout().strip() +version_string = '@0@, git commit @1@'.format(tuxclocker_version, git_commit) +# Used in preprocessor +version_string_def = '-DTUXCLOCKER_VERSION_STRING="@0@"'.format(version_string) # OpenSSL is used for hash functions openssl_dep = dependency('openssl') @@ -15,6 +20,7 @@ plugin_path_def = plugin_path_def_template.format(get_option('prefix'), get_opti locale_path_def_template = '-DTUXCLOCKER_LOCALE_PATH="@0@/@1@/locale"' locale_path_def = locale_path_def_template.format(get_option('prefix'), get_option('datadir')) +# Define libtuxclocker target here since others depend on it libtuxclocker = shared_library('tuxclocker', ['lib/Crypto.cpp', 'lib/Plugin.cpp'], diff --git a/src/tuxclocker-qt/main.cpp b/src/tuxclocker-qt/main.cpp index 59dc13b..4fc9759 100644 --- a/src/tuxclocker-qt/main.cpp +++ b/src/tuxclocker-qt/main.cpp @@ -1,10 +1,16 @@ #include #include +#include #include "MainWindow.hpp" int main(int argc, char **argv) { QApplication app(argc, argv); + app.setApplicationVersion(TUXCLOCKER_VERSION_STRING); + + QCommandLineParser parser; + parser.addVersionOption(); + parser.process(app); setlocale(LC_MESSAGES, ""); bindtextdomain("tuxclocker", TUXCLOCKER_LOCALE_PATH); diff --git a/src/tuxclocker-qt/meson.build b/src/tuxclocker-qt/meson.build index a2df79b..9281702 100644 --- a/src/tuxclocker-qt/meson.build +++ b/src/tuxclocker-qt/meson.build @@ -46,5 +46,5 @@ executable('tuxclocker-qt', override_options : ['cpp_std=c++17'], dependencies: qt5_dep, include_directories: [incdir, local_incdir], - cpp_args : locale_path_def, + cpp_args : [locale_path_def, version_string_def], install: true) diff --git a/src/tuxclockerd/main.cpp b/src/tuxclockerd/main.cpp index c1a63f5..ce84aec 100644 --- a/src/tuxclockerd/main.cpp +++ b/src/tuxclockerd/main.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -21,6 +22,11 @@ namespace TCDBus = TuxClocker::DBus; int main(int argc, char **argv) { QCoreApplication a(argc, argv); + a.setApplicationVersion(TUXCLOCKER_VERSION_STRING); + + QCommandLineParser parser; + parser.addVersionOption(); + parser.process(a); // TODO: should numbers here be localized or not? setlocale(LC_MESSAGES, ""); diff --git a/src/tuxclockerd/meson.build b/src/tuxclockerd/meson.build index fc07272..2f10465 100644 --- a/src/tuxclockerd/meson.build +++ b/src/tuxclockerd/meson.build @@ -18,7 +18,7 @@ executable('tuxclockerd', include_directories : [incdir, patterns_inc], dependencies : [qt5_dep, boost_dep], link_with : libtuxclocker, - cpp_args : locale_path_def, + cpp_args : [locale_path_def, version_string_def], install : true) # DBus data directories