GenerateSCMRev.cmake 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Gets a UTC timstamp and sets the provided variable to it
  2. function(get_timestamp _var)
  3. string(TIMESTAMP timestamp UTC)
  4. set(${_var} "${timestamp}" PARENT_SCOPE)
  5. endfunction()
  6. list(APPEND CMAKE_MODULE_PATH "${SRC_DIR}/externals/cmake-modules")
  7. # Find the package here with the known path so that the GetGit commands can find it as well
  8. find_package(Git QUIET PATHS "${GIT_EXECUTABLE}")
  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. 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. # The variable SRC_DIR must be passed into the script
  53. # (since it uses the current build directory for all values of CMAKE_*_DIR)
  54. configure_file("${SRC_DIR}/src/common/scm_rev.cpp.in" "scm_rev.cpp" @ONLY)