1# Gets a UTC timstamp and sets the provided variable to it
2function(get_timestamp _var)
3    string(TIMESTAMP timestamp UTC)
4    set(${_var} "${timestamp}" PARENT_SCOPE)
5endfunction()
6
7list(APPEND CMAKE_MODULE_PATH "${SRC_DIR}/externals/cmake-modules")
8
9# Find the package here with the known path so that the GetGit commands can find it as well
10find_package(Git QUIET PATHS "${GIT_EXECUTABLE}")
11
12# generate git/build information
13include(GetGitRevisionDescription)
14get_git_head_revision(GIT_REF_SPEC GIT_REV)
15git_describe(GIT_DESC --always --long --dirty)
16git_branch_name(GIT_BRANCH)
17get_timestamp(BUILD_DATE)
18
19# Generate cpp with Git revision from template
20# Also if this is a CI build, add the build name (ie: Nightly, Canary) to the scm_rev file as well
21set(REPO_NAME "")
22set(BUILD_VERSION "0")
23if (DEFINED ENV{CI})
24  if (DEFINED ENV{GITHUB_ACTIONS})
25    set(BUILD_REPOSITORY $ENV{GITHUB_REPOSITORY})
26    set(BUILD_TAG $ENV{GIT_TAG_NAME})
27  elseif(DEFINED ENV{APPVEYOR})
28    set(BUILD_REPOSITORY $ENV{APPVEYOR_REPO_NAME})
29    set(BUILD_TAG $ENV{APPVEYOR_REPO_TAG_NAME})
30  elseif(DEFINED ENV{BITRISE_IO})
31    set(BUILD_REPOSITORY "$ENV{BITRISEIO_GIT_REPOSITORY_OWNER}/$ENV{BITRISEIO_GIT_REPOSITORY_SLUG}")
32    set(BUILD_TAG $ENV{BITRISE_GIT_TAG})
33  endif()
34
35  # regex capture the string nightly or canary into CMAKE_MATCH_1
36  string(REGEX MATCH "citra-emu/citra-?(.*)" OUTVAR ${BUILD_REPOSITORY})
37  if ("${CMAKE_MATCH_COUNT}" GREATER 0)
38    # capitalize the first letter of each word in the repo name.
39    string(REPLACE "-" ";" REPO_NAME_LIST ${CMAKE_MATCH_1})
40    foreach(WORD ${REPO_NAME_LIST})
41      string(SUBSTRING ${WORD} 0 1 FIRST_LETTER)
42      string(SUBSTRING ${WORD} 1 -1 REMAINDER)
43      string(TOUPPER ${FIRST_LETTER} FIRST_LETTER)
44      set(REPO_NAME "${REPO_NAME}${FIRST_LETTER}${REMAINDER}")
45    endforeach()
46    if (BUILD_TAG)
47      string(REGEX MATCH "${CMAKE_MATCH_1}-([0-9]+)" OUTVAR ${BUILD_TAG})
48      if (${CMAKE_MATCH_COUNT} GREATER 0)
49        set(BUILD_VERSION ${CMAKE_MATCH_1})
50      endif()
51      if (BUILD_VERSION)
52        # This leaves a trailing space on the last word, but we actually want that
53        # because of how it's styled in the title bar.
54        set(BUILD_FULLNAME "${REPO_NAME} ${BUILD_VERSION} ")
55      else()
56        set(BUILD_FULLNAME "")
57      endif()
58    endif()
59  endif()
60endif()
61
62# The variable SRC_DIR must be passed into the script (since it uses the current build directory for all values of CMAKE_*_DIR)
63set(VIDEO_CORE "${SRC_DIR}/src/video_core")
64set(HASH_FILES
65    "${VIDEO_CORE}/renderer_opengl/gl_shader_decompiler.cpp"
66    "${VIDEO_CORE}/renderer_opengl/gl_shader_decompiler.h"
67    "${VIDEO_CORE}/renderer_opengl/gl_shader_disk_cache.cpp"
68    "${VIDEO_CORE}/renderer_opengl/gl_shader_disk_cache.h"
69    "${VIDEO_CORE}/renderer_opengl/gl_shader_gen.cpp"
70    "${VIDEO_CORE}/renderer_opengl/gl_shader_gen.h"
71    "${VIDEO_CORE}/shader/shader.cpp"
72    "${VIDEO_CORE}/shader/shader.h"
73    "${VIDEO_CORE}/pica.cpp"
74    "${VIDEO_CORE}/pica.h"
75    "${VIDEO_CORE}/regs_framebuffer.h"
76    "${VIDEO_CORE}/regs_lighting.h"
77    "${VIDEO_CORE}/regs_pipeline.h"
78    "${VIDEO_CORE}/regs_rasterizer.h"
79    "${VIDEO_CORE}/regs_shader.h"
80    "${VIDEO_CORE}/regs_texturing.h"
81    "${VIDEO_CORE}/regs.cpp"
82    "${VIDEO_CORE}/regs.h"
83)
84set(COMBINED "")
85foreach (F IN LISTS HASH_FILES)
86    file(READ ${F} TMP)
87    set(COMBINED "${COMBINED}${TMP}")
88endforeach()
89string(MD5 SHADER_CACHE_VERSION "${COMBINED}")
90configure_file("${SRC_DIR}/src/common/scm_rev.cpp.in" "scm_rev.cpp" @ONLY)
91