]> git.donarmstrong.com Git - kiibohd-controller.git/blob - setup.cmake
CMake generated strings that configure the USB info section
[kiibohd-controller.git] / setup.cmake
1 ###| CMAKE Kiibohd Controller Source Configurator |###
2 #
3 # Written by Jacob Alexander in 2011-2013 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 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  "MBC-55X" )
24
25 ##| Uses the key index and potentially applies special conditions to it, mapping it to a usb key code
26 set( MacroModule  "buffer"  )
27
28 ##| Sends the current list of usb key codes through USB HID
29 set(   USBModule  "pjrc"   )
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 ###
38 # Module Overrides (Used in the buildall.bash script)
39 #
40 if ( ( DEFINED ${ScanModuleOverride} ) AND ( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Scan/${ScanModuleOverride} ) )
41         set( ScanModule ${ScanModuleOverride} )
42 endif ( ( DEFINED ${ScanModuleOverride} ) AND ( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Scan/${ScanModuleOverride} ) )
43
44
45
46 ###
47 # Path Setup
48
49 set(  ScanModulePath  "Scan/${ScanModule}"  )
50 set( MacroModulePath "Macro/${MacroModule}" )
51 set(   USBModulePath   "USB/${USBModule}"   )
52 set( DebugModulePath "Debug/${DebugModule}" )
53
54 #| Top-level directory adjustment
55 set( HEAD_DIR "${CMAKE_CURRENT_SOURCE_DIR}" )
56
57
58
59 ###
60 # Module Check Function
61 #
62
63 #| Usage:
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
70                         return()
71                 endif ( ${mod_var} STREQUAL ${COMPILER_FAMILY} )
72         endforeach( mod_var ${ARGN} )
73
74         message( FATAL_ERROR "${ModulePath} does not support the ${COMPILER_FAMILY} family..." )
75 endfunction( ModuleCompatibility ModulePath )
76
77
78
79 ###
80 # Module Configuration
81 #
82
83 #| Additional options, usually define settings
84 add_definitions()
85
86 #| Include path for each of the modules
87 add_definitions(
88         -I${HEAD_DIR}/${ScanModulePath}
89         -I${HEAD_DIR}/${MacroModulePath}
90         -I${HEAD_DIR}/${USBModulePath}
91         -I${HEAD_DIR}/${DebugModulePath}
92 )
93
94
95
96
97 ###
98 # Module Processing
99 #
100
101 #| Go through lists of sources and append paths
102 #| Usage:
103 #|  PathPrepend( OutputListOfSources <Prepend Path> <InputListOfSources> )
104 macro( PathPrepend Output SourcesPath )
105         unset( tmpSource )
106
107         # Loop through items
108         foreach( item ${ARGN} )
109                 # Set the path
110                 set( tmpSource ${tmpSource} "${SourcesPath}/${item}" )
111         endforeach( item )
112
113         # Finalize by writing the new list back over the old one
114         set( ${Output} ${tmpSource} )
115 endmacro( PathPrepend )
116
117
118 #| Scan Module
119 include    (            "${ScanModulePath}/setup.cmake"  )
120 PathPrepend(  SCAN_SRCS  ${ScanModulePath} ${SCAN_SRCS}  )
121
122 #| Macro Module
123 include    (           "${MacroModulePath}/setup.cmake"  )
124 PathPrepend( MACRO_SRCS ${MacroModulePath} ${MACRO_SRCS} )
125
126 #| USB Module
127 include    (             "${USBModulePath}/setup.cmake"  )
128 PathPrepend(   USB_SRCS   ${USBModulePath} ${USB_SRCS}   )
129
130 #| Debugging Module
131 include    (           "${DebugModulePath}/setup.cmake"  )
132 PathPrepend( DEBUG_SRCS ${DebugModulePath} ${DEBUG_SRCS} )
133
134
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}" )
144
145
146
147 ###
148 # Generate USB Defines
149 #
150
151 #| Manufacturer name
152 set( MANUFACTURER "Kiibohd" )
153
154
155 #| Serial Number
156 #| Attempt to call Git to get the branch, last commit date, and whether code modified since last commit
157
158 #| Modified
159 #| Takes a bit of work to extract the "M " using CMake, and not using it if there are not modifications
160 execute_process( COMMAND git status -s -uno --porcelain
161         WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
162         OUTPUT_VARIABLE Git_Modified_INFO
163         ERROR_QUIET
164         OUTPUT_STRIP_TRAILING_WHITESPACE
165 )
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 )
169 endif ( ${Git_Modified_LENGTH} GREATER 2 )
170
171 #| Branch
172 execute_process( COMMAND git rev-parse --abbrev-ref HEAD
173         WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
174         OUTPUT_VARIABLE Git_Branch_INFO
175         ERROR_QUIET
176         OUTPUT_STRIP_TRAILING_WHITESPACE
177 )
178
179 #| Date
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
184         ERROR_QUIET
185         OUTPUT_STRIP_TRAILING_WHITESPACE
186 )
187
188
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}" )
192 else ( ${Git_RETURN} EQUAL 0 )
193         # TODO Figure out a good way of finding the current branch + commit date + modified
194         set( GitLastCommitDate "Pft...Windows Build" )
195 endif ( ${Git_RETURN} EQUAL 0 )
196
197
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 )
201