]> git.donarmstrong.com Git - kiibohd-controller.git/blob - setup.cmake
Added more CLI commands.
[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 look at 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( OutputModule  "pjrcUSB" )
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 ()
43
44
45
46 ###
47 # Path Setup
48 #
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}" )
54
55 #| Top-level directory adjustment
56 set( HEAD_DIR "${CMAKE_CURRENT_SOURCE_DIR}" )
57
58
59
60 ###
61 # Module Check Function
62 #
63
64 #| Usage:
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
71                         return()
72                 endif ()
73         endforeach()
74
75         message( FATAL_ERROR "${ModulePath} does not support the ${COMPILER_FAMILY} family..." )
76 endfunction()
77
78
79
80 ###
81 # Module Configuration
82 #
83
84 #| Additional options, usually define settings
85 add_definitions()
86
87 #| Include path for each of the modules
88 add_definitions(
89         -I${HEAD_DIR}/${ScanModulePath}
90         -I${HEAD_DIR}/${MacroModulePath}
91         -I${HEAD_DIR}/${OutputModulePath}
92         -I${HEAD_DIR}/${DebugModulePath}
93 )
94
95
96
97
98 ###
99 # Module Processing
100 #
101
102 #| Go through lists of sources and append paths
103 #| Usage:
104 #|  PathPrepend( OutputListOfSources <Prepend Path> <InputListOfSources> )
105 macro( PathPrepend Output SourcesPath )
106         unset( tmpSource )
107
108         # Loop through items
109         foreach( item ${ARGN} )
110                 # Set the path
111                 set( tmpSource ${tmpSource} "${SourcesPath}/${item}" )
112         endforeach()
113
114         # Finalize by writing the new list back over the old one
115         set( ${Output} ${tmpSource} )
116 endmacro()
117
118
119 #| Scan Module
120 include    (            "${ScanModulePath}/setup.cmake"  )
121 PathPrepend(  SCAN_SRCS  ${ScanModulePath} ${SCAN_SRCS}  )
122
123 #| Macro Module
124 include    (           "${MacroModulePath}/setup.cmake"  )
125 PathPrepend( MACRO_SRCS ${MacroModulePath} ${MACRO_SRCS} )
126
127 #| Output Module
128 include    (             "${OutputModulePath}/setup.cmake"   )
129 PathPrepend( OUTPUT_SRCS  ${OutputModulePath} ${OUTPUT_SRCS} )
130
131 #| Debugging Module
132 include    (           "${DebugModulePath}/setup.cmake"  )
133 PathPrepend( DEBUG_SRCS ${DebugModulePath} ${DEBUG_SRCS} )
134
135
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}" )
145
146
147
148 ###
149 # Generate USB Defines
150 #
151
152 #| Manufacturer name
153 set( MANUFACTURER "Kiibohd" )
154
155
156 #| Serial Number
157 #| Attempt to call Git to get the branch, last commit date, and whether code modified since last commit
158
159 #| Modified
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
164         ERROR_QUIET
165         OUTPUT_STRIP_TRAILING_WHITESPACE
166 )
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" )
172 endif ()
173
174 #| Branch
175 execute_process( COMMAND git rev-parse --abbrev-ref HEAD
176         WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
177         OUTPUT_VARIABLE Git_Branch_INFO
178         ERROR_QUIET
179         OUTPUT_STRIP_TRAILING_WHITESPACE
180 )
181
182 #| Date
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
187         ERROR_QUIET
188         OUTPUT_STRIP_TRAILING_WHITESPACE
189 )
190
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
196         ERROR_QUIET
197         OUTPUT_STRIP_TRAILING_WHITESPACE
198 )
199
200 #| Commit Revision
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
205         ERROR_QUIET
206         OUTPUT_STRIP_TRAILING_WHITESPACE
207 )
208
209 #| Origin URL
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
214         ERROR_QUIET
215         OUTPUT_STRIP_TRAILING_WHITESPACE
216 )
217
218 #| Date Macro
219 macro ( dateNow RESULT )
220         if ( WIN32 )
221                 execute_process( COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE ${RESULT} OUTPUT_STRIP_TRAILING_WHITESPACE )
222         elseif ( UNIX )
223                 execute_process( COMMAND "date" "+%Y-%m-%d %T %z" OUTPUT_VARIABLE ${RESULT} OUTPUT_STRIP_TRAILING_WHITESPACE )
224         else ()
225                 message( send_error "date not implemented" )
226                 set( ${RESULT} 000000 )
227         endif ()
228 endmacro (dateNow)
229 dateNow( Build_Date )
230
231
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}" )
235 else ()
236         # TODO Figure out a good way of finding the current branch + commit date + modified
237         set( GitLastCommitDate "Pft...Windows Build" )
238 endif ()
239
240
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 )
244