Make CMake the source of truth for versioning

pull/196/head
VintagePC 2022-07-31 09:41:45 -04:00 committed by DRracer
parent 39caece714
commit fc5e8a6ae0
10 changed files with 65 additions and 84 deletions

View File

@ -3,4 +3,4 @@ set(HEX_PREFIX "\; device = mm-control\n\n")
file(READ ${WORK_DIR}/firmware.hex HEX)
file(WRITE ${WORK_DIR}/${HEX_NAME} ${HEX_PREFIX})
file(APPEND ${WORK_DIR}/${HEX_NAME} ${HEX})
message(status "Successfully built ${HEX_NAME}!")
message(STATUS "Successfully built ${HEX_NAME}!")

View File

@ -13,13 +13,9 @@
#
# ~~~
# PROJECT_VERSION
file(READ "${CMAKE_SOURCE_DIR}/version.txt" content)
string(REGEX MATCH "([0-9]+)\.([0-9]+)\.([0-9]+)" result "${content}")
if(NOT result)
message(FATAL_ERROR "Failed to read version info from ${version_file}")
endif()
set(PROJECT_VERSION ${CMAKE_MATCH_0})
include(${CMAKE_SOURCE_DIR}/version.cmake)
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_REV}")
function(resolve_version_variables)
# BUILD_NUMBER

View File

@ -1,18 +1,19 @@
target_sources(firmware PRIVATE application.cpp debug.cpp main.cpp registers.cpp version.c)
target_sources(firmware PRIVATE application.cpp debug.cpp main.cpp registers.cpp version.hpp)
target_link_libraries(firmware LUFA)
set_property(
SOURCE src/version.c
APPEND
PROPERTY COMPILE_DEFINITIONS
FW_BUILD_NUMBER=${BUILD_NUMBER}
FW_VERSION_FULL=${PROJECT_VERSION_FULL}
FW_VERSION=${PROJECT_VERSION}
FW_VERSION_SUFFIX=${PROJECT_VERSION_SUFFIX}
FW_VERSION_SUFFIX_SHORT=${PROJECT_VERSION_SUFFIX_SHORT}
target_compile_definitions(
firmware
PRIVATE
PROJECT_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
PROJECT_VERSION_MINOR=${PROJECT_VERSION_MINOR}
PROJECT_VERSION_REV=${PROJECT_VERSION_REV}
PROJECT_BUILD_NUMBER=${BUILD_NUMBER}
FW_VERSION_FULL_STR="${PROJECT_VERSION_FULL}"
FW_VERSION_STR="${PROJECT_VERSION}"
FW_VERSION_SUFFIX_STR="${PROJECT_VERSION_SUFFIX}"
FW_VERSION_SUFFIX_SHORT_STR="${PROJECT_VERSION_SUFFIX_SHORT}"
)
add_subdirectory(hal)
add_subdirectory(logic)
add_subdirectory(modules)

View File

@ -20,7 +20,7 @@
#include "logic/tool_change.h"
#include "logic/unload_filament.h"
#include "version.h"
#include "version.hpp"
#include "panic.h"

View File

@ -6,7 +6,7 @@
#include "registers.h"
#include "application.h"
#include "version.h"
#include "version.hpp"
#include "modules/finda.h"
#include "modules/fsensor.h"

View File

@ -1,18 +0,0 @@
/// @file version.c
#include "version.h"
#define _STR(x) #x
#define STR(x) _STR(x)
const char project_version[] = STR(FW_VERSION);
const char project_version_full[] = STR(FW_VERSION_FULL);
const char project_version_suffix[] = STR(FW_VERSION_SUFFIX);
const char project_version_suffix_short[] = STR(FW_VERSION_SUFFIX_SHORT);
const uint8_t project_major = project_version_major;
const uint8_t project_minor = project_version_minor;
const uint16_t project_revision = project_version_revision;
const uint16_t project_build_number = project_version_build;

View File

@ -1,44 +0,0 @@
/// @file version.h
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif //__cplusplus
#define project_version_major 2
#define project_version_minor 1
#define project_version_revision 1
#define project_version_build 634
#define FW_BUILD_NUMBER 0
/// Project's version (2.0.0)
extern const char project_version[];
/// Full project's version (2.0.0-BETA+1035.PR111.B4)
extern const char project_version_full[];
/// Project's version suffix (-BETA+1035.PR111.B4)
extern const char project_version_suffix[];
/// Project's short version suffix (+1035)
extern const char project_version_suffix_short[];
/// Project's major version
extern const uint8_t project_major;
/// Project's minor version
extern const uint8_t project_minor;
/// Project's revision number
extern const uint16_t project_revision;
/// Project's build number (number of commits in a branch)
extern const uint16_t project_build_number;
/// Firmware name
extern const char project_firmware_name[];
#ifdef __cplusplus
}
#endif //__cplusplus

32
src/version.hpp Normal file
View File

@ -0,0 +1,32 @@
/// @file version.h
#pragma once
#include <stdint.h>
/// Project's version (2.0.0)
static constexpr char project_version[] = FW_VERSION_STR;
/// Full project's version (2.0.0-BETA+1035.PR111.B4)
static constexpr char project_version_full[] = FW_VERSION_FULL_STR;
/// Project's version suffix (-BETA+1035.PR111.B4)
static constexpr char project_version_suffix[] = FW_VERSION_SUFFIX_STR;
/// Project's short version suffix (+1035)
static constexpr char project_version_suffix_short[] = FW_VERSION_SUFFIX_SHORT_STR;
/// Project's major version
static constexpr uint8_t project_major = PROJECT_VERSION_MAJOR;
/// Project's minor version
static constexpr uint8_t project_minor = PROJECT_VERSION_MINOR;
/// Project's revision number
static constexpr uint16_t project_revision = PROJECT_VERSION_REV;
/// Project's build number (number of commits in a branch)
static constexpr uint16_t project_build_number = PROJECT_BUILD_NUMBER;
static_assert(PROJECT_VERSION_MAJOR <= UINT8_MAX);
static_assert(PROJECT_VERSION_MINOR <= UINT8_MAX);
static_assert(PROJECT_VERSION_REV <= UINT8_MAX);
static_assert(PROJECT_BUILD_NUMBER <= UINT16_MAX);

15
version.cmake Normal file
View File

@ -0,0 +1,15 @@
# The project's version definition/source of truth. It could have been just pasted at the top of
# ProjectVersion.cmake but that makes it a bit harder to locate...
set(PROJECT_VERSION_MAJOR
2
CACHE STRING "Project major version" FORCE
)
set(PROJECT_VERSION_MINOR
1
CACHE STRING "Project minor version" FORCE
)
set(PROJECT_VERSION_REV
1
CACHE STRING "Project revision" FORCE
)

View File

@ -1 +0,0 @@
2.0.19