diff options
author | Dmitry Volosnykh <dmitry.volosnykh@gmail.com> | 2020-05-04 23:23:41 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-04 13:23:41 -0700 |
commit | 7e4124d6e6ccafb267f80f3e57e3780913d5cbe5 (patch) | |
tree | e4f2290026425f1ad978489461b1875e5c8f89a1 | |
parent | a875d247add6889d405aadf7cc35aae4b26a59eb (diff) | |
download | flatbuffers-7e4124d6e6ccafb267f80f3e57e3780913d5cbe5.tar.gz flatbuffers-7e4124d6e6ccafb267f80f3e57e3780913d5cbe5.tar.bz2 flatbuffers-7e4124d6e6ccafb267f80f3e57e3780913d5cbe5.zip |
Handle git program or .git folder absence (#5878)
Assume version is 0.0.0.0 in such cases.
-rw-r--r-- | CMake/Version.cmake | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/CMake/Version.cmake b/CMake/Version.cmake index db6613b8..0bed50f6 100644 --- a/CMake/Version.cmake +++ b/CMake/Version.cmake @@ -1,11 +1,28 @@ +set(VERSION_MAJOR 1) +set(VERSION_MINOR 12) +set(VERSION_PATCH 0) +set(VERSION_COMMIT 0) + find_program(GIT git) -execute_process( - COMMAND ${GIT} describe - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - OUTPUT_VARIABLE GIT_DESCRIBE_DIRTY - OUTPUT_STRIP_TRAILING_WHITESPACE -) -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]+\\.([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}") +if(GIT) + execute_process( + COMMAND ${GIT} describe + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_DESCRIBE_DIRTY + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE GIT_DESCRIBE_RESULT + ) + + if(GIT_DESCRIBE_RESULT EQUAL 0) + 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]+\\.([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}") + else() + message(WARNING "git describe failed with exit code: ${GIT_DESCRIBE_RESULT}") + endif() +else() + message(WARNING "git is not found") +endif() + +message("Proceeding with version: ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_COMMIT}") |