2014-08-15 17:53:43 +00:00
###| CMAKE Kiibohd Controller Bootloader |###
#
# Jacob Alexander 2011-2014
# 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
#|
set ( CHIP
2015-01-11 03:53:46 +00:00
" m k 2 0 d x 1 2 8 v l f 5 " # McHCK mk20dx128vlf5
# "mk20dx256vlh7" # Kiibohd-dfu mk20dx256vlh7
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
set ( COMPILER
" g c c " # arm-none-eabi-gcc / avr-gcc - Default
# "clang" # arm-none-eabi
C A C H E S T R I N G " C o m p i l e r T y p e " )
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 )
include ( initialize )
##
# Source Defines
#
set ( SRCS
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
)
message ( STATUS "Bootloader Source Files:" )
message ( "${SRCS}" )
#| Add Lib sources to main list
foreach ( SRC_FILE ${ COMPILER_SRCS } )
set ( SRCS ${ SRCS } ${ CMAKE_SOURCE_DIR } /../ ${ SRC_FILE } )
endforeach ( )
###
# Directory Includes
#
include_directories ( ${ CMAKE_SOURCE_DIR } /../Lib )
###
# Project Description
#
#| Project
project ( kiibohd_bootloader )
#| Target Name (output name)
set ( TARGET kiibohd_bootloader )
#| General Settings
cmake_minimum_required ( VERSION 2.8 )
###
# Generate Header Files
#
configure_file ( _buildvars.h buildvars.h )
include_directories ( ${ CMAKE_BINARY_DIR } )
###
# CMake Module Checking
#
find_package ( Git REQUIRED )
find_package ( Ctags ) # Optional
###
# ctag Generation
#
if ( CTAGS_EXECUTABLE )
# 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 }
)
endif ( )
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
set ( TARGET_ELF ${ TARGET } .elf )
add_executable ( ${ TARGET_ELF } ${ SRCS } )
#| .ELF Properties
set_target_properties ( ${ TARGET_ELF } PROPERTIES
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
set ( TARGET_BIN ${ TARGET } .bin )
add_custom_command ( TARGET ${ TARGET_ELF } POST_BUILD
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
set ( TARGET_LSS ${ TARGET } .lss )
add_custom_command ( TARGET ${ TARGET_ELF } POST_BUILD
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
set ( TARGET_SYM ${ TARGET } .sym )
add_custom_command ( TARGET ${ TARGET_ELF } POST_BUILD
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
add_custom_command ( TARGET ${ TARGET_ELF } POST_BUILD
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
add_custom_target ( SizeAfter ALL
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 } "
)