mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-07-30 17:29:14 -04:00
Generate core/version.hpp from `git describe --tags --abbrev=0` so the client always reports the last tagged release, refreshed on every build rather than only when cmake happens to reconfigure. The date carries no clock time, so the header changes at most once a day instead of forcing a recompile every build. Also un-ignore cmake/*.cmake: the repo's *.cmake rule is aimed at build output, and would have silently dropped the new module from the tree.
53 lines
1.8 KiB
CMake
53 lines
1.8 KiB
CMake
# Writes core/version.hpp from `git describe`, so the version shown in the client
|
|
# is always the last tag reachable from HEAD.
|
|
#
|
|
# Run as a script (cmake -P) from a build-time custom target, not just at configure
|
|
# time — otherwise tagging a release would not change the binary until someone
|
|
# happened to re-run cmake.
|
|
#
|
|
# Expects: SRC_DIR, IN_FILE, OUT_FILE
|
|
|
|
find_package(Git QUIET)
|
|
|
|
set(WOWEE_GIT_VERSION "unknown")
|
|
if(GIT_FOUND)
|
|
# The last tag reachable from HEAD — the released version this build descends from.
|
|
execute_process(
|
|
COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0
|
|
WORKING_DIRECTORY ${SRC_DIR}
|
|
OUTPUT_VARIABLE _git_tag
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
ERROR_QUIET
|
|
RESULT_VARIABLE _git_result
|
|
)
|
|
if(_git_result EQUAL 0 AND _git_tag)
|
|
set(WOWEE_GIT_VERSION "${_git_tag}")
|
|
else()
|
|
# No tags (shallow clone, fresh fork): fall back to the short commit.
|
|
execute_process(
|
|
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
|
|
WORKING_DIRECTORY ${SRC_DIR}
|
|
OUTPUT_VARIABLE _git_sha
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
ERROR_QUIET
|
|
RESULT_VARIABLE _sha_result
|
|
)
|
|
if(_sha_result EQUAL 0 AND _git_sha)
|
|
set(WOWEE_GIT_VERSION "${_git_sha}")
|
|
endif()
|
|
endif()
|
|
endif()
|
|
|
|
# Date only, no clock time: a timestamp would differ on every build and force a
|
|
# recompile of everything including this header.
|
|
string(TIMESTAMP WOWEE_BUILD_DATE "%Y-%m-%d" UTC)
|
|
|
|
configure_file(${IN_FILE} ${OUT_FILE}.tmp @ONLY)
|
|
|
|
# Only touch the real header when the version actually changed; rewriting it every
|
|
# build would rebuild every translation unit that includes it.
|
|
execute_process(
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${OUT_FILE}.tmp ${OUT_FILE}
|
|
)
|
|
file(REMOVE ${OUT_FILE}.tmp)
|