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