1 ###| CMAKE Kiibohd Controller Source Configurator |###
3 # Written by Jacob Alexander in 2011-2014 for the Kiibohd Controller
5 # Released into the Public Domain
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
20 #| Please look at the {Scan,Macro,USB,Debug}/module.txt for information on the modules and how to create new ones
22 ##| Deals with acquiring the keypress information and turning it into a key index
23 set( ScanModule "ADCTest" )
25 ##| Provides the mapping functions for DefaultMap and handles any macro processing before sending to the OutputModule
26 set( MacroModule "PartialMap" )
28 ##| Sends the current list of usb key codes through USB HID
29 set( OutputModule "pjrcUSB" )
31 ##| Debugging source to use, each module has it's own set of defines that it sets
32 set( DebugModule "full" )
37 # Keymap Configuration
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" )
43 ##| PartialMap combined keymap layering. The first keymap has the "least" precedence.
44 set( CombinedMap colemak capslock2ctrl )
46 ##| ParitalMaps available on top of the CombinedMap. If there are input conflicts, the last PartialMap takes precedence.
47 set( PartialMaps hhkbnav kbdctrl )
49 ##| MacroSets define extra capabilities that are not provided by the Scan or Output modules. Last MacroSet takes precedence.
50 set( MacroSets retype )
54 # Module Overrides (Used in the buildall.bash script)
56 if ( ( DEFINED ScanModuleOverride ) AND ( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Scan/${ScanModuleOverride} ) )
57 set( ScanModule ${ScanModuleOverride} )
65 set( ScanModulePath "Scan/${ScanModule}" )
66 set( MacroModulePath "Macro/${MacroModule}" )
67 set( OutputModulePath "Output/${OutputModule}" )
68 set( DebugModulePath "Debug/${DebugModule}" )
70 #| Top-level directory adjustment
71 set( HEAD_DIR "${CMAKE_CURRENT_SOURCE_DIR}" )
76 # Module Check Function
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
90 message( FATAL_ERROR "${ModulePath} does not support the ${COMPILER_FAMILY} family..." )
96 # Module Configuration
99 #| Additional options, usually define settings
102 #| Include path for each of the modules
104 -I${HEAD_DIR}/${ScanModulePath}
105 -I${HEAD_DIR}/${MacroModulePath}
106 -I${HEAD_DIR}/${OutputModulePath}
107 -I${HEAD_DIR}/${DebugModulePath}
117 #| Go through lists of sources and append paths
119 #| PathPrepend( OutputListOfSources <Prepend Path> <InputListOfSources> )
120 macro( PathPrepend Output SourcesPath )
124 foreach( item ${ARGN} )
126 set( tmpSource ${tmpSource} "${SourcesPath}/${item}" )
129 # Finalize by writing the new list back over the old one
130 set( ${Output} ${tmpSource} )
135 include ( "${ScanModulePath}/setup.cmake" )
136 PathPrepend( SCAN_SRCS ${ScanModulePath} ${SCAN_SRCS} )
139 include ( "${MacroModulePath}/setup.cmake" )
140 PathPrepend( MACRO_SRCS ${MacroModulePath} ${MACRO_SRCS} )
143 include ( "${OutputModulePath}/setup.cmake" )
144 PathPrepend( OUTPUT_SRCS ${OutputModulePath} ${OUTPUT_SRCS} )
147 include ( "${DebugModulePath}/setup.cmake" )
148 PathPrepend( DEBUG_SRCS ${DebugModulePath} ${DEBUG_SRCS} )
152 # TODO Add support for different defaultMaps
153 configure_file( "${ScanModulePath}/defaultMap.h" defaultMap.h )
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}" )
169 # Generate USB Defines
173 set( MANUFACTURER "Kiibohd" )
177 #| Attempt to call Git to get the branch, last commit date, and whether code modified since last commit
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
185 OUTPUT_STRIP_TRAILING_WHITESPACE
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" )
195 execute_process( COMMAND git rev-parse --abbrev-ref HEAD
196 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
197 OUTPUT_VARIABLE Git_Branch_INFO
199 OUTPUT_STRIP_TRAILING_WHITESPACE
203 execute_process( COMMAND git show -s --format=%ci
204 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
205 OUTPUT_VARIABLE Git_Date_INFO
207 OUTPUT_STRIP_TRAILING_WHITESPACE
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
215 OUTPUT_STRIP_TRAILING_WHITESPACE
219 execute_process( COMMAND git show -s --format=%H
220 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
221 OUTPUT_VARIABLE Git_Commit_Revision
223 OUTPUT_STRIP_TRAILING_WHITESPACE
227 execute_process( COMMAND git config --get remote.origin.url
228 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
229 OUTPUT_VARIABLE Git_Origin_URL
231 OUTPUT_STRIP_TRAILING_WHITESPACE
235 execute_process( COMMAND "date" "+%Y-%m-%d %T %z"
236 OUTPUT_VARIABLE Build_Date
238 OUTPUT_STRIP_TRAILING_WHITESPACE
242 set( GitLastCommitDate "${Git_Modified_Status} ${Git_Branch_INFO} - ${Git_Date_INFO}" )
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 )