]> git.donarmstrong.com Git - kiibohd-controller.git/blob - Bootloader/CMakeLists.txt
Pre-merge cleanup.
[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         CACHE STRING "Chip"
26 )
27
28
29
30 ###
31 # Compiler Selection
32 #
33
34 #| *** EXPERIMENTAL ***
35 #| Stick with gcc unless you know what you're doing
36 #| Currently only arm is supported with clang
37 set( COMPILER
38         "gcc"   # arm-none-eabi-gcc / avr-gcc - Default
39 #       "clang" # arm-none-eabi
40         CACHE STRING "Compiler Type"
41 )
42
43
44
45 ###
46 # Bootloader Configuration
47 #
48 set ( BOOTLOADER 1 )
49
50
51
52 ###
53 # Compiler Intialization
54 #
55 set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/../Lib/CMake )
56 include( initialize )
57
58
59
60 ##
61 # Source Defines
62 #
63 set( SRCS
64         main.c
65         dfu.c
66         dfu.desc.c
67         flash.c
68         kinetis.c
69         usb.c
70 )
71
72 # Only compile in if necessary
73 if( CHIP STREQUAL "mk20dx256vlh7" )
74         set( SRCS ${SRCS}
75                 debug.c
76         )
77 endif()
78
79
80 message( STATUS "Bootloader Source Files:" )
81 message( "${SRCS}" )
82
83 #| Add Lib sources to main list
84 foreach( SRC_FILE ${COMPILER_SRCS} )
85         set( SRCS ${SRCS} ${CMAKE_SOURCE_DIR}/../${SRC_FILE} )
86 endforeach()
87
88
89
90
91 ###
92 # Directory Includes
93 #
94 include_directories (
95         ${CMAKE_SOURCE_DIR}/../Lib
96         ${CMAKE_SOURCE_DIR}
97 )
98
99
100
101 ###
102 # Project Description
103 #
104
105 #| Project
106 project( kiibohd_bootloader )
107
108 #| Target Name (output name)
109 set( TARGET kiibohd_bootloader )
110
111 #| General Settings
112 cmake_minimum_required( VERSION 2.8 )
113
114
115
116 ###
117 # Generate Header Files
118 #
119 configure_file( _buildvars.h buildvars.h )
120 include_directories( ${CMAKE_BINARY_DIR} )
121
122
123
124 ###
125 # CMake Module Checking
126 #
127 find_package( Git REQUIRED )
128 find_package( Ctags ) # Optional
129
130
131
132 ###
133 # ctag Generation
134 #
135 if( CTAGS_EXECUTABLE )
136         # Generate the ctags
137         execute_process( COMMAND ctags ${SRCS}
138                 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
139         )
140 endif()
141
142
143
144 ###
145 # Disable -Wl,-search_paths_first for OSX (not supported by arm-none-eabi-gcc)
146 #
147
148 if ( APPLE )
149         string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_C_LINK_FLAGS ${CMAKE_C_LINK_FLAGS} )
150         string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} )
151
152         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." )
153 endif ()
154
155
156
157 ###
158 # Build Targets
159 #
160
161 #| Create the .ELF file
162 set( TARGET_ELF ${TARGET}.elf )
163 add_executable( ${TARGET_ELF} ${SRCS} )
164
165
166 #| .ELF Properties
167 set_target_properties( ${TARGET_ELF} PROPERTIES
168         LINK_FLAGS ${LINKER_FLAGS}
169         SUFFIX ""                               # XXX Force Windows to keep the .exe off
170 )
171
172
173 #| Convert the .ELF into a .bin to load onto the McHCK
174 set( TARGET_BIN ${TARGET}.bin )
175 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
176         COMMAND ${CMAKE_OBJCOPY} ${BIN_FLAGS} ${TARGET_ELF} ${TARGET_BIN}
177         COMMENT "Creating binary file to load:  ${TARGET_BIN}"
178 )
179
180
181 #| Generate the Extended .LSS
182 set( TARGET_LSS ${TARGET}.lss )
183 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
184         COMMAND ${CMAKE_OBJDUMP} ${LSS_FLAGS} ${TARGET_ELF} > ${TARGET_LSS}
185         COMMENT "Creating Extended Listing:     ${TARGET_LSS}"
186 )
187
188
189 #| Generate the Symbol Table .SYM
190 set( TARGET_SYM ${TARGET}.sym )
191 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
192         COMMAND ${CMAKE_NM} -n ${TARGET_ELF} > ${TARGET_SYM}
193         COMMENT "Creating Symbol Table:         ${TARGET_SYM}"
194 )
195
196
197 #| Compiler Selection Record
198 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
199         COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/writer compiler ${COMPILER_FAMILY}
200 )
201
202
203
204 ###
205 # Size Information
206 #
207
208 #| After Changes Size Information
209 add_custom_target( SizeAfter ALL
210         COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/sizeCalculator ${CMAKE_SIZE} ram   ${TARGET_ELF} ${SIZE_RAM}   " SRAM"
211         COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/sizeCalculator ${CMAKE_SIZE} flash ${TARGET_ELF} ${SIZE_FLASH} "Flash"
212         DEPENDS ${TARGET_ELF}
213         COMMENT "Chip usage for ${CHIP}"
214 )
215