Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor cmake #39

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 15 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,22 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

if(LIBPARAMS_PLATFORM STREQUAL "stm32f103")
elseif(LIBPARAMS_PLATFORM STREQUAL "stm32g0b1")
elseif(LIBPARAMS_PLATFORM STREQUAL "ubuntu")
else()
message(SEND_ERROR "LIBPARAMS_PLATFORM is not specified! Options: stm32f103, stm32g0b1, ubuntu.")
cmake_minimum_required(VERSION 3.15.3)
project(libparams VERSION 0.9.0)

set(SUPPORTED_PLATFORMS "stm32f103;stm32g0b1;ubuntu")
if(NOT LIBPARAMS_PLATFORM IN_LIST SUPPORTED_PLATFORMS)
message(SEND_ERROR "LIBPARAMS_PLATFORM is not specified or unsupported! Options: stm32f103, stm32g0b1, ubuntu.")
endif()

FILE(GLOB libparamsPlatformSpecificSrc
${CMAKE_CURRENT_LIST_DIR}/platform_specific/${LIBPARAMS_PLATFORM}/*.c*
)

FILE(GLOB libparamsPlatformSpecificHeaders
${CMAKE_CURRENT_LIST_DIR}/platform_specific/${LIBPARAMS_PLATFORM}/
)

set(libparamsSrc
${CMAKE_CURRENT_LIST_DIR}/libparams/rom.c
${CMAKE_CURRENT_LIST_DIR}/libparams/storage.c
include(${CMAKE_CURRENT_LIST_DIR}/platform_specific/${LIBPARAMS_PLATFORM}/config.cmake)

add_library(${PROJECT_NAME} STATIC
${CMAKE_CURRENT_LIST_DIR}/src/rom.c
${CMAKE_CURRENT_LIST_DIR}/src/storage.c
${libparamsPlatformSpecificSrc}
)

set(libparamsHeaders
${CMAKE_CURRENT_LIST_DIR}/libparams/
- ${CMAKE_CURRENT_LIST_DIR}/platform_specific/${LIBPARAMS_PLATFORM}/
${libparamsPlatformSpecificHeaders}
)
target_include_directories(${PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include/libparams/
${CMAKE_CURRENT_LIST_DIR}/platform_specific/${LIBPARAMS_PLATFORM}/
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions platform_specific/stm32f103/config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set(libparamsPlatformSpecificSrc
${CMAKE_CURRENT_LIST_DIR}/flash_driver.c
)
3 changes: 3 additions & 0 deletions platform_specific/stm32g0b1/config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set(libparamsPlatformSpecificSrc
${CMAKE_CURRENT_LIST_DIR}/flash_driver.c
)
4 changes: 4 additions & 0 deletions platform_specific/ubuntu/config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set(libparamsPlatformSpecificSrc
${CMAKE_CURRENT_LIST_DIR}/flash_driver.cpp
${CMAKE_CURRENT_LIST_DIR}/YamlParameters.cpp
)
3 changes: 2 additions & 1 deletion scripts/code_style/get_pathes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ SCRIPTS_DIR="$(dirname "$CODE_STYLE_DIR")"
REPO_DIR="$(dirname "$SCRIPTS_DIR")"

FOLDERS=(
"$REPO_DIR/libparams/*"
"$REPO_DIR/src/*"
"$REPO_DIR/include/*"
"$REPO_DIR/platform_specific/*/*"
)

Expand Down
4 changes: 2 additions & 2 deletions scripts/cppcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cppcheck --enable=all \
--suppress=missingIncludeSystem \
--suppress=unusedFunction \
--suppress=toomanyconfigs \
-I ${REPO_DIR}/libparams \
-I ${REPO_DIR}/include/libparams \
-I ${REPO_DIR}/platform_specific/ubuntu/ \
-I /usr/include/ \
${REPO_DIR}/libparams/
${REPO_DIR}/src/
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sonar.organization=ponomarevda
sonar.projectKey=PonomarevDA_libparams
sonar.sources=libparams
sonar.sources=src,include
sonar.cfamily.build-wrapper-output=bw-output
sonar.host.url=https://sonarcloud.io
sonar.cfamily.gcov.reportsPath=build
File renamed without changes.
File renamed without changes.
8 changes: 3 additions & 5 deletions tests/params_generator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ set(CMAKE_CXX_STANDARD 17)

cmake_path(GET CMAKE_CURRENT_LIST_DIR PARENT_PATH TESTS_DIR)
cmake_path(GET TESTS_DIR PARENT_PATH LIBPARAMS_ROOT_DIR)
set(LIBPARAMS_SOURCE_CODE_PATH ${LIBPARAMS_ROOT_DIR}/libparams)
set(PLATFORM_SPECIFIC_PATH ${LIBPARAMS_ROOT_DIR}/platform_specific/ubuntu)
set(PARAMS_PATH ${LIBPARAMS_ROOT_DIR}/build/tests/params_generator)

include_directories(
${LIBPARAMS_SOURCE_CODE_PATH}
${PLATFORM_SPECIFIC_PATH}
${PARAMS_PATH}
)
set(LIBPARAMS_PLATFORM ubuntu)
add_subdirectory(${LIBPARAMS_ROOT_DIR} ${CMAKE_BINARY_DIR}/libparams)

