GenerateSCMRev.cmake 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # SPDX-FileCopyrightText: 2019 yuzu Emulator Project
  2. # SPDX-License-Identifier: GPL-2.0-or-later
  3. # Gets a UTC timstamp 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. list(APPEND CMAKE_MODULE_PATH "${SRC_DIR}/externals/cmake-modules")
  9. # Find the package here with the known path so that the GetGit commands can find it as well
  10. find_package(Git QUIET PATHS "${GIT_EXECUTABLE}")
  11. # generate git/build information
  12. include(GetGitRevisionDescription)
  13. if(NOT GIT_REF_SPEC)
  14. get_git_head_revision(GIT_REF_SPEC GIT_REV)
  15. endif()
  16. if(NOT GIT_DESC)
  17. git_describe(GIT_DESC --always --long --dirty)
  18. endif()
  19. if (NOT GIT_BRANCH)
  20. git_branch_name(GIT_BRANCH)
  21. endif()
  22. get_timestamp(BUILD_DATE)
  23. # Generate cpp with Git revision from template
  24. # Also if this is a CI build, add the build name (ie: Nightly, Canary) to the scm_rev file as well
  25. set(REPO_NAME "")
  26. set(BUILD_VERSION "0")
  27. if (BUILD_REPOSITORY)
  28. # regex capture the string nightly or canary into CMAKE_MATCH_1
  29. string(REGEX MATCH "yuzu-emu/yuzu-?(.*)" OUTVAR ${BUILD_REPOSITORY})
  30. if ("${CMAKE_MATCH_COUNT}" GREATER 0)
  31. # capitalize the first letter of each word in the repo name.
  32. string(REPLACE "-" ";" REPO_NAME_LIST ${CMAKE_MATCH_1})
  33. foreach(WORD ${REPO_NAME_LIST})
  34. string(SUBSTRING ${WORD} 0 1 FIRST_LETTER)
  35. string(SUBSTRING ${WORD} 1 -1 REMAINDER)
  36. string(TOUPPER ${FIRST_LETTER} FIRST_LETTER)
  37. set(REPO_NAME "${REPO_NAME}${FIRST_LETTER}${REMAINDER}")
  38. endforeach()
  39. if (BUILD_TAG)
  40. string(REGEX MATCH "${CMAKE_MATCH_1}-([0-9]+)" OUTVAR ${BUILD_TAG})
  41. if (${CMAKE_MATCH_COUNT} GREATER 0)
  42. set(BUILD_VERSION ${CMAKE_MATCH_1})
  43. endif()
  44. if (BUILD_VERSION)
  45. # This leaves a trailing space on the last word, but we actually want that
  46. # because of how it's styled in the title bar.
  47. set(BUILD_FULLNAME "${REPO_NAME} ${BUILD_VERSION} ")
  48. else()
  49. set(BUILD_FULLNAME "")
  50. endif()
  51. endif()
  52. endif()
  53. endif()
  54. # The variable SRC_DIR must be passed into the script
  55. # (since it uses the current build directory for all values of CMAKE_*_DIR)
  56. configure_file("${SRC_DIR}/src/common/scm_rev.cpp.in" "scm_rev.cpp" @ONLY)