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.

modules.cmake 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. # CMake Custom Modules Path
  10. #
  11. set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/Lib/CMake/" )
  12. ###
  13. # Module Overrides (Used in the buildall.bash script)
  14. #
  15. if ( ( DEFINED ScanModuleOverride ) AND ( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Scan/${ScanModuleOverride} ) )
  16. set( ScanModule ${ScanModuleOverride} )
  17. endif ()
  18. ###
  19. # Path Setup
  20. #
  21. set( ScanModulePath "Scan/${ScanModule}" )
  22. set( MacroModulePath "Macro/${MacroModule}" )
  23. set( OutputModulePath "Output/${OutputModule}" )
  24. set( DebugModulePath "Debug/${DebugModule}" )
  25. #| Top-level directory adjustment
  26. set( HEAD_DIR "${CMAKE_CURRENT_SOURCE_DIR}" )
  27. ###
  28. # Module Check Function
  29. #
  30. #| Usage:
  31. #| PathPrepend( ModulePath <ListOfFamiliesSupported> )
  32. #| Uses the ${COMPILER_FAMILY} variable
  33. function( ModuleCompatibility ModulePath )
  34. foreach( mod_var ${ARGN} )
  35. if ( ${mod_var} STREQUAL ${COMPILER_FAMILY} )
  36. # Module found, no need to scan further
  37. return()
  38. endif ()
  39. endforeach()
  40. message( FATAL_ERROR "${ModulePath} does not support the ${COMPILER_FAMILY} family..." )
  41. endfunction()
  42. ###
  43. # Module Configuration
  44. #
  45. #| Additional options, usually define settings
  46. add_definitions()
  47. #| Include path for each of the modules
  48. add_definitions(
  49. -I${HEAD_DIR}/${ScanModulePath}
  50. -I${HEAD_DIR}/${MacroModulePath}
  51. -I${HEAD_DIR}/${OutputModulePath}
  52. -I${HEAD_DIR}/${DebugModulePath}
  53. )
  54. ###
  55. # Module Processing
  56. #
  57. #| Go through lists of sources and append paths
  58. #| Usage:
  59. #| PathPrepend( OutputListOfSources <Prepend Path> <InputListOfSources> )
  60. macro( PathPrepend Output SourcesPath )
  61. unset( tmpSource )
  62. # Loop through items
  63. foreach( item ${ARGN} )
  64. # Set the path
  65. set( tmpSource ${tmpSource} "${SourcesPath}/${item}" )
  66. endforeach()
  67. # Finalize by writing the new list back over the old one
  68. set( ${Output} ${tmpSource} )
  69. endmacro()
  70. #| Scan Module
  71. include ( "${ScanModulePath}/setup.cmake" )
  72. PathPrepend( SCAN_SRCS ${ScanModulePath} ${SCAN_SRCS} )
  73. #| Macro Module
  74. include ( "${MacroModulePath}/setup.cmake" )
  75. PathPrepend( MACRO_SRCS ${MacroModulePath} ${MACRO_SRCS} )
  76. #| Output Module
  77. include ( "${OutputModulePath}/setup.cmake" )
  78. PathPrepend( OUTPUT_SRCS ${OutputModulePath} ${OUTPUT_SRCS} )
  79. #| Debugging Module
  80. include ( "${DebugModulePath}/setup.cmake" )
  81. PathPrepend( DEBUG_SRCS ${DebugModulePath} ${DEBUG_SRCS} )
  82. #| Print list of all module sources
  83. message( STATUS "Detected Scan Module Source Files:" )
  84. message( "${SCAN_SRCS}" )
  85. message( STATUS "Detected Macro Module Source Files:" )
  86. message( "${MACRO_SRCS}" )
  87. message( STATUS "Detected Output Module Source Files:" )
  88. message( "${OUTPUT_SRCS}" )
  89. message( STATUS "Detected Debug Module Source Files:" )
  90. message( "${DEBUG_SRCS}" )
  91. ###
  92. # CMake Module Checking
  93. #
  94. find_package( Git REQUIRED )
  95. find_package( Ctags ) # Optional
  96. ###
  97. # Generate USB Defines
  98. #
  99. #| Manufacturer name
  100. set( MANUFACTURER "Kiibohd" )
  101. #| Serial Number
  102. #| Attempt to call Git to get the branch, last commit date, and whether code modified since last commit
  103. #| Modified
  104. #| Takes a bit of work to extract the "M " using CMake, and not using it if there are no modifications
  105. execute_process( COMMAND ${GIT_EXECUTABLE} status -s -uno --porcelain
  106. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  107. OUTPUT_VARIABLE Git_Modified_INFO
  108. ERROR_QUIET
  109. OUTPUT_STRIP_TRAILING_WHITESPACE
  110. )
  111. string( LENGTH "${Git_Modified_INFO}" Git_Modified_LENGTH )
  112. set( Git_Modified_Status "Clean" )
  113. if ( ${Git_Modified_LENGTH} GREATER 2 )
  114. string( SUBSTRING "${Git_Modified_INFO}" 1 2 Git_Modified_Flag_INFO )
  115. set( Git_Modified_Status "Dirty" )
  116. endif ()
  117. #| Branch
  118. execute_process( COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
  119. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  120. OUTPUT_VARIABLE Git_Branch_INFO
  121. ERROR_QUIET
  122. OUTPUT_STRIP_TRAILING_WHITESPACE
  123. )
  124. #| Date
  125. execute_process( COMMAND ${GIT_EXECUTABLE} show -s --format=%ci
  126. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  127. OUTPUT_VARIABLE Git_Date_INFO
  128. ERROR_QUIET
  129. OUTPUT_STRIP_TRAILING_WHITESPACE
  130. )
  131. #| Commit Author and Email
  132. execute_process( COMMAND ${GIT_EXECUTABLE} show -s --format="%cn <%ce>"
  133. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  134. OUTPUT_VARIABLE Git_Commit_Author
  135. ERROR_QUIET
  136. OUTPUT_STRIP_TRAILING_WHITESPACE
  137. )
  138. #| Commit Revision
  139. execute_process( COMMAND ${GIT_EXECUTABLE} show -s --format=%H
  140. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  141. OUTPUT_VARIABLE Git_Commit_Revision
  142. ERROR_QUIET
  143. OUTPUT_STRIP_TRAILING_WHITESPACE
  144. )
  145. #| Origin URL
  146. execute_process( COMMAND ${GIT_EXECUTABLE} config --get remote.origin.url
  147. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  148. OUTPUT_VARIABLE Git_Origin_URL
  149. ERROR_QUIET
  150. OUTPUT_STRIP_TRAILING_WHITESPACE
  151. )
  152. #| Build Date
  153. execute_process( COMMAND "date" "+%Y-%m-%d %T %z"
  154. OUTPUT_VARIABLE Build_Date
  155. ERROR_QUIET
  156. OUTPUT_STRIP_TRAILING_WHITESPACE
  157. )
  158. #| Last Commit Date
  159. set( GitLastCommitDate "${Git_Modified_Status} ${Git_Branch_INFO} - ${Git_Date_INFO}" )
  160. #| Uses CMake variables to include as defines
  161. #| Primarily for USB configuration
  162. configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/Lib/_buildvars.h buildvars.h )
  163. ###
  164. # Source Defines
  165. #
  166. set( SRCS
  167. ${MAIN_SRCS}
  168. ${COMPILER_SRCS}
  169. ${SCAN_SRCS}
  170. ${MACRO_SRCS}
  171. ${OUTPUT_SRCS}
  172. ${DEBUG_SRCS}
  173. )
  174. #| Directories to include by default
  175. include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )
  176. ###
  177. # Module Compatibility Check
  178. #
  179. #| Check for whether the set modules are compatible with the specified compiler family
  180. ModuleCompatibility( ${ScanModulePath} ${ScanModuleCompatibility} )
  181. ModuleCompatibility( ${MacroModulePath} ${MacroModuleCompatibility} )
  182. ModuleCompatibility( ${OutputModulePath} ${OutputModuleCompatibility} )
  183. ModuleCompatibility( ${DebugModulePath} ${DebugModuleCompatibility} )
  184. ###
  185. # ctag Generation
  186. #
  187. if( CTAGS_EXECUTABLE )
  188. # Populate list of directories for ctags to parse
  189. # NOTE: Doesn't support dots in the folder names...
  190. foreach( filename ${SRCS} )
  191. string( REGEX REPLACE "/[a-zA-Z0-9_-]+.c$" "" pathglob ${filename} )
  192. file( GLOB filenames "${pathglob}/*.c" )
  193. set( CTAG_PATHS ${CTAG_PATHS} ${filenames} )
  194. file( GLOB filenames "${pathglob}/*.h" )
  195. set( CTAG_PATHS ${CTAG_PATHS} ${filenames} )
  196. endforeach()
  197. # Generate the ctags
  198. execute_process( COMMAND ctags ${CTAG_PATHS}
  199. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  200. )
  201. endif()
  202. ###
  203. # Setup Loader Script and Program
  204. #
  205. #| Provides the user with the correct teensy-loader-cli command for the built .HEX file
  206. #| Windows
  207. if( CMAKE_SYSTEM_NAME MATCHES "Windows" )
  208. configure_file( LoadFile/winload load NEWLINE_STYLE UNIX )
  209. #| Default
  210. else()
  211. configure_file( LoadFile/load load NEWLINE_STYLE UNIX )
  212. endif()