]> git.donarmstrong.com Git - kiibohd-controller.git/blob - CMakeLists.txt
Finished major changes on the CMakeLists.txt.
[kiibohd-controller.git] / CMakeLists.txt
1 ###| CMAKE Kiibohd Controller |###
2 #
3 # Written by Jacob Alexander in 2011 for the Kiibohd Controller
4 # Due to this file's usefulness:
5 #
6 # Released into the Public Domain
7 #
8 ###
9
10 #| Set the Compilers (must be set first)
11 include( CMakeForceCompiler )
12 set( CMAKE_SYSTEM_NAME Generic )
13 cmake_force_c_compiler  ( avr-gcc AVRCCompiler )
14 cmake_force_cxx_compiler( avr-g++ AVRCxxCompiler )
15
16
17 ###
18 # Project Description
19 #
20
21 #| Project
22 project( kiibohd_controller )
23
24 #| Target Name (output name)
25 set( TARGET kiibohd )
26
27 #| General Settings
28 cmake_minimum_required( VERSION 2.8 )
29
30
31
32 ###
33 # Source Defines
34 #
35
36 #| Sources 
37 set( SRCS
38         ./main.c
39         ./print.c
40         ./usb_keyboard_debug.c
41         ./scan_loop.c
42 )
43
44
45
46 ###
47 # Atmel Defines and Linker Options
48 #
49
50 #| MCU Name
51 #| You _MUST_ set this to match the board you are using
52 #| type "make clean" after changing this, so all files will be rebuilt
53 #|
54 #| "at90usb162"       # Teensy   1.0
55 #| "atmega32u4"       # Teensy   2.0
56 #| "at90usb646"       # Teensy++ 1.0
57 #| "at90usb1286"      # Teensy++ 2.0
58 set( MCU "at90usb1286" )
59
60
61 #| Compiler flag to set the C Standard level.
62 #|     c89   = "ANSI" C
63 #|     gnu89 = c89 plus GCC extensions
64 #|     c99   = ISO C99 standard (not yet fully implemented)
65 #|     gnu99 = c99 plus GCC extensions
66 set( CSTANDARD "-std=gnu99" )
67
68
69 #| Warning Options
70 #|  -Wall...:     warning level
71 set( WARN "-Wall -Wstrict-prototypes" )
72
73
74 #| Tuning Options
75 #|  -f...:        tuning, see GCC manual and avr-libc documentation
76 set( TUNING "-funsigned-char -funsigned-bitfields -ffunction-sections -fpack-struct -fshort-enums" )
77
78
79 #| Optimization level, can be [0, 1, 2, 3, s]. 
80 #|     0 = turn off optimization. s = optimize for size.
81 #|     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
82 set( OPT "s" )
83
84
85 #| Output Format
86 #| srec, ihex, binary
87 set( FORMAT "ihex" )
88
89
90 #| Processor frequency.
91 #|   Normally the first thing your program should do is set the clock prescaler,
92 #|   so your program will run at the correct speed.  You should also set this
93 #|   variable to same clock speed.  The _delay_ms() macro uses this, and many
94 #|   examples use this variable to calculate timings.  Do not add a "UL" here.
95 set( F_CPU "16000000" )
96
97
98 #| Dependency Files
99 #| Compiler flags to generate dependency files.
100 set( GENDEPFLAGS "-MMD -MP" )
101
102
103 #| Listing file
104 set( TARGET_LST ${TARGET}.lst )
105
106
107 #| Compiler Flags
108 add_definitions( "-mmcu=${MCU} -DF_CPU=${F_CPU} -O${OPT} ${TUNING} ${WARN} ${CSTANDARD} ${GENDEPFLAGS}" )
109
110
111 #| Linker Flags
112 set( LINKER_FLAGS "-mmcu=${MCU} -Wl,-Map=${TARGET}.map,--cref -Wl,--relax -Wl,--gc-sections" )
113
114
115 #| Hex Flags (XXX, CMake seems to have issues if you quote the arguments for the custom commands...)
116 set( HEX_FLAGS -O ${FORMAT} -R .eeprom -R .fuse -R .lock -R .signature )
117
118
119 #| Eep Flags
120 set( EEP_FLAGS -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ${FORMAT} )
121
122
123 #| Lss Flags
124 set( LSS_FLAGS -h -S -z )
125
126
127
128 ###
129 # Build Targets
130 #
131
132 #| Create the .ELF file
133 set( TARGET_ELF ${TARGET}.elf )
134 add_executable( ${TARGET_ELF} ${SRCS} )
135
136
137 #| .ELF Properties
138 set_target_properties( ${TARGET_ELF} PROPERTIES
139         LINK_FLAGS ${LINKER_FLAGS}
140 )
141
142
143 #| Convert the .ELF into a .HEX to load onto the Teensy
144 set( TARGET_HEX ${TARGET}.hex )
145 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
146         COMMAND avr-objcopy ${HEX_FLAGS} ${TARGET_ELF} ${TARGET_HEX}
147         COMMENT "Creating load file for Flash:  ${TARGET_HEX}"
148 )
149
150
151 #| Convert the .ELF into a .EEP
152 set( TARGET_EEP ${TARGET}.eep )
153 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
154         COMMAND avr-objcopy ${EEP_FLAGS} ${TARGET_ELF} ${TARGET_EEP}
155         COMMENT "Creating load file for EEPROM: ${TARGET_EEP}"
156 )
157
158
159 #| Generate the Extended .LSS
160 set( TARGET_LSS ${TARGET}.lss )
161 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
162         COMMAND avr-objdump ${LSS_FLAGS} ${TARGET_ELF} > ${TARGET_LSS}
163         COMMENT "Creating Extended Listing:     ${TARGET_LSS}"
164 )
165
166
167 #| Generate the Symbol Table .SYM
168 set( TARGET_SYM ${TARGET}.sym )
169 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
170         COMMAND avr-nm -n ${TARGET_ELF} > ${TARGET_SYM}
171         COMMENT "Creating Symbol Table:         ${TARGET_SYM}"
172 )
173
174
175
176 ###
177 # Size Information
178 #
179
180 #| After Changes Size Information
181 add_custom_target( SizeAfter ALL avr-size --target=${FORMAT} ${TARGET_HEX} ${TARGET_ELF}
182         DEPENDS ${TARGET_ELF}
183         COMMENT "Size after generation:"
184 )
185