]> git.donarmstrong.com Git - kiibohd-controller.git/blob - Bootloader/CMakeLists.txt
Fixing bugs in mk20dx128vlf5 support
[kiibohd-controller.git] / Bootloader / CMakeLists.txt
1 ###| CMAKE Kiibohd Controller Bootloader |###
2 #
3 # Jacob Alexander 2011-2014
4 # Due to this file's usefulness:
5 #
6 # Released into the Public Domain
7 #
8 # This bootloader is based upon the MCHCK dfu-usb bootloader.
9 # DO NOT USE with Teensy based microcontrollers.
10 #
11 ###
12
13
14
15 ###
16 # Chip Selection
17 #
18
19 #| You _MUST_ set this to match the microcontroller you are trying to compile for
20 #| You _MUST_ clean the build directory if you change this value
21 #|
22 set( CHIP
23         #"mk20dx128vlf5"    # McHCK       mk20dx128vlf5
24         "mk20dx256vlh7"    # Kiibohd-dfu mk20dx256vlh7
25 )
26
27
28
29 ###
30 # Compiler Selection
31 #
32
33 #| *** EXPERIMENTAL ***
34 #| Stick with gcc unless you know what you're doing
35 #| Currently only arm is supported with clang
36 set( COMPILER
37         "gcc"   # arm-none-eabi-gcc / avr-gcc - Default
38 #       "clang" # arm-none-eabi
39         CACHE STRING "Compiler Type" )
40
41
42
43 ###
44 # Bootloader Configuration
45 #
46 set ( BOOTLOADER 1 )
47
48
49
50 ###
51 # Compiler Intialization
52 #
53 set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/../Lib/CMake )
54 include( initialize )
55
56
57
58 ##
59 # Source Defines
60 #
61 set( SRCS
62         main.c
63         dfu.c
64         dfu.desc.c
65         flash.c
66         kinetis.c
67         usb.c
68 )
69
70 # Only compile in if necessary
71 if( CHIP STREQUAL "mk20dx256vlh7" )
72         set( SRCS ${SRCS}
73                 debug.c
74         )
75 endif()
76
77
78 message( STATUS "Bootloader Source Files:" )
79 message( "${SRCS}" )
80
81 #| Add Lib sources to main list
82 foreach( SRC_FILE ${COMPILER_SRCS} )
83         set( SRCS ${SRCS} ${CMAKE_SOURCE_DIR}/../${SRC_FILE} )
84 endforeach()
85
86
87
88
89 ###
90 # Directory Includes
91 #
92 include_directories( ${CMAKE_SOURCE_DIR}/../Lib )
93
94
95
96 ###
97 # Project Description
98 #
99
100 #| Project
101 project( kiibohd_bootloader )
102
103 #| Target Name (output name)
104 set( TARGET kiibohd_bootloader )
105
106 #| General Settings
107 cmake_minimum_required( VERSION 2.8 )
108
109
110
111 ###
112 # Generate Header Files
113 #
114 configure_file( _buildvars.h buildvars.h )
115 include_directories( ${CMAKE_BINARY_DIR} )
116
117
118
119 ###
120 # CMake Module Checking
121 #
122 find_package( Git REQUIRED )
123 find_package( Ctags ) # Optional
124
125
126
127 ###
128 # ctag Generation
129 #
130 if( CTAGS_EXECUTABLE )
131         # Generate the ctags
132         execute_process( COMMAND ctags ${SRCS}
133                 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
134         )
135 endif()
136
137
138
139 ###
140 # Disable -Wl,-search_paths_first for OSX (not supported by arm-none-eabi-gcc)
141 #
142
143 if ( APPLE )
144         string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_C_LINK_FLAGS ${CMAKE_C_LINK_FLAGS} )
145         string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} )
146
147         message ( AUTHOR_WARNING "Bootloader binary may not fit on device (must be less than 4096 bytes). Macports arm-none-eabi-gcc 4.7.3 doesn't seem to work properly with -flto. However, even disabling it doesn't shrink the binary enough... 4.9.1 is known to work on Arch Linux." )
148 endif ()
149
150
151
152 ###
153 # Build Targets
154 #
155
156 #| Create the .ELF file
157 set( TARGET_ELF ${TARGET}.elf )
158 add_executable( ${TARGET_ELF} ${SRCS} )
159
160
161 #| .ELF Properties
162 set_target_properties( ${TARGET_ELF} PROPERTIES
163         LINK_FLAGS ${LINKER_FLAGS}
164         SUFFIX ""                               # XXX Force Windows to keep the .exe off
165 )
166
167
168 #| Convert the .ELF into a .bin to load onto the McHCK
169 set( TARGET_BIN ${TARGET}.bin )
170 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
171         COMMAND ${CMAKE_OBJCOPY} ${BIN_FLAGS} ${TARGET_ELF} ${TARGET_BIN}
172         COMMENT "Creating binary file to load:  ${TARGET_BIN}"
173 )
174
175
176 #| Generate the Extended .LSS
177 set( TARGET_LSS ${TARGET}.lss )
178 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
179         COMMAND ${CMAKE_OBJDUMP} ${LSS_FLAGS} ${TARGET_ELF} > ${TARGET_LSS}
180         COMMENT "Creating Extended Listing:     ${TARGET_LSS}"
181 )
182
183
184 #| Generate the Symbol Table .SYM
185 set( TARGET_SYM ${TARGET}.sym )
186 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
187         COMMAND ${CMAKE_NM} -n ${TARGET_ELF} > ${TARGET_SYM}
188         COMMENT "Creating Symbol Table:         ${TARGET_SYM}"
189 )
190
191
192 #| Compiler Selection Record
193 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
194         COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/writer compiler ${COMPILER_FAMILY}
195 )
196
197
198
199 ###
200 # Size Information
201 #
202
203 #| After Changes Size Information
204 add_custom_target( SizeAfter ALL
205         COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/sizeCalculator ${CMAKE_SIZE} ram   ${TARGET_ELF} ${SIZE_RAM}   " SRAM"
206         COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/sizeCalculator ${CMAKE_SIZE} flash ${TARGET_ELF} ${SIZE_FLASH} "Flash"
207         DEPENDS ${TARGET_ELF}
208         COMMENT "Chip usage for ${CHIP}"
209 )
210