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
33 #| *** EXPERIMENTAL ***
34 #| Stick with gcc unless you know what you're doing
35 #| Currently only arm is supported with clang
37 "gcc" # arm-none-eabi-gcc / avr-gcc - Default
38 # "clang" # arm-none-eabi
39 CACHE STRING "Compiler Type" )
44 # Bootloader Configuration
51 # Compiler Intialization
53 set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/../Lib/CMake )
63 debug.c # TODO only compile in if necessary
71 message( STATUS "Bootloader Source Files:" )
74 #| Add Lib sources to main list
75 foreach( SRC_FILE ${COMPILER_SRCS} )
76 set( SRCS ${SRCS} ${CMAKE_SOURCE_DIR}/../${SRC_FILE} )
85 include_directories( ${CMAKE_SOURCE_DIR}/../Lib )
94 project( kiibohd_bootloader )
96 #| Target Name (output name)
97 set( TARGET kiibohd_bootloader )
100 cmake_minimum_required( VERSION 2.8 )
105 # Generate Header Files
107 configure_file( _buildvars.h buildvars.h )
108 include_directories( ${CMAKE_BINARY_DIR} )
113 # CMake Module Checking
115 find_package( Git REQUIRED )
116 find_package( Ctags ) # Optional
123 if( CTAGS_EXECUTABLE )
125 execute_process( COMMAND ctags ${SRCS}
126 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
133 # Disable -Wl,-search_paths_first for OSX (not supported by arm-none-eabi-gcc)
137 string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_C_LINK_FLAGS ${CMAKE_C_LINK_FLAGS} )
138 string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} )
140 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." )
149 #| Create the .ELF file
150 set( TARGET_ELF ${TARGET}.elf )
151 add_executable( ${TARGET_ELF} ${SRCS} )
155 set_target_properties( ${TARGET_ELF} PROPERTIES
156 LINK_FLAGS ${LINKER_FLAGS}
157 SUFFIX "" # XXX Force Windows to keep the .exe off
161 #| Convert the .ELF into a .bin to load onto the McHCK
162 set( TARGET_BIN ${TARGET}.bin )
163 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
164 COMMAND ${CMAKE_OBJCOPY} ${BIN_FLAGS} ${TARGET_ELF} ${TARGET_BIN}
165 COMMENT "Creating binary file to load: ${TARGET_BIN}"
169 #| Generate the Extended .LSS
170 set( TARGET_LSS ${TARGET}.lss )
171 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
172 COMMAND ${CMAKE_OBJDUMP} ${LSS_FLAGS} ${TARGET_ELF} > ${TARGET_LSS}
173 COMMENT "Creating Extended Listing: ${TARGET_LSS}"
177 #| Generate the Symbol Table .SYM
178 set( TARGET_SYM ${TARGET}.sym )
179 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
180 COMMAND ${CMAKE_NM} -n ${TARGET_ELF} > ${TARGET_SYM}
181 COMMENT "Creating Symbol Table: ${TARGET_SYM}"
185 #| Compiler Selection Record
186 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
187 COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/writer compiler ${COMPILER_FAMILY}
196 #| After Changes Size Information
197 add_custom_target( SizeAfter ALL
198 COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/sizeCalculator ${CMAKE_SIZE} ram ${TARGET_ELF} ${SIZE_RAM} " SRAM"
199 COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/sizeCalculator ${CMAKE_SIZE} flash ${TARGET_ELF} ${SIZE_FLASH} "Flash"
200 DEPENDS ${TARGET_ELF}
201 COMMENT "Chip usage for ${CHIP}"