Skip to content

Commit b0ec3f2

Browse files
committed
add CMakeLists.txt and rewrite unit tests with add_subdirectory
1 parent 6481843 commit b0ec3f2

File tree

29 files changed

+122
-77
lines changed

29 files changed

+122
-77
lines changed

CMakeLists.txt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright (c) 2025 Dmitry Ponomarev <ponomarevda96@gmail.com>
2+
#
3+
# This Source Code Form is subject to the terms of the Mozilla Public
4+
# License, v. 2.0. If a copy of the MPL was not distributed with this
5+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
6+
7+
cmake_minimum_required(VERSION 3.22)
8+
project(libparams VERSION 1.0 LANGUAGES CXX C)
9+
10+
if(LIBPARAMS_PLATFORM STREQUAL "stm32f103")
11+
elseif(LIBPARAMS_PLATFORM STREQUAL "stm32g0b1")
12+
elseif(LIBPARAMS_PLATFORM STREQUAL "ubuntu")
13+
else()
14+
message(SEND_ERROR "LIBPARAMS_PLATFORM is not specified! Options: stm32f103, stm32g0b1, ubuntu.")
15+
endif()
16+
17+
execute_process(
18+
COMMAND ${ROOT_DIR}/scripts/generate_default_params.py
19+
--out-dir ${CMAKE_CURRENT_BINARY_DIR}/params
20+
-f ${TESTS_DIR}/params/params.c
21+
--out-file-name "init_params"
22+
RESULT_VARIABLE ret
23+
)
24+
if(NOT ret EQUAL 0)
25+
message( FATAL_ERROR "Default Params Generator has been failed. Abort.")
26+
endif()
27+
set(LIBPARAMS_PARAMS_DIR="${CMAKE_CURRENT_BINARY_DIR}/params")
28+
add_definitions(-DLIBPARAMS_PARAMS_DIR="${CMAKE_CURRENT_BINARY_DIR}/params")
29+
30+
FILE(GLOB libparamsPlatformSpecificSrc
31+
${CMAKE_CURRENT_LIST_DIR}/platform_specific/${LIBPARAMS_PLATFORM}/*.c*
32+
)
33+
34+
FILE(GLOB libparamsGeneratedParams
35+
${LIBPARAMS_GENERATED_PARAMS_DIR}/*.c*
36+
${LIBPARAMS_GENERATED_PARAMS_DIR}/*.cpp*
37+
)
38+
39+
add_library(${PROJECT_NAME} STATIC
40+
src/rom.c
41+
src/storage.c
42+
${libparamsPlatformSpecificSrc}
43+
${libparamsGeneratedParams}
44+
)
45+
46+
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
47+
48+
target_include_directories(${PROJECT_NAME}
49+
PUBLIC
50+
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
51+
$<BUILD_INTERFACE:${LIBPARAMS_GENERATED_PARAMS_DIR}>
52+
$<INSTALL_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
53+
$<INSTALL_INTERFACE:${LIBPARAMS_GENERATED_PARAMS_DIR}>
54+
PRIVATE
55+
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
56+
)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ You can create params.c and params.h files with the following content:
114114
```c++
115115
// params.h
116116
#pragma once
117-
#include "storage.h"
117+
#include "libparams/storage.h"
118118

119119
enum IntParamsIndexes : ParamIndex_t {
120120
PARAM_NODE_ID,

include/libparams/storage.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
#include <stdint.h>
1313
#include <stdbool.h>
1414
#include <assert.h>
15-
#include "rom.h"
16-
#include "libparams_error_codes.h"
17-
#include "_legacy_functions.h"
15+
#include "libparams/rom.h"
16+
#include "libparams/libparams_error_codes.h"
17+
#include "libparams/_legacy_functions.h"
1818

1919
#ifdef __cplusplus
2020
extern "C" {

libparams.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ set(libparamsSrc
2828
)
2929

3030
set(libparamsHeaders
31-
${CMAKE_CURRENT_LIST_DIR}/include/libparams/
31+
${CMAKE_CURRENT_LIST_DIR}/include/
3232
${CMAKE_CURRENT_LIST_DIR}/platform_specific/${LIBPARAMS_PLATFORM}/
3333
${libparamsPlatformSpecificHeaders}
3434
)

platform_specific/stm32f103/flash_driver.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
77
*/
88

9-
#include "flash_driver.h"
9+
#include "libparams/flash_driver.h"
1010
#include <string.h>
11-
#include "libparams_error_codes.h"
11+
#include "libparams/libparams_error_codes.h"
1212
#include "flash_registers.h"
1313

1414

platform_specific/stm32g0b1/flash_driver.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
77
*/
88

9-
#include "flash_driver.h"
9+
#include "libparams/flash_driver.h"
1010
#include <string.h>
1111
#include "main.h"
12-
#include "libparams_error_codes.h"
12+
#include "libparams/libparams_error_codes.h"
1313

1414

1515
static uint8_t* flashGetPointer();

platform_specific/ubuntu/FlashMemoryLayout.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef LIBPARAM_FLASH_MEMORY_LAYOUT_HPP_
1010
#define LIBPARAM_FLASH_MEMORY_LAYOUT_HPP_
1111

12-
#include "storage.h"
12+
#include "libparams/storage.h"
1313

1414
typedef struct {
1515
IntegerDesc_t* integer_desc_pool;

platform_specific/ubuntu/YamlParameters.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <iostream>
1313
#include <iomanip>
1414

15-
#include "storage.h"
15+
#include "libparams/storage.h"
1616
#include "YamlParameters.hpp"
1717

1818
YamlParameters::YamlParameters(FlashMemoryLayout_t flash_desc,

platform_specific/ubuntu/flash_driver.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
*/
88

99
#include <string.h>
10-
#include "storage.h"
11-
#include "flash_driver.h"
12-
#include "libparams_error_codes.h"
10+
#include "libparams/storage.h"
11+
#include "libparams/flash_driver.h"
12+
#include "libparams/libparams_error_codes.h"
1313
#include "params.hpp"
1414
#include "YamlParameters.hpp"
1515

@@ -115,3 +115,7 @@ int32_t __save_to_files() {
115115
int8_t __read_from_files() {
116116
return yaml_params.read_from_dir(LIBPARAMS_PARAMS_DIR);
117117
}
118+
119+
const char* get_libparams_params_dir() {
120+
return LIBPARAMS_PARAMS_DIR;
121+
}

scripts/_constants.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class CppHeader:
1010
INTEGER_HEAD = """#pragma once
11-
#include "storage.h"
11+
#include "libparams/storage.h"
1212
#include "string_params.hpp"
1313
enum IntParamsIndexes : ParamIndex_t {
1414
"""
@@ -39,7 +39,7 @@ class CHeader:
3939

4040
class CSource:
4141
INTEGER_HEAD="""#include "params.h"
42-
#include "storage.h"
42+
#include "libparams/storage.h"
4343
IntegerDesc_t integer_desc_pool[] = {
4444
"""
4545

@@ -49,7 +49,7 @@ class CSource:
4949
"""
5050

5151
STRING_HEAD="""#include "string_params.h"
52-
#include "storage.h"
52+
#include "libparams/storage.h"
5353
StringDesc_t __attribute__((weak)) string_desc_pool[NUM_OF_STR_PARAMS] = {
5454
"""
5555
STRING_TAIL="""
@@ -68,7 +68,7 @@ class CppSource:
6868
"""
6969

7070
STRING_HEAD="""#include "string_params.hpp"
71-
#include "storage.h"
71+
#include "libparams/storage.h"
7272
StringDesc_t __attribute__((weak)) string_desc_pool[NUM_OF_STR_PARAMS] = {
7373
"""
7474
STRING_TAIL="""

0 commit comments

Comments
 (0)