Skip to content

Commit f01debf

Browse files
committed
cmake: rework patch version computation
1 parent 4f9d32f commit f01debf

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

cmake/utils.cmake

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,28 @@ function(get_patch_from_git VERSION_PATCH VERSION_MAJOR)
1717
message(STATUS "Did not find git package.")
1818
set(PATCH 9999)
1919
else()
20-
# If no tags can be found, it is a git shallow clone
20+
# If no tags can be found, it is a git shallow clone or a new major
2121
execute_process(COMMAND
2222
${GIT_EXECUTABLE} rev-list --count v${VERSION_MAJOR}.0..HEAD
2323
RESULT_VARIABLE RESULT_VAR
2424
OUTPUT_VARIABLE PATCH
2525
ERROR_QUIET
2626
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
2727
if(RESULT_VAR) # since 0 is success, need invert it
28-
message(STATUS "Did not be able to compute patch from v${VERSION_MAJOR}.0.")
29-
set(PATCH 9999)
28+
message(STATUS "Did not be able to compute patch from 'v${VERSION_MAJOR}.0'.")
29+
execute_process(COMMAND
30+
${GIT_EXECUTABLE} rev-parse --is-shallow-repository
31+
OUTPUT_VARIABLE IS_SHALLOW_VAR
32+
ERROR_QUIET
33+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
34+
)
35+
if(${IS_SHALLOW_VAR} MATCHES "false")
36+
message(STATUS "Repo is not shallow, use 0 as patch.")
37+
set(PATCH 0)
38+
else()
39+
message(STATUS "Repo is shallow, use 9999 as patch.")
40+
set(PATCH 9999)
41+
endif()
3042
endif()
3143
STRING(STRIP PATCH ${PATCH})
3244
STRING(REGEX REPLACE "\n$" "" PATCH ${PATCH})

0 commit comments

Comments
 (0)