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