-
Notifications
You must be signed in to change notification settings - Fork 4
/
toolchain-avr-gcc.cmake
94 lines (73 loc) · 4.23 KB
/
toolchain-avr-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
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
# To be able to use Force Compiler macros.
include(CMakeForceCompiler)
# Add the location of your "toolchains" folder to the module path
SET(TOOLCHAINS_PATH "/home/chintal/code/toolchains")
LIST(APPEND CMAKE_MODULE_PATH ${TOOLCHAINS_PATH})
SET(PLATFORM_PACKAGES_PATH "${TOOLCHAINS_PATH}/packages/avr")
LIST(APPEND CMAKE_MODULE_PATH "${PLATFORM_PACKAGES_PATH}/lib/cmake")
LIST(APPEND CMAKE_PREFIX_PATH "${PLATFORM_PACKAGES_PATH}/lib/cmake")
INCLUDE_DIRECTORIES("${PLATFORM_PACKAGES_PATH}/include ${INCLUDE_DIRECTORIES}")
SET(SUPPORTED_DEVICES "atmega16;atmega32;atmega644;atmega48;atmega88;atmega168;atmega328"
CACHE STRING "Supported Target Devices")
# Name should be 'Generic' or something for which a
# Platform/<name>.cmake (or other derivatives thereof, see cmake docs)
# file exists. The cmake installation comes with a Platform folder with
# defined platforms, and we add our custom ones to the "Platform" folder
# within the "toolchain" folder.
set(CMAKE_SYSTEM_NAME avr-gcc)
# Compiler and related toochain configuration
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SET(AVR_LIBC_FOLDER /usr/lib/avr)
SET(AVR_INCLUDE_FOLDER ${AVR_LIBC_FOLDER}/include)
SET(TOOLCHAIN_PREFIX avr)
INCLUDE_DIRECTORIES(${AVR_INCLUDE_FOLDER} ${INCLUDE_DIRECTORIES})
# This can be skipped to directly set paths below, or augmented with hints
# and such. See cmake docs of FIND_PROGRAM for details.
FIND_PROGRAM(AVR_CC ${TOOLCHAIN_PREFIX}-gcc)
FIND_PROGRAM(AVR_CXX ${TOOLCHAIN_PREFIX}-g++)
FIND_PROGRAM(AVR_AR ${TOOLCHAIN_PREFIX}-ar)
FIND_PROGRAM(AVR_AS ${TOOLCHAIN_PREFIX}-as)
FIND_PROGRAM(AVR_OBJDUMP ${TOOLCHAIN_PREFIX}-objdump)
FIND_PROGRAM(AVR_OBJCOPY ${TOOLCHAIN_PREFIX}-objcopy)
FIND_PROGRAM(AVR_SIZE ${TOOLCHAIN_PREFIX}-size)
FIND_PROGRAM(AVR_NM ${TOOLCHAIN_PREFIX}-nm)
FIND_PROGRAM(AVR_DUDE avrdude)
# Since the compiler needs an -mmcu flag to do anything, checks need to be bypassed
SET(CMAKE_C_COMPILER ${AVR_CC} CACHE STRING "C Compiler")
SET(CMAKE_CXX_COMPILER ${AVR_CXX} CACHE STRING "C++ Compiler")
SET(AS ${AVR_AS} CACHE STRING "AS Binary")
SET(AR ${AVR_AR} CACHE STRING "AR Binary")
SET(OBJCOPY ${AVR_OBJCOPY} CACHE STRING "OBJCOPY Binary")
SET(OBJDUMP ${AVR_OBJDUMP} CACHE STRING "OBJDUMP Binary")
SET(SIZE ${AVR_SIZE} CACHE STRING "SIZE Binary")
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
ENDIF(NOT CMAKE_BUILD_TYPE)
SET(AVR_OPT_LEVEL "0"
CACHE STRING "Optimization Level")
SET(AVR_WARN_PROFILE "-Wall -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wsign-compare -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wunused"
CACHE STRING "AVR GCC Warnings")
SET(AVR_DISABLED_BUILTINS "-fno-builtin-printf -fno-builtin-sprintf"
CACHE STRING "AVR GCC Disabled Builtins")
SET(AVR_OPTIONS "-g -fdata-sections -ffunction-sections -fverbose-asm -std=gnu11 ${AVR_DISABLED_BUILTINS}"
CACHE STRING "AVR GCC OPTIONS")
SET(CMAKE_C_FLAGS "${AVR_WARN_PROFILE} ${AVR_OPTIONS} -O${AVR_OPT_LEVEL} -DGCC_AVR"
CACHE STRING "AVR GCC C Flags")
SET(CMAKE_SHARED_LINKER_FLAGS "-Wl,--gc-sections -Wl,--print-gc-sections"
CACHE STRING "Linker Flags")
SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections"
CACHE STRING "Linker Flags")
# Specify linker command. This is needed to use gcc as linker instead of ld
# This seems to be the preferred way for MSPGCC atleast, seemingly to avoid
# linking against stdlib.
set(CMAKE_CXX_LINK_EXECUTABLE
"<CMAKE_C_COMPILER> ${CMAKE_EXE_LINKER_FLAGS} <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
CACHE STRING "C++ Executable Link Command")
set(CMAKE_C_LINK_EXECUTABLE ${CMAKE_CXX_LINK_EXECUTABLE}
CACHE STRING "C Executable Link Command")
# Programmer and related toochain configuration
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
set(PROGBIN ${AVR_DUDE} CACHE STRING "Programmer Application")
set(PROGRAMMER tilib CACHE STRING "Programmer driver")