aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2018-07-18 10:43:48 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2018-07-18 10:43:48 +0200
commitf6d08b36552ee2aae412086123a571b9929c0ae3 (patch)
treec579692982ef772d20e33fa788aa20dd2f2bedf5
parent430e4b4116ec00c4875170642f8ae04bc3497d88 (diff)
downloadlibnitrokey-f6d08b36552ee2aae412086123a571b9929c0ae3.tar.gz
libnitrokey-f6d08b36552ee2aae412086123a571b9929c0ae3.tar.bz2
Handle build without Git repository info
Sets version to "unknown" Fixes #126 Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rw-r--r--CMakeLists.txt16
1 files changed, 15 insertions, 1 deletions
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)