GenerateSCMRev.cmake 2.0 KB

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