2011-09-28 08:47:50 +00:00
###| CMAKE Kiibohd Controller |###
#
2013-01-26 09:34:33 +00:00
# Jacob Alexander 2011-2013
2011-09-28 08:47:50 +00:00
# Due to this file's usefulness:
#
# Released into the Public Domain
#
###
2012-11-24 19:41:41 +00:00
#| Windows / Cygwin Compatibility options
set ( CMAKE_LEGACY_CYGWIN_WIN32 0 )
set ( CMAKE_USE_RELATIVE_PATHS 1 )
2013-01-26 09:34:33 +00:00
#| Add Dependency Macro
include ( AddFileDependencies )
2012-11-24 19:41:41 +00:00
2011-09-28 08:47:50 +00:00
2013-01-26 09:34:33 +00:00
###
# Compiler Family
#
#| Specify the compiler family to use
#| Currently only supports AVR and ARM
#| "avr" # Teensy 1.0
#| "avr" # Teensy 2.0
#| "avr" # Teensy++ 1.0
#| "avr" # Teensy++ 2.0
#| "arm" # Teensy 3.0
2013-04-14 02:35:59 +00:00
#set( COMPILER_FAMILY "arm" )
set ( COMPILER_FAMILY "avr" )
2013-01-26 09:34:33 +00:00
2013-01-26 20:43:59 +00:00
message ( STATUS "Compiler Family:" )
message ( "${COMPILER_FAMILY}" )
2013-01-26 09:34:33 +00:00
#| Load the compiler family specific configurations
include ( ${ COMPILER_FAMILY } .cmake )
2011-11-13 10:04:44 +00:00
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
2013-01-26 09:34:33 +00:00
$ { C O M P I L E R _ S R C S }
2011-11-13 10:04:44 +00:00
$ { 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
2013-02-02 01:02:55 +00:00
#| Directories to include by default
include_directories ( ${ CMAKE_CURRENT_SOURCE_DIR } ${ CMAKE_CURRENT_BINARY_DIR } )
2011-09-28 08:47:50 +00:00
2013-01-30 23:13:49 +00:00
###
# Module Compatibility Check
#
#| Check for whether the set modules are compatible with the specified compiler family
ModuleCompatibility ( ${ ScanModulePath } ${ ScanModuleCompatibility } )
ModuleCompatibility ( ${ MacroModulePath } ${ MacroModuleCompatibility } )
ModuleCompatibility ( ${ USBModulePath } ${ USBModuleCompatibility } )
ModuleCompatibility ( ${ DebugModulePath } ${ DebugModuleCompatibility } )
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 }
2012-11-24 19:41:41 +00:00
S U F F I X " " # XXX Force Windows to keep the .exe off
2011-09-28 08:47:50 +00:00
)
#| Convert the .ELF into a .HEX to load onto the Teensy
set ( TARGET_HEX ${ TARGET } .hex )
add_custom_command ( TARGET ${ TARGET_ELF } POST_BUILD
2013-01-26 09:34:33 +00:00
C O M M A N D $ { 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 }
2011-09-28 08:47:50 +00:00
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 } "
)
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
2013-01-26 09:34:33 +00:00
C O M M A N D $ { 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
2013-01-26 09:34:33 +00:00
C O M M A N D $ { N M } - n $ { T A R G E T _ E L F } > $ { T A R G E T _ S Y M }
2011-09-28 08:47:50 +00:00
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
2013-01-26 09:34:33 +00:00
add_custom_target ( SizeAfter ALL ${ SIZE } --target= ${ FORMAT } ${ TARGET_HEX } ${ TARGET_ELF }
2011-09-28 08:47:50 +00:00
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 )
2013-02-02 02:19:31 +00:00
endif ( )
2011-09-30 05:22:19 +00:00
#| TODO Windows
if ( ${ CMAKE_SYSTEM_NAME } MATCHES "Windows" )
2012-11-24 19:41:41 +00:00
configure_file ( LoadFile/bash load )
2013-02-02 02:19:31 +00:00
endif ( )
2011-09-30 05:22:19 +00:00