1 ###| CMAKE Kiibohd Controller Source Configurator |###
3 # Written by Jacob Alexander in 2011-2013 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( USBModulePath "USB/${USBModule}" )
53 set( DebugModulePath "Debug/${DebugModule}" )
55 #| Top-level directory adjustment
56 set( HEAD_DIR "${CMAKE_CURRENT_SOURCE_DIR}" )
61 # Module Check Function
65 #| PathPrepend( ModulePath <ListOfFamiliesSupported> )
66 #| Uses the ${COMPILER_FAMILY} variable
67 function( ModuleCompatibility ModulePath )
68 foreach( mod_var ${ARGN} )
69 if ( ${mod_var} STREQUAL ${COMPILER_FAMILY} )
70 # Module found, no need to scan further
75 message( FATAL_ERROR "${ModulePath} does not support the ${COMPILER_FAMILY} family..." )
81 # Module Configuration
84 #| Additional options, usually define settings
87 #| Include path for each of the modules
89 -I${HEAD_DIR}/${ScanModulePath}
90 -I${HEAD_DIR}/${MacroModulePath}
91 -I${HEAD_DIR}/${OutputModulePath}
92 -I${HEAD_DIR}/${DebugModulePath}
102 #| Go through lists of sources and append paths
104 #| PathPrepend( OutputListOfSources <Prepend Path> <InputListOfSources> )
105 macro( PathPrepend Output SourcesPath )
109 foreach( item ${ARGN} )
111 set( tmpSource ${tmpSource} "${SourcesPath}/${item}" )
114 # Finalize by writing the new list back over the old one
115 set( ${Output} ${tmpSource} )
120 include ( "${ScanModulePath}/setup.cmake" )
121 PathPrepend( SCAN_SRCS ${ScanModulePath} ${SCAN_SRCS} )
124 include ( "${MacroModulePath}/setup.cmake" )
125 PathPrepend( MACRO_SRCS ${MacroModulePath} ${MACRO_SRCS} )
128 include ( "${OutputModulePath}/setup.cmake" )
129 PathPrepend( OUTPUT_SRCS ${OutputModulePath} ${OUTPUT_SRCS} )
132 include ( "${DebugModulePath}/setup.cmake" )
133 PathPrepend( DEBUG_SRCS ${DebugModulePath} ${DEBUG_SRCS} )
136 #| Print list of all module sources
137 message( STATUS "Detected Scan Module Source Files:" )
138 message( "${SCAN_SRCS}" )
139 message( STATUS "Detected Macro Module Source Files:" )
140 message( "${MACRO_SRCS}" )
141 message( STATUS "Detected USB Module Source Files:" )
142 message( "${OUTPUT_SRCS}" )
143 message( STATUS "Detected Debug Module Source Files:" )
144 message( "${DEBUG_SRCS}" )
149 # Generate USB Defines
153 set( MANUFACTURER "Kiibohd" )
157 #| Attempt to call Git to get the branch, last commit date, and whether code modified since last commit
160 #| Takes a bit of work to extract the "M " using CMake, and not using it if there are no modifications
161 execute_process( COMMAND git status -s -uno --porcelain
162 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
163 OUTPUT_VARIABLE Git_Modified_INFO
165 OUTPUT_STRIP_TRAILING_WHITESPACE
167 string( LENGTH "${Git_Modified_INFO}" Git_Modified_LENGTH )
168 set( Git_Modified_Status "Clean" )
169 if ( ${Git_Modified_LENGTH} GREATER 2 )
170 string( SUBSTRING "${Git_Modified_INFO}" 1 2 Git_Modified_Flag_INFO )
171 set( Git_Modified_Status "Dirty" )
175 execute_process( COMMAND git rev-parse --abbrev-ref HEAD
176 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
177 OUTPUT_VARIABLE Git_Branch_INFO
179 OUTPUT_STRIP_TRAILING_WHITESPACE
183 execute_process( COMMAND git show -s --format=%ci
184 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
185 OUTPUT_VARIABLE Git_Date_INFO
186 RESULT_VARIABLE Git_RETURN
188 OUTPUT_STRIP_TRAILING_WHITESPACE
191 #| Commit Author and Email
192 execute_process( COMMAND git show -s --format="%cn <%ce>"
193 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
194 OUTPUT_VARIABLE Git_Commit_Author
195 RESULT_VARIABLE Git_RETURN
197 OUTPUT_STRIP_TRAILING_WHITESPACE
201 execute_process( COMMAND git show -s --format=%H
202 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
203 OUTPUT_VARIABLE Git_Commit_Revision
204 RESULT_VARIABLE Git_RETURN
206 OUTPUT_STRIP_TRAILING_WHITESPACE
210 execute_process( COMMAND git config --get remote.origin.url
211 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
212 OUTPUT_VARIABLE Git_Origin_URL
213 RESULT_VARIABLE Git_RETURN
215 OUTPUT_STRIP_TRAILING_WHITESPACE
219 macro ( dateNow RESULT )
221 execute_process( COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE ${RESULT} OUTPUT_STRIP_TRAILING_WHITESPACE )
223 execute_process( COMMAND "date" "+%Y-%m-%d %T %z" OUTPUT_VARIABLE ${RESULT} OUTPUT_STRIP_TRAILING_WHITESPACE )
225 message( send_error "date not implemented" )
226 set( ${RESULT} 000000 )
229 dateNow( Build_Date )
232 #| Only use Git variables if we were successful in calling the commands
233 if ( ${Git_RETURN} EQUAL 0 )
234 set( GitLastCommitDate "${Git_Modified_Flag_INFO}${Git_Branch_INFO} - ${Git_Date_INFO}" )
236 # TODO Figure out a good way of finding the current branch + commit date + modified
237 set( GitLastCommitDate "Pft...Windows Build" )
241 #| Uses CMake variables to include as defines
242 #| Primarily for USB configuration
243 configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/Lib/_buildvars.h buildvars.h )