GenerateSCMRev.cmake 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. get_git_head_revision(GIT_REF_SPEC GIT_REV)
  12. git_describe(GIT_DESC --always --long --dirty)
  13. git_branch_name(GIT_BRANCH)
  14. get_timestamp(BUILD_DATE)
  15. # Generate cpp with Git revision from template
  16. # Also if this is a CI build, add the build name (ie: Nightly, Canary) to the scm_rev file as well
  17. set(REPO_NAME "")
  18. set(BUILD_VERSION "0")
  19. if (BUILD_REPOSITORY)
  20. # regex capture the string nightly or canary into CMAKE_MATCH_1
  21. string(REGEX MATCH "yuzu-emu/yuzu-?(.*)" OUTVAR ${BUILD_REPOSITORY})
  22. if ("${CMAKE_MATCH_COUNT}" GREATER 0)
  23. # capitalize the first letter of each word in the repo name.
  24. string(REPLACE "-" ";" REPO_NAME_LIST ${CMAKE_MATCH_1})
  25. foreach(WORD ${REPO_NAME_LIST})
  26. string(SUBSTRING ${WORD} 0 1 FIRST_LETTER)
  27. string(SUBSTRING ${WORD} 1 -1 REMAINDER)
  28. string(TOUPPER ${FIRST_LETTER} FIRST_LETTER)
  29. set(REPO_NAME "${REPO_NAME}${FIRST_LETTER}${REMAINDER}")
  30. endforeach()
  31. if (BUILD_TAG)
  32. string(REGEX MATCH "${CMAKE_MATCH_1}-([0-9]+)" OUTVAR ${BUILD_TAG})
  33. if (${CMAKE_MATCH_COUNT} GREATER 0)
  34. set(BUILD_VERSION ${CMAKE_MATCH_1})
  35. endif()
  36. if (BUILD_VERSION)
  37. # This leaves a trailing space on the last word, but we actually want that
  38. # because of how it's styled in the title bar.
  39. set(BUILD_FULLNAME "${REPO_NAME} ${BUILD_VERSION} ")
  40. else()
  41. set(BUILD_FULLNAME "")
  42. endif()
  43. endif()
  44. endif()
  45. endif()
  46. # The variable SRC_DIR must be passed into the script
  47. # (since it uses the current build directory for all values of CMAKE_*_DIR)
  48. configure_file("${SRC_DIR}/src/common/scm_rev.cpp.in" "scm_rev.cpp" @ONLY)