1 ###| CMAKE Kiibohd Controller |###
3 # Jacob Alexander 2011-2014
4 # Due to this file's usefulness:
6 # Released into the Public Domain
10 #| Windows / Cygwin Compatibility options
11 set( CMAKE_LEGACY_CYGWIN_WIN32 0 )
12 set( CMAKE_USE_RELATIVE_PATHS 1 )
20 #| Specify the compiler family to use
21 #| Currently only supports AVR and ARM
24 #| "avr" # Teensy++ 1.0
25 #| "avr" # Teensy++ 2.0
28 #set( COMPILER_FAMILY "arm" )
29 set( COMPILER_FAMILY "avr" )
31 message( STATUS "Compiler Family:" )
32 message( "${COMPILER_FAMILY}" )
36 #| Load the compiler family specific configurations
37 include( ${COMPILER_FAMILY}.cmake )
39 #| Binutils not set by CMake
40 set( CMAKE_SIZE "${_CMAKE_TOOLCHAIN_PREFIX}size" )
49 project( kiibohd_controller )
51 #| Target Name (output name)
55 cmake_minimum_required( VERSION 2.8 )
63 #| Sources (see setup.h for configuring in/away code blocks or other complete modules)
64 #| XXX Not set here in this project, see setup.cmake
67 #| Instead, include the module source selector
68 include( setup.cmake )
78 #| Directories to include by default
79 include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )
84 # Module Compatibility Check
87 #| Check for whether the set modules are compatible with the specified compiler family
88 ModuleCompatibility( ${ScanModulePath} ${ScanModuleCompatibility} )
89 ModuleCompatibility( ${MacroModulePath} ${MacroModuleCompatibility} )
90 ModuleCompatibility( ${OutputModulePath} ${OutputModuleCompatibility} )
91 ModuleCompatibility( ${DebugModulePath} ${DebugModuleCompatibility} )
96 # CMake Module Checking
98 find_package( Git REQUIRED )
105 #| Create the .ELF file
106 set( TARGET_ELF ${TARGET}.elf )
107 add_executable( ${TARGET_ELF} ${SRCS} )
111 set_target_properties( ${TARGET_ELF} PROPERTIES
112 LINK_FLAGS ${LINKER_FLAGS}
113 SUFFIX "" # XXX Force Windows to keep the .exe off
117 #| Convert the .ELF into a .HEX to load onto the Teensy
118 set( TARGET_HEX ${TARGET}.hex )
119 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
120 COMMAND ${CMAKE_OBJCOPY} ${HEX_FLAGS} ${TARGET_ELF} ${TARGET_HEX}
121 COMMENT "Creating load file for Flash: ${TARGET_HEX}"
125 #| Generate the Extended .LSS
126 set( TARGET_LSS ${TARGET}.lss )
127 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
128 COMMAND ${CMAKE_OBJDUMP} ${LSS_FLAGS} ${TARGET_ELF} > ${TARGET_LSS}
129 COMMENT "Creating Extended Listing: ${TARGET_LSS}"
133 #| Generate the Symbol Table .SYM
134 set( TARGET_SYM ${TARGET}.sym )
135 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
136 COMMAND ${CMAKE_NM} -n ${TARGET_ELF} > ${TARGET_SYM}
137 COMMENT "Creating Symbol Table: ${TARGET_SYM}"
146 #| After Changes Size Information
147 #| TODO Do lookup on Flash and RAM sizes and do % used
148 add_custom_target( SizeAfter ALL
149 COMMAND ${CMAKE_SIZE} --target=${FORMAT} ${TARGET_HEX} ${TARGET_ELF}
150 DEPENDS ${TARGET_ELF}
151 COMMENT "Size after generation\n\tFlash Usage: data (hex)\n\t RAM Usage: data (elf)"
157 # Setup Loader Script and Program
161 #| Provides the user with the correct teensy-loader-cli command for the built .HEX file
163 if( CMAKE_SYSTEM_NAME MATCHES "Windows" )
164 configure_file( LoadFile/winload load NEWLINE_STYLE UNIX )
167 configure_file( LoadFile/load load NEWLINE_STYLE UNIX )