Skip to content

Commit 2e01288

Browse files
committed
cmake: gen_version_h: add commit hash as integer
Include the first 32 bits of the git commit hash into the generated version files in integer form. This can be an easier form to work with than the `APP_BUILD_VERSION` define, which includes a superset of the same information but in string form. Signed-off-by: Jordan Yates <[email protected]>
1 parent 634cd72 commit 2e01288

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

cmake/gen_version_h.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ if(NOT DEFINED ${BUILD_VERSION_NAME})
1818
git_describe(${work_dir} ${BUILD_VERSION_NAME})
1919
endif()
2020

21+
git_commit_hash(${work_dir} GIT_COMMIT_HASH)
22+
git_commit_hash_short("${GIT_COMMIT_HASH}" GIT_COMMIT_HASH_SHORT GIT_COMMIT_HASH_SHORT_UINT32)
23+
set(GIT_COMMIT_HASH_SHORT_0X "0x${GIT_COMMIT_HASH_SHORT}")
24+
2125
include(${ZEPHYR_BASE}/cmake/modules/version.cmake)
2226
file(READ ${ZEPHYR_BASE}/version.h.in version_content)
2327
string(CONFIGURE "${version_content}" version_content)

version.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#define @VERSION_TYPE@_VERSION_EXTENDED_STRING "@@VERSION_TYPE@_VERSION_EXTENDED_STRING@"
2020
#define @VERSION_TYPE@_VERSION_TWEAK_STRING "@@VERSION_TYPE@_VERSION_TWEAK_STRING@"
2121

22+
#define @VERSION_TYPE@_GIT_COMMIT_HASH_SHORT @GIT_COMMIT_HASH_SHORT_0X@
23+
2224
#define @BUILD_VERSION_NAME@ @@BUILD_VERSION_NAME@@
2325
@@VERSION_TYPE@_VERSION_CUSTOMIZATION@
2426

0 commit comments

Comments
 (0)