version: Replace bespoke application version with new version system

Uses Zephyr's new version infrastruction system for configuring the
version of the application and displaying it.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
This commit is contained in:
Jamie McCrae 2023-05-19 14:18:08 +01:00 committed by Carles Cufí
parent be3bfb0ec3
commit 2c85d9224f
4 changed files with 8 additions and 36 deletions

View file

@ -7,9 +7,6 @@
cmake_minimum_required(VERSION 3.13.1) cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(app LANGUAGES C VERSION 1.0.0) project(app LANGUAGES C)
configure_file(app_version.h.in ${CMAKE_BINARY_DIR}/app/include/app_version.h)
target_include_directories(app PRIVATE ${CMAKE_BINARY_DIR}/app/include src)
target_sources(app PRIVATE src/main.c) target_sources(app PRIVATE src/main.c)

5
app/VERSION Normal file
View file

@ -0,0 +1,5 @@
VERSION_MAJOR = 1
VERSION_MINOR = 0
PATCHLEVEL = 0
VERSION_TWEAK = 0
EXTRAVERSION =

View file

@ -1,29 +0,0 @@
/**
* @file app_version.h
*
* Application version information.
*
* Copyright (c) 2021 Nordic Semiconductor ASA
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef APP_VERSION_H_
#define APP_VERSION_H_
/** Application major version. */
#define APP_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}
/** Application minor version. */
#define APP_VERSION_MINOR ${PROJECT_VERSION_MINOR}
/** Application patch version. */
#define APP_VERSION_PATCH ${PROJECT_VERSION_PATCH}
/** Application version. */
#define APP_VERSION \
((APP_VERSION_MAJOR << 16) + \
(APP_VERSION_MINOR << 8) + \
APP_VERSION_PATCH)
/** Application version (string). */
#define APP_VERSION_STR "${PROJECT_VERSION}"
#endif /* APP_VERSION_H_ */

View file

@ -5,8 +5,7 @@
#include <zephyr/kernel.h> #include <zephyr/kernel.h>
#include <zephyr/drivers/sensor.h> #include <zephyr/drivers/sensor.h>
#include <app_version.h>
#include "app_version.h"
#include <zephyr/logging/log.h> #include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(main, CONFIG_APP_LOG_LEVEL); LOG_MODULE_REGISTER(main, CONFIG_APP_LOG_LEVEL);
@ -16,7 +15,7 @@ int main(void)
int ret; int ret;
const struct device *sensor; const struct device *sensor;
printk("Zephyr Example Application %s\n", APP_VERSION_STR); printk("Zephyr Example Application %s\n", APP_VERSION_STRING);
sensor = DEVICE_DT_GET(DT_NODELABEL(examplesensor0)); sensor = DEVICE_DT_GET(DT_NODELABEL(examplesensor0));
if (!device_is_ready(sensor)) { if (!device_is_ready(sensor)) {