GenerateSCMRev.cmake 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # SPDX-FileCopyrightText: 2019 yuzu Emulator Project
  2. # SPDX-License-Identifier: GPL-2.0-or-later
  3. # Gets a UTC timestamp and sets the provided variable to it
  4. function(get_timestamp _var)
  5. string(TIMESTAMP timestamp UTC)
  6. set(${_var} "${timestamp}" PARENT_SCOPE)
  7. endfunction()
  8. # generate git/build information
  9. include(GetGitRevisionDescription)
  10. if(NOT GIT_REF_SPEC)
  11. get_git_head_revision(GIT_REF_SPEC GIT_REV)
  12. endif()
  13. if(NOT GIT_DESC)
  14. git_describe(GIT_DESC --always --long --dirty)
  15. endif()
  16. if (NOT GIT_BRANCH)
  17. git_branch_name(GIT_BRANCH)
  18. endif()
  19. get_timestamp(BUILD_DATE)
  20. # Generate cpp with Git revision from template
  21. # Also if this is a CI build, add the build name (ie: Nightly, Canary) to the scm_rev file as well
  22. set(REPO_NAME "")
  23. set(BUILD_VERSION "0")
  24. set(BUILD_ID ${DISPLAY_VERSION})
  25. if (BUILD_REPOSITORY)
  26. # regex capture the string nightly or canary into CMAKE_MATCH_1
  27. string(REGEX MATCH "yuzu-emu/yuzu-?(.*)" OUTVAR ${BUILD_REPOSITORY})
  28. if ("${CMAKE_MATCH_COUNT}" GREATER 0)
  29. # capitalize the first letter of each word in the repo name.
  30. string(REPLACE "-" ";" REPO_NAME_LIST ${CMAKE_MATCH_1})
  31. foreach(WORD ${REPO_NAME_LIST})
  32. string(SUBSTRING ${WORD} 0 1 FIRST_LETTER)
  33. string(SUBSTRING ${WORD} 1 -1 REMAINDER)
  34. string(TOUPPER ${FIRST_LETTER} FIRST_LETTER)
  35. set(REPO_NAME "${REPO_NAME}${FIRST_LETTER}${REMAINDER}")
  36. endforeach()
  37. if (BUILD_TAG)
  38. string(REGEX MATCH "${CMAKE_MATCH_1}-([0-9]+)" OUTVAR ${BUILD_TAG})
  39. if (${CMAKE_MATCH_COUNT} GREATER 0)
  40. set(BUILD_VERSION ${CMAKE_MATCH_1})
  41. endif()
  42. if (BUILD_VERSION)
  43. # This leaves a trailing space on the last word, but we actually want that
  44. # because of how it's styled in the title bar.
  45. set(BUILD_FULLNAME "${REPO_NAME} ${BUILD_VERSION} ")
  46. else()
  47. set(BUILD_FULLNAME "")
  48. endif()
  49. endif()
  50. endif()
  51. endif()
  52. configure_file(scm_rev.cpp.in scm_rev.cpp @ONLY)