GenerateVersion.cmake 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. set(NVIM_VERSION
  2. "v${NVIM_VERSION_MAJOR}.${NVIM_VERSION_MINOR}.${NVIM_VERSION_PATCH}${NVIM_VERSION_PRERELEASE}")
  3. execute_process(
  4. COMMAND git --git-dir=${NVIM_SOURCE_DIR}/.git --work-tree=${NVIM_SOURCE_DIR} describe --first-parent --dirty --always
  5. OUTPUT_VARIABLE GIT_TAG
  6. OUTPUT_STRIP_TRAILING_WHITESPACE
  7. RESULT_VARIABLE RES)
  8. if(RES AND NOT RES EQUAL 0)
  9. message(STATUS "Using NVIM_VERSION: ${NVIM_VERSION}")
  10. file(WRITE "${OUTPUT}" "")
  11. return()
  12. endif()
  13. # `git describe` annotates the most recent tagged release; for pre-release
  14. # builds we append that to the dev version.
  15. if(NVIM_VERSION_PRERELEASE)
  16. string(REGEX REPLACE "^v[0-9]+.[0-9]+.[0-9]+-" "" NVIM_VERSION_GIT "${GIT_TAG}")
  17. string(REGEX REPLACE "^([0-9]+)-([a-z0-9]+)" "\\1+\\2" NVIM_VERSION_GIT "${NVIM_VERSION_GIT}")
  18. set(NVIM_VERSION "${NVIM_VERSION}-${NVIM_VERSION_GIT}")
  19. endif()
  20. set(NVIM_VERSION_STRING "#define NVIM_VERSION_MEDIUM \"${NVIM_VERSION}\"\n")
  21. string(SHA1 CURRENT_VERSION_HASH "${NVIM_VERSION_STRING}")
  22. if(EXISTS ${OUTPUT})
  23. file(SHA1 "${OUTPUT}" NVIM_VERSION_HASH)
  24. endif()
  25. if(NOT "${NVIM_VERSION_HASH}" STREQUAL "${CURRENT_VERSION_HASH}")
  26. message(STATUS "Using NVIM_VERSION: ${NVIM_VERSION}")
  27. file(WRITE "${OUTPUT}" "${NVIM_VERSION_STRING}")
  28. endif()