1
0
Fork 0
forked from len0rd/rockbox

rbutil: Create git version information at build time.

Change-Id: Iaf701f4d64d6852423f6a28a753b27abc43477e2
This commit is contained in:
Dominik Riebeling 2021-12-25 13:02:05 +01:00
parent 6783b2c8a7
commit eb8dc75d38
4 changed files with 79 additions and 3 deletions

View file

@ -0,0 +1,58 @@
#
# __________ __ ___.
# Open \______ \ ____ ____ | | _\_ |__ _______ ___
# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
# \/ \/ \/ \/ \/
#
# All files in this archive are subject to the GNU General Public License.
# See the file COPYING in the source tree root for full license agreement.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
find_package(Git QUIET)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --verify --short=10 HEAD
OUTPUT_VARIABLE GIT_HASH
ERROR_QUIET)
# Check whether we got any revision (which isn't
# always the case, e.g. when someone downloaded a zip
# file from Github instead of a checkout)
if ("${GIT_HASH}" STREQUAL "")
set(GIT_HASH "N/A")
else()
execute_process(
COMMAND git diff --quiet --exit-code
RESULT_VARIABLE GIT_DIFF_EXITCODE)
string(STRIP "${GIT_HASH}" GIT_HASH)
if (${GIT_DIFF_EXITCODE})
set(GIT_DIFF "M")
endif()
endif()
string(TIMESTAMP TODAY "%y%m%d")
set(VERSION "
#ifndef GITVERSION
#define GITVERSION \"${GIT_HASH}${GIT_DIFF}-${TODAY}\"
#define GITHASH \"${GIT_HASH}${GIT_DIFF}\"
#define BUILDDATE \"${TODAY}\"
#endif
")
if(EXISTS ${OUTFILE})
file(READ "${OUTFILE}" _version)
else()
set(_version "")
endif()
if (NOT "${VERSION}" STREQUAL "${_version}")
file(WRITE "${OUTFILE}" "${VERSION}")
endif()
message("-- Revision: ${GIT_HASH}${GIT_DIFF}")