generated from RaccoonlabDev/mini_v2_node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
143 lines (125 loc) · 3.83 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
cmake_minimum_required(VERSION 3.15.3)
project(example CXX C ASM)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(PLATFORM bxcan)
set(libparamsPath ${CMAKE_CURRENT_LIST_DIR}/Libs/libparams)
set(stm32cubeMxProjectPath ${CMAKE_CURRENT_LIST_DIR}/Libs/stm32-cube-project)
if(USE_DRONECAN)
include(Libs/libsqcan/CMakeLists.txt)
set(libsSourceCode
${libparamsPath}/libparams/rom.c
${libparamsPath}/libparams/storage.c
${libparamsPath}/platform_specific/stm32f103/flash_driver.c
${dronecanSources}
)
set(libsHeaders
${libparamsPath}/libparams/
${libparamsPath}/platform_specific/stm32f103/
${dronecanHeaders}
)
include(Src/dronecan_application/CMakeLists.txt)
else()
add_definitions(-DBXCAN_MAX_IFACE_INDEX=0)
include(Libs/Cyphal/CMakeLists.txt)
set(libsSourceCode ${CYPHAL_SRC})
set(libsHeaders
Libs/Cyphal/Cyphal
Libs/Cyphal/Libs/libcanard/libcanard
${libparamsPath}/libparams
Libs/Cyphal/Libs/o1heap/o1heap
build/nunavut_out
)
set(cyphalRegisters ${CMAKE_CURRENT_LIST_DIR}/Libs/Cyphal/Cyphal/params.yaml)
include(Src/cyphal_application/CMakeLists.txt)
list(APPEND applicationSourceCode
build/src/params.cpp
build/src/string_params.cpp
)
endif()
set(TOOLCHAIN_PREFIX arm-none-eabi-)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)
set(CMAKE_CXX_STANDARD 20)
FILE(GLOB coreSources ${stm32cubeMxProjectPath}/Core/Src/*)
FILE(GLOB driversSources ${stm32cubeMxProjectPath}/Drivers/STM32F1xx_HAL_Driver/Src/*.c*)
set(gitRelatedHeaders
build/src
)
set(stm32CubeMxGeneratedFiles
${coreSources}
${driversSources}
${stm32cubeMxProjectPath}/startup_stm32f103xb.s
)
set(stm32CubeMxHeaders
${stm32cubeMxProjectPath}/Core/Inc
${stm32cubeMxProjectPath}/Drivers/CMSIS/Device/ST/STM32F1xx/Include
${stm32cubeMxProjectPath}/Drivers/CMSIS/Include
${stm32cubeMxProjectPath}/Drivers/STM32F1xx_HAL_Driver/Inc
${stm32cubeMxProjectPath}/Drivers/STM32F1xx_HAL_Driver/Inc/Legacy
)
set(EXECUTABLE ${PROJECT_NAME}.out)
add_executable(${EXECUTABLE}
${libparams}
${stm32CubeMxGeneratedFiles}
${libsSourceCode}
${applicationSourceCode}
)
target_compile_definitions(${EXECUTABLE} PRIVATE
-DUSE_HAL_DRIVER
-DSTM32F103xB
)
include_directories(${libsHeaders})
target_include_directories(${EXECUTABLE} PRIVATE
${gitRelatedHeaders}
${stm32CubeMxHeaders}
${applicationHeaders}
)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-volatile")
target_compile_options(${EXECUTABLE} PRIVATE
-mcpu=cortex-m3
-mthumb
-fdata-sections
-ffunction-sections
-lc -lm -lnosys
-specs=nano.specs
-Wall
--specs=nosys.specs
)
target_link_options(${EXECUTABLE} PRIVATE
-T${stm32cubeMxProjectPath}/STM32F103T8Ux_FLASH.ld
-mcpu=cortex-m3
-mthumb
--specs=nosys.specs
-specs=nano.specs
-lc
-lm
-lnosys
-Wl,-Map=${PROJECT_NAME}.map,--cref
-Wl,--gc-sections
)
if(NOT USE_DRONECAN)
execute_process(
COMMAND ${CMAKE_CURRENT_LIST_DIR}/scripts/prebuild_cyphal.sh ${cyphalRegisters}
)
endif()
add_custom_command(TARGET ${EXECUTABLE}
POST_BUILD
COMMAND arm-none-eabi-size ${EXECUTABLE}
)
execute_process(
COMMAND git rev-parse --short=16 HEAD
COMMAND_ERROR_IS_FATAL ANY
OUTPUT_VARIABLE GIT_HASH_SHORT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(GIT_HASH "0x${GIT_HASH_SHORT}")
add_definitions(-DGIT_HASH=${GIT_HASH})
add_custom_command(TARGET ${EXECUTABLE}
POST_BUILD
COMMAND arm-none-eabi-objcopy -O ihex ${EXECUTABLE} ${PROJECT_NAME}.hex
COMMAND arm-none-eabi-objcopy -O binary ${EXECUTABLE} ${PROJECT_NAME}.bin
COMMAND arm-none-eabi-objcopy -I binary -O elf32-little ${EXECUTABLE} ${PROJECT_NAME}.elf
)