From f6d08b36552ee2aae412086123a571b9929c0ae3 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Wed, 18 Jul 2018 10:43:48 +0200 Subject: Handle build without Git repository info Sets version to "unknown" Fixes #126 Signed-off-by: Szczepan Zalega --- CMakeLists.txt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 43d15df..d29c087 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,8 +117,22 @@ IF (LOG_VOLATILE_DATA) ENDIF() +OPTION(ADD_GIT_INFO "Add information about source code version from Git repository" TRUE) # generate version.h -exec_program("git" ${CMAKE_CURRENT_SOURCE_DIR} ARGS "describe --always" OUTPUT_VARIABLE PROJECT_VERSION_GIT) +IF(ADD_GIT_INFO) +execute_process( + COMMAND git describe --always --abbrev=4 HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE PROJECT_VERSION_GIT_RETURN_CODE + OUTPUT_VARIABLE PROJECT_VERSION_GIT + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET +) +ENDIF() +IF((NOT ${ADD_GIT_INFO}) OR (${PROJECT_VERSION_GIT_RETURN_CODE})) + SET(PROJECT_VERSION_GIT "unknown") + MESSAGE(STATUS "Setting Git library version to: " ${PROJECT_VERSION_GIT} ) +ENDIF() configure_file("version.cc.in" "version.cc" @ONLY) -- cgit v1.2.3