tao_z
2022-05-29 fa8669b0092240642af78e84c0e89f596444fdad
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
project(SX7H_Shifter VERSION 0.2.0 LANGUAGES C ASM)
 
add_executable(SX7H_Shifter ${CMAKE_CURRENT_SOURCE_DIR}/Application/source/main.c)
set_target_properties(SX7H_Shifter PROPERTIES SUFFIX ".elf")
 
# get git tag
execute_process(
    COMMAND git --git-dir ${PROJECT_SOURCE_DIR}/.git describe --tags
    TIMEOUT 10  # if this lasts more then 10s something is wrong
    OUTPUT_VARIABLE GIT_TAG
)
string(REGEX REPLACE "\n$" "" GIT_TAG "${GIT_TAG}")
string(REGEX MATCH "[0-9][0-9].[0-9][0-9].[0-9][0-9][0-9]" SX7H_Shifter_VERSION "${GIT_TAG}")
 
# get git commit id
execute_process(
    COMMAND git --git-dir ${PROJECT_SOURCE_DIR}/.git rev-parse --short HEAD
    TIMEOUT 10  # if this lasts more then 10s something is wrong
    OUTPUT_VARIABLE COMMIT_ID
)
string(REGEX REPLACE "\n$" "" COMMIT_ID "${COMMIT_ID}")
 
# get cmake arguments list
get_cmake_property(CACHE_VARS CACHE_VARIABLES)
foreach(CACHE_VAR ${CACHE_VARS})
  get_property(CACHE_VAR_HELPSTRING CACHE ${CACHE_VAR} PROPERTY HELPSTRING)
  if(CACHE_VAR_HELPSTRING STREQUAL "No help, variable specified on the command line.")
    get_property(CACHE_VAR_TYPE CACHE ${CACHE_VAR} PROPERTY TYPE)
    if(CACHE_VAR_TYPE STREQUAL "UNINITIALIZED")
      set(CACHE_VAR_TYPE)
    else()
      set(CACHE_VAR_TYPE :${CACHE_VAR_TYPE})
    endif()
    set(CMAKE_ARGS "${CMAKE_ARGS} -D${CACHE_VAR}${CACHE_VAR_TYPE}=\"${${CACHE_VAR}}\"")
  endif()
endforeach()
string(REGEX REPLACE "\"" "'" CMAKE_ARGS "${CMAKE_ARGS}")
 
# version info
set(PROJECT_NAME ${PROJECT_NAME})
set(SX7H_Shifter_VERSION ${SX7H_Shifter_VERSION})
set(BUILD_ID 0)
set(GIT_TAG ${GIT_TAG})
set(COMMIT_ID ${COMMIT_ID})
set(BOARD_CONFIG ${BOARD_CONFIG})
set(CMAKE_STRING ${CMAKE_ARGS})
 
# add version info in version.h
configure_file (
  "${PROJECT_SOURCE_DIR}/version.h.in"
  "${PROJECT_BINARY_DIR}/version.h"  )
 
# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  message(STATUS "[INFO]: Setting build type to Debug as none was specified.")
  set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build." FORCE)
  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Release" "Debug" "RelWithDebInfo") # Set the possible values of build type for cmake-gui
endif()
 
# set(BOARD_CONFIG "L1_BP_f091" CACHE STRING "Choose the type of board configuration")
# set_property(CACHE BOARD_CONFIG PROPERTY STRINGS L1_BP_f091 L1_BP_l443 L4_CAHB_f091 L4_CAHB_l443 L3_XXXX_f091)
 
# if(BOARD_CONFIG STREQUAL "L1_BP_f091" OR BOARD_CONFIG STREQUAL "L1_BP_l443")
#     set(ACTUATOR_TYPE "TLT" CACHE STRING "Choose the type of ACTUATOR version")
#     set_property(CACHE ACTUATOR_TYPE PROPERTY STRINGS TLT MAX7)
# elseif(BOARD_CONFIG STREQUAL "L4_CAHB_f091" OR BOARD_CONFIG STREQUAL "L4_CAHB_l443")
#     set(ACTUATOR_TYPE "CAHB12" CACHE STRING "Choose the type of ACTUATOR version")
#     set_property(CACHE ACTUATOR_TYPE PROPERTY STRINGS CAHB12 CAHB24)
# elseif(BOARD_CONFIG STREQUAL "L3_XXXX_f091")
#     set(ACTUATOR_TYPE "CAHB12" CACHE STRING "Choose the type of ACTUATOR version")
#     set_property(CACHE ACTUATOR_TYPE PROPERTY STRINGS CAHB12 CAHB24)
# endif()
 
# set(APP_CONFIG "SIMPLE_SLAVE" CACHE STRING "Choose the type of can node")
# set_property(CACHE APP_CONFIG PROPERTY STRINGS SYNC2 SIMPLE_SLAVE IO SYNC2IO)
 
# set(COMM_CONFIG "CANOPEN" CACHE STRING "Choose the type of communication")
# set_property(CACHE COMM_CONFIG PROPERTY STRINGS CANOPEN J1939 USART)
 
