2014-08-15 17:53:43 +00:00
###| CMAKE Kiibohd Controller Bootloader |###
#
2016-07-23 23:16:16 +00:00
# Jacob Alexander 2011-2016
2014-08-15 17:53:43 +00:00
# Due to this file's usefulness:
#
# Released into the Public Domain
#
# This bootloader is based upon the MCHCK dfu-usb bootloader.
# DO NOT USE with Teensy based microcontrollers.
#
###
###
# Chip Selection
#
#| You _MUST_ set this to match the microcontroller you are trying to compile for
#| You _MUST_ clean the build directory if you change this value
#|
2016-07-23 23:16:16 +00:00
set ( CHIP
2015-06-14 21:32:42 +00:00
" m k 2 0 d x 1 2 8 v l f 5 " # McHCK mk20dx128vlf5
# "mk20dx256vlh7" # Kiibohd-dfu mk20dx256vlh7
2015-06-09 03:42:52 +00:00
C A C H E S T R I N G " C h i p "
2014-08-15 17:53:43 +00:00
)
2015-01-11 03:53:46 +00:00
###
# Compiler Selection
#
#| *** EXPERIMENTAL ***
#| Stick with gcc unless you know what you're doing
#| Currently only arm is supported with clang
2016-07-23 23:16:16 +00:00
set ( COMPILER
2015-03-09 01:40:01 +00:00
" g c c " # arm-none-eabi-gcc / avr-gcc - Default
# "clang" # arm-none-eabi
2015-06-09 03:42:52 +00:00
C A C H E S T R I N G " C o m p i l e r T y p e "
)
2015-01-11 03:53:46 +00:00
2014-08-15 17:53:43 +00:00
###
# Bootloader Configuration
#
set ( BOOTLOADER 1 )
###
# Compiler Intialization
#
set ( CMAKE_MODULE_PATH ${ CMAKE_MODULE_PATH } ${ CMAKE_SOURCE_DIR } /../Lib/CMake )
2016-07-23 23:16:16 +00:00
include ( initialize )
2014-08-15 17:53:43 +00:00
##
# Source Defines
#
2016-07-23 23:16:16 +00:00
set ( SRCS
2014-08-15 17:53:43 +00:00
m a i n . c
d f u . c
d f u . d e s c . c
f l a s h . c
k i n e t i s . c
u s b . c
)
2015-05-26 00:50:32 +00:00
# Only compile in if necessary
2016-07-23 23:16:16 +00:00
if ( CHIP STREQUAL "mk20dx256vlh7" )
2015-05-26 00:50:32 +00:00
set ( SRCS ${ SRCS }
d e b u g . c
)
2016-07-23 23:16:16 +00:00
endif ( )
2015-05-26 00:50:32 +00:00
2016-07-23 23:16:16 +00:00
message ( STATUS "Bootloader Source Files:" )
message ( "${SRCS}" )
2014-08-15 17:53:43 +00:00
#| Add Lib sources to main list
2016-07-23 23:16:16 +00:00
foreach ( SRC_FILE ${ COMPILER_SRCS } )
set ( SRCS ${ SRCS } ${ CMAKE_SOURCE_DIR } /../ ${ SRC_FILE } )
endforeach ( )
2014-08-15 17:53:43 +00:00
###
# Directory Includes
#
2015-06-14 03:42:12 +00:00
include_directories (
$ { C M A K E _ S O U R C E _ D I R } / . . / L i b
$ { C M A K E _ S O U R C E _ D I R }
)
2014-08-15 17:53:43 +00:00
###
# Project Description
#
#| Project
2016-07-23 23:16:16 +00:00
project ( kiibohd_bootloader )
2014-08-15 17:53:43 +00:00
#| Target Name (output name)
2016-07-23 23:16:16 +00:00
set ( TARGET kiibohd_bootloader )
2014-08-15 17:53:43 +00:00
#| General Settings
2016-07-23 23:16:16 +00:00
cmake_minimum_required ( VERSION 2.8 )
2014-08-15 17:53:43 +00:00
###
2016-07-23 23:16:16 +00:00
# CMake Build Env
2014-08-15 17:53:43 +00:00
#
2016-07-23 23:16:16 +00:00
include ( buildinfo )
2014-08-15 17:53:43 +00:00
###
2016-07-23 23:16:16 +00:00
# Generate Header Files
2014-08-15 17:53:43 +00:00
#
2016-07-23 23:16:16 +00:00
configure_file ( _buildvars.h buildvars.h )
include_directories ( ${ CMAKE_BINARY_DIR } )
2014-08-15 17:53:43 +00:00
###
# ctag Generation
#
2016-07-23 23:16:16 +00:00
find_package ( Ctags ) # Optional
if ( CTAGS_EXECUTABLE )
2014-08-15 17:53:43 +00:00
# Generate the ctags
execute_process ( COMMAND ctags ${ SRCS }
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ S O U R C E _ D I R }
)
2016-07-23 23:16:16 +00:00
endif ( )
2014-08-15 17:53:43 +00:00
2014-09-15 03:07:40 +00:00
###
# Disable -Wl,-search_paths_first for OSX (not supported by arm-none-eabi-gcc)
#
if ( APPLE )
string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_C_LINK_FLAGS ${ CMAKE_C_LINK_FLAGS } )
string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_CXX_LINK_FLAGS ${ CMAKE_CXX_LINK_FLAGS } )
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." )
endif ( )
2014-08-15 17:53:43 +00:00
###
# Build Targets
#
#| Create the .ELF file
2016-07-23 23:16:16 +00:00
set ( TARGET_ELF ${ TARGET } .elf )
add_executable ( ${ TARGET_ELF } ${ SRCS } )
2014-08-15 17:53:43 +00:00
#| .ELF Properties
2016-07-23 23:16:16 +00:00
set_target_properties ( ${ TARGET_ELF } PROPERTIES
2014-08-15 17:53:43 +00:00
L I N K _ F L A G S $ { L I N K E R _ F L A G S }
S U F F I X " " # XXX Force Windows to keep the .exe off
)
#| Convert the .ELF into a .bin to load onto the McHCK
2016-07-23 23:16:16 +00:00
set ( TARGET_BIN ${ TARGET } .bin )
add_custom_command ( TARGET ${ TARGET_ELF } POST_BUILD
2014-08-15 17:53:43 +00:00
C O M M A N D $ { C M A K E _ O B J C O P Y } $ { B I N _ F L A G S } $ { T A R G E T _ E L F } $ { T A R G E T _ B I N }
C O M M E N T " C r e a t i n g b i n a r y f i l e t o l o a d : $ { T A R G E T _ B I N } "
)
#| Generate the Extended .LSS
2016-07-23 23:16:16 +00:00
set ( TARGET_LSS ${ TARGET } .lss )
add_custom_command ( TARGET ${ TARGET_ELF } POST_BUILD
2014-08-15 17:53:43 +00:00
C O M M A N D $ { C M A K E _ O B J D U M P } $ { L S S _ F L A G S } $ { T A R G E T _ E L F } > $ { T A R G E T _ L S S }
C O M M E N T " C r e a t i n g E x t e n d e d L i s t i n g : $ { T A R G E T _ L S S } "
)
#| Generate the Symbol Table .SYM
2016-07-23 23:16:16 +00:00
set ( TARGET_SYM ${ TARGET } .sym )
add_custom_command ( TARGET ${ TARGET_ELF } POST_BUILD
2014-08-15 17:53:43 +00:00
C O M M A N D $ { C M A K E _ N M } - n $ { T A R G E T _ E L F } > $ { T A R G E T _ S Y M }
C O M M E N T " C r e a t i n g S y m b o l T a b l e : $ { T A R G E T _ S Y M } "
)
#| Compiler Selection Record
2016-07-23 23:16:16 +00:00
add_custom_command ( TARGET ${ TARGET_ELF } POST_BUILD
2014-08-15 17:53:43 +00:00
C O M M A N D $ { C M A K E _ S O U R C E _ D I R } / . . / L i b / C M a k e / w r i t e r c o m p i l e r $ { C O M P I L E R _ F A M I L Y }
)
###
# Size Information
#
#| After Changes Size Information
2016-07-23 23:16:16 +00:00
add_custom_target ( SizeAfter ALL
2014-08-15 17:53:43 +00:00
C O M M A N D $ { C M A K E _ S O U R C E _ D I R } / . . / L i b / C M a k e / s i z e C a l c u l a t o r $ { C M A K E _ S I Z E } r a m $ { T A R G E T _ E L F } $ { S I Z E _ R A M } " S R A M "
C O M M A N D $ { C M A K E _ S O U R C E _ D I R } / . . / L i b / C M a k e / s i z e C a l c u l a t o r $ { C M A K E _ S I Z E } f l a s h $ { T A R G E T _ E L F } $ { S I Z E _ F L A S H } " F l a s h "
D E P E N D S $ { T A R G E T _ E L F }
C O M M E N T " C h i p u s a g e f o r $ { C H I P } "
)