From 24303c1309cf6372fc25fb4de55ca5720ce0db9c Mon Sep 17 00:00:00 2001 From: Vladimir Stackov Date: Sun, 25 Jan 2015 20:56:41 +0300 Subject: [PATCH] Include git version in binary build --- CMakeLists.txt | 9 +++++++++ version.cc | 9 +++++++++ version.hh | 10 ++++++++++ zbackup.cc | 5 +++-- 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 version.cc create mode 100644 version.hh diff --git a/CMakeLists.txt b/CMakeLists.txt index 2922a2a..c80607c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,15 @@ else ( LIBUNWIND_FOUND ) set( LIBUNWIND_LIBRARIES ) endif( LIBUNWIND_FOUND ) +add_custom_target( invalidate_files ALL + COMMAND ${CMAKE_COMMAND} -E touch "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt" ) +execute_process( OUTPUT_VARIABLE ZBACKUP_VERSION + COMMAND git describe --tags --always + OUTPUT_STRIP_TRAILING_WHITESPACE ) +if ( ZBACKUP_VERSION ) + ADD_DEFINITIONS( -DZBACKUP_VERSION="${ZBACKUP_VERSION}" ) +endif( ZBACKUP_VERSION ) + file( GLOB sourceFiles "*.cc" ) add_executable( zbackup ${sourceFiles} ${protoSrcs} ${protoHdrs} ) diff --git a/version.cc b/version.cc new file mode 100644 index 0000000..c5d22a3 --- /dev/null +++ b/version.cc @@ -0,0 +1,9 @@ +// Copyright (c) 2012-2014 Konstantin Isakov and ZBackup contributors, see CONTRIBUTORS +// Part of ZBackup. Licensed under GNU GPLv2 or later + OpenSSL, see LICENSE + +#include +#ifndef ZBACKUP_VERSION +std::string zbackup_version( "1.4" ); +#else +std::string zbackup_version( ZBACKUP_VERSION ); +#endif diff --git a/version.hh b/version.hh new file mode 100644 index 0000000..8e693d3 --- /dev/null +++ b/version.hh @@ -0,0 +1,10 @@ +// Copyright (c) 2012-2014 Konstantin Isakov and ZBackup contributors, see CONTRIBUTORS +// Part of ZBackup. Licensed under GNU GPLv2 or later + OpenSSL, see LICENSE + +#ifndef VERSION_HH_INCLUDED +#define VERSION_HH_INCLUDED +#include + +extern std::string zbackup_version; + +#endif diff --git a/zbackup.cc b/zbackup.cc index cdd5e13..08fbf47 100644 --- a/zbackup.cc +++ b/zbackup.cc @@ -10,6 +10,7 @@ #include "backup_collector.hh" #include "config.hh" #include "utils.hh" +#include "version.hh" using std::vector; using std::bitset; @@ -443,7 +444,7 @@ invalid_option: if ( args.size() < 1 || printHelp ) { fprintf( stderr, -"ZBackup, a versatile deduplicating backup tool, version 1.4\n" +"ZBackup, a versatile deduplicating backup tool, version %s\n" "Copyright (c) 2012-2014 Konstantin Isakov and\n" "ZBackup contributors\n" "Comes with no warranty. Licensed under GNU GPLv2 or later + OpenSSL.\n" @@ -475,7 +476,7 @@ invalid_option: " config [show|edit|set] - performs configuration\n" " manipulations (default is show)\n" " For export/import storage path must be a valid (initialized) storage\n" -"", *argv ); +"", zbackup_version.c_str(), *argv ); return EXIT_FAILURE; }