]> git.donarmstrong.com Git - kiibohd-controller.git/blob - CMakeLists.txt
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
[kiibohd-controller.git] / CMakeLists.txt
1 ###| CMAKE Kiibohd Controller |###
2 #
3 # Jacob Alexander 2011-2014
4 # Due to this file's usefulness:
5 #
6 # Released into the Public Domain
7 #
8 ###
9
10 #| Windows / Cygwin Compatibility options
11 set( CMAKE_LEGACY_CYGWIN_WIN32 0 )
12 set( CMAKE_USE_RELATIVE_PATHS  1 )
13
14 #| Add Dependency Macro
15 include( AddFileDependencies )
16
17
18
19 ###
20 # Compiler Family
21 #
22
23 #| Specify the compiler family to use
24 #| Currently only supports AVR and ARM
25 #| "avr"       # Teensy   1.0
26 #| "avr"       # Teensy   2.0
27 #| "avr"       # Teensy++ 1.0
28 #| "avr"       # Teensy++ 2.0
29 #| "arm"       # Teensy   3.0
30 #| "arm"       # Teensy   3.1
31 #set( COMPILER_FAMILY "arm" )
32 set( COMPILER_FAMILY "avr" )
33
34 message( STATUS "Compiler Family:" )
35 message( "${COMPILER_FAMILY}" )
36
37
38
39 #| Load the compiler family specific configurations
40 include( ${COMPILER_FAMILY}.cmake )
41
42
43
44 ###
45 # Project Description
46 #
47
48 #| Project
49 project( kiibohd_controller )
50
51 #| Target Name (output name)
52 set( TARGET kiibohd )
53
54 #| General Settings
55 cmake_minimum_required( VERSION 2.8 )
56
57
58
59 ###
60 # Source Defines
61 #
62
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
65 #set( SRCS ./main.c )
66
67 #| Instead, include the module source selector
68 include( setup.cmake )
69 set( SRCS
70         main.c
71         ${COMPILER_SRCS}
72         ${SCAN_SRCS}
73         ${MACRO_SRCS}
74         ${OUTPUT_SRCS}
75         ${DEBUG_SRCS}
76 )
77
78 #| Directories to include by default
79 include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )
80
81
82
83 ###
84 # Module Compatibility Check
85 #
86
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}  )
92
93
94
95 ###
96 # Build Targets
97 #
98
99 #| Create the .ELF file
100 set( TARGET_ELF ${TARGET}.elf )
101 add_executable( ${TARGET_ELF} ${SRCS} )
102
103
104 #| .ELF Properties
105 set_target_properties( ${TARGET_ELF} PROPERTIES
106         LINK_FLAGS ${LINKER_FLAGS}
107         SUFFIX ""                               # XXX Force Windows to keep the .exe off
108 )
109
110
111 #| Convert the .ELF into a .HEX to load onto the Teensy
112 set( TARGET_HEX ${TARGET}.hex )
113 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
114         COMMAND ${OBJCOPY} ${HEX_FLAGS} ${TARGET_ELF} ${TARGET_HEX}
115         COMMENT "Creating load file for Flash:  ${TARGET_HEX}"
116 )
117
118
119 #| Generate the Extended .LSS
120 set( TARGET_LSS ${TARGET}.lss )
121 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
122         COMMAND ${OBJDUMP} ${LSS_FLAGS} ${TARGET_ELF} > ${TARGET_LSS}
123         COMMENT "Creating Extended Listing:     ${TARGET_LSS}"
124 )
125
126
127 #| Generate the Symbol Table .SYM
128 set( TARGET_SYM ${TARGET}.sym )
129 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
130         COMMAND ${NM} -n ${TARGET_ELF} > ${TARGET_SYM}
131         COMMENT "Creating Symbol Table:         ${TARGET_SYM}"
132 )
133
134
135
136 ###
137 # Size Information
138 #
139
140 #| After Changes Size Information
141 #| TODO Do lookup on Flash and RAM sizes and do % used
142 add_custom_target( SizeAfter ALL ${SIZE} --target=${FORMAT} ${TARGET_HEX} ${TARGET_ELF}
143         DEPENDS ${TARGET_ELF}
144         COMMENT "Size after generation\n\tFlash Usage: data (hex)\n\t  RAM Usage: data (elf)"
145 )
146
147
148
149 ###
150 # Setup Loader Script
151 #
152
153 #| Provides the user with the correct teensy-loader-cli command for the built .HEX file
154 #| teensy-loader-cli must be in the user's path
155 if( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
156         configure_file( LoadFile/bash load )
157 endif()
158
159 #| TODO Windows
160 if( ${CMAKE_SYSTEM_NAME} MATCHES "Windows" )
161         configure_file( LoadFile/bash load )
162 endif()
163