Kiibohd Controller
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

setup.cmake 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. ###| CMAKE Kiibohd Controller Source Configurator |###
  2. #
  3. # Written by Jacob Alexander in 2011-2014 for the Kiibohd Controller
  4. #
  5. # Released into the Public Domain
  6. #
  7. ###
  8. ###
  9. # Project Modules
  10. #
  11. #| Note: This is the only section you probably want to modify
  12. #| Each module is defined by it's own folder (e.g. Scan/Matrix represents the "Matrix" module)
  13. #| All of the modules must be specified, as they generate the sources list of files to compile
  14. #| Any modifications to this file will cause a complete rebuild of the project
  15. #| Please look at the {Scan,Macro,USB,Debug}/module.txt for information on the modules and how to create new ones
  16. ##| Deals with acquiring the keypress information and turning it into a key index
  17. set( ScanModule "SKM67001" )
  18. ##| Provides the mapping functions for DefaultMap and handles any macro processing before sending to the OutputModule
  19. set( MacroModule "PartialMap" )
  20. ##| Sends the current list of usb key codes through USB HID
  21. set( OutputModule "pjrcUSB" )
  22. ##| Debugging source to use, each module has it's own set of defines that it sets
  23. set( DebugModule "full" )
  24. ###
  25. # Keymap Configuration
  26. #
  27. ##| If there are multiple DefaultMaps, it is defined here. If, the specified DefaultMap is not found, defaultMap.h is used.
  28. set( DefaultMap "kishsaver" )
  29. ##| PartialMap combined keymap layering. The first keymap has the "least" precedence.
  30. set( CombinedMap colemak capslock2ctrl )
  31. ##| ParitalMaps available on top of the CombinedMap. If there are input conflicts, the last PartialMap takes precedence.
  32. set( PartialMaps hhkbnav kbdctrl )
  33. ##| MacroSets define extra capabilities that are not provided by the Scan or Output modules. Last MacroSet takes precedence.
  34. set( MacroSets retype )
  35. ###
  36. # Module Overrides (Used in the buildall.bash script)
  37. #
  38. if ( ( DEFINED ScanModuleOverride ) AND ( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Scan/${ScanModuleOverride} ) )
  39. set( ScanModule ${ScanModuleOverride} )
  40. endif ()
  41. ###
  42. # Path Setup
  43. #
  44. set( ScanModulePath "Scan/${ScanModule}" )
  45. set( MacroModulePath "Macro/${MacroModule}" )
  46. set( OutputModulePath "Output/${OutputModule}" )
  47. set( DebugModulePath "Debug/${DebugModule}" )
  48. #| Top-level directory adjustment
  49. set( HEAD_DIR "${CMAKE_CURRENT_SOURCE_DIR}" )
  50. ###
  51. # Module Check Function
  52. #
  53. #| Usage:
  54. #| PathPrepend( ModulePath <ListOfFamiliesSupported> )
  55. #| Uses the ${COMPILER_FAMILY} variable
  56. function( ModuleCompatibility ModulePath )
  57. foreach( mod_var ${ARGN} )
  58. if ( ${mod_var} STREQUAL ${COMPILER_FAMILY} )
  59. # Module found, no need to scan further
  60. return()
  61. endif ()
  62. endforeach()
  63. message( FATAL_ERROR "${ModulePath} does not support the ${COMPILER_FAMILY} family..." )
  64. endfunction()
  65. ###
  66. # Module Configuration
  67. #
  68. #| Additional options, usually define settings
  69. add_definitions()
  70. #| Include path for each of the modules
  71. add_definitions(
  72. -I${HEAD_DIR}/${ScanModulePath}
  73. -I${HEAD_DIR}/${MacroModulePath}
  74. -I${HEAD_DIR}/${OutputModulePath}
  75. -I${HEAD_DIR}/${DebugModulePath}
  76. )
  77. ###
  78. # Module Processing
  79. #
  80. #| Go through lists of sources and append paths
  81. #| Usage:
  82. #| PathPrepend( OutputListOfSources <Prepend Path> <InputListOfSources> )
  83. macro( PathPrepend Output SourcesPath )
  84. unset( tmpSource )
  85. # Loop through items
  86. foreach( item ${ARGN} )
  87. # Set the path
  88. set( tmpSource ${tmpSource} "${SourcesPath}/${item}" )
  89. endforeach()
  90. # Finalize by writing the new list back over the old one
  91. set( ${Output} ${tmpSource} )
  92. endmacro()
  93. #| Scan Module
  94. include ( "${ScanModulePath}/setup.cmake" )
  95. PathPrepend( SCAN_SRCS ${ScanModulePath} ${SCAN_SRCS} )
  96. #| Macro Module
  97. include ( "${MacroModulePath}/setup.cmake" )
  98. PathPrepend( MACRO_SRCS ${MacroModulePath} ${MACRO_SRCS} )
  99. #| Output Module
  100. include ( "${OutputModulePath}/setup.cmake" )
  101. PathPrepend( OUTPUT_SRCS ${OutputModulePath} ${OUTPUT_SRCS} )
  102. #| Debugging Module
  103. include ( "${DebugModulePath}/setup.cmake" )
  104. PathPrepend( DEBUG_SRCS ${DebugModulePath} ${DEBUG_SRCS} )
  105. #| Default Map
  106. # TODO Add support for different defaultMaps
  107. configure_file( "${ScanModulePath}/defaultMap.h" defaultMap.h )
  108. #| Print list of all module sources
  109. message( STATUS "Detected Scan Module Source Files:" )
  110. message( "${SCAN_SRCS}" )
  111. message( STATUS "Detected Macro Module Source Files:" )
  112. message( "${MACRO_SRCS}" )
  113. message( STATUS "Detected Output Module Source Files:" )
  114. message( "${OUTPUT_SRCS}" )
  115. message( STATUS "Detected Debug Module Source Files:" )
  116. message( "${DEBUG_SRCS}" )
  117. ###
  118. # Generate USB Defines
  119. #
  120. #| Manufacturer name
  121. set( MANUFACTURER "Kiibohd" )
  122. #| Serial Number
  123. #| Attempt to call Git to get the branch, last commit date, and whether code modified since last commit
  124. #| Modified
  125. #| Takes a bit of work to extract the "M " using CMake, and not using it if there are no modifications
  126. execute_process( COMMAND git status -s -uno --porcelain
  127. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  128. OUTPUT_VARIABLE Git_Modified_INFO
  129. ERROR_QUIET
  130. OUTPUT_STRIP_TRAILING_WHITESPACE
  131. )
  132. string( LENGTH "${Git_Modified_INFO}" Git_Modified_LENGTH )
  133. set( Git_Modified_Status "Clean" )
  134. if ( ${Git_Modified_LENGTH} GREATER 2 )
  135. string( SUBSTRING "${Git_Modified_INFO}" 1 2 Git_Modified_Flag_INFO )
  136. set( Git_Modified_Status "Dirty" )
  137. endif ()
  138. #| Branch
  139. execute_process( COMMAND git rev-parse --abbrev-ref HEAD
  140. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  141. OUTPUT_VARIABLE Git_Branch_INFO
  142. ERROR_QUIET
  143. OUTPUT_STRIP_TRAILING_WHITESPACE
  144. )
  145. #| Date
  146. execute_process( COMMAND git show -s --format=%ci
  147. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  148. OUTPUT_VARIABLE Git_Date_INFO
  149. RESULT_VARIABLE Git_RETURN
  150. ERROR_QUIET
  151. OUTPUT_STRIP_TRAILING_WHITESPACE
  152. )
  153. #| Commit Author and Email
  154. execute_process( COMMAND git show -s --format="%cn <%ce>"
  155. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  156. OUTPUT_VARIABLE Git_Commit_Author
  157. RESULT_VARIABLE Git_RETURN
  158. ERROR_QUIET
  159. OUTPUT_STRIP_TRAILING_WHITESPACE
  160. )
  161. #| Commit Revision
  162. execute_process( COMMAND git show -s --format=%H
  163. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  164. OUTPUT_VARIABLE Git_Commit_Revision
  165. RESULT_VARIABLE Git_RETURN
  166. ERROR_QUIET
  167. OUTPUT_STRIP_TRAILING_WHITESPACE
  168. )
  169. #| Origin URL
  170. execute_process( COMMAND git config --get remote.origin.url
  171. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  172. OUTPUT_VARIABLE Git_Origin_URL
  173. RESULT_VARIABLE Git_RETURN
  174. ERROR_QUIET
  175. OUTPUT_STRIP_TRAILING_WHITESPACE
  176. )
  177. #| Date Macro
  178. macro ( dateNow RESULT )
  179. if ( WIN32 )
  180. execute_process( COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE ${RESULT} OUTPUT_STRIP_TRAILING_WHITESPACE )
  181. elseif ( UNIX )
  182. execute_process( COMMAND "date" "+%Y-%m-%d %T %z" OUTPUT_VARIABLE ${RESULT} OUTPUT_STRIP_TRAILING_WHITESPACE )
  183. else ()
  184. message( send_error "date not implemented" )
  185. set( ${RESULT} 000000 )
  186. endif ()
  187. endmacro (dateNow)
  188. dateNow( Build_Date )
  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 ()
  193. # TODO Figure out a good way of finding the current branch + commit date + modified
  194. set( GitLastCommitDate "Pft...Windows Build" )
  195. endif ()
  196. #| Uses CMake variables to include as defines
  197. #| Primarily for USB configuration
  198. configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/Lib/_buildvars.h buildvars.h )