GenerateVersion.cmake 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. ERROR_QUIET
  8. RESULT_VARIABLE RES)
  9. if(RES)
  10. message(STATUS "Using NVIM_VERSION: ${NVIM_VERSION}")
  11. file(WRITE "${OUTPUT}" "")
  12. return()
  13. endif()
  14. # Extract build info: "v0.9.0-145-g0f9113907" => "g0f9113907"
  15. string(REGEX REPLACE ".*\\-" "" NVIM_VERSION_BUILD "${GIT_TAG}")
  16. # `git describe` annotates the most recent tagged release; for pre-release
  17. # builds we append that to the dev version.
  18. if(NVIM_VERSION_PRERELEASE)
  19. # Extract pre-release info: "v0.8.0-145-g0f9113907" => "145-g0f9113907"
  20. string(REGEX REPLACE "^v[0-9]+.[0-9]+.[0-9]+-" "" NVIM_VERSION_GIT "${GIT_TAG}")
  21. # Replace "-" with "+": "145-g0f9113907" => "145+g0f9113907"
  22. string(REGEX REPLACE "^([0-9]+)-([a-z0-9]+)" "\\1+\\2" NVIM_VERSION_GIT "${NVIM_VERSION_GIT}")
  23. set(NVIM_VERSION "${NVIM_VERSION}-${NVIM_VERSION_GIT}")
  24. endif()
  25. set(NVIM_VERSION_STRING "#define NVIM_VERSION_MEDIUM \"${NVIM_VERSION}\"\n#define NVIM_VERSION_BUILD \"${NVIM_VERSION_BUILD}\"\n")
  26. string(SHA1 CURRENT_VERSION_HASH "${NVIM_VERSION_STRING}")
  27. if(EXISTS ${OUTPUT})
  28. file(SHA1 "${OUTPUT}" NVIM_VERSION_HASH)
  29. endif()
  30. if(NOT "${NVIM_VERSION_HASH}" STREQUAL "${CURRENT_VERSION_HASH}")
  31. message(STATUS "Using NVIM_VERSION: ${NVIM_VERSION}")
  32. file(WRITE "${OUTPUT}" "${NVIM_VERSION_STRING}")
  33. if(WIN32)
  34. configure_file("${OUTPUT}" "${OUTPUT}" NEWLINE_STYLE UNIX)
  35. endif()
  36. endif()