From: Jonathan McDowell Date: Fri, 15 Sep 2023 02:59:00 +0000 (+0530) Subject: Support shallow git checkouts when configuring cmake X-Git-Tag: onak-0.6.3~17 X-Git-Url: https://the.earth.li/gitweb/?a=commitdiff_plain;h=810840e09b049f96ac706abb1cd7d4fb8f1c03a2;p=onak.git 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. --- 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()