From 3e5ef9e181084cc88ef59811e6eba1d7d82ba4cf Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Sun, 22 Oct 2017 09:02:41 +0200 Subject: Use hand-inserted version. Remove one Git pass. Full version name should consist of official version and Git one Git describe should never fail with --always switch Add more build specific information Save compilation definitions and flags Move getting information to the end of CMakeLists.txt Use configuration over definitions Proper implementation in C API for getting version Test case for getting version. Working configure file Signed-off-by: Szczepan Zalega --- CMakeLists.txt | 56 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 25 deletions(-) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index 537a54a..f82df8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,43 +28,19 @@ IF (UNIX) ENDIF() project(libnitrokey) -SET(PROJECT_VERSION "3.1") set(CMAKE_CXX_STANDARD 14) set(LIBNK_VERSION_MAJOR 3) # reminder: incompatible API changes set(LIBNK_VERSION_MINOR 1) # add functionality in a backwards-compatible manner set(LIBNK_VERSION_PATCH 0) # make backwards-compatible bug fixes set(LIBNK_VERSION ${LIBNK_VERSION_MAJOR}.${LIBNK_VERSION_MINOR}.${LIBNK_VERSION_PATCH} ) +SET(PROJECT_VERSION "${LIBNK_VERSION}") 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) # Issues occur when build with enabled optimizations @@ -98,6 +74,8 @@ set(SOURCE_FILES device.cc log.cc misc.cc + version.cc + version.h NitrokeyManager.cc NK_C_API.h NK_C_API.cc @@ -196,6 +174,34 @@ IF (COMPILE_TESTS) ENDIF() +# Getter for the library version +exec_program( + "git" + ${CMAKE_CURRENT_SOURCE_DIR} + ARGS "describe --always --dirty=-modified" + OUTPUT_VARIABLE GIT_VERSION) + +get_target_property(COMPILE_DEFINITIONS ${LIBNAME} COMPILE_DEFINITIONS) +get_target_property(COMPILE_FLAGS ${LIBNAME} COMPILE_FLAGS) +SET(FULL_VERSION "${PROJECT_VERSION}/${GIT_VERSION}") +SET(VERSION_MORE "${CMAKE_BUILD_TYPE}/${COMPILE_FLAGS}") +IF(COMPILE_DEFINITIONS) + SET(VERSION_MORE "${VERSION_MORE}/${COMPILE_DEFINITIONS}") +ENDIF() +IF(ADD_TSAN) + SET(VERSION_MORE "${VERSION_MORE} TSAN") +ENDIF() +IF(ADD_ASAN) + SET(VERSION_MORE "${VERSION_MORE} ASAN") +ENDIF() +IF(LIBNITROKEY_STATIC) + SET(VERSION_MORE "${VERSION_MORE} STATIC") +ENDIF() +MESSAGE("${PROJECT_NAME}: Version set: ${FULL_VERSION}") +MESSAGE("${PROJECT_NAME}: Version additional: ${VERSION_MORE}") + +configure_file(version.cc.in ${CMAKE_SOURCE_DIR}/version.cc) + #SET(CPACK_GENERATOR # "DEB;RPM") -- cgit v1.2.3