summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2021-12-25 13:02:05 +0100
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2021-12-25 17:47:14 +0100
commiteb8dc75d3808c93068df232ddb3afda704cc36bb (patch)
treef9741fde39c9b3480fe9718234cda92b47fcb2c0 /utils
parent6783b2c8a7349863e05935d93927e8192fba39fe (diff)
downloadrockbox-eb8dc75d3808c93068df232ddb3afda704cc36bb.tar.gz
rockbox-eb8dc75d3808c93068df232ddb3afda704cc36bb.zip
rbutil: Create git version information at build time.
Change-Id: Iaf701f4d64d6852423f6a28a753b27abc43477e2
Diffstat (limited to 'utils')
-rw-r--r--utils/CMakeLists.txt16
-rw-r--r--utils/cmake/gitversion.cmake58
-rw-r--r--utils/rbutilqt/CMakeLists.txt2
-rw-r--r--utils/rbutilqt/version.h6
4 files changed, 79 insertions, 3 deletions
diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt
index cb0e683d75..55e2a60407 100644
--- a/utils/CMakeLists.txt
+++ b/utils/CMakeLists.txt
@@ -333,5 +333,21 @@ add_library(rbtomcrypt
333 ) 333 )
334target_include_directories(rbtomcrypt PUBLIC ${CMAKE_CURRENT_LIST_DIR}/tomcrypt/src/headers) 334target_include_directories(rbtomcrypt PUBLIC ${CMAKE_CURRENT_LIST_DIR}/tomcrypt/src/headers)
335 335
336
337# target will always be build. File is only updated when contents change.
338add_custom_target(gitversion.h
339 COMMENT "Updating gitversion.h"
340 COMMAND ${CMAKE_COMMAND}
341 -DOUTFILE=${CMAKE_CURRENT_BINARY_DIR}/gitversion/gitversion.h
342 -P ${CMAKE_CURRENT_LIST_DIR}/cmake/gitversion.cmake
343 BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/gitversion/gitversion.h)
344
345# link to get git version header.
346add_library(gitversion INTERFACE
347 ${CMAKE_CURRENT_BINARY_DIR}/gitversion/gitversion.h)
348
349add_dependencies(gitversion gitversion.h)
350target_include_directories(gitversion INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/gitversion)
351
336include(${CMAKE_CURRENT_LIST_DIR}/cmake/deploy.cmake) 352include(${CMAKE_CURRENT_LIST_DIR}/cmake/deploy.cmake)
337add_subdirectory(rbutilqt) 353add_subdirectory(rbutilqt)
diff --git a/utils/cmake/gitversion.cmake b/utils/cmake/gitversion.cmake
new file mode 100644
index 0000000000..b13dfc0a0f
--- /dev/null
+++ b/utils/cmake/gitversion.cmake
@@ -0,0 +1,58 @@
1#
2# __________ __ ___.
3# Open \______ \ ____ ____ | | _\_ |__ _______ ___
4# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7# \/ \/ \/ \/ \/
8#
9# All files in this archive are subject to the GNU General Public License.
10# See the file COPYING in the source tree root for full license agreement.
11#
12# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
13# KIND, either express or implied.
14#
15
16find_package(Git QUIET)
17
18execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --verify --short=10 HEAD
19 OUTPUT_VARIABLE GIT_HASH
20 ERROR_QUIET)
21
22# Check whether we got any revision (which isn't
23# always the case, e.g. when someone downloaded a zip
24# file from Github instead of a checkout)
25if ("${GIT_HASH}" STREQUAL "")
26 set(GIT_HASH "N/A")
27else()
28 execute_process(
29 COMMAND git diff --quiet --exit-code
30 RESULT_VARIABLE GIT_DIFF_EXITCODE)
31
32 string(STRIP "${GIT_HASH}" GIT_HASH)
33 if (${GIT_DIFF_EXITCODE})
34 set(GIT_DIFF "M")
35 endif()
36endif()
37
38string(TIMESTAMP TODAY "%y%m%d")
39set(VERSION "
40#ifndef GITVERSION
41#define GITVERSION \"${GIT_HASH}${GIT_DIFF}-${TODAY}\"
42#define GITHASH \"${GIT_HASH}${GIT_DIFF}\"
43#define BUILDDATE \"${TODAY}\"
44#endif
45")
46
47if(EXISTS ${OUTFILE})
48 file(READ "${OUTFILE}" _version)
49else()
50 set(_version "")
51endif()
52
53if (NOT "${VERSION}" STREQUAL "${_version}")
54 file(WRITE "${OUTFILE}" "${VERSION}")
55endif()
56
57message("-- Revision: ${GIT_HASH}${GIT_DIFF}")
58
diff --git a/utils/rbutilqt/CMakeLists.txt b/utils/rbutilqt/CMakeLists.txt
index 138d0903cf..da453c3d11 100644
--- a/utils/rbutilqt/CMakeLists.txt
+++ b/utils/rbutilqt/CMakeLists.txt
@@ -122,7 +122,7 @@ if(APPLE)
122 PROPERTIES MACOSX_PACKAGE_LOCATION Resources) 122 PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
123endif() 123endif()
124 124
125target_link_libraries(RockboxUtility rbbase cutelogger 125target_link_libraries(RockboxUtility rbbase cutelogger gitversion
126 Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Multimedia) 126 Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Multimedia)
127 127
128target_include_directories(RockboxUtility PRIVATE 128target_include_directories(RockboxUtility PRIVATE
diff --git a/utils/rbutilqt/version.h b/utils/rbutilqt/version.h
index b2d24d369b..1a1d78f643 100644
--- a/utils/rbutilqt/version.h
+++ b/utils/rbutilqt/version.h
@@ -18,6 +18,8 @@
18 * 18 *
19 ****************************************************************************/ 19 ****************************************************************************/
20 20
21#include "gitversion.h"
22
21// PUREVERSION is needed to be able to just compare versions. It does not 23// PUREVERSION is needed to be able to just compare versions. It does not
22// contain a build timestamp because it needs to be the same in different 24// contain a build timestamp because it needs to be the same in different
23// files 25// files
@@ -38,7 +40,7 @@
38#define VERSIONSTRING(a, b, c) STR(a) "." STR(b) "." STR(c) 40#define VERSIONSTRING(a, b, c) STR(a) "." STR(b) "." STR(c)
39#define VERSION VERSIONSTRING(VERSION_MAJOR, VERSION_MINOR, VERSION_MICRO) BUILDID 41#define VERSION VERSIONSTRING(VERSION_MAJOR, VERSION_MINOR, VERSION_MICRO) BUILDID
40// PUREVERSION should identify the build uniquely. Use version string for now. 42// PUREVERSION should identify the build uniquely. Use version string for now.
41#define PUREVERSION "$Rev$" 43#define PUREVERSION GITHASH
42 44
43#define FULLVERSION VERSION " (" PUREVERSION "), built " __DATE__ " " __TIME__ 45#define FULLVERSION VERSION " (" GITHASH "), built " __DATE__ " " __TIME__
44 46