Allow getting available version information even when clone is shallow

pull/183/head
Nikolay Kasyanov 8 years ago
parent e24cb0fe5d
commit 7f429f26e1

@ -35,17 +35,13 @@ set(OPENMW_VERSION "${OPENMW_VERSION_MAJOR}.${OPENMW_VERSION_MINOR}.${OPENMW_VER
set(GIT_CHECKOUT FALSE) set(GIT_CHECKOUT FALSE)
if(EXISTS ${PROJECT_SOURCE_DIR}/.git) if(EXISTS ${PROJECT_SOURCE_DIR}/.git)
if(NOT EXISTS ${PROJECT_SOURCE_DIR}/.git/shallow) find_package(Git)
find_package(Git)
if(GIT_FOUND)
if(GIT_FOUND) set(GIT_CHECKOUT TRUE)
set(GIT_CHECKOUT TRUE) else(GIT_FOUND)
else(GIT_FOUND) message(WARNING "Git executable not found")
message(WARNING "Git executable not found") endif(GIT_FOUND)
endif(GIT_FOUND)
else(NOT EXISTS ${PROJECT_SOURCE_DIR}/.git/shallow)
message(STATUS "Shallow Git clone detected, not attempting to retrieve version info")
endif(NOT EXISTS ${PROJECT_SOURCE_DIR}/.git/shallow)
endif(EXISTS ${PROJECT_SOURCE_DIR}/.git) endif(EXISTS ${PROJECT_SOURCE_DIR}/.git)
# Macros # Macros

@ -3,7 +3,8 @@ execute_process (
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
RESULT_VARIABLE EXITCODE1 RESULT_VARIABLE EXITCODE1
OUTPUT_VARIABLE TAGHASH OUTPUT_VARIABLE TAGHASH
OUTPUT_STRIP_TRAILING_WHITESPACE) OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)
execute_process ( execute_process (
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
@ -12,13 +13,17 @@ execute_process (
OUTPUT_VARIABLE COMMITHASH OUTPUT_VARIABLE COMMITHASH
OUTPUT_STRIP_TRAILING_WHITESPACE) OUTPUT_STRIP_TRAILING_WHITESPACE)
string (COMPARE EQUAL "${EXITCODE1}:${EXITCODE2}" "0:0" SUCCESS) string (COMPARE EQUAL "${EXITCODE1}:${EXITCODE2}" "0:0" FULL_SUCCESS)
if (SUCCESS) string (COMPARE EQUAL "${EXITCODE2}" "0" COMMIT_SUCCESS)
if (FULL_SUCCESS)
set(OPENMW_VERSION_COMMITHASH "${COMMITHASH}") set(OPENMW_VERSION_COMMITHASH "${COMMITHASH}")
set(OPENMW_VERSION_TAGHASH "${TAGHASH}") set(OPENMW_VERSION_TAGHASH "${TAGHASH}")
message(STATUS "OpenMW version ${OPENMW_VERSION}") message(STATUS "OpenMW version ${OPENMW_VERSION}")
else (SUCCESS) elseif (COMMIT_SUCCESS)
set(OPENMW_VERSION_COMMITHASH "${COMMITHASH}")
message(STATUS "OpenMW version ${OPENMW_VERSION}")
else ()
message(WARNING "Failed to get valid version information from Git") message(WARNING "Failed to get valid version information from Git")
endif (SUCCESS) endif ()
configure_file(${VERSION_IN_FILE} ${VERSION_FILE}) configure_file(${VERSION_IN_FILE} ${VERSION_FILE})

@ -23,8 +23,7 @@ std::string Version::describe()
{ {
std::string str = "OpenMW version " + mVersion; std::string str = "OpenMW version " + mVersion;
std::string rev = mCommitHash; std::string rev = mCommitHash;
std::string tag = mTagHash; if (!rev.empty())
if (!rev.empty() && !tag.empty())
{ {
rev = rev.substr(0, 10); rev = rev.substr(0, 10);
str += "\nRevision: " + rev; str += "\nRevision: " + rev;

Loading…
Cancel
Save