-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
128 lines (101 loc) · 3.57 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
cmake_minimum_required(VERSION 3.15.3)
project(stm32-devops-template)
message("HOST=${HOST}")
# Enable testing
enable_testing()
enable_language(C ASM)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)
set(COMMON_SOURCES
lib/linked_list/linked_list.c
lib/linked_list/linked_list.h
)
if( HOST )
# Collect all test source files matching test/test_*.c
file(GLOB TEST_SOURCES "test/test_*.c")
# Loop over each test source file
foreach(TEST_SOURCE ${TEST_SOURCES})
# Get the file name without the directory and extension
get_filename_component(TEST_NAME ${TEST_SOURCE} NAME_WE)
# Create an executable for each test
add_executable(${TEST_NAME}
${TEST_SOURCE}
${COMMON_SOURCES} # Common sources if needed
lib/Unity/src/unity.c
)
# Set compile definitions if needed
target_compile_definitions(${TEST_NAME} PRIVATE
)
# Include directories
target_include_directories(${TEST_NAME} PRIVATE
lib/linked_list
lib/Unity/src
)
# Set compile options
target_compile_options(${TEST_NAME} PRIVATE
-Wall
$<$<CONFIG:Debug>:-Og>
)
# Set link options if needed
target_link_options(${TEST_NAME} PRIVATE
)
# Register the test with ctest
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
endforeach()
else()
set(TARGET_SOURCES
src/main.c
src/main.h
src/startup_stm32f407xx.c
src/syscalls.c
)
include(${CMAKE_SOURCE_DIR}/config/project_info.cmake)
set(TARGET_EXECUTABLE
${PROJECT_NAME}_${ENVIRONMENT}_${CLIENT}_${FEATURE}_${FW_VERSION}.out
)
add_executable(${TARGET_EXECUTABLE}
${TARGET_SOURCES}
${COMMON_SOURCES}
)
target_compile_definitions(${TARGET_EXECUTABLE} PRIVATE
-DSTM32F407xx
)
target_include_directories(${TARGET_EXECUTABLE} PRIVATE
lib/linked_list
)
target_compile_options(${TARGET_EXECUTABLE} PRIVATE
-mcpu=cortex-m4
-mthumb
-mfpu=fpv4-sp-d16
-mfloat-abi=hard
-fdata-sections
-ffunction-sections
-Wall
$<$<CONFIG:Debug>:-Og>
)
target_link_options(${TARGET_EXECUTABLE} PRIVATE
-T${CMAKE_SOURCE_DIR}/src/linker_script.ld
-mcpu=cortex-m4
-mthumb
-mfpu=fpv4-sp-d16
-mfloat-abi=hard
-specs=nano.specs
-lc
-lm
# -lnosys
-Wl,-Map=${PROJECT_NAME}_${ENVIRONMENT}_${CLIENT}_${FEATURE}_${FW_VERSION}.map,--cref
-Wl,--gc-sections
)
# Print executable size
add_custom_command(TARGET ${TARGET_EXECUTABLE}
POST_BUILD
COMMAND arm-none-eabi-size ${TARGET_EXECUTABLE}
)
# Create hex file
add_custom_command(TARGET ${TARGET_EXECUTABLE}
POST_BUILD
COMMAND arm-none-eabi-objcopy -O ihex ${TARGET_EXECUTABLE} ${PROJECT_NAME}_${ENVIRONMENT}_${CLIENT}_${FEATURE}_${FW_VERSION}.hex
COMMAND arm-none-eabi-objcopy -O binary ${TARGET_EXECUTABLE} ${PROJECT_NAME}_${ENVIRONMENT}_${CLIENT}_${FEATURE}_${FW_VERSION}.bin
)
endif()