1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-11-09 20:49:42 +01:00
VVVVVV/desktop_version/version.cmake
Misa d4425ed762 Always have interim version indicators
Previously, the interim version indicators (commit, date, and branch)
would go away on development builds if git didn't exist. And if it did
exist but provided blank output for whatever reason, that was almost
exactly the same as not having them at all (save for the window title
saying "VVVVVV []" which can be easy to overlook). This was bad because
it complicates troubleshooting when you potentially have an unofficial
or in-development build since those get distributed around or compiled
by some people frequently.

Now, there will always be an interim version indicators unless the game
is compiled with -DOFFICIAL_BUILD=ON. And if the indicators are blank
for any reason, they will just be replaced with placeholder defaults so
they will still show up.
2024-07-12 21:34:53 -07:00

42 lines
1.3 KiB
CMake

# Expects INPUT_FILE and OUTPUT_FILE to be defined
# find_package sets GIT_FOUND and GIT_EXECUTABLE
find_package(Git)
if(GIT_FOUND)
# Get interim commit and date of commit
EXECUTE_PROCESS(
COMMAND "${GIT_EXECUTABLE}" log -1 --format=%h
OUTPUT_VARIABLE INTERIM_COMMIT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
EXECUTE_PROCESS(
COMMAND "${GIT_EXECUTABLE}" log -1 --format=%cd --date=short
OUTPUT_VARIABLE COMMIT_DATE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
EXECUTE_PROCESS(
COMMAND "${GIT_EXECUTABLE}" branch --show-current
OUTPUT_VARIABLE BRANCH_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
# Defaults if we don't have git or its commands fail for any reason or give blanks
# For annoying CMake reasons, must use "${VAR}" syntax rather than VAR
if("${INTERIM_COMMIT}" STREQUAL "")
set(INTERIM_COMMIT "(commit?)")
endif()
if("${COMMIT_DATE}" STREQUAL "")
set(COMMIT_DATE "(date?)")
endif()
if("${BRANCH_NAME}" STREQUAL "")
set(BRANCH_NAME "(branch?)")
endif()
MESSAGE(STATUS "This is interim commit ${INTERIM_COMMIT} (committed ${COMMIT_DATE}) on branch ${BRANCH_NAME}")
# Take the template file and replace the macros with what we have
CONFIGURE_FILE(${INPUT_FILE} ${OUTPUT_FILE})