From 810840e09b049f96ac706abb1cd7d4fb8f1c03a2 Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Fri, 15 Sep 2023 08:29:00 +0530 Subject: [PATCH] Support shallow git checkouts when configuring cmake git will bale out if we're using a shallow checkout with no tags. Just fall back to the short commit hash when that happens, so we can still try and identify when the build was from. --- CMakeLists.txt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index acacb34..2355ebe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,10 +41,18 @@ endif() # Pick up a git based version number for development builds find_package(Git) if (GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git") - EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} describe --tags --dirty - OUTPUT_VARIABLE GIT_VERSION - OUTPUT_STRIP_TRAILING_WHITESPACE) - string(REPLACE "onak-" "" VERSION ${GIT_VERSION}) + if (EXISTS "${CMAKE_SOURCE_DIR}/.git/refs/tags/onak-0.6.2") + EXECUTE_PROCESS( + COMMAND ${GIT_EXECUTABLE} describe --tags --dirty + OUTPUT_VARIABLE GIT_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) + string(REPLACE "onak-" "" VERSION ${GIT_VERSION}) + else() + EXECUTE_PROCESS( + COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD + OUTPUT_VARIABLE VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) + endif() else() set(VERSION ${PROJECT_VERSION}) endif() -- 2.39.5