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
28 # Bootloader Configuration
35 # Compiler Intialization
37 set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/../Lib/CMake )
54 message( STATUS "Bootloader Source Files:" )
57 #| Add Lib sources to main list
58 foreach( SRC_FILE ${COMPILER_SRCS} )
59 set( SRCS ${SRCS} ${CMAKE_SOURCE_DIR}/../${SRC_FILE} )
68 include_directories( ${CMAKE_SOURCE_DIR}/../Lib )
77 project( kiibohd_bootloader )
79 #| Target Name (output name)
80 set( TARGET kiibohd_bootloader )
83 cmake_minimum_required( VERSION 2.8 )
88 # Generate Header Files
90 configure_file( _buildvars.h buildvars.h )
91 include_directories( ${CMAKE_BINARY_DIR} )
96 # CMake Module Checking
98 find_package( Git REQUIRED )
99 find_package( Ctags ) # Optional
106 if( CTAGS_EXECUTABLE )
108 execute_process( COMMAND ctags ${SRCS}
109 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
119 #| Create the .ELF file
120 set( TARGET_ELF ${TARGET}.elf )
121 add_executable( ${TARGET_ELF} ${SRCS} )
125 set_target_properties( ${TARGET_ELF} PROPERTIES
126 LINK_FLAGS ${LINKER_FLAGS}
127 SUFFIX "" # XXX Force Windows to keep the .exe off
131 #| Convert the .ELF into a .bin to load onto the McHCK
132 set( TARGET_BIN ${TARGET}.bin )
133 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
134 COMMAND ${CMAKE_OBJCOPY} ${BIN_FLAGS} ${TARGET_ELF} ${TARGET_BIN}
135 COMMENT "Creating binary file to load: ${TARGET_BIN}"
139 #| Generate the Extended .LSS
140 set( TARGET_LSS ${TARGET}.lss )
141 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
142 COMMAND ${CMAKE_OBJDUMP} ${LSS_FLAGS} ${TARGET_ELF} > ${TARGET_LSS}
143 COMMENT "Creating Extended Listing: ${TARGET_LSS}"
147 #| Generate the Symbol Table .SYM
148 set( TARGET_SYM ${TARGET}.sym )
149 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
150 COMMAND ${CMAKE_NM} -n ${TARGET_ELF} > ${TARGET_SYM}
151 COMMENT "Creating Symbol Table: ${TARGET_SYM}"
155 #| Compiler Selection Record
156 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
157 COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/writer compiler ${COMPILER_FAMILY}
166 #| After Changes Size Information
167 add_custom_target( SizeAfter ALL
168 COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/sizeCalculator ${CMAKE_SIZE} ram ${TARGET_ELF} ${SIZE_RAM} " SRAM"
169 COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/sizeCalculator ${CMAKE_SIZE} flash ${TARGET_ELF} ${SIZE_FLASH} "Flash"
170 DEPENDS ${TARGET_ELF}
171 COMMENT "Chip usage for ${CHIP}"