From 0c1ae9bbdd8f271062abac2935521f8a32ca549b Mon Sep 17 00:00:00 2001 From: Constantine Evans Date: Tue, 17 Dec 2024 03:15:21 -0500 Subject: [PATCH] Parse version from directory name if not a git repository. (#142) If the oxDNA folder is not a git repo, parse the version from directory name, or set it to unknown/none when info cannot be extracted in any way. Fixes #141 --- CMakeLists.txt | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 989d65a0d..6c9de99a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,11 +125,30 @@ endif(JSON_ENABLED) # get the current git revision, if git is installed. Avoid warnings if it isn't FIND_PACKAGE(Git) IF(Git_FOUND) + EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-parse --git-dir WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_VARIABLE git_dir OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) + IF(git_dir STREQUAL "${PROJECT_SOURCE_DIR}/.git") + SET(IS_GIT_REPO TRUE) + ELSE() + SET(IS_GIT_REPO FALSE) + ENDIF() +ELSE() + SET(IS_GIT_REPO FALSE) +ENDIF(Git_FOUND) + +IF(IS_GIT_REPO) EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_VARIABLE revision OUTPUT_STRIP_TRAILING_WHITESPACE) EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0 HEAD WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_VARIABLE tag OUTPUT_STRIP_TRAILING_WHITESPACE) ELSE() - SET(revision GIT_NOT_FOUND) -ENDIF(Git_FOUND) + get_filename_component(dir_name ${PROJECT_SOURCE_DIR} NAME) + string(REGEX MATCH "-([0-9]+\\.[0-9]+\\.[0-9]+.*)$" version_match ${dir_name}) + SET(revision "none") + if(version_match) + SET(tag "v${CMAKE_MATCH_1}") + else() + SET(tag "unknown") + endif() +ENDIF(IS_GIT_REPO) + # return the current date as day/month/year MACRO(CURRENT_DATE result)