Fix FW_COMMIT_HASH compiler warning
On my end, the default length for the abbreviated commit hash is 9 characters. This won't fit into uint32_t (4 bytes). Instead change FW_COMMIT_HASH into a string and create preprocessor symbol for the string length such that it's known at compile time. If the string should be longer or shorter then only FW_COMMIT_HASH_LENGTH needs to be configured on the CMake side
This commit is contained in:
parent
fab47e63bf
commit
415c0c79d1
|
|
@ -367,7 +367,8 @@ function(add_base_binary variant_name)
|
||||||
target_compile_definitions(
|
target_compile_definitions(
|
||||||
${variant_name}
|
${variant_name}
|
||||||
PRIVATE CMAKE_CONTROL FW_REPOSITORY="${PROJECT_REPOSITORY}"
|
PRIVATE CMAKE_CONTROL FW_REPOSITORY="${PROJECT_REPOSITORY}"
|
||||||
FW_COMMIT_HASH=0x${FW_COMMIT_HASH}
|
FW_COMMIT_HASH="${FW_COMMIT_HASH}"
|
||||||
|
FW_COMMIT_HASH_LENGTH=${FW_COMMIT_HASH_LENGTH}
|
||||||
FW_MAJOR=${PROJECT_VERSION_MAJOR}
|
FW_MAJOR=${PROJECT_VERSION_MAJOR}
|
||||||
FW_MINOR=${PROJECT_VERSION_MINOR}
|
FW_MINOR=${PROJECT_VERSION_MINOR}
|
||||||
FW_REVISION=${PROJECT_VERSION_REV}
|
FW_REVISION=${PROJECT_VERSION_REV}
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,8 @@ extern const char _sPrinterMmuName[] PROGMEM;
|
||||||
|
|
||||||
// The full version string and repository source are set via cmake
|
// The full version string and repository source are set via cmake
|
||||||
#ifndef CMAKE_CONTROL
|
#ifndef CMAKE_CONTROL
|
||||||
#define FW_COMMIT_HASH 0
|
#define FW_COMMIT_HASH_LENGTH 1
|
||||||
|
#define FW_COMMIT_HASH "0"
|
||||||
#define FW_REPOSITORY "Unknown"
|
#define FW_REPOSITORY "Unknown"
|
||||||
#define FW_VERSION_FULL FW_VERSION "-unknown"
|
#define FW_VERSION_FULL FW_VERSION "-unknown"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,13 @@ const uint16_t FW_VERSION_NR[4] PROGMEM = {
|
||||||
FW_TWEAK,
|
FW_TWEAK,
|
||||||
};
|
};
|
||||||
|
|
||||||
const uint32_t FW_VERSION_HASH PROGMEM = FW_COMMIT_HASH;
|
const char FW_VERSION_HASH[] PROGMEM = FW_COMMIT_HASH;
|
||||||
|
static_assert(sizeof(FW_VERSION_HASH) == FW_COMMIT_HASH_LENGTH + 1);
|
||||||
|
|
||||||
|
const char* FW_VERSION_HASH_P()
|
||||||
|
{
|
||||||
|
return FW_VERSION_HASH;
|
||||||
|
}
|
||||||
|
|
||||||
const char* FW_VERSION_STR_P()
|
const char* FW_VERSION_STR_P()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
extern const uint16_t FW_VERSION_NR[4];
|
extern const uint16_t FW_VERSION_NR[4];
|
||||||
extern const char* FW_VERSION_STR_P();
|
const char* FW_VERSION_STR_P();
|
||||||
|
|
||||||
extern const uint32_t FW_VERSION_HASH PROGMEM;
|
extern const char FW_VERSION_HASH[];
|
||||||
static inline uint32_t FW_VERSION_HASH_P() { return (uint32_t)pgm_read_dword(&FW_VERSION_HASH); }
|
const char* FW_VERSION_HASH_P();
|
||||||
|
|
||||||
// Definition of a firmware flavor numerical values.
|
// Definition of a firmware flavor numerical values.
|
||||||
// To keep it short as possible
|
// To keep it short as possible
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,12 @@ ENDIF()
|
||||||
|
|
||||||
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_REV}.${PROJECT_VERSION_TWEAK}")
|
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_REV}.${PROJECT_VERSION_TWEAK}")
|
||||||
|
|
||||||
|
# Define a constant length for the commit hash
|
||||||
|
set(FW_COMMIT_HASH_LENGTH 9)
|
||||||
|
|
||||||
|
# Create fallback value with constant length
|
||||||
|
string(REPEAT "0" ${FW_COMMIT_HASH_LENGTH} FW_COMMIT_HASH_UNKNOWN)
|
||||||
|
|
||||||
function(resolve_version_variables)
|
function(resolve_version_variables)
|
||||||
if(FW_COMMIT_DSC)
|
if(FW_COMMIT_DSC)
|
||||||
return()
|
return()
|
||||||
|
|
@ -94,11 +100,17 @@ function(resolve_version_variables)
|
||||||
if(NOT GIT_FOUND)
|
if(NOT GIT_FOUND)
|
||||||
find_package(Git QUIET)
|
find_package(Git QUIET)
|
||||||
endif()
|
endif()
|
||||||
git_head_commit_data(FW_COMMIT_HASH "%h")
|
|
||||||
|
# Get the full commit hash
|
||||||
|
git_head_commit_data(FW_COMMIT_HASH "%H")
|
||||||
|
|
||||||
|
# Keep only the first 'FW_COMMIT_HASH_LENGTH' characters
|
||||||
|
string(SUBSTRING "${FW_COMMIT_HASH}" 0 ${FW_COMMIT_HASH_LENGTH} FW_COMMIT_HASH)
|
||||||
|
|
||||||
set(ERRORS "GIT-NOTFOUND" "HEAD-FORMAT-NOTFOUND")
|
set(ERRORS "GIT-NOTFOUND" "HEAD-FORMAT-NOTFOUND")
|
||||||
if(FW_COMMIT_HASH IN_LIST ERRORS)
|
if(FW_COMMIT_HASH IN_LIST ERRORS)
|
||||||
# git not available, set fallback values
|
# git not available, set fallback values
|
||||||
set(FW_COMMIT_HASH "UNKNOWN")
|
set(FW_COMMIT_HASH ${FW_COMMIT_HASH_UNKNOWN})
|
||||||
set(FW_COMMIT_DSC "v${PROJECT_VERSION}-${FW_COMMIT_HASH}")
|
set(FW_COMMIT_DSC "v${PROJECT_VERSION}-${FW_COMMIT_HASH}")
|
||||||
string(TIMESTAMP FW_COMMIT_DATE "%s")
|
string(TIMESTAMP FW_COMMIT_DATE "%s")
|
||||||
else()
|
else()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue