diff options
author | Elie Tournier <tournier.elie@gmail.com> | 2017-04-20 14:06:56 +0100 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2017-11-02 16:10:06 +0100 |
commit | dab6f2bcf292dfd6ee629a4ad9b2216e104d7c1d (patch) | |
tree | 5cba9802797b105365d263dcdbce734975553b36 | |
parent | 7797c8fb5fa69068dd659c369bc774ca74f592fe (diff) | |
download | libnitrokey-dab6f2bcf292dfd6ee629a4ad9b2216e104d7c1d.tar.gz libnitrokey-dab6f2bcf292dfd6ee629a4ad9b2216e104d7c1d.tar.bz2 |
Add a getter for the library version.
This value is save when running CMake.
Signed-off-by: Elie Tournier <tournier.elie@gmail.com>
-rw-r--r-- | CMakeLists.txt | 23 | ||||
-rw-r--r-- | NK_C_API.cc | 4 | ||||
-rw-r--r-- | NK_C_API.h | 8 |
3 files changed, 35 insertions, 0 deletions
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) diff --git a/NK_C_API.cc b/NK_C_API.cc index e730bae..6f4c757 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -532,6 +532,10 @@ extern "C" { } + NK_C_API const char * NK_version() { + return VERSION; + } + #ifdef __cplusplus } #endif @@ -475,6 +475,14 @@ extern "C" { */ NK_C_API int NK_get_progress_bar_value(); + /** + * Return the version of the library. + * If a git tag is available, return it else return the git version. + * This value is defined at the compilation time. + * @return the version of the library + */ + NK_C_API const char * NK_version(); + #ifdef __cplusplus } #endif |