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 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 "avr-capsense" )
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( USBModule "pjrc" )
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( USBModulePath "USB/${USBModule}" )
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}/${USBModulePath}
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 ( "${USBModulePath}/setup.cmake" )
128 PathPrepend( USB_SRCS ${USBModulePath} ${USB_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 USB Module Source Files:" )
141 message( "${USB_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 if ( ${Git_Modified_LENGTH} GREATER 2 )
168 string( SUBSTRING "${Git_Modified_INFO}" 1 2 Git_Modified_Flag_INFO )
172 execute_process( COMMAND git rev-parse --abbrev-ref HEAD
173 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
174 OUTPUT_VARIABLE Git_Branch_INFO
176 OUTPUT_STRIP_TRAILING_WHITESPACE
180 execute_process( COMMAND git show -s --format=%ci
181 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
182 OUTPUT_VARIABLE Git_Date_INFO
183 RESULT_VARIABLE Git_RETURN
185 OUTPUT_STRIP_TRAILING_WHITESPACE
189 #| Only use Git variables if we were successful in calling the commands
190 if ( ${Git_RETURN} EQUAL 0 )
191 set( GitLastCommitDate "${Git_Modified_Flag_INFO}${Git_Branch_INFO} - ${Git_Date_INFO}" )
193 # TODO Figure out a good way of finding the current branch + commit date + modified
194 set( GitLastCommitDate "Pft...Windows Build" )
198 #| Uses CMake variables to include as defines
199 #| Primarily for USB configuration
200 configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/Lib/_buildvars.h buildvars.h )