]> git.donarmstrong.com Git - kiibohd-controller.git/blob - Lib/CMake/avr.cmake
7e92a10b6ac503792cd79d9fb5e32da9e835a697
[kiibohd-controller.git] / Lib / CMake / avr.cmake
1 ###| CMAKE Kiibohd Controller |###
2 #
3 # Jacob Alexander 2011-2014
4 # Due to this file's usefulness:
5 #
6 # Released into the Public Domain
7 #
8 # avr-gcc CMake Build Configuration
9 #
10 ###
11
12
13
14 #| Set the Compilers (must be set first)
15 include( CMakeForceCompiler )
16 cmake_force_c_compiler  ( avr-gcc AVRCCompiler )
17 cmake_force_cxx_compiler( avr-g++ AVRCxxCompiler )
18 set( _CMAKE_TOOLCHAIN_PREFIX avr- )
19
20
21
22 ###
23 # Atmel Defines and Linker Options
24 #
25
26 #| MCU Name
27 #|
28 #| "at90usb162"       # Teensy   1.0
29 #| "atmega32u4"       # Teensy   2.0
30 #| "at90usb646"       # Teensy++ 1.0
31 #| "at90usb1286"      # Teensy++ 2.0
32
33 set( MCU "${CHIP}" )
34
35 message( STATUS "MCU Selected:" )
36 message( "${MCU}" )
37
38
39 #| Chip Size Database
40 #| Teensy 1.0
41 if ( "${CHIP}" MATCHES "at90usb162" )
42         set( SIZE_RAM      512 )
43         set( SIZE_FLASH  15872 )
44
45 #| Teensy 2.0
46 elseif ( "${CHIP}" MATCHES "atmega32u4" )
47         set( SIZE_RAM     2560 )
48         set( SIZE_FLASH  32256 )
49
50 #| Teensy++ 1.0
51 elseif ( "${CHIP}" MATCHES "at90usb646" )
52         set( SIZE_RAM     4096 )
53         set( SIZE_FLASH  64512 )
54
55 #| Teensy++ 2.0
56 elseif ( "${CHIP}" MATCHES "at90usb1286" )
57         set( SIZE_RAM     8192 )
58         set( SIZE_FLASH 130048 )
59
60 #| Unknown AVR
61 else ()
62         message( AUTHOR_WARNING "CHIP: ${CHIP} - Unknown AVR microcontroller" )
63 endif ()
64
65
66 #| Extra Compiler Sources
67 #| Mostly for convenience functions like interrupt handlers
68 set( COMPILER_SRCS
69         # XXX Not needed for avr-gcc
70 )
71
72
73 #| CPU Type
74 #| This is only informational for AVR microcontrollers
75 #| The field can be determined by the microcontroller chip, but currently only one CPU type is used atm
76 set( CPU "megaAVR" )
77
78 message( STATUS "CPU Selected:" )
79 message( "${CPU}" )
80
81
82 #| USB Defines
83 set( VENDOR_ID  "0x16C0" )
84 set( PRODUCT_ID "0x047D" )
85
86
87 #| Compiler flag to set the C Standard level.
88 #|     c89   = "ANSI" C
89 #|     gnu89 = c89 plus GCC extensions
90 #|     c99   = ISO C99 standard (not yet fully implemented)
91 #|     gnu99 = c99 plus GCC extensions
92 set( CSTANDARD "-std=gnu99" )
93
94
95 #| Warning Options
96 #|  -Wall...:     warning level
97 set( WARN "-Wall" )
98
99
100 #| Tuning Options
101 #|  -f...:        tuning, see GCC manual and avr-libc documentation
102 #| NOTE: -fshort-wchar is specified to allow USB strings be passed conveniently
103 set( TUNING "-funsigned-char -funsigned-bitfields -ffunction-sections -fpack-struct -fshort-enums" )
104
105
106 #| Optimization level, can be [0, 1, 2, 3, s].
107 #|     0 = turn off optimization. s = optimize for size.
108 #|     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
109 set( OPT "s" )
110
111
112 #| Output Format
113 #| srec, ihex, binary
114 set( FORMAT "ihex" )
115
116
117 #| Processor frequency.
118 #|   Normally the first thing your program should do is set the clock prescaler,
119 #|   so your program will run at the correct speed.  You should also set this
120 #|   variable to same clock speed.  The _delay_ms() macro uses this, and many
121 #|   examples use this variable to calculate timings.  Do not add a "UL" here.
122 set( F_CPU "16000000" )
123
124
125 #| Dependency Files
126 #| Compiler flags to generate dependency files.
127 set( GENDEPFLAGS "-MMD -MP" )
128
129
130 #| Compiler Flags
131 add_definitions( "-mmcu=${MCU} -DF_CPU=${F_CPU} -D_${MCU}_=1 -O${OPT} ${TUNING} ${WARN} ${CSTANDARD} ${GENDEPFLAGS}" )
132
133
134 #| Linker Flags
135 set( LINKER_FLAGS "-mmcu=${MCU} -Wl,-Map=link.map,--cref -Wl,--relax -Wl,--gc-sections" )
136
137
138 #| Hex Flags (XXX, CMake seems to have issues if you quote the arguments for the custom commands...)
139 set( HEX_FLAGS -O ${FORMAT} -R .eeprom -R .fuse -R .lock -R .signature )
140
141
142 #| Eep Flags (XXX, I've removed this target from the builds, but keeping the set line as a note)
143 set( EEP_FLAGS -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ${FORMAT} )
144
145
146 #| Lss Flags
147 set( LSS_FLAGS -h -S -z )
148