From dab6f2bcf292dfd6ee629a4ad9b2216e104d7c1d Mon Sep 17 00:00:00 2001 From: Elie Tournier Date: Thu, 20 Apr 2017 14:06:56 +0100 Subject: Add a getter for the library version. This value is save when running CMake. Signed-off-by: Elie Tournier --- CMakeLists.txt | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index 8259f67..537a54a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,29 @@ include(GNUInstallDirs) OPTION(LIBNITROKEY_STATIC "Build libnitrokey statically" FALSE) +# Getter for the library version +# +# If a git tag is available, we use it. +# Else, we use a git version and we raise a warning. +# +exec_program( + "git" + ${CMAKE_CURRENT_SOURCE_DIR} + ARGS "describe" + OUTPUT_VARIABLE GIT_VERSION) + +IF(${GIT_TAG} MATCHES "fatal:.*") +MESSAGE(WARNING "Unable to find a git tag. Using git version instead.") +exec_program( + "git" + ${CMAKE_CURRENT_SOURCE_DIR} + ARGS "rev-parse HEAD" + OUTPUT_VARIABLE GIT_VERSION) +ENDIF() + +MESSAGE("LIBRARY VERSION: ${GIT_VERSION} ") +ADD_DEFINITIONS(-DVERSION="${GIT_VERSION}") + IF (NOT CMAKE_BUILD_TYPE) IF(APPLE) -- cgit v1.2.1