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