2011-09-28 08:47:50 +00:00
###| CMAKE Kiibohd Controller |###
#
# Written by Jacob Alexander in 2011 for the Kiibohd Controller
# Due to this file's usefulness:
#
# Released into the Public Domain
#
###
2011-09-29 03:37:19 +00:00
#| Set the Compilers (must be set first)
2011-09-28 08:47:50 +00:00
include ( CMakeForceCompiler )
cmake_force_c_compiler ( avr-gcc AVRCCompiler )
cmake_force_cxx_compiler ( avr-g++ AVRCxxCompiler )
2011-11-13 10:04:44 +00:00
#| Add Dependency Macro
include ( AddFileDependencies )
2011-09-29 03:37:19 +00:00
###
# Project Description
#
2011-09-28 08:47:50 +00:00
#| Project
project ( kiibohd_controller )
2011-09-29 03:37:19 +00:00
#| Target Name (output name)
set ( TARGET kiibohd )
2011-09-28 08:47:50 +00:00
#| General Settings
cmake_minimum_required ( VERSION 2.8 )
2011-09-29 03:37:19 +00:00
###
# Source Defines
#
2011-09-28 08:47:50 +00:00
2011-09-29 06:25:51 +00:00
#| Sources (see setup.h for configuring in/away code blocks or other complete modules)
#| XXX Not set here in this project, see setup.cmake
#set( SRCS ./main.c )
#| Instead, include the module source selector
include ( setup.cmake )
2011-11-13 10:04:44 +00:00
set ( SRCS
m a i n . c
$ { S C A N _ S R C S }
$ { M A C R O _ S R C S }
$ { U S B _ S R C S }
$ { D E B U G _ S R C S }
)
2011-09-28 08:47:50 +00:00
2011-09-29 03:37:19 +00:00
###
# Atmel Defines and Linker Options
#
2011-09-28 08:47:50 +00:00
2011-09-29 03:37:19 +00:00
#| MCU Name
#| You _MUST_ set this to match the board you are using
#| type "make clean" after changing this, so all files will be rebuilt
#|
#| "at90usb162" # Teensy 1.0
#| "atmega32u4" # Teensy 2.0
#| "at90usb646" # Teensy++ 1.0
#| "at90usb1286" # Teensy++ 2.0
2011-12-19 03:02:56 +00:00
set ( MCU "atmega32u4" )
#set( MCU "at90usb1286" )
2011-09-28 08:47:50 +00:00
#| Compiler flag to set the C Standard level.
#| c89 = "ANSI" C
#| gnu89 = c89 plus GCC extensions
#| c99 = ISO C99 standard (not yet fully implemented)
#| gnu99 = c99 plus GCC extensions
set ( CSTANDARD "-std=gnu99" )
#| Warning Options
#| -Wall...: warning level
set ( WARN "-Wall -Wstrict-prototypes" )
#| Tuning Options
#| -f...: tuning, see GCC manual and avr-libc documentation
set ( TUNING "-funsigned-char -funsigned-bitfields -ffunction-sections -fpack-struct -fshort-enums" )
#| Optimization level, can be [0, 1, 2, 3, s].
#| 0 = turn off optimization. s = optimize for size.
#| (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
set ( OPT "s" )
#| Output Format
#| srec, ihex, binary
set ( FORMAT "ihex" )
#| Processor frequency.
#| Normally the first thing your program should do is set the clock prescaler,
#| so your program will run at the correct speed. You should also set this
#| variable to same clock speed. The _delay_ms() macro uses this, and many
#| examples use this variable to calculate timings. Do not add a "UL" here.
set ( F_CPU "16000000" )
#| Dependency Files
#| Compiler flags to generate dependency files.
set ( GENDEPFLAGS "-MMD -MP" )
#| Listing file
set ( TARGET_LST ${ TARGET } .lst )
#| Compiler Flags
2011-09-29 03:37:19 +00:00
add_definitions ( "-mmcu=${MCU} -DF_CPU=${F_CPU} -O${OPT} ${TUNING} ${WARN} ${CSTANDARD} ${GENDEPFLAGS}" )
2011-09-28 08:47:50 +00:00
#| Linker Flags
set ( LINKER_FLAGS "-mmcu=${MCU} -Wl,-Map=${TARGET}.map,--cref -Wl,--relax -Wl,--gc-sections" )
#| Hex Flags (XXX, CMake seems to have issues if you quote the arguments for the custom commands...)
set ( HEX_FLAGS -O ${ FORMAT } -R .eeprom -R .fuse -R .lock -R .signature )
#| Eep Flags
set ( EEP_FLAGS -j .eeprom --set-section-flags=.eeprom= "alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ${ FORMAT } )
#| Lss Flags
set ( LSS_FLAGS -h -S -z )
2011-09-29 03:37:19 +00:00
###
# Build Targets
#
2011-09-28 08:47:50 +00:00
#| 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 }
)
#| Convert the .ELF into a .HEX to load onto the Teensy
set ( TARGET_HEX ${ TARGET } .hex )
add_custom_command ( TARGET ${ TARGET_ELF } POST_BUILD
C O M M A N D a v r - o b j c o p y $ { H E X _ F L A G S } $ { T A R G E T _ E L F } $ { T A R G E T _ H E X }
C O M M E N T " C r e a t i n g l o a d f i l e f o r F l a s h : $ { T A R G E T _ H E X } "
)
#| Convert the .ELF into a .EEP
set ( TARGET_EEP ${ TARGET } .eep )
add_custom_command ( TARGET ${ TARGET_ELF } POST_BUILD
C O M M A N D a v r - o b j c o p y $ { E E P _ F L A G S } $ { T A R G E T _ E L F } $ { T A R G E T _ E E P }
C O M M E N T " C r e a t i n g l o a d f i l e f o r E E P R O M : $ { T A R G E T _ E E P } "
)
2011-09-29 03:37:19 +00:00
#| Generate the Extended .LSS
2011-09-28 08:47:50 +00:00
set ( TARGET_LSS ${ TARGET } .lss )
add_custom_command ( TARGET ${ TARGET_ELF } POST_BUILD
2011-09-29 03:37:19 +00:00
C O M M A N D a v r - 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 }
2011-09-28 08:47:50 +00:00
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 a v r - 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 } "
)
2011-09-29 03:37:19 +00:00
###
# Size Information
#
2011-09-28 08:47:50 +00:00
#| After Changes Size Information
add_custom_target ( SizeAfter ALL avr-size --target= ${ FORMAT } ${ TARGET_HEX } ${ TARGET_ELF }
D E P E N D S $ { T A R G E T _ E L F }
C O M M E N T " S i z e a f t e r g e n e r a t i o n : "
)
2011-09-30 05:22:19 +00:00
###
# Setup Loader Script
#
#| Provides the user with the correct teensy-loader-cli command for the built .HEX file
#| teensy-loader-cli must be in the user's path
if ( ${ CMAKE_SYSTEM_NAME } MATCHES "Linux" OR ${ CMAKE_SYSTEM_NAME } MATCHES "Darwin" )
configure_file ( LoadFile/bash load )
endif ( ${ CMAKE_SYSTEM_NAME } MATCHES "Linux" OR ${ CMAKE_SYSTEM_NAME } MATCHES "Darwin" )
#| TODO Windows
if ( ${ CMAKE_SYSTEM_NAME } MATCHES "Windows" )
message ( STATUS "Load Script is on my TODO List for Windows..." )
endif ( ${ CMAKE_SYSTEM_NAME } MATCHES "Windows" )