# set(ENCODER_TYPE "CAPACITIVE" CACHE STRING "Choose the type of the encoder")
# set_property(CACHE ENCODER_TYPE PROPERTY STRINGS CAPACITIVE MAGNETIC INCREMENTAL)
 
 
# #Board Selection
# if(BOARD_CONFIG STREQUAL "L1_BP_f091")
#     set_target_properties(SX7H_Shifter PROPERTIES OUTPUT_NAME "bp_f091")
#     set(ENCODER_TYPE "CAPACITIVE")  # this will overwrite whatever parameter is set in command line
#     set(COMM_CONFIG "CANOPEN")      # this will overwrite whatever parameter is set in command line
#     set(GENERIC_FLAGS "-mcpu=cortex-m0 -mthumb")
#     set(CMAKE_C_FLAGS "${GENERIC_FLAGS} --specs=nano.specs  -std=gnu11 -ffunction-sections -fdata-sections -Wall -fstack-usage" CACHE INTERNAL "C Compiler options")
#     set(CMAKE_ASM_FLAGS "${GENERIC_FLAGS}" CACHE INTERNAL "ASM Compiler options")
#     set(CMAKE_EXE_LINKER_FLAGS "--specs=nosys.specs -Wl,-Map=${CMAKE_PROJECT_NAME}.map -Wl,--gc-sections -static -Wl,--print-memory-usage -Wl,--start-group -lc -lm -Wl,--end-group" CACHE INTERNAL "Linker options")
#     set(LINKER_SCRIPT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/SX7H_Shifter_hal/L1_BP_f091/STM32F091CBTx_FLASH.ld")
#     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T${LINKER_SCRIPT_PATH}")
#     add_subdirectory(SX7H_Shifter_hal/L1_BP_f091)
# elseif(BOARD_CONFIG STREQUAL "L1_BP_l443")
#     set_target_properties(SX7H_Shifter PROPERTIES OUTPUT_NAME "bp_l443")
#     set(ENCODER_TYPE "CAPACITIVE")  # this will overwrite whatever parameter is set in command line
#     set(COMM_CONFIG "CANOPEN")      # this will overwrite whatever parameter is set in command line
#     set(GENERIC_FLAGS "-mcpu=cortex-m4 -mthumb")
#     set(CMAKE_C_FLAGS "${GENERIC_FLAGS} --specs=nano.specs  -std=gnu11 -ffunction-sections -fdata-sections -Wall -fstack-usage" CACHE INTERNAL "C Compiler options")
#     set(CMAKE_ASM_FLAGS "${GENERIC_FLAGS}" CACHE INTERNAL "ASM Compiler options")
#     set(CMAKE_EXE_LINKER_FLAGS "--specs=nosys.specs -Wl,-Map=${CMAKE_PROJECT_NAME}.map -Wl,--gc-sections -static -Wl,--print-memory-usage -Wl,--start-group -lc -lm -Wl,--end-group" CACHE INTERNAL "Linker options")
#     set(LINKER_SCRIPT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/SX7H_Shifter_hal/L1_BP_l443/STM32L443CCTX_FLASH.ld")
#     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T${LINKER_SCRIPT_PATH}")
#     add_subdirectory(SX7H_Shifter_hal/L1_BP_l443)
# elseif(BOARD_CONFIG STREQUAL "L4_CAHB_f091")
#     set_target_properties(SX7H_Shifter PROPERTIES OUTPUT_NAME "cahb_f091")
#     set(ENCODER_TYPE "MAGNETIC")  # this will overwrite whatever parameter is set in command line
#     set(COMM_CONFIG "J1939")      # this will overwrite whatever parameter is set in command line
#     set(GENERIC_FLAGS "-mcpu=cortex-m0 -mthumb")
#     set(CMAKE_C_FLAGS "${GENERIC_FLAGS} --specs=nano.specs  -std=gnu11 -ffunction-sections -fdata-sections -Wall -fstack-usage" CACHE INTERNAL "C Compiler options")
#     set(CMAKE_ASM_FLAGS "${GENERIC_FLAGS}" CACHE INTERNAL "ASM Compiler options")
#     set(CMAKE_EXE_LINKER_FLAGS "--specs=nosys.specs -Wl,-Map=${CMAKE_PROJECT_NAME}.map -Wl,--gc-sections -static -Wl,--print-memory-usage -Wl,--start-group -lc -lm -Wl,--end-group" CACHE INTERNAL "Linker options")
#     set(LINKER_SCRIPT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/SX7H_Shifter_hal/L4_CAHB_f091/STM32F091CBTx_FLASH.ld")
#     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T${LINKER_SCRIPT_PATH}")
#     add_subdirectory(SX7H_Shifter_hal/L4_CAHB_f091)
# elseif(BOARD_CONFIG STREQUAL "L4_CAHB_l443")
#     set_target_properties(SX7H_Shifter PROPERTIES OUTPUT_NAME "cahb_l443")
#     set(ENCODER_TYPE "MAGNETIC")  # this will overwrite whatever parameter is set in command line
#     set(COMM_CONFIG "J1939")      # this will overwrite whatever parameter is set in command line
#     set(GENERIC_FLAGS "-mcpu=cortex-m4 -mthumb")
#     set(CMAKE_C_FLAGS "${GENERIC_FLAGS} --specs=nano.specs  -std=gnu11 -ffunction-sections -fdata-sections -Wall -fstack-usage" CACHE INTERNAL "C Compiler options")
#     set(CMAKE_ASM_FLAGS "${GENERIC_FLAGS}" CACHE INTERNAL "ASM Compiler options")
#     set(CMAKE_EXE_LINKER_FLAGS "--specs=nosys.specs -Wl,-Map=${CMAKE_PROJECT_NAME}.map -Wl,--gc-sections -static -Wl,--print-memory-usage -Wl,--start-group -lc -lm -Wl,--end-group" CACHE INTERNAL "Linker options")
#     set(LINKER_SCRIPT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/SX7H_Shifter_hal/L4_CAHB_l443/STM32L443CCTX_FLASH.ld")
#     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T${LINKER_SCRIPT_PATH}")
#     add_subdirectory(SX7H_Shifter_hal/L4_CAHB_l443)
# elseif(BOARD_CONFIG STREQUAL "L3_XXXX_f091")
    set_target_properties(SX7H_Shifter PROPERTIES OUTPUT_NAME "xl6600")
#     set(ENCODER_TYPE "MAGNETIC")  # this will overwrite whatever parameter is set in command line
#     set(COMM_CONFIG "J1939")      # this will overwrite whatever parameter is set in command line
    set(GENERIC_FLAGS "-mcpu=cortex-m3 -mthumb")
    set(CMAKE_C_FLAGS "${GENERIC_FLAGS} --specs=nano.specs  -std=gnu11 -ffunction-sections -fdata-sections -Wall -fstack-usage" CACHE INTERNAL "C Compiler options")
    set(CMAKE_ASM_FLAGS "${GENERIC_FLAGS}" CACHE INTERNAL "ASM Compiler options")
    set(CMAKE_EXE_LINKER_FLAGS "--specs=nosys.specs -Wl,-Map=${CMAKE_PROJECT_NAME}.map -Wl,--gc-sections -static -Wl,--print-memory-usage -Wl,--start-group -lc -lm -Wl,--end-group" CACHE INTERNAL "Linker options")
    set(LINKER_SCRIPT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/SX7H_Shifter_hal/L3_XXXX_f091/STM32F091CBTx_FLASH.ld")
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T${LINKER_SCRIPT_PATH}")
#     add_subdirectory(SX7H_Shifter_hal/L3_XXXX_f091)
# endif()
 
#string(APPEND CMAKE_C_FLAGS " -lglapi")
string(APPEND CMAKE_C_FLAGS " -save-temps")
 
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-wchar-size-warning")
 
#CAN communication stack Selection
# if(COMM_CONFIG STREQUAL "CANOPEN")
#     add_subdirectory(drivers/canopen)
#     target_link_libraries(SX7H_Shifter PRIVATE SX7H_Shifter-hal canfestival LL-SX7H_Shifter Appl-SX7H_Shifter)
# elseif(COMM_CONFIG STREQUAL "J1939")
#     add_subdirectory(drivers/j1939)
#     target_link_libraries(SX7H_Shifter PRIVATE SX7H_Shifter-hal j1939-hal LL-SX7H_Shifter Appl-SX7H_Shifter)
# elseif(COMM_CONFIG STREQUAL "USART")
# endif()
 
target_compile_definitions(SX7H_Shifter PRIVATE ${MCU_CONFIG})
 
get_target_property(ELF_NAME SX7H_Shifter OUTPUT_NAME)
 
if(CMAKE_BUILD_TYPE STREQUAL "Release")
    set_target_properties(SX7H_Shifter PROPERTIES OUTPUT_NAME "${ELF_NAME}_Release")
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
    set_target_properties(SX7H_Shifter PROPERTIES OUTPUT_NAME "${ELF_NAME}_Debug")
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
    set_target_properties(SX7H_Shifter PROPERTIES OUTPUT_NAME "${ELF_NAME}_RelWithDebInfo")
endif()
 
add_subdirectory(Application)
add_subdirectory(Cmsis)
add_subdirectory(Driver)
add_subdirectory(Hal)
 
target_include_directories(SX7H_Shifter PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Application/include)
target_include_directories(SX7H_Shifter PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Cmsis/Core)
target_include_directories(SX7H_Shifter PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Cmsis/Startup)
target_include_directories(SX7H_Shifter PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Driver/include)
target_include_directories(SX7H_Shifter PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Hal/include)
 
get_target_property(PREFIX SX7H_Shifter PREFIX)
get_target_property(NAME SX7H_Shifter OUTPUT_NAME)
get_target_property(SUFFIX SX7H_Shifter SUFFIX)
add_custom_target(bin)
add_custom_command(
                    TARGET bin POST_BUILD
                    COMMAND ${CMAKE_OBJCOPY} --gap-fill 0xFF -O binary --remove-section=.isr_vector_dup ${PREFIX}${NAME}${SUFFIX} ${PREFIX}${NAME}.bin
                    DEPENDS "${PREFIX}${NAME}${SUFFIX}"
)