diff options
-rw-r--r-- | utils/CMakeLists.txt | 16 | ||||
-rw-r--r-- | utils/cmake/gitversion.cmake | 58 | ||||
-rw-r--r-- | utils/rbutilqt/CMakeLists.txt | 2 | ||||
-rw-r--r-- | utils/rbutilqt/version.h | 6 |
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 | ) |
334 | target_include_directories(rbtomcrypt PUBLIC ${CMAKE_CURRENT_LIST_DIR}/tomcrypt/src/headers) | 334 | target_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. | ||
338 | add_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. | ||
346 | add_library(gitversion INTERFACE | ||
347 | ${CMAKE_CURRENT_BINARY_DIR}/gitversion/gitversion.h) | ||
348 | |||
349 | add_dependencies(gitversion gitversion.h) | ||
350 | target_include_directories(gitversion INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/gitversion) | ||
351 | |||
336 | include(${CMAKE_CURRENT_LIST_DIR}/cmake/deploy.cmake) | 352 | include(${CMAKE_CURRENT_LIST_DIR}/cmake/deploy.cmake) |
337 | add_subdirectory(rbutilqt) | 353 | add_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 | |||
16 | find_package(Git QUIET) | ||
17 | |||
18 | execute_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) | ||
25 | if ("${GIT_HASH}" STREQUAL "") | ||
26 | set(GIT_HASH "N/A") | ||
27 | else() | ||
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() | ||
36 | endif() | ||
37 | |||
38 | string(TIMESTAMP TODAY "%y%m%d") | ||
39 | set(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 | |||
47 | if(EXISTS ${OUTFILE}) | ||
48 | file(READ "${OUTFILE}" _version) | ||
49 | else() | ||
50 | set(_version "") | ||
51 | endif() | ||
52 | |||
53 | if (NOT "${VERSION}" STREQUAL "${_version}") | ||
54 | file(WRITE "${OUTFILE}" "${VERSION}") | ||
55 | endif() | ||
56 | |||
57 | message("-- 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) |
123 | endif() | 123 | endif() |
124 | 124 | ||
125 | target_link_libraries(RockboxUtility rbbase cutelogger | 125 | target_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 | ||
128 | target_include_directories(RockboxUtility PRIVATE | 128 | target_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 | ||