enable_testing()
find_package(GTest REQUIRED)
Expand All @@ -27,9 +27,7 @@ include(GoogleTest)
FILE(GLOB GENERATED_PARAMS ${PARAMS_PATH}/*.c*)

add_executable(${PROJECT_NAME} test.cpp
${LIBPARAMS_SOURCE_CODE_PATH}/storage.c
${LIBPARAMS_SOURCE_CODE_PATH}/rom.c
${GENERATED_PARAMS}
${PLATFORM_SPECIFIC_PATH}/flash_driver.cpp)
target_link_libraries(${PROJECT_NAME} GTest::GTest GTest::Main)
target_link_libraries(${PROJECT_NAME} GTest::GTest GTest::Main libparams)
gtest_discover_tests(${PROJECT_NAME})
6 changes: 3 additions & 3 deletions tests/platform_specific/stm32f103/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ BUILD_DIR = ${ROOT_DIR}/build/tests/stm32f103_build
# source
######################################
C_SOURCES = \
${ROOT_DIR}/libparams/rom.c \
${ROOT_DIR}/src/rom.c \
${ROOT_DIR}/platform_specific/stm32f103/flash_driver.c \
${ROOT_DIR}/libparams/storage.c \
${ROOT_DIR}/src/storage.c \
../../params.c \
main.c \
application.c

# C includes
C_INCLUDES = \
-I${ROOT_DIR}/libparams/ \
-I${ROOT_DIR}/include/libparams/ \
-I${ROOT_DIR}/platform_specific/stm32f103/ \
-I./ \
-I../../
Expand Down
6 changes: 3 additions & 3 deletions tests/platform_specific/stm32g0b1/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ BUILD_DIR = ${ROOT_DIR}/build/tests/stm32g0b1_build
# source
######################################
C_SOURCES = \
${ROOT_DIR}/libparams/rom.c \
${ROOT_DIR}/src/rom.c \
${ROOT_DIR}/platform_specific/stm32g0b1/flash_driver.c \
${ROOT_DIR}/libparams/storage.c \
${ROOT_DIR}/src/storage.c \
../../params.c \
main.c \
application.c

# C includes
C_INCLUDES = \
-I${ROOT_DIR}/libparams/ \
-I${ROOT_DIR}/include/libparams/ \
-I${ROOT_DIR}/platform_specific/stm32g0b1/ \
-I./ \
-I../../
Expand Down
14 changes: 7 additions & 7 deletions tests/platform_specific/ubuntu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@ set(CMAKE_CXX_FLAGS_RELEASE "-O3")

# Libraries
set(LIBPARAMS_PLATFORM ubuntu)
include(${ROOT_DIR}/CMakeLists.txt)

include_directories(
${CMAKE_CURRENT_BINARY_DIR}
)

add_subdirectory(${ROOT_DIR} ${CMAKE_BINARY_DIR}/libparams)

add_definitions(-DFLASH_DRIVER_STORAGE_FILE="${CMAKE_CURRENT_LIST_DIR}/default_params.yaml")

add_executable(application
${libparamsSrc}
${CMAKE_CURRENT_BINARY_DIR}/params.cpp
${CMAKE_CURRENT_LIST_DIR}/main.cpp
)
target_link_libraries(application libparams)

execute_process(
COMMAND ${ROOT_DIR}/scripts/generate_params.py --out-dir . -f ${CMAKE_CURRENT_LIST_DIR}/params.yaml
Expand All @@ -37,8 +42,3 @@ execute_process(
if(NOT ret EQUAL 0)
message( FATAL_ERROR "Params Generator has been failed. Abort.")
endif()

include_directories(
${libparamsHeaders}
${CMAKE_CURRENT_BINARY_DIR}
)
16 changes: 9 additions & 7 deletions tests/unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@ enable_testing()
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIR})

include_directories(.)
include_directories(
${UNIT_TESTS_DIR}
${TESTS_DIR}
${ROOT_DIR}/include/libparams
${ROOT_DIR}/platform_specific/ubuntu
)
set(LIBPARAMS_PLATFORM ubuntu)
include(${ROOT_DIR}/CMakeLists.txt)

function(gen_test app_name test_file)
include_directories(
${libparamsHeaders}
${TESTS_DIR}
)
add_executable(${app_name}
${test_file}
${libparamsSrc}
${TESTS_DIR}/params.c
${ROOT_DIR}/src/rom.c
${ROOT_DIR}/src/storage.c
${ROOT_DIR}/platform_specific/ubuntu/flash_driver.cpp
)
target_link_libraries(${app_name} gtest)
endfunction()
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ coverage: create_build_dir
cd ${BUILD_DIR} && ./flash_driver

echo "\n1. Storage:"
cd ${BUILD_DIR} && gcov ${BUILD_DIR}/CMakeFiles/storage.dir${REPO_DIR}/libparams/storage.c.gcda
cd ${BUILD_DIR} && gcov ${BUILD_DIR}/CMakeFiles/storage.dir${REPO_DIR}/src/storage.c.gcda

echo "\n2. ROM:"
cd ${BUILD_DIR} && gcov ${BUILD_DIR}/CMakeFiles/rom.dir${REPO_DIR}/libparams/rom.c.gcda
cd ${BUILD_DIR} && gcov ${BUILD_DIR}/CMakeFiles/rom.dir${REPO_DIR}/src/rom.c.gcda

# echo "\n3. Ubuntu flash driver:"
cd ${BUILD_DIR} && gcov ${BUILD_DIR}/CMakeFiles/flash_driver.dir${REPO_DIR}/platform_specific/ubuntu/flash_driver.cpp.gcda
Expand Down
Loading