From b75b9794d19d6a6e3b51418ff9e9c038520c1974 Mon Sep 17 00:00:00 2001 From: pixl Date: Wed, 15 Jul 2020 13:16:43 -0400 Subject: [PATCH] Fix versioning system --- CMakeLists.txt | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a1d9fd9..b147ab7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,37 +14,27 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Git) # Set version number -if(EXISTS ${CMAKE_SOURCE_DIR}/version.txt) +if(GIT_FOUND AND EXISTS ${CMAKE_SOURCE_DIR}/.git) + execute_process(COMMAND ${GIT_EXECUTABLE} describe + OUTPUT_VARIABLE LOGIOPS_VERSION + RESULT_VARIABLE LOGIOPS_VERSION_RET + ERROR_QUIET) + if(NOT LOGIOPS_VERSION_RET EQUAL "0") + execute_process(COMMAND ${GIT_EXECUTABLE} + rev-parse --short HEAD + OUTPUT_VARIABLE LOGIOPS_COMMIT_HASH) + set(LOGIOPS_VERSION git-${LOGIOPS_COMMIT_HASH}) + endif() + string(REGEX REPLACE "\n$" "" LOGIOPS_VERSION ${LOGIOPS_VERSION}) +elseif(EXISTS ${CMAKE_SOURCE_DIR}/version.txt) file(READ version.txt LOGIOPS_VERSION) string(REGEX REPLACE "\n$" "" LOGIOPS_VERSION ${LOGIOPS_VERSION}) endif() -if(GIT_FOUND AND EXISTS ${CMAKE_SOURCE_DIR}/.git) - execute_process(COMMAND ${GIT_EXECUTABLE} - rev-parse --abbrev-ref HEAD - OUTPUT_VARIABLE LOGIOPS_GIT_BRANCH) - string(REGEX REPLACE "\n$" "" LOGIOPS_GIT_BRANCH ${LOGIOPS_GIT_BRANCH}) - if(LOGIOPS_GIT_BRANCH MATCHES "^tags/?") - STRING(REGEX REPLACE "^tags/" "" - LOGIOPS_VERSION ${LOGIOPS_GIT_BRANCH}) - else() - execute_process(COMMAND ${GIT_EXECUTABLE} - rev-parse --short HEAD - OUTPUT_VARIABLE LOGIOPS_COMMIT_HASH) - string(REGEX REPLACE "\n$" "" LOGIOPS_COMMIT_HASH ${LOGIOPS_COMMIT_HASH}) - if(LOGIOPS_VERSION) - string(APPEND LOGIOPS_VERSION -${LOGIOPS_COMMIT_HASH}) - else() - set(LOGIOPS_VERSION git-${LOGIOPS_COMMIT_HASH}) - endif() - endif() -endif() - -if(LOGIOPS_VERSION) - message("LogiOps Version Number: ${LOGIOPS_VERSION}") -else() +if(NOT LOGIOPS_VERSION) set(LOGIOPS_VERSION "null") endif() +message("LogiOps Version Number: ${LOGIOPS_VERSION}") add_definitions( -DLOGIOPS_VERSION="${LOGIOPS_VERSION}")