/ CMakeModules / GenerateBuildInfo.cmake
GenerateBuildInfo.cmake
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 get_timestamp(BUILD_DATE) 7 8 list(APPEND CMAKE_MODULE_PATH "${SRC_DIR}/externals/cmake-modules") 9 10 if (EXISTS "${SRC_DIR}/.git/objects") 11 # Find the package here with the known path so that the GetGit commands can find it as well 12 find_package(Git QUIET PATHS "${GIT_EXECUTABLE}") 13 14 # only use Git to check revision info when source is obtained via Git 15 include(GetGitRevisionDescription) 16 get_git_head_revision(GIT_REF_SPEC GIT_REV) 17 git_describe(GIT_DESC --always --long --dirty) 18 git_branch_name(GIT_BRANCH) 19 elseif (EXISTS "${SRC_DIR}/GIT-COMMIT" AND EXISTS "${SRC_DIR}/GIT-TAG") 20 # unified source archive 21 file(READ "${SRC_DIR}/GIT-COMMIT" GIT_REV_RAW LIMIT 64) 22 string(STRIP "${GIT_REV_RAW}" GIT_REV) 23 string(SUBSTRING "${GIT_REV_RAW}" 0 9 GIT_DESC) 24 set(GIT_BRANCH "HEAD") 25 else() 26 # self-packed archive? 27 set(GIT_REV "UNKNOWN") 28 set(GIT_DESC "UNKNOWN") 29 set(GIT_BRANCH "UNKNOWN") 30 endif() 31 string(SUBSTRING "${GIT_REV}" 0 7 GIT_SHORT_REV) 32 33 # Generate cpp with Git revision from template 34 # Also if this is a CI build, add the build name (ie: Nightly, Canary) to the scm_rev file as well 35 set(REPO_NAME "") 36 set(BUILD_VERSION "0") 37 set(BUILD_FULLNAME "${GIT_SHORT_REV}") 38 if (DEFINED ENV{CI}) 39 if (DEFINED ENV{GITHUB_ACTIONS}) 40 set(BUILD_REPOSITORY $ENV{GITHUB_REPOSITORY}) 41 set(BUILD_TAG $ENV{GITHUB_REF_NAME}) 42 endif() 43 44 # regex capture the string nightly or canary into CMAKE_MATCH_1 45 string(REGEX MATCH "citra-emu/citra-?(.*)" OUTVAR ${BUILD_REPOSITORY}) 46 if ("${CMAKE_MATCH_COUNT}" GREATER 0) 47 # capitalize the first letter of each word in the repo name. 48 string(REPLACE "-" ";" REPO_NAME_LIST ${CMAKE_MATCH_1}) 49 foreach(WORD ${REPO_NAME_LIST}) 50 string(SUBSTRING ${WORD} 0 1 FIRST_LETTER) 51 string(SUBSTRING ${WORD} 1 -1 REMAINDER) 52 string(TOUPPER ${FIRST_LETTER} FIRST_LETTER) 53 set(REPO_NAME "${REPO_NAME}${FIRST_LETTER}${REMAINDER}") 54 endforeach() 55 string(REGEX MATCH "${CMAKE_MATCH_1}-([0-9]+)" OUTVAR ${BUILD_TAG}) 56 if (${CMAKE_MATCH_COUNT} GREATER 0) 57 set(BUILD_VERSION ${CMAKE_MATCH_1}) 58 endif() 59 if (BUILD_VERSION) 60 set(BUILD_FULLNAME "${REPO_NAME} ${BUILD_VERSION}") 61 else() 62 set(BUILD_FULLNAME "") 63 endif() 64 endif() 65 endif()