1 ###| CMAKE Kiibohd Controller Bootloader |###
3 # Jacob Alexander 2011-2014
4 # Due to this file's usefulness:
6 # Released into the Public Domain
8 # This bootloader is based upon the MCHCK dfu-usb bootloader.
9 # DO NOT USE with Teensy based microcontrollers.
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
23 #"mk20dx128vlf5" # McHCK mk20dx128vlf5
24 "mk20dx256vlh7" # Kiibohd-dfu mk20dx256vlh7
34 #| *** EXPERIMENTAL ***
35 #| Stick with gcc unless you know what you're doing
36 #| Currently only arm is supported with clang
38 "gcc" # arm-none-eabi-gcc / avr-gcc - Default
39 # "clang" # arm-none-eabi
40 CACHE STRING "Compiler Type"
46 # Bootloader Configuration
53 # Compiler Intialization
55 set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/../Lib/CMake )
72 # Only compile in if necessary
73 if( CHIP STREQUAL "mk20dx256vlh7" )
80 message( STATUS "Bootloader Source Files:" )
83 #| Add Lib sources to main list
84 foreach( SRC_FILE ${COMPILER_SRCS} )
85 set( SRCS ${SRCS} ${CMAKE_SOURCE_DIR}/../${SRC_FILE} )
94 include_directories( ${CMAKE_SOURCE_DIR}/../Lib )
103 project( kiibohd_bootloader )
105 #| Target Name (output name)
106 set( TARGET kiibohd_bootloader )
109 cmake_minimum_required( VERSION 2.8 )
114 # Generate Header Files
116 configure_file( _buildvars.h buildvars.h )
117 include_directories( ${CMAKE_BINARY_DIR} )
122 # CMake Module Checking
124 find_package( Git REQUIRED )
125 find_package( Ctags ) # Optional
132 if( CTAGS_EXECUTABLE )
134 execute_process( COMMAND ctags ${SRCS}
135 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
142 # Disable -Wl,-search_paths_first for OSX (not supported by arm-none-eabi-gcc)
146 string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_C_LINK_FLAGS ${CMAKE_C_LINK_FLAGS} )
147 string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} )
149 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." )
158 #| Create the .ELF file
159 set( TARGET_ELF ${TARGET}.elf )
160 add_executable( ${TARGET_ELF} ${SRCS} )
164 set_target_properties( ${TARGET_ELF} PROPERTIES
165 LINK_FLAGS ${LINKER_FLAGS}
166 SUFFIX "" # XXX Force Windows to keep the .exe off
170 #| Convert the .ELF into a .bin to load onto the McHCK
171 set( TARGET_BIN ${TARGET}.bin )
172 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
173 COMMAND ${CMAKE_OBJCOPY} ${BIN_FLAGS} ${TARGET_ELF} ${TARGET_BIN}
174 COMMENT "Creating binary file to load: ${TARGET_BIN}"
178 #| Generate the Extended .LSS
179 set( TARGET_LSS ${TARGET}.lss )
180 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
181 COMMAND ${CMAKE_OBJDUMP} ${LSS_FLAGS} ${TARGET_ELF} > ${TARGET_LSS}
182 COMMENT "Creating Extended Listing: ${TARGET_LSS}"
186 #| Generate the Symbol Table .SYM
187 set( TARGET_SYM ${TARGET}.sym )
188 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
189 COMMAND ${CMAKE_NM} -n ${TARGET_ELF} > ${TARGET_SYM}
190 COMMENT "Creating Symbol Table: ${TARGET_SYM}"
194 #| Compiler Selection Record
195 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
196 COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/writer compiler ${COMPILER_FAMILY}
205 #| After Changes Size Information
206 add_custom_target( SizeAfter ALL
207 COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/sizeCalculator ${CMAKE_SIZE} ram ${TARGET_ELF} ${SIZE_RAM} " SRAM"
208 COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/sizeCalculator ${CMAKE_SIZE} flash ${TARGET_ELF} ${SIZE_FLASH} "Flash"
209 DEPENDS ${TARGET_ELF}
210 COMMENT "Chip usage for ${CHIP}"