Skip to content

Commit

Permalink
Make git revision detection optional
Browse files Browse the repository at this point in the history
Potentially fixes clementine-player#7355
  • Loading branch information
bassmadrigal committed Oct 31, 2024
1 parent cecc1c1 commit ff87a7f
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions cmake/Version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -119,39 +119,41 @@ else(CLEMENTINE_VERSION_PRERELEASE)
endif(CLEMENTINE_VERSION_PRERELEASE)

# Add git revision
if(FORCE_GIT_REVISION)
set(GIT_REV ${FORCE_GIT_REVISION})
set(GIT_INFO_RESULT 0)
else(FORCE_GIT_REVISION)
find_program(GIT_EXECUTABLE git)
message(STATUS "Found git: ${GIT_EXECUTABLE}")

if(NOT GIT_EXECUTABLE-NOTFOUND)
execute_process(COMMAND ${GIT_EXECUTABLE} describe
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE GIT_INFO_RESULT
OUTPUT_VARIABLE GIT_REV
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT ${GIT_INFO_RESULT} EQUAL 0)
message(SEND_ERROR "git describe failed with code ${GIT_INFO_RESULT}: ${GIT_REV}")
if(INCLUDE_GIT_REVISION)
if(FORCE_GIT_REVISION)
set(GIT_REV ${FORCE_GIT_REVISION})
set(GIT_INFO_RESULT 0)
else(FORCE_GIT_REVISION)
find_program(GIT_EXECUTABLE git)
message(STATUS "Found git: ${GIT_EXECUTABLE}")

if(NOT GIT_EXECUTABLE-NOTFOUND)
execute_process(COMMAND ${GIT_EXECUTABLE} describe
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE GIT_INFO_RESULT
OUTPUT_VARIABLE GIT_REV
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT ${GIT_INFO_RESULT} EQUAL 0)
message(SEND_ERROR "git describe failed with code ${GIT_INFO_RESULT}: ${GIT_REV}")
endif()
endif()
endif()
endif()

string(REGEX REPLACE "^(.+)-([0-9]+)-(g[a-f0-9]+)$" "\\1;\\2;\\3"
GIT_PARTS ${GIT_REV})
string(REGEX REPLACE "^(.+)-([0-9]+)-(g[a-f0-9]+)$" "\\1;\\2;\\3"
GIT_PARTS ${GIT_REV})

if(NOT GIT_PARTS)
message(FATAL_ERROR "Failed to parse git revision string '${GIT_REV}'")
endif(NOT GIT_PARTS)
if(NOT GIT_PARTS)
message(FATAL_ERROR "Failed to parse git revision string '${GIT_REV}'")
endif(NOT GIT_PARTS)

list(LENGTH GIT_PARTS GIT_PARTS_LENGTH)
if(GIT_PARTS_LENGTH EQUAL 3)
list(GET GIT_PARTS 0 GIT_TAGNAME)
list(GET GIT_PARTS 1 GIT_COMMITCOUNT)
list(GET GIT_PARTS 2 GIT_SHA1)
set(HAS_GIT_REVISION ON)
endif(GIT_PARTS_LENGTH EQUAL 3)
list(LENGTH GIT_PARTS GIT_PARTS_LENGTH)
if(GIT_PARTS_LENGTH EQUAL 3)
list(GET GIT_PARTS 0 GIT_TAGNAME)
list(GET GIT_PARTS 1 GIT_COMMITCOUNT)
list(GET GIT_PARTS 2 GIT_SHA1)
set(HAS_GIT_REVISION ON)
endif(GIT_PARTS_LENGTH EQUAL 3)
endif()

if(INCLUDE_GIT_REVISION AND HAS_GIT_REVISION)
set(CLEMENTINE_VERSION_DISPLAY "${GIT_REV}")
Expand Down

0 comments on commit ff87a7f

Please sign in to comment.