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