cmake: handle the scenario of a commit having more than 1 tag (#3662)
Some checks failed
Build / 🖥️ Windows (push) Has been cancelled
Build / 🐧 Linux (push) Has been cancelled
Build / 🍎 MacOS (push) Has been cancelled
Lint / 📝 Formatting (push) Has been cancelled
Lint / 📝 Required Checks (push) Has been cancelled
Lint / 📝 Optional Checks (push) Has been cancelled

This commit is contained in:
Tyler Wilding 2024-09-09 23:49:03 -04:00 committed by GitHub
parent 69d879f901
commit 431508aab1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -15,6 +15,13 @@ function(write_revision_h)
OUTPUT_VARIABLE GIT_TAG OUTPUT_VARIABLE GIT_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET) ERROR_QUIET)
# To support being on a commit with mutiple tags
if(${GIT_TAG} MATCHES "\n")
string(REPLACE "\n" ";" GIT_TAG_LIST "${GIT_TAG}")
list(LENGTH GIT_TAG_LIST GIT_TAG_LIST_LENGTH)
math(EXPR GIT_TAG_LAST_INDEX "${GIT_TAG_LIST_LENGTH} - 1")
list(GET GIT_TAG_LIST ${GIT_TAG_LAST_INDEX} GIT_TAG)
endif()
endif() endif()
file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/versions/revision.h "#define BUILT_TAG \"${GIT_TAG}\"\n#define BUILT_SHA \"${GIT_SHORT_SHA}\"\n") file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/versions/revision.h "#define BUILT_TAG \"${GIT_TAG}\"\n#define BUILT_SHA \"${GIT_SHORT_SHA}\"\n")
endfunction() endfunction()