-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgeneric-msp430-gcc.cmake
64 lines (48 loc) · 2.04 KB
/
generic-msp430-gcc.cmake
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
#toolchain cmake file for msp430-gcc/avrdude toolchain
# needs the following variables:
# MSP430_MCU : mcu type
# MSP430_MCU_FREQ : clock frequency (defines F_CPU)
INCLUDE(CMakeForceCompiler)
#generic avr flags
set(MSP430_CFLAGS "-ffunction-sections -fdata-sections" CACHE STRING "MSP430 compilation flags")
set(MSP430_LFLAGS "-Wl,--relax,--gc-sections" CACHE STRING "MSP430 link flags")
#find toolchain programs
find_program(MSP430-GCC msp430-gcc)
find_program(MSP430-GXX msp430-g++)
find_program(MSP430-OBJCOPY msp430-objcopy)
find_program(MSP430-SIZE msp430-size)
find_program(MSP430-OBJDUMP msp430-objdump)
find_program(MSPDEBUG mspdebug)
#define toolchain
set(CMAKE_SYSTEM_NAME Generic)
CMAKE_FORCE_C_COMPILER(${MSP430-GCC} GNU)
CMAKE_FORCE_CXX_COMPILER(${MSP430-GXX} GNU)
#Release by default
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
endif(NOT CMAKE_BUILD_TYPE)
function(msp430_add_executable_compilation EXECUTABLE)
set(EXECUTABLE_ELF "${EXECUTABLE}.elf")
# main target for the executable depends of elf
add_custom_target(${EXECUTABLE} ALL DEPENDS ${EXECUTABLE_ELF})
# compile and link elf file
add_executable(${EXECUTABLE_ELF} ${ARGN})
set_target_properties(${EXECUTABLE_ELF} PROPERTIES
COMPILE_FLAGS "-mmcu=${MSP430_MCU} -DF_CPU=${MSP430_MCU_FREQ} ${MSP430_CFLAGS}"
LINK_FLAGS "-mmcu=${MSP430_MCU} ${MSP430_LFLAGS}")
# display size info after compilation
add_custom_command(TARGET ${EXECUTABLE} POST_BUILD
COMMAND ${MSP430-SIZE} ${EXECUTABLE_ELF})
endfunction(msp430_add_executable_compilation)
function(msp430_add_executable_upload ${EXECUTABLE})
add_custom_target(upload_${EXECUTABLE}
COMMAND ${MSPDEBUG} -q rf2500 "prog ${EXECUTABLE}.elf"
DEPENDS ${EXECUTABLE})
endfunction(msp430_add_executable_upload)
function(msp430_add_executable EXECUTABLE)
if(NOT MSP430_MCU)
message(FATAL_ERROR "MSP430_MCU not defined")
endif(NOT MSP430_MCU)
msp430_add_executable_compilation(${EXECUTABLE} ${ARGN})
msp430_add_executable_upload(${EXECUTABLE})
endfunction(msp430_add_executable)