diff options
author | Josh Rahm <rahm@google.com> | 2022-07-18 19:37:18 +0000 |
---|---|---|
committer | Josh Rahm <rahm@google.com> | 2022-07-18 19:37:18 +0000 |
commit | 308e1940dcd64aa6c344c403d4f9e0dda58d9c5c (patch) | |
tree | 35fe43e01755e0f312650667004487a44d6b7941 /cmake/GenerateVersion.cmake | |
parent | 96a00c7c588b2f38a2424aeeb4ea3581d370bf2d (diff) | |
parent | e8c94697bcbe23a5c7b07c292b90a6b70aadfa87 (diff) | |
download | rneovim-308e1940dcd64aa6c344c403d4f9e0dda58d9c5c.tar.gz rneovim-308e1940dcd64aa6c344c403d4f9e0dda58d9c5c.tar.bz2 rneovim-308e1940dcd64aa6c344c403d4f9e0dda58d9c5c.zip |
Merge remote-tracking branch 'upstream/master' into rahm
Diffstat (limited to 'cmake/GenerateVersion.cmake')
-rw-r--r-- | cmake/GenerateVersion.cmake | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/cmake/GenerateVersion.cmake b/cmake/GenerateVersion.cmake new file mode 100644 index 0000000000..b9313f2498 --- /dev/null +++ b/cmake/GenerateVersion.cmake @@ -0,0 +1,48 @@ +# Handle generating version from Git. +set(use_git_version 0) +if(NVIM_VERSION_MEDIUM) + message(STATUS "USING NVIM_VERSION_MEDIUM: ${NVIM_VERSION_MEDIUM}") + return() +endif() + +find_program(GIT_EXECUTABLE git) +if(NOT GIT_EXECUTABLE) + message(AUTHOR_WARNING "Skipping version-string generation (cannot find git)") + file(WRITE "${OUTPUT}" "") + return() +endif() + +execute_process( + COMMAND git describe --first-parent --tags --always --dirty + OUTPUT_VARIABLE GIT_TAG + ERROR_VARIABLE ERR + RESULT_VARIABLE RES +) + +if("${RES}" EQUAL 1) + if(EXISTS ${OUTPUT}) + message(STATUS "Unable to extract version-string from git: keeping the last known version") + else() + # this will only be executed once since the file will get generated afterwards + message(AUTHOR_WARNING "Git tag extraction failed with: " "${ERR}") + file(WRITE "${OUTPUT}" "") + endif() + return() +endif() + +string(STRIP "${GIT_TAG}" GIT_TAG) +string(REGEX REPLACE "^v[0-9]+.[0-9]+.[0-9]+-" "" NVIM_VERSION_GIT "${GIT_TAG}") +set(NVIM_VERSION_MEDIUM + "v${NVIM_VERSION_MAJOR}.${NVIM_VERSION_MINOR}.${NVIM_VERSION_PATCH}-dev-${NVIM_VERSION_GIT}" +) +set(NVIM_VERSION_STRING "#define NVIM_VERSION_MEDIUM \"${NVIM_VERSION_MEDIUM}\"\n") +string(SHA1 CURRENT_VERSION_HASH "${NVIM_VERSION_STRING}") + +if(EXISTS ${OUTPUT}) + file(SHA1 "${OUTPUT}" NVIM_VERSION_HASH) +endif() + +if(NOT "${NVIM_VERSION_HASH}" STREQUAL "${CURRENT_VERSION_HASH}") + message(STATUS "Updating NVIM_VERSION_MEDIUM: ${NVIM_VERSION_MEDIUM}") + file(WRITE "${OUTPUT}" "${NVIM_VERSION_STRING}") +endif() |