-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
executable file
·153 lines (110 loc) · 4.87 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
144
145
146
147
148
149
150
151
152
153
cmake_minimum_required (VERSION 2.6)
project (mm32_irmp_irsnd)
set(MY_TARGET mm32_irmp_irsnd)
# debug build?
set(DEBUG "1")
# optimization
set(OPT "-Og")
ENABLE_LANGUAGE(ASM)
set(CMAKE_SYSTEM Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)
if(!CROSS_COMPILER_PATH)
message(FATAL_ERROR,"please use -CROSS_COMPILER_PATH=xxxx in command line")
endif()
# cross compiler
# set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(CROSS_COMPILER_PATH "/usr")
set(CMAKE_C_COMPILER "${CROSS_COMPILER_PATH}/bin/arm-none-eabi-gcc")
MESSAGE(STATUS,"compiler is ${CMAKE_C_COMPILER}")
set(CMAKE_ASM_COMPILER "${CROSS_COMPILER_PATH}/bin/arm-none-eabi-g++")
set(CMAKE_CXX_COMPILER "${CROSS_COMPILER_PATH}/bin/arm-none-eabi-gcc")
set(CMAKE_OBJCOPY "${CROSS_COMPILER_PATH}/bin/arm-none-eabi-objcopy")
set(CMAKE_OBJDUMP "${CROSS_COMPILER_PATH}/bin/arm-none-eabi-objdump" )
set(CMAKE_SIZE "${CROSS_COMPILER_PATH}/bin/arm-none-eabi-size" )
set(CMAKE_NM "${CROSS_COMPILER_PATH}/bin/arm-none-eabi-nm" )
set(CMAKE_DEBUGER "${CROSS_COMPILER_PATH}/bin/arm-none-eabi-gdb")
set(CMAKE_CPPFILT "${CROSS_COMPILER_PATH}/bin/arm-none-eabi-c++filt" )
set(CMAKE_FIND_ROOT_PATH "${CROSS_COMPILER_PATH}")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
# set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
message("++++++++++++++Start Build+++++++++++++++++")
if(MCU_TYPE STREQUAL "MM32SPIN0x")
set(mcu_path_dir mm32spin0x_q)
add_definitions(-DMM32SPIN0x)
elseif(MCU_TYPE STREQUAL "MM32F013x")
set(mcu_path_dir mm32f013x)
add_definitions(-DMM32F013x)
else()
message(FATAL_ERROR,"please use -DMCU_TYPE=xxxx in command line")
endif()
# header folder
include_directories(${PROJECT_SOURCE_DIR}/hal_device/cmsis)
include_directories(${PROJECT_SOURCE_DIR}/hal_device/${mcu_path_dir}/HAL_Lib/Inc)
include_directories(${PROJECT_SOURCE_DIR}/hal_device/${mcu_path_dir}/Include)
include_directories(${PROJECT_SOURCE_DIR}/src/driver/${mcu_path_dir}/)
# IRMP and IRSND header
include_directories(${PROJECT_SOURCE_DIR}/src/components/Irsnd/)
include_directories(${PROJECT_SOURCE_DIR}/src/components/Irmp/)
# source file
aux_source_directory(${PROJECT_SOURCE_DIR}/src/ USRMAIN)
aux_source_directory(${PROJECT_SOURCE_DIR}/src/driver/${mcu_path_dir} USRDRIVER)
aux_source_directory(${PROJECT_SOURCE_DIR}/hal_device/${mcu_path_dir}/HAL_Lib/Src LIBSRC)
aux_source_directory(${PROJECT_SOURCE_DIR}/hal_device/${mcu_path_dir}/Source HALSRC)
# IRMP and IRSND source
set(IRMP_SRCS
${PROJECT_SOURCE_DIR}/src/components/Irmp/irmp.c
${PROJECT_SOURCE_DIR}/src/components/Irmp/irmp.c
)
set(IRSND_SRCS
${PROJECT_SOURCE_DIR}/src/components/Irsnd/irsnd.c
)
# the hal source is same for kinds of m32f00 for cortex-m0 machine
# cpu
set(CPU "-mcpu=cortex-m0")
# fpu
#set(FPU "-mfpu=fpv4-sp-d16")
# float-abi
#set(FLOAT-ABI "-mfloat-abi=hard")
# mcu
set(MCU "${CPU} -mthumb")
set(DEPFLAGS "-MMD -MP")
add_compile_definitions(USE_STDPERIPH_DRIVER)
set(CMAKE_C_FLAGS "${MCU} -fno-builtin ${OPT} -Wall -O0 -g3 -std=gnu99 -fdata-sections -ffunction-sections ${DEPFLAGS}")
set(CMAKE_CXX_FLAGS "${MCU} -fno-builtin ${OPT} -Wall -O0 -g3 -std=c++11 -fdata-sections -ffunction-sections ${DEPFLAGS}")
set(CMAKE_ASM_FLAGS "-x assembler-with-cpp ${MCU}")
set(CMAKE_ASM_FLAGS "${MCU} -x assembler")
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
set(LIBS "-lc -lm -lnosys" )
if(MCU_TYPE)
set(LDSCRIPT "${PROJECT_SOURCE_DIR}/hal_device/${mcu_path_dir}/Source/GCC_StartAsm/startup_${mcu_path_dir}.ld")
else()
message(FATAL_ERROR,"please select mcu type")
endif()
set(CMAKE_EXE_LINKER_FLAGS "${MCU} -specs=nano.specs -specs=nosys.specs -T${LDSCRIPT} -Wl,-Map=${PROJECT_BINARY_DIR}/${MY_TARGET}.map,--cref -Wl,--gc-sections")
if(MCU_TYPE)
add_executable(${MY_TARGET}.elf ${USRMAIN} ${USRDRIVER} ${LIBSRC} ${HALSRC} ${IRMP_SRCS} ${IRSND_SRCS}
${PROJECT_SOURCE_DIR}/hal_device/${mcu_path_dir}/Source/GCC_StartAsm/startup_${mcu_path_dir}.s)
else()
message(FATAL_ERROR,"please select mcu type")
endif()
target_link_libraries(${MY_TARGET}.elf ${LIBS})
set_target_properties(${MY_TARGET}.elf PROPERTIES LINK_DEPENDS ${LDSCRIPT})
add_custom_command(
TARGET ${MY_TARGET}.elf
COMMAND ${CMAKE_OBJCOPY} -O ihex ${MY_TARGET}.elf ${MY_TARGET}.hex)
add_custom_command(
TARGET ${MY_TARGET}.elf
POST_BUILD COMMAND ${CMAKE_OBJCOPY} -O binary ${MY_TARGET}.elf ${MY_TARGET}.bin)
add_custom_command(OUTPUT ${PROJECT_NAME}.lst
DEPENDS ${PROJECT_NAME}
COMMAND ${CMAKE_OBJDUMP} -S ${PROJECT_NAME} > ${PROJECT_NAME}.lst)
add_custom_command(
TARGET ${MY_TARGET}.elf
POST_BUILD COMMAND ${CMAKE_SIZE} ${MY_TARGET}.elf )
add_custom_command(
TARGET ${MY_TARGET}.elf
POST_BUILD COMMAND ${CMAKE_OBJDUMP} -S -l ${PROJECT_NAME}.elf > ${PROJECT_NAME}.lst )