mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-27 19:58:06 +00:00
[CMake]: only warn when the working directory in a git worktree (#7562)
Signed-off-by: Rudi Heitbaum <rudi@heitbaum.com> Signed-off-by: Rudi Heitbaum <rudi@heitbaum.com> Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
@@ -3,35 +3,37 @@ set(VERSION_MINOR 10)
|
|||||||
set(VERSION_PATCH 26)
|
set(VERSION_PATCH 26)
|
||||||
set(VERSION_COMMIT 0)
|
set(VERSION_COMMIT 0)
|
||||||
|
|
||||||
find_program(GIT git)
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
||||||
if(GIT AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
find_program(GIT git)
|
||||||
execute_process(
|
if(GIT)
|
||||||
|
execute_process(
|
||||||
COMMAND ${GIT} describe --tags
|
COMMAND ${GIT} describe --tags
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
OUTPUT_VARIABLE GIT_DESCRIBE_DIRTY
|
OUTPUT_VARIABLE GIT_DESCRIBE_DIRTY
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
RESULT_VARIABLE GIT_DESCRIBE_RESULT
|
RESULT_VARIABLE GIT_DESCRIBE_RESULT
|
||||||
)
|
)
|
||||||
|
|
||||||
if(GIT_DESCRIBE_RESULT EQUAL 0)
|
if(GIT_DESCRIBE_RESULT EQUAL 0)
|
||||||
# Test if the most recent Git tag matches the pattern "v<major>.<minor>.<patch>*"
|
# Test if the most recent Git tag matches the pattern "v<major>.<minor>.<patch>*"
|
||||||
if(GIT_DESCRIBE_DIRTY MATCHES "^v[0-9]+\\.[0-9]+\\.[0-9]+.*")
|
if(GIT_DESCRIBE_DIRTY MATCHES "^v[0-9]+\\.[0-9]+\\.[0-9]+.*")
|
||||||
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${GIT_DESCRIBE_DIRTY}")
|
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${GIT_DESCRIBE_DIRTY}")
|
||||||
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${GIT_DESCRIBE_DIRTY}")
|
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${GIT_DESCRIBE_DIRTY}")
|
||||||
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${GIT_DESCRIBE_DIRTY}")
|
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${GIT_DESCRIBE_DIRTY}")
|
||||||
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+).*" "\\1" VERSION_COMMIT "${GIT_DESCRIBE_DIRTY}")
|
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+).*" "\\1" VERSION_COMMIT "${GIT_DESCRIBE_DIRTY}")
|
||||||
# If the tag points to the commit, then only the tag is shown in "git describe"
|
# If the tag points to the commit, then only the tag is shown in "git describe"
|
||||||
if(VERSION_COMMIT STREQUAL GIT_DESCRIBE_DIRTY)
|
if(VERSION_COMMIT STREQUAL GIT_DESCRIBE_DIRTY)
|
||||||
set(VERSION_COMMIT 0)
|
set(VERSION_COMMIT 0)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(WARNING "\"${GIT_DESCRIBE_DIRTY}\" does not match pattern v<major>.<minor>.<patch>-<commit>")
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
message(WARNING "\"${GIT_DESCRIBE_DIRTY}\" does not match pattern v<major>.<minor>.<patch>-<commit>")
|
message(WARNING "git describe failed with exit code: ${GIT_DESCRIBE_RESULT}")
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
message(WARNING "git describe failed with exit code: ${GIT_DESCRIBE_RESULT}")
|
message(WARNING "git is not found")
|
||||||
endif()
|
endif()
|
||||||
else()
|
|
||||||
message(WARNING "git is not found")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
message(STATUS "Proceeding with version: ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_COMMIT}")
|
message(STATUS "Proceeding with version: ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_COMMIT}")
|
||||||
|
|||||||
Reference in New Issue
Block a user