1 ###| CMAKE Kiibohd Controller |###
3 # Jacob Alexander 2011-2014
4 # Due to this file's usefulness:
6 # Released into the Public Domain
8 # avr-gcc CMake Build Configuration
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- )
23 # Atmel Defines and Linker Options
28 #| "at90usb162" # Teensy 1.0
29 #| "atmega32u4" # Teensy 2.0
30 #| "at90usb646" # Teensy++ 1.0
31 #| "at90usb1286" # Teensy++ 2.0
35 message( STATUS "MCU Selected:" )
39 #| Indicate to later build step that this is a Teensy
45 if ( "${CHIP}" MATCHES "at90usb162" )
47 set( SIZE_FLASH 15872 )
50 elseif ( "${CHIP}" MATCHES "atmega32u4" )
52 set( SIZE_FLASH 32256 )
55 elseif ( "${CHIP}" MATCHES "at90usb646" )
57 set( SIZE_FLASH 64512 )
60 elseif ( "${CHIP}" MATCHES "at90usb1286" )
62 set( SIZE_FLASH 130048 )
66 message( AUTHOR_WARNING "CHIP: ${CHIP} - Unknown AVR microcontroller" )
70 #| Only Teensy based AVRs supported
74 #| Extra Compiler Sources
75 #| Mostly for convenience functions like interrupt handlers
77 # XXX Not needed for avr-gcc
82 #| This is only informational for AVR microcontrollers
83 #| The field can be determined by the microcontroller chip, but currently only one CPU type is used atm
86 message( STATUS "CPU Selected:" )
91 set( VENDOR_ID "0x1C11" )
92 set( PRODUCT_ID "0xB04D" )
93 set( BOOT_VENDOR_ID "0x16C0" ) # TODO Double check, this is likely incorrect
94 set( BOOT_PRODUCT_ID "0x047D" )
97 #| Compiler flag to set the C Standard level.
99 #| gnu89 = c89 plus GCC extensions
100 #| c99 = ISO C99 standard (not yet fully implemented)
101 #| gnu99 = c99 plus GCC extensions
102 set( CSTANDARD "-std=gnu99" )
106 #| -Wall...: warning level
111 #| -f...: tuning, see GCC manual and avr-libc documentation
112 #| NOTE: -fshort-wchar is specified to allow USB strings be passed conveniently
113 set( TUNING "-funsigned-char -funsigned-bitfields -ffunction-sections -fpack-struct -fshort-enums" )
116 #| Optimization level, can be [0, 1, 2, 3, s].
117 #| 0 = turn off optimization. s = optimize for size.
118 #| (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
123 #| srec, ihex, binary
127 #| Processor frequency.
128 #| Normally the first thing your program should do is set the clock prescaler,
129 #| so your program will run at the correct speed. You should also set this
130 #| variable to same clock speed. The _delay_ms() macro uses this, and many
131 #| examples use this variable to calculate timings. Do not add a "UL" here.
132 set( F_CPU "16000000" )
136 #| Compiler flags to generate dependency files.
137 set( GENDEPFLAGS "-MMD -MP" )
141 add_definitions( "-mmcu=${MCU} -DF_CPU=${F_CPU} -D_${MCU}_=1 -O${OPT} ${TUNING} ${WARN} ${CSTANDARD} ${GENDEPFLAGS}" )
145 set( LINKER_FLAGS "-mmcu=${MCU} -Wl,-Map=link.map,--cref -Wl,--relax -Wl,--gc-sections" )
148 #| Hex Flags (XXX, CMake seems to have issues if you quote the arguments for the custom commands...)
149 set( HEX_FLAGS -O ${FORMAT} -R .eeprom -R .fuse -R .lock -R .signature )
152 #| Eep Flags (XXX, I've removed this target from the builds, but keeping the set line as a note)
153 set( EEP_FLAGS -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ${FORMAT} )
157 set( LSS_FLAGS -h -S -z )