From fb804938886368d0c806ac7325ce15fb7111bf3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Urs=20F=C3=A4ssler?= Date: Thu, 9 May 2024 21:16:33 +0200 Subject: [PATCH] allow compilation without git or when git fails This happens when the code is downloaded as source archive. This does not contain the git repository, hence the git version script fails. Now the version 0.0.0+YEAR.MONTH.DAY is used when we fail to get the version from git. --- cmake/modules/GitVersion.cmake | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cmake/modules/GitVersion.cmake b/cmake/modules/GitVersion.cmake index b5c4e756..d13f2166 100644 --- a/cmake/modules/GitVersion.cmake +++ b/cmake/modules/GitVersion.cmake @@ -1,8 +1,12 @@ function(git_get_version VERSION_VARIABLE) + string(TIMESTAMP TODAY "%Y.%m.%d") + set(${VERSION_VARIABLE} "0.0.0+${TODAY}" PARENT_SCOPE) + find_program(GIT_EXECUTABLE git) if(NOT GIT_EXECUTABLE) - message(FATAL_ERROR "Git not found. Please install Git and make sure it is in your system's PATH.") + message(WARNING "Git not found, using fallback version.") + return() endif() execute_process( @@ -15,7 +19,9 @@ function(git_get_version VERSION_VARIABLE) ) if(NOT GIT_DESCRIBE_RESULT EQUAL 0) - message(FATAL_ERROR "Error running 'git describe': ${GIT_DESCRIBE_ERROR}") + message(INFO "Error running 'git describe': ${GIT_DESCRIBE_ERROR}") + message(WARNING "Git failed, using fallback version.") + return() endif() string(LENGTH "${VERSION_STRING}" VERSION_STRING_LENGTH)