]> git.donarmstrong.com Git - kiibohd-controller.git/blob - CMakeLists.txt
Windows is now working with libusb1.0 for the teensy-loader-cli.
[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 # CMake Module Checking
94 #
95 find_package( Git REQUIRED )
96
97
98 ###
99 # Build Targets
100 #
101
102 #| Create the .ELF file
103 set( TARGET_ELF ${TARGET}.elf )
104 add_executable( ${TARGET_ELF} ${SRCS} )
105
106
107 #| .ELF Properties
108 set_target_properties( ${TARGET_ELF} PROPERTIES
109         LINK_FLAGS ${LINKER_FLAGS}
110         SUFFIX ""                               # XXX Force Windows to keep the .exe off
111 )
112
113
114 #| Convert the .ELF into a .HEX to load onto the Teensy
115 set( TARGET_HEX ${TARGET}.hex )
116 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
117         COMMAND ${OBJCOPY} ${HEX_FLAGS} ${TARGET_ELF} ${TARGET_HEX}
118         COMMENT "Creating load file for Flash:  ${TARGET_HEX}"
119 )
120
121
122 #| Generate the Extended .LSS
123 set( TARGET_LSS ${TARGET}.lss )
124 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
125         COMMAND ${OBJDUMP} ${LSS_FLAGS} ${TARGET_ELF} > ${TARGET_LSS}
126         COMMENT "Creating Extended Listing:     ${TARGET_LSS}"
127 )
128
129
130 #| Generate the Symbol Table .SYM
131 set( TARGET_SYM ${TARGET}.sym )
132 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
133         COMMAND ${NM} -n ${TARGET_ELF} > ${TARGET_SYM}
134         COMMENT "Creating Symbol Table:         ${TARGET_SYM}"
135 )
136
137
138
139 ###
140 # Size Information
141 #
142
143 #| After Changes Size Information
144 #| TODO Do lookup on Flash and RAM sizes and do % used
145 add_custom_target( SizeAfter ALL
146         COMMAND ${SIZE} --target=${FORMAT} ${TARGET_HEX} ${TARGET_ELF}
147         DEPENDS ${TARGET_ELF}
148         COMMENT "Size after generation\n\tFlash Usage: data (hex)\n\t  RAM Usage: data (elf)"
149 )
150
151
152
153 ###
154 # Setup Loader Script and Program
155 #
156
157
158 #| Provides the user with the correct teensy-loader-cli command for the built .HEX file
159 #| Windows
160 if( CMAKE_SYSTEM_NAME MATCHES "Windows" )
161         configure_file( LoadFile/winload load NEWLINE_STYLE UNIX )
162 #| Default
163 else()
164         configure_file( LoadFile/load load NEWLINE_STYLE UNIX )
165 endif()
166