]> the.earth.li Git - onak.git/commitdiff
Support shallow git checkouts when configuring cmake
authorJonathan McDowell <noodles@earth.li>
Fri, 15 Sep 2023 02:59:00 +0000 (08:29 +0530)
committerJonathan McDowell <noodles@earth.li>
Fri, 15 Sep 2023 02:59:00 +0000 (08:29 +0530)
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

index acacb34a2a510aa58f5d98d92073419b2a7764ed..2355ebe1c8b682d358f15734adf0a9f899c51e29 100644 (file)
@@ -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()