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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. ###| CMAKE Kiibohd Controller Source Configurator |###
  2. #
  3. # Written by Jacob Alexander in 2011-2016 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. function ( ModuleCompatibility ModulePath )
  31. foreach ( mod_var ${ARGN} )
  32. if ( ${mod_var} STREQUAL ${COMPILER_FAMILY} )
  33. # Module found, no need to scan further
  34. return()
  35. endif ()
  36. endforeach ()
  37. message ( FATAL_ERROR "${ModulePath} does not support the ${COMPILER_FAMILY} family..." )
  38. endfunction ()
  39. ###
  40. # Module Processing
  41. #
  42. #| Go through lists of sources and append paths
  43. #| Usage:
  44. #| PathPrepend( OutputListOfSources <Prepend Path> <InputListOfSources> )
  45. macro ( PathPrepend Output SourcesPath )
  46. unset ( tmpSource )
  47. # Loop through items
  48. foreach ( item ${ARGN} )
  49. # Set the path
  50. set ( tmpSource ${tmpSource} "${SourcesPath}/${item}" )
  51. endforeach ()
  52. # Finalize by writing the new list back over the old one
  53. set ( ${Output} ${tmpSource} )
  54. endmacro ()
  55. ###
  56. # Add Module Macro
  57. #
  58. # Optional Arg 1: Main Module Check, set to True/1 if adding a main module
  59. function ( AddModule ModuleType ModuleName )
  60. # Module path
  61. set ( ModulePath ${ModuleType}/${ModuleName} )
  62. set ( ModuleFullPath ${HEAD_DIR}/${ModuleType}/${ModuleName} )
  63. # Include setup.cmake file
  64. include ( ${ModuleFullPath}/setup.cmake )
  65. # Check if this is a main module add
  66. foreach ( extraArg ${ARGN} )
  67. # Make sure this isn't a submodule
  68. if ( DEFINED SubModule )
  69. message ( FATAL_ERROR
  70. "The '${ModuleName}' module is not a stand-alone module, and requires further setup."
  71. )
  72. endif ()
  73. endforeach ()
  74. # PathPrepend to give proper paths to each of the source files
  75. PathPrepend ( Module_SRCS ${ModulePath} ${Module_SRCS} )
  76. # Check the current scope to see if a sub-module added some source files
  77. # Append each of the sources to each type of module srcs list
  78. set ( ${ModuleType}_SRCS ${${ModuleType}_SRCS} ${Module_SRCS} )
  79. # Add .h files
  80. add_definitions ( -I${ModuleFullPath} )
  81. # Check module compatibility
  82. ModuleCompatibility( ${ModulePath} ${ModuleCompatibility} )
  83. # Check if this is a main module add
  84. foreach ( extraArg ${ARGN} )
  85. # Display detected source files
  86. if ( NOT DEFINED SubModule )
  87. message ( STATUS "Detected ${ModuleType} Module Source Files:" )
  88. message ( "${${ModuleType}_SRCS}" )
  89. endif ()
  90. endforeach ()
  91. # Check for any capabilities.kll files in the Module
  92. set ( kll_capabilities_file "${ModuleFullPath}/capabilities.kll" )
  93. if ( EXISTS ${kll_capabilities_file} )
  94. # Add the kll file and any submodule kll files to the running list
  95. set ( ${ModuleType}Module_KLL ${${ModuleType}Module_KLL} ${kll_capabilities_file} )
  96. endif ()
  97. # Finally, add the sources and kll files to the parent scope (i.e. return)
  98. set ( ${ModuleType}_SRCS ${${ModuleType}_SRCS} PARENT_SCOPE )
  99. set ( ${ModuleType}Module_KLL ${${ModuleType}Module_KLL} PARENT_SCOPE )
  100. endfunction ()
  101. #| Add main modules
  102. AddModule ( Scan ${ScanModule} 1 )
  103. AddModule ( Macro ${MacroModule} 1 )
  104. AddModule ( Output ${OutputModule} 1 )
  105. AddModule ( Debug ${DebugModule} 1 )
  106. ###
  107. # CMake Build Env Checking
  108. #
  109. include( buildinfo )
  110. #| Uses CMake variables to include as defines
  111. #| Primarily for USB configuration
  112. configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/Lib/_buildvars.h buildvars.h )
  113. ###
  114. # Source Defines
  115. #
  116. set ( SRCS
  117. ${MAIN_SRCS}
  118. ${COMPILER_SRCS}
  119. ${Scan_SRCS}
  120. ${Macro_SRCS}
  121. ${Output_SRCS}
  122. ${Debug_SRCS}
  123. )
  124. #| Directories to include by default
  125. include_directories ( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )
  126. ###
  127. # ctag Generation
  128. #
  129. find_package ( Ctags ) # Optional
  130. if ( CTAGS_EXECUTABLE )
  131. # Populate list of directories for ctags to parse
  132. # NOTE: Doesn't support dots in the folder names...
  133. foreach ( filename ${SRCS} )
  134. string ( REGEX REPLACE "/[a-zA-Z0-9_-]+.c$" "" pathglob ${filename} )
  135. file ( GLOB filenames "${pathglob}/*.c" )
  136. set ( CTAG_PATHS ${CTAG_PATHS} ${filenames} )
  137. file ( GLOB filenames "${pathglob}/*.h" )
  138. set ( CTAG_PATHS ${CTAG_PATHS} ${filenames} )
  139. endforeach ()
  140. # Generate the ctags
  141. execute_process ( COMMAND ctags --fields=+l ${CTAG_PATHS}
  142. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  143. )
  144. endif ()