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.

kll.cmake 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. ###| CMAKE Kiibohd Controller KLL Configurator |###
  2. #
  3. # Written by Jacob Alexander in 2014 for the Kiibohd Controller
  4. #
  5. # Released into the Public Domain
  6. #
  7. ###
  8. ###
  9. # Check if KLL compiler is needed
  10. #
  11. if ( "${MacroModule}" STREQUAL "PartialMap" )
  12. ###
  13. # KLL Installation (Make sure repo has been cloned)
  14. #
  15. if ( NOT EXISTS "${PROJECT_SOURCE_DIR}/kll/kll.py" )
  16. message ( STATUS "Downloading latest kll version:" )
  17. # Make sure git is available
  18. find_package ( Git REQUIRED )
  19. # Clone kll git repo
  20. execute_process ( COMMAND ${GIT_EXECUTABLE} clone https://github.com/kiibohd/kll.git
  21. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  22. )
  23. elseif ( REFRESH_KLL ) # Otherwise attempt to update the repo
  24. message ( STATUS "Checking for latest kll version:" )
  25. # Clone kll git repo
  26. execute_process ( COMMAND ${GIT_EXECUTABLE} pull --rebase
  27. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/kll
  28. )
  29. endif () # kll/kll.py exists
  30. ###
  31. # Prepare KLL layout arguments
  32. #
  33. #| KLL_DEPENDS is used to build a dependency tree for kll.py, this way when files are changed, kll.py gets re-run
  34. #| Search for capabilities.kll in each module directory
  35. foreach ( DIR ${ScanModulePath} ${MacroModulePath} ${OutputModulePath} ${DebugModulePath} )
  36. # capabilities.kll exists, add to BaseMap
  37. set ( filename "${PROJECT_SOURCE_DIR}/${DIR}/capabilities.kll" )
  38. if ( EXISTS ${filename} )
  39. set ( BaseMap_Args ${BaseMap_Args} ${filename} )
  40. set ( KLL_DEPENDS ${KLL_DEPENDS} ${filename} )
  41. endif ()
  42. endforeach ()
  43. #| If set BaseMap cannot be found, use default map
  44. set ( pathname "${PROJECT_SOURCE_DIR}/${ScanModulePath}" )
  45. if ( NOT EXISTS ${pathname}/${BaseMap}.kll )
  46. set ( BaseMap_Args ${BaseMap_Args} ${pathname}/defaultMap.kll )
  47. set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/defaultMap.kll )
  48. else ()
  49. set ( BaseMap_Args ${BaseMap_Args} ${pathname}/${BaseMap}.kll )
  50. set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/${BaseMap}.kll )
  51. endif ()
  52. #| Configure DefaultMap if specified
  53. if ( NOT "${DefaultMap}" STREQUAL "" )
  54. set ( DefaultMap_Args -d )
  55. string ( REPLACE " " ";" MAP_LIST ${DefaultMap} ) # Change spaces to semicolons
  56. foreach ( MAP ${MAP_LIST} )
  57. # Check if kll file is in build directory, otherwise default to layout directory
  58. if ( EXISTS "${PROJECT_BINARY_DIR}/${MAP}.kll" )
  59. set ( DefaultMap_Args ${DefaultMap_Args} ${MAP}.kll )
  60. set ( KLL_DEPENDS ${KLL_DEPENDS} ${MAP}.kll )
  61. else ()
  62. set ( DefaultMap_Args ${DefaultMap_Args} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll )
  63. set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll )
  64. endif ()
  65. endforeach ()
  66. endif ()
  67. #| Configure PartialMaps if specified
  68. if ( NOT "${PartialMaps}" STREQUAL "" )
  69. # For each partial layer
  70. foreach ( MAP ${PartialMaps} )
  71. set ( PartialMap_Args ${PartialMap_Args} -p )
  72. # Combine each layer
  73. string ( REPLACE " " ";" MAP_LIST ${MAP} ) # Change spaces to semicolons
  74. foreach ( MAP_PART ${MAP_LIST} )
  75. # Check if kll file is in build directory, otherwise default to layout directory
  76. if ( EXISTS "${PROJECT_BINARY_DIR}/${MAP_PART}.kll" )
  77. set ( PartialMap_Args ${PartialMap_Args} ${MAP_PART}.kll )
  78. set ( KLL_DEPENDS ${KLL_DEPENDS} ${MAP_PART}.kll )
  79. else ()
  80. set ( PartialMap_Args ${PartialMap_Args} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP_PART}.kll )
  81. set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP_PART}.kll )
  82. endif ()
  83. endforeach ()
  84. endforeach ()
  85. endif ()
  86. #| Print list of layout sources used
  87. message ( STATUS "Detected Layout Files:" )
  88. foreach ( filename ${KLL_DEPENDS} )
  89. message ( "${filename}" )
  90. endforeach ()
  91. ###
  92. # Run KLL Compiler
  93. #
  94. #| KLL Options
  95. set ( kll_backend -b kiibohd )
  96. set ( kll_template -t ${PROJECT_SOURCE_DIR}/kll/templates/kiibohdKeymap.h )
  97. set ( kll_outputname generatedKeymap.h )
  98. set ( kll_output -o ${kll_outputname} )
  99. set ( kll_define_output --defines-output kll_defs.h )
  100. set ( kll_define_template --defines-template ${PROJECT_SOURCE_DIR}/kll/templates/kiibohdDefs.h )
  101. #| KLL Cmd
  102. set ( kll_cmd ${PROJECT_SOURCE_DIR}/kll/kll.py ${BaseMap_Args} ${DefaultMap_Args} ${PartialMap_Args} ${kll_backend} ${kll_template} ${kll_output} ${kll_define_template} ${kll_define_output} )
  103. add_custom_command ( OUTPUT ${kll_outputname}
  104. COMMAND ${kll_cmd}
  105. DEPENDS ${KLL_DEPENDS}
  106. COMMENT "Generating KLL Layout"
  107. )
  108. #| Append generated file to required sources so it becomes a dependency in the main build
  109. set ( SRCS ${SRCS} ${kll_outputname} )
  110. endif () # PartialMap