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