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 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. # 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 "MBC-55X" )
  18. ##| Uses the key index and potentially applies special conditions to it, mapping it to a usb key code
  19. set( MacroModule "buffer" )
  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. # Module Overrides (Used in the buildall.bash script)
  26. #
  27. if ( ( DEFINED ScanModuleOverride ) AND ( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Scan/${ScanModuleOverride} ) )
  28. set( ScanModule ${ScanModuleOverride} )
  29. endif ()
  30. ###
  31. # Path Setup
  32. #
  33. set( ScanModulePath "Scan/${ScanModule}" )
  34. set( MacroModulePath "Macro/${MacroModule}" )
  35. set( OutputModulePath "Output/${OutputModule}" )
  36. set( USBModulePath "USB/${USBModule}" )
  37. set( DebugModulePath "Debug/${DebugModule}" )
  38. #| Top-level directory adjustment
  39. set( HEAD_DIR "${CMAKE_CURRENT_SOURCE_DIR}" )
  40. ###
  41. # Module Check Function
  42. #
  43. #| Usage:
  44. #| PathPrepend( ModulePath <ListOfFamiliesSupported> )
  45. #| Uses the ${COMPILER_FAMILY} variable
  46. function( ModuleCompatibility ModulePath )
  47. foreach( mod_var ${ARGN} )
  48. if ( ${mod_var} STREQUAL ${COMPILER_FAMILY} )
  49. # Module found, no need to scan further
  50. return()
  51. endif ()
  52. endforeach()
  53. message( FATAL_ERROR "${ModulePath} does not support the ${COMPILER_FAMILY} family..." )
  54. endfunction()
  55. ###
  56. # Module Configuration
  57. #
  58. #| Additional options, usually define settings
  59. add_definitions()
  60. #| Include path for each of the modules
  61. add_definitions(
  62. -I${HEAD_DIR}/${ScanModulePath}
  63. -I${HEAD_DIR}/${MacroModulePath}
  64. -I${HEAD_DIR}/${OutputModulePath}
  65. -I${HEAD_DIR}/${DebugModulePath}
  66. )
  67. ###
  68. # Module Processing
  69. #
  70. #| Go through lists of sources and append paths
  71. #| Usage:
  72. #| PathPrepend( OutputListOfSources <Prepend Path> <InputListOfSources> )
  73. macro( PathPrepend Output SourcesPath )
  74. unset( tmpSource )
  75. # Loop through items
  76. foreach( item ${ARGN} )
  77. # Set the path
  78. set( tmpSource ${tmpSource} "${SourcesPath}/${item}" )
  79. endforeach()
  80. # Finalize by writing the new list back over the old one
  81. set( ${Output} ${tmpSource} )
  82. endmacro()
  83. #| Scan Module
  84. include ( "${ScanModulePath}/setup.cmake" )
  85. PathPrepend( SCAN_SRCS ${ScanModulePath} ${SCAN_SRCS} )
  86. #| Macro Module
  87. include ( "${MacroModulePath}/setup.cmake" )
  88. PathPrepend( MACRO_SRCS ${MacroModulePath} ${MACRO_SRCS} )
  89. #| Output Module
  90. include ( "${OutputModulePath}/setup.cmake" )
  91. PathPrepend( OUTPUT_SRCS ${OutputModulePath} ${OUTPUT_SRCS} )
  92. #| Debugging Module
  93. include ( "${DebugModulePath}/setup.cmake" )
  94. PathPrepend( DEBUG_SRCS ${DebugModulePath} ${DEBUG_SRCS} )
  95. #| Print list of all module sources
  96. message( STATUS "Detected Scan Module Source Files:" )
  97. message( "${SCAN_SRCS}" )
  98. message( STATUS "Detected Macro Module Source Files:" )
  99. message( "${MACRO_SRCS}" )
  100. message( STATUS "Detected USB Module Source Files:" )
  101. message( "${OUTPUT_SRCS}" )
  102. message( STATUS "Detected Debug Module Source Files:" )
  103. message( "${DEBUG_SRCS}" )
  104. ###
  105. # Generate USB Defines
  106. #
  107. #| Manufacturer name
  108. set( MANUFACTURER "Kiibohd" )
  109. #| Serial Number
  110. #| Attempt to call Git to get the branch, last commit date, and whether code modified since last commit
  111. #| Modified
  112. #| Takes a bit of work to extract the "M " using CMake, and not using it if there are no modifications
  113. execute_process( COMMAND git status -s -uno --porcelain
  114. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  115. OUTPUT_VARIABLE Git_Modified_INFO
  116. ERROR_QUIET
  117. OUTPUT_STRIP_TRAILING_WHITESPACE
  118. )
  119. string( LENGTH "${Git_Modified_INFO}" Git_Modified_LENGTH )
  120. set( Git_Modified_Status "Clean" )
  121. if ( ${Git_Modified_LENGTH} GREATER 2 )
  122. string( SUBSTRING "${Git_Modified_INFO}" 1 2 Git_Modified_Flag_INFO )
  123. set( Git_Modified_Status "Dirty" )
  124. endif ()
  125. #| Branch
  126. execute_process( COMMAND git rev-parse --abbrev-ref HEAD
  127. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  128. OUTPUT_VARIABLE Git_Branch_INFO
  129. ERROR_QUIET
  130. OUTPUT_STRIP_TRAILING_WHITESPACE
  131. )
  132. #| Date
  133. execute_process( COMMAND git show -s --format=%ci
  134. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  135. OUTPUT_VARIABLE Git_Date_INFO
  136. RESULT_VARIABLE Git_RETURN
  137. ERROR_QUIET
  138. OUTPUT_STRIP_TRAILING_WHITESPACE
  139. )
  140. #| Commit Author and Email
  141. execute_process( COMMAND git show -s --format="%cn <%ce>"
  142. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  143. OUTPUT_VARIABLE Git_Commit_Author
  144. RESULT_VARIABLE Git_RETURN
  145. ERROR_QUIET
  146. OUTPUT_STRIP_TRAILING_WHITESPACE
  147. )
  148. #| Commit Revision
  149. execute_process( COMMAND git show -s --format=%H
  150. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  151. OUTPUT_VARIABLE Git_Commit_Revision
  152. RESULT_VARIABLE Git_RETURN
  153. ERROR_QUIET
  154. OUTPUT_STRIP_TRAILING_WHITESPACE
  155. )
  156. #| Origin URL
  157. execute_process( COMMAND git config --get remote.origin.url
  158. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  159. OUTPUT_VARIABLE Git_Origin_URL
  160. RESULT_VARIABLE Git_RETURN
  161. ERROR_QUIET
  162. OUTPUT_STRIP_TRAILING_WHITESPACE
  163. )
  164. #| Date Macro
  165. macro ( dateNow RESULT )
  166. if ( WIN32 )
  167. execute_process( COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE ${RESULT} OUTPUT_STRIP_TRAILING_WHITESPACE )
  168. elseif ( UNIX )
  169. execute_process( COMMAND "date" "+%Y-%m-%d %T %z" OUTPUT_VARIABLE ${RESULT} OUTPUT_STRIP_TRAILING_WHITESPACE )
  170. else ()
  171. message( send_error "date not implemented" )
  172. set( ${RESULT} 000000 )
  173. endif ()
  174. endmacro (dateNow)
  175. dateNow( Build_Date )
  176. #| Only use Git variables if we were successful in calling the commands
  177. if ( ${Git_RETURN} EQUAL 0 )
  178. set( GitLastCommitDate "${Git_Modified_Flag_INFO}${Git_Branch_INFO} - ${Git_Date_INFO}" )
  179. else ()
  180. # TODO Figure out a good way of finding the current branch + commit date + modified
  181. set( GitLastCommitDate "Pft...Windows Build" )
  182. endif ()
  183. #| Uses CMake variables to include as defines
  184. #| Primarily for USB configuration
  185. configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/Lib/_buildvars.h buildvars.h )