From 1be2d32fd502eeb68bd63fb07b0325b25ee357bd Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Mon, 4 May 2015 18:46:49 -0400 Subject: Make Git version detection use VERSION_STRING instead of tags This fixes the problem where 0.4.12-dev versions were erroneously shown as 0.4.11-dev because the tag was added on a separate branch. It also fixes a similar issue when builders didn't fetch new tags when updating. This also removes the number-of-commits-since-tag field, since it's incompatible with this. Said field doesn't seem to be useful anyway if you have the commit hash. --- cmake/Modules/GenerateVersion.cmake | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'cmake') diff --git a/cmake/Modules/GenerateVersion.cmake b/cmake/Modules/GenerateVersion.cmake index 9b5304ad5..ad0e38263 100644 --- a/cmake/Modules/GenerateVersion.cmake +++ b/cmake/Modules/GenerateVersion.cmake @@ -1,28 +1,24 @@ # Always run during 'make' -if(VERSION_EXTRA) - set(VERSION_GITHASH "${VERSION_STRING}") -else() - execute_process(COMMAND git describe --tag --dirty +if(DEVELOPMENT_BUILD) + execute_process(COMMAND git rev-parse --short HEAD WORKING_DIRECTORY "${GENERATE_VERSION_SOURCE_DIR}" OUTPUT_VARIABLE VERSION_GITHASH OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) - if(VERSION_GITHASH) - message(STATUS "*** Detected Git version ${VERSION_GITHASH} ***") - else() - execute_process(COMMAND git describe --always --tag --dirty + set(VERSION_GITHASH "${VERSION_STRING}-${VERSION_GITHASH}") + execute_process(COMMAND git diff-index --quiet HEAD WORKING_DIRECTORY "${GENERATE_VERSION_SOURCE_DIR}" - OUTPUT_VARIABLE VERSION_GITHASH OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_QUIET) - if(VERSION_GITHASH) - set(VERSION_GITHASH "${VERSION_STRING}-${VERSION_GITHASH}") - message(STATUS "*** Detected shallow Git version ${VERSION_GITHASH} ***") - else() - set(VERSION_GITHASH "${VERSION_STRING}") + RESULT_VARIABLE IS_DIRTY) + if(IS_DIRTY) + set(VERSION_GITHASH "${VERSION_GITHASH}-dirty") endif() + message(STATUS "*** Detected Git version ${VERSION_GITHASH} ***") endif() endif() +if(NOT VERSION_GITHASH) + set(VERSION_GITHASH "${VERSION_STRING}") +endif() configure_file( ${GENERATE_VERSION_SOURCE_DIR}/cmake_config_githash.h.in -- cgit v1.2.3