diff --git a/doorlockd/CMakeLists.txt b/doorlockd/CMakeLists.txt index 8afed37..af6d1c1 100644 --- a/doorlockd/CMakeLists.txt +++ b/doorlockd/CMakeLists.txt @@ -3,6 +3,32 @@ project(doorlockd) option(USE_COLORIZED_LOGS "Colorized logging" ON) +set(DOORLOCKD_VERSION_MAJOR 1) +set(DOORLOCKD_VERSION_MINOR 0) +set(DOORLOCKD_VERSION_PATCH 0) + +set(DOORLOCKD_VERSION "${DOORLOCKD_VERSION_MAJOR}.${DOORLOCKD_VERSION_MINOR}.${DOORLOCKD_VERSION_PATCH}") + +MESSAGE(STATUS "doorlockd version: ${DOORLOCKD_VERSION}") + +# Get the current working branch +execute_process( + COMMAND git rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE +) +set(GIT_BRANCH "\"${GIT_BRANCH}\"") + +# Get the latest abbreviated commit hash of the working branch +execute_process( + COMMAND git log -1 --format=%h + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE +) +set(GIT_COMMIT_HASH "\"${GIT_COMMIT_HASH}\"") + add_definitions(-std=c++11) configure_file ( diff --git a/doorlockd/config.h.in b/doorlockd/config.h.in index 1d9dae8..06de1b5 100644 --- a/doorlockd/config.h.in +++ b/doorlockd/config.h.in @@ -3,6 +3,13 @@ #cmakedefine USE_COLORIZED_LOGS +#define DOORLOCKD_VERSION_MAJOR "@DOORLOCKD_VERSION_MAJOR@" +#define DOORLOCKD_VERSION_MINOR "@DOORLOCKD_VERSION_MINOR@" +#define DOORLOCKD_VERSION_PATCH "@DOORLOCKD_VERSION_PATCH@" + +#define DOORLOCKD_GIT_BRANCH @GIT_BRANCH@ +#define DOORLOCKD_GIT_COMMIT_HASH @GIT_COMMIT_HASH@ + #ifdef DEBUG #define DEFAULT_LOG_LEVEL LogLevel::debug2 #else diff --git a/doorlockd/main.cpp b/doorlockd/main.cpp index 75440d5..9246a54 100644 --- a/doorlockd/main.cpp +++ b/doorlockd/main.cpp @@ -18,6 +18,13 @@ namespace po = boost::program_options; using boost::asio::ip::tcp; +// Info about doorlockd version +const static std::string version = + (std::string)"doorlockd-" + DOORLOCKD_VERSION_MAJOR + "." + + DOORLOCKD_VERSION_MINOR + "-" + DOORLOCKD_VERSION_PATCH; +const static std::string gitversion = + DOORLOCKD_GIT_BRANCH "-" DOORLOCKD_GIT_COMMIT_HASH; + // The receive buffer length of the TCP socket const int constexpr SOCKET_BUFFERLENGTH = 2048; @@ -139,11 +146,13 @@ int main(int argc, char** argv) std::string serDev; unsigned int baudrate; + l((std::string)"Hello, this is " + version + " built on " + gitversion, + LogLevel::info); l(LogLevel::notice, "Starting doorlockd"); try { unsigned int timeout; - po::options_description desc("usage: doorlockd"); + po::options_description desc("doorlockd (" + version + " built on " + gitversion + ")"); desc.add_options() ("help,h", "print help")