Browse Source

Fix git log in CMake for older Git

Christian W. Zuckschwerdt 11 months ago
parent
commit
4c2748bb5d
1 changed files with 6 additions and 1 deletions
  1. 6 1
      cmake/Modules/GetGitRevisionDescription.cmake

+ 6 - 1
cmake/Modules/GetGitRevisionDescription.cmake

@@ -158,13 +158,18 @@ function(git_timestamp _var)
     return()
   endif()
 
-  execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --format=%cI ${hash} ${ARGN}
+  execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --format=%ci ${hash} ${ARGN}
     WORKING_DIRECTORY ${GIT_DIR}
     RESULT_VARIABLE res
     OUTPUT_VARIABLE out
     ERROR_QUIET
     OUTPUT_STRIP_TRAILING_WHITESPACE)
   if(res EQUAL 0)
+    # older Git does not have %cI, create ISO8601 from %ci
+    string(SUBSTRING ${out} 0 10 date)
+    string(SUBSTRING ${out} 10 -1 time)
+    string(REPLACE " " "" time ${time})
+    set(out "${date}T${time}")
     set(${_var}_ISO ${out} PARENT_SCOPE)
     string(REGEX REPLACE "[-T:]" "" out ${out})
     string(SUBSTRING ${out} 0 12 out)