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 "MBC-55X" )
25 ##| Uses the key index and potentially applies special conditions to it, mapping it to a usb key code
26 set( MacroModule "buffer" )
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" )
38 # Module Overrides (Used in the buildall.bash script)
40 if ( ( DEFINED ScanModuleOverride ) AND ( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Scan/${ScanModuleOverride} ) )
41 set( ScanModule ${ScanModuleOverride} )
49 set( ScanModulePath "Scan/${ScanModule}" )
50 set( MacroModulePath "Macro/${MacroModule}" )
51 set( OutputModulePath "Output/${OutputModule}" )
52 set( DebugModulePath "Debug/${DebugModule}" )
54 #| Top-level directory adjustment
55 set( HEAD_DIR "${CMAKE_CURRENT_SOURCE_DIR}" )
60 # Module Check Function
64 #| PathPrepend( ModulePath <ListOfFamiliesSupported> )
65 #| Uses the ${COMPILER_FAMILY} variable
66 function( ModuleCompatibility ModulePath )
67 foreach( mod_var ${ARGN} )
68 if ( ${mod_var} STREQUAL ${COMPILER_FAMILY} )
69 # Module found, no need to scan further
74 message( FATAL_ERROR "${ModulePath} does not support the ${COMPILER_FAMILY} family..." )
80 # Module Configuration
83 #| Additional options, usually define settings
86 #| Include path for each of the modules
88 -I${HEAD_DIR}/${ScanModulePath}
89 -I${HEAD_DIR}/${MacroModulePath}
90 -I${HEAD_DIR}/${OutputModulePath}
91 -I${HEAD_DIR}/${DebugModulePath}
101 #| Go through lists of sources and append paths
103 #| PathPrepend( OutputListOfSources <Prepend Path> <InputListOfSources> )
104 macro( PathPrepend Output SourcesPath )
108 foreach( item ${ARGN} )
110 set( tmpSource ${tmpSource} "${SourcesPath}/${item}" )
113 # Finalize by writing the new list back over the old one
114 set( ${Output} ${tmpSource} )
119 include ( "${ScanModulePath}/setup.cmake" )
120 PathPrepend( SCAN_SRCS ${ScanModulePath} ${SCAN_SRCS} )
123 include ( "${MacroModulePath}/setup.cmake" )
124 PathPrepend( MACRO_SRCS ${MacroModulePath} ${MACRO_SRCS} )
127 include ( "${OutputModulePath}/setup.cmake" )
128 PathPrepend( OUTPUT_SRCS ${OutputModulePath} ${OUTPUT_SRCS} )
131 include ( "${DebugModulePath}/setup.cmake" )
132 PathPrepend( DEBUG_SRCS ${DebugModulePath} ${DEBUG_SRCS} )
135 #| Print list of all module sources
136 message( STATUS "Detected Scan Module Source Files:" )
137 message( "${SCAN_SRCS}" )
138 message( STATUS "Detected Macro Module Source Files:" )
139 message( "${MACRO_SRCS}" )
140 message( STATUS "Detected Output Module Source Files:" )
141 message( "${OUTPUT_SRCS}" )
142 message( STATUS "Detected Debug Module Source Files:" )
143 message( "${DEBUG_SRCS}" )
148 # Generate USB Defines
152 set( MANUFACTURER "Kiibohd" )
156 #| Attempt to call Git to get the branch, last commit date, and whether code modified since last commit
159 #| Takes a bit of work to extract the "M " using CMake, and not using it if there are no modifications
160 execute_process( COMMAND git status -s -uno --porcelain
161 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
162 OUTPUT_VARIABLE Git_Modified_INFO
164 OUTPUT_STRIP_TRAILING_WHITESPACE
166 string( LENGTH "${Git_Modified_INFO}" Git_Modified_LENGTH )
167 set( Git_Modified_Status "Clean" )
168 if ( ${Git_Modified_LENGTH} GREATER 2 )
169 string( SUBSTRING "${Git_Modified_INFO}" 1 2 Git_Modified_Flag_INFO )
170 set( Git_Modified_Status "Dirty" )
174 execute_process( COMMAND git rev-parse --abbrev-ref HEAD
175 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
176 OUTPUT_VARIABLE Git_Branch_INFO
178 OUTPUT_STRIP_TRAILING_WHITESPACE
182 execute_process( COMMAND git show -s --format=%ci
183 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
184 OUTPUT_VARIABLE Git_Date_INFO
185 RESULT_VARIABLE Git_RETURN
187 OUTPUT_STRIP_TRAILING_WHITESPACE
190 #| Commit Author and Email
191 execute_process( COMMAND git show -s --format="%cn <%ce>"
192 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
193 OUTPUT_VARIABLE Git_Commit_Author
194 RESULT_VARIABLE Git_RETURN
196 OUTPUT_STRIP_TRAILING_WHITESPACE
200 execute_process( COMMAND git show -s --format=%H
201 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
202 OUTPUT_VARIABLE Git_Commit_Revision
203 RESULT_VARIABLE Git_RETURN
205 OUTPUT_STRIP_TRAILING_WHITESPACE
209 execute_process( COMMAND git config --get remote.origin.url
210 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
211 OUTPUT_VARIABLE Git_Origin_URL
212 RESULT_VARIABLE Git_RETURN
214 OUTPUT_STRIP_TRAILING_WHITESPACE
218 macro ( dateNow RESULT )
220 execute_process( COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE ${RESULT} OUTPUT_STRIP_TRAILING_WHITESPACE )
222 execute_process( COMMAND "date" "+%Y-%m-%d %T %z" OUTPUT_VARIABLE ${RESULT} OUTPUT_STRIP_TRAILING_WHITESPACE )
224 message( send_error "date not implemented" )
225 set( ${RESULT} 000000 )
228 dateNow( Build_Date )
231 #| Only use Git variables if we were successful in calling the commands
232 if ( ${Git_RETURN} EQUAL 0 )
233 set( GitLastCommitDate "${Git_Modified_Flag_INFO}${Git_Branch_INFO} - ${Git_Date_INFO}" )
235 # TODO Figure out a good way of finding the current branch + commit date + modified
236 set( GitLastCommitDate "Pft...Windows Build" )
240 #| Uses CMake variables to include as defines
241 #| Primarily for USB configuration
242 configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/Lib/_buildvars.h buildvars.h )