From 8ff47ee559f21f7d0f88528daaebe3517d513de1 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sun, 26 Jul 2020 11:49:02 +0000 Subject: [PATCH] Add a way to learn the version of wayvnc and its dependencies --- meson.build | 13 +++++++++++++ src/main.c | 22 +++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 6302e36..6eb1a93 100644 --- a/meson.build +++ b/meson.build @@ -13,9 +13,22 @@ host_system = host_machine.system() prefix = get_option('prefix') c_args = [ + '-DPROJECT_VERSION="@0@"'.format(meson.project_version()), '-D_GNU_SOURCE', ] +git = find_program('git', native: true, required: false) +if git.found() + git_describe = run_command([git, 'describe', '--tags', '--long']) + git_branch = run_command([git, 'rev-parse', '--abbrev-ref', 'HEAD']) + if git_describe.returncode() == 0 and git_branch.returncode() == 0 + c_args += '-DGIT_VERSION="@0@ (@1@)"'.format( + git_describe.stdout().strip(), + git_branch.stdout().strip(), + ) + endif +endif + if buildtype != 'debug' and buildtype != 'debugoptimized' c_args += '-DNDEBUG' endif diff --git a/src/main.c b/src/main.c index d3e4f36..d5c3a10 100644 --- a/src/main.c +++ b/src/main.c @@ -101,6 +101,14 @@ void wayvnc_exit(struct wayvnc* self); void on_capture_done(struct screencopy* sc); static void on_render(struct nvnc_display* display, struct nvnc_fb* fb); +#if defined(GIT_VERSION) +static const char wayvnc_version[] = GIT_VERSION; +#elif defined(PROJECT_VERSION) +static const char wayvnc_version[] = PROJECT_VERSION; +#else +static const char wayvnc_version[] = "UNKNOWN"; +#endif + struct wl_shm* wl_shm = NULL; struct zwp_linux_dmabuf_v1* zwp_linux_dmabuf = NULL; struct gbm_device* gbm_device = NULL; @@ -631,6 +639,7 @@ int wayvnc_usage(FILE* stream, int rc) " -r,--render-cursor Enable overlay cursor rendering.\n" " -f,--max-fps= Set the rate limit (default 30).\n" " -p,--show-performance Show performance counters.\n" +" -V,--version Show version info.\n" " -h,--help Get help (this text).\n" "\n"; @@ -703,6 +712,14 @@ static void start_performance_ticker(struct wayvnc* self) aml_unref(ticker); } +int show_version(void) +{ + printf("wayvnc: %s\n", wayvnc_version); + printf("neatvnc: %s\n", nvnc_version); + printf("aml: %s\n", aml_version); + return 0; +} + int main(int argc, char* argv[]) { struct wayvnc self = { 0 }; @@ -719,7 +736,7 @@ int main(int argc, char* argv[]) bool show_performance = false; int max_rate = 30; - static const char* shortopts = "C:o:k:s:rf:hp"; + static const char* shortopts = "C:o:k:s:rf:hpV"; int drm_fd = -1; static const struct option longopts[] = { @@ -731,6 +748,7 @@ int main(int argc, char* argv[]) { "max-fps", required_argument, NULL, 'f' }, { "help", no_argument, NULL, 'h' }, { "show-performance", no_argument, NULL, 'p' }, + { "version", no_argument, NULL, 'V' }, { NULL, 0, NULL, 0 } }; @@ -761,6 +779,8 @@ int main(int argc, char* argv[]) case 'p': show_performance = true; break; + case 'V': + return show_version(); case 'h': return wayvnc_usage(stdout, 0); default: