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