]> git.donarmstrong.com Git - kiibohd-controller.git/blob - CMakeLists.txt
Let CMake do more autoconfiguration.
[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 #| Binutils not set by CMake
40 set( CMAKE_SIZE "${_CMAKE_TOOLCHAIN_PREFIX}size" )
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 # CMake Module Checking
97 #
98 find_package( Git REQUIRED )
99
100
101 ###
102 # Build Targets
103 #
104
105 #| Create the .ELF file
106 set( TARGET_ELF ${TARGET}.elf )
107 add_executable( ${TARGET_ELF} ${SRCS} )
108
109
110 #| .ELF Properties
111 set_target_properties( ${TARGET_ELF} PROPERTIES
112         LINK_FLAGS ${LINKER_FLAGS}
113         SUFFIX ""                               # XXX Force Windows to keep the .exe off
114 )
115
116
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}"
122 )
123
124
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}"
130 )
131
132
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}"
138 )
139
140
141
142 ###
143 # Size Information
144 #
145
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)"
152 )
153
154
155
156 ###
157 # Setup Loader Script and Program
158 #
159
160
161 #| Provides the user with the correct teensy-loader-cli command for the built .HEX file
162 #| Windows
163 if( CMAKE_SYSTEM_NAME MATCHES "Windows" )
164         configure_file( LoadFile/winload load NEWLINE_STYLE UNIX )
165 #| Default
166 else()
167         configure_file( LoadFile/load load NEWLINE_STYLE UNIX )
168 endif()
169