]> git.donarmstrong.com Git - kiibohd-controller.git/blob - setup.cmake
Updating pin map for Teensy 3.0/3.1
[kiibohd-controller.git] / setup.cmake
1 ###| CMAKE Kiibohd Controller Source Configurator |###
2 #
3 # Written by Jacob Alexander in 2011-2014 for the Kiibohd Controller
4 #
5 # Released into the Public Domain
6 #
7 ###
8
9
10
11 ###
12 # Project Modules
13 #
14
15 #| Note: This is the only section you probably want to modify
16 #| Each module is defined by it's own folder (e.g. Scan/Matrix represents the "Matrix" module)
17 #| All of the modules must be specified, as they generate the sources list of files to compile
18 #| Any modifications to this file will cause a complete rebuild of the project
19
20 #| Please look at the {Scan,Macro,USB,Debug}/module.txt for information on the modules and how to create new ones
21
22 ##| Deals with acquiring the keypress information and turning it into a key index
23 set(   ScanModule "ADCTest" )
24
25 ##| Provides the mapping functions for DefaultMap and handles any macro processing before sending to the OutputModule
26 set(  MacroModule "PartialMap" )
27
28 ##| Sends the current list of usb key codes through USB HID
29 set( OutputModule "pjrcUSB" )
30
31 ##| Debugging source to use, each module has it's own set of defines that it sets
32 set(  DebugModule "full" )
33
34
35
36 ###
37 # Keymap Configuration
38 #
39
40 ##| If there are multiple DefaultMaps, it is defined here. If, the specified DefaultMap is not found, defaultMap.h is used.
41 set(   DefaultMap "kishsaver" )
42
43 ##| PartialMap combined keymap layering. The first keymap has the "least" precedence.
44 set(  CombinedMap colemak capslock2ctrl )
45
46 ##| ParitalMaps available on top of the CombinedMap. If there are input conflicts, the last PartialMap takes precedence.
47 set(  PartialMaps hhkbnav kbdctrl )
48
49 ##| MacroSets define extra capabilities that are not provided by the Scan or Output modules. Last MacroSet takes precedence.
50 set(    MacroSets retype )
51
52
53 ###
54 # Module Overrides (Used in the buildall.bash script)
55 #
56 if ( ( DEFINED ScanModuleOverride ) AND ( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Scan/${ScanModuleOverride} ) )
57         set( ScanModule ${ScanModuleOverride} )
58 endif ()
59
60
61
62 ###
63 # Path Setup
64 #
65 set(  ScanModulePath    "Scan/${ScanModule}"   )
66 set( MacroModulePath   "Macro/${MacroModule}"  )
67 set( OutputModulePath "Output/${OutputModule}" )
68 set( DebugModulePath   "Debug/${DebugModule}"  )
69
70 #| Top-level directory adjustment
71 set( HEAD_DIR "${CMAKE_CURRENT_SOURCE_DIR}" )
72
73
74
75 ###
76 # Module Check Function
77 #
78
79 #| Usage:
80 #|  PathPrepend( ModulePath <ListOfFamiliesSupported> )
81 #| Uses the ${COMPILER_FAMILY} variable
82 function( ModuleCompatibility ModulePath )
83         foreach( mod_var ${ARGN} )
84                 if ( ${mod_var} STREQUAL ${COMPILER_FAMILY} )
85                         # Module found, no need to scan further
86                         return()
87                 endif ()
88         endforeach()
89
90         message( FATAL_ERROR "${ModulePath} does not support the ${COMPILER_FAMILY} family..." )
91 endfunction()
92
93
94
95 ###
96 # Module Configuration
97 #
98
99 #| Additional options, usually define settings
100 add_definitions()
101
102 #| Include path for each of the modules
103 add_definitions(
104         -I${HEAD_DIR}/${ScanModulePath}
105         -I${HEAD_DIR}/${MacroModulePath}
106         -I${HEAD_DIR}/${OutputModulePath}
107         -I${HEAD_DIR}/${DebugModulePath}
108 )
109
110
111
112
113 ###
114 # Module Processing
115 #
116
117 #| Go through lists of sources and append paths
118 #| Usage:
119 #|  PathPrepend( OutputListOfSources <Prepend Path> <InputListOfSources> )
120 macro( PathPrepend Output SourcesPath )
121         unset( tmpSource )
122
123         # Loop through items
124         foreach( item ${ARGN} )
125                 # Set the path
126                 set( tmpSource ${tmpSource} "${SourcesPath}/${item}" )
127         endforeach()
128
129         # Finalize by writing the new list back over the old one
130         set( ${Output} ${tmpSource} )
131 endmacro()
132
133
134 #| Scan Module
135 include    (            "${ScanModulePath}/setup.cmake"  )
136 PathPrepend(  SCAN_SRCS  ${ScanModulePath} ${SCAN_SRCS}  )
137
138 #| Macro Module
139 include    (           "${MacroModulePath}/setup.cmake"  )
140 PathPrepend( MACRO_SRCS ${MacroModulePath} ${MACRO_SRCS} )
141
142 #| Output Module
143 include    (             "${OutputModulePath}/setup.cmake"   )
144 PathPrepend( OUTPUT_SRCS  ${OutputModulePath} ${OUTPUT_SRCS} )
145
146 #| Debugging Module
147 include    (           "${DebugModulePath}/setup.cmake"  )
148 PathPrepend( DEBUG_SRCS ${DebugModulePath} ${DEBUG_SRCS} )
149
150
151 #| Default Map
152 # TODO Add support for different defaultMaps
153 configure_file( "${ScanModulePath}/defaultMap.h" defaultMap.h )
154
155
156 #| Print list of all module sources
157 message( STATUS "Detected Scan Module Source Files:" )
158 message( "${SCAN_SRCS}" )
159 message( STATUS "Detected Macro Module Source Files:" )
160 message( "${MACRO_SRCS}" )
161 message( STATUS "Detected Output Module Source Files:" )
162 message( "${OUTPUT_SRCS}" )
163 message( STATUS "Detected Debug Module Source Files:" )
164 message( "${DEBUG_SRCS}" )
165
166
167
168 ###
169 # Generate USB Defines
170 #
171
172 #| Manufacturer name
173 set( MANUFACTURER "Kiibohd" )
174
175
176 #| Serial Number
177 #| Attempt to call Git to get the branch, last commit date, and whether code modified since last commit
178
179 #| Modified
180 #| Takes a bit of work to extract the "M " using CMake, and not using it if there are no modifications
181 execute_process( COMMAND git status -s -uno --porcelain
182         WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
183         OUTPUT_VARIABLE Git_Modified_INFO
184         ERROR_QUIET
185         OUTPUT_STRIP_TRAILING_WHITESPACE
186 )
187 string( LENGTH "${Git_Modified_INFO}" Git_Modified_LENGTH )
188 set( Git_Modified_Status "Clean" )
189 if ( ${Git_Modified_LENGTH} GREATER 2 )
190         string( SUBSTRING "${Git_Modified_INFO}" 1 2 Git_Modified_Flag_INFO )
191         set( Git_Modified_Status "Dirty" )
192 endif ()
193
194 #| Branch
195 execute_process( COMMAND git rev-parse --abbrev-ref HEAD
196         WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
197         OUTPUT_VARIABLE Git_Branch_INFO
198         ERROR_QUIET
199         OUTPUT_STRIP_TRAILING_WHITESPACE
200 )
201
202 #| Date
203 execute_process( COMMAND git show -s --format=%ci
204         WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
205         OUTPUT_VARIABLE Git_Date_INFO
206         ERROR_QUIET
207         OUTPUT_STRIP_TRAILING_WHITESPACE
208 )
209
210 #| Commit Author and Email
211 execute_process( COMMAND git show -s --format="%cn <%ce>"
212         WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
213         OUTPUT_VARIABLE Git_Commit_Author
214         ERROR_QUIET
215         OUTPUT_STRIP_TRAILING_WHITESPACE
216 )
217
218 #| Commit Revision
219 execute_process( COMMAND git show -s --format=%H
220         WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
221         OUTPUT_VARIABLE Git_Commit_Revision
222         ERROR_QUIET
223         OUTPUT_STRIP_TRAILING_WHITESPACE
224 )
225
226 #| Origin URL
227 execute_process( COMMAND git config --get remote.origin.url
228         WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
229         OUTPUT_VARIABLE Git_Origin_URL
230         ERROR_QUIET
231         OUTPUT_STRIP_TRAILING_WHITESPACE
232 )
233
234 #| Build Date
235 execute_process( COMMAND "date" "+%Y-%m-%d %T %z"
236         OUTPUT_VARIABLE Build_Date
237         ERROR_QUIET
238         OUTPUT_STRIP_TRAILING_WHITESPACE
239 )
240
241 #| Last Commit Date
242 set( GitLastCommitDate "${Git_Modified_Status} ${Git_Branch_INFO} - ${Git_Date_INFO}" )
243
244 #| Uses CMake variables to include as defines
245 #| Primarily for USB configuration
246 configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/Lib/_buildvars.h buildvars.h )
247