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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. ###| CMAKE Kiibohd Controller KLL Configurator |###
  2. #
  3. # Written by Jacob Alexander in 2014-2015 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. #| Add each of the detected capabilities.kll
  35. foreach ( filename ${ScanModule_KLL} ${MacroModule_KLL} ${OutputModule_KLL} ${DebugModule_KLL} )
  36. set ( BaseMap_Args ${BaseMap_Args} ${filename} )
  37. set ( KLL_DEPENDS ${KLL_DEPENDS} ${filename} )
  38. endforeach ()
  39. #| If set BaseMap cannot be found, use default map
  40. set ( pathname "${PROJECT_SOURCE_DIR}/${ScanModulePath}" )
  41. string ( REPLACE " " ";" MAP_LIST ${BaseMap} ) # Change spaces to semicolons
  42. foreach ( MAP ${MAP_LIST} )
  43. # Only check the Scan Module for BaseMap .kll files, default to scancode_map.kll or defaultMap.kll
  44. if ( NOT EXISTS ${pathname}/${MAP}.kll )
  45. if ( EXISTS ${pathname}/scancode_map.kll )
  46. set ( BaseMap_Args ${BaseMap_Args} ${pathname}/scancode_map.kll )
  47. set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/scancode_map.kll )
  48. else ()
  49. set ( BaseMap_Args ${BaseMap_Args} ${pathname}/defaultMap.kll )
  50. set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/defaultMap.kll )
  51. endif ()
  52. elseif ( EXISTS "${pathname}/${MAP}.kll" )
  53. set ( BaseMap_Args ${BaseMap_Args} ${pathname}/${MAP}.kll )
  54. set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/${MAP}.kll )
  55. else ()
  56. message ( FATAL " Could not find '${MAP}.kll' BaseMap in Scan module directory" )
  57. endif ()
  58. endforeach ()
  59. #| Configure DefaultMap if specified
  60. if ( NOT "${DefaultMap}" STREQUAL "" )
  61. set ( DefaultMap_Args -d )
  62. string ( REPLACE " " ";" MAP_LIST ${DefaultMap} ) # Change spaces to semicolons
  63. foreach ( MAP ${MAP_LIST} )
  64. # Check if kll file is in build directory, otherwise default to layout directory
  65. if ( EXISTS "${PROJECT_BINARY_DIR}/${MAP}.kll" )
  66. set ( DefaultMap_Args ${DefaultMap_Args} ${MAP}.kll )
  67. set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_BINARY_DIR}/${MAP}.kll )
  68. elseif ( EXISTS "${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll" )
  69. set ( DefaultMap_Args ${DefaultMap_Args} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll )
  70. set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll )
  71. else ()
  72. message ( FATAL " Could not find '${MAP}.kll' DefaultMap" )
  73. endif ()
  74. endforeach ()
  75. endif ()
  76. #| Configure PartialMaps if specified
  77. if ( NOT "${PartialMaps}" STREQUAL "" )
  78. # For each partial layer
  79. foreach ( MAP ${PartialMaps} )
  80. set ( PartialMap_Args ${PartialMap_Args} -p )
  81. # Combine each layer
  82. string ( REPLACE " " ";" MAP_LIST ${MAP} ) # Change spaces to semicolons
  83. foreach ( MAP_PART ${MAP_LIST} )
  84. # Check if kll file is in build directory, otherwise default to layout directory
  85. if ( EXISTS "${PROJECT_BINARY_DIR}/${MAP_PART}.kll" )
  86. set ( PartialMap_Args ${PartialMap_Args} ${MAP_PART}.kll )
  87. set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_BINARY_DIR}/${MAP_PART}.kll )
  88. elseif ( EXISTS "${PROJECT_SOURCE_DIR}/kll/layouts/${MAP_PART}.kll" )
  89. set ( PartialMap_Args ${PartialMap_Args} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP_PART}.kll )
  90. set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP_PART}.kll )
  91. else ()
  92. message ( FATAL " Could not find '${MAP_PART}.kll' PartialMap" )
  93. endif ()
  94. endforeach ()
  95. endforeach ()
  96. endif ()
  97. #| Print list of layout sources used
  98. message ( STATUS "Detected Layout Files:" )
  99. foreach ( filename ${KLL_DEPENDS} )
  100. message ( "${filename}" )
  101. endforeach ()
  102. ###
  103. # Run KLL Compiler
  104. #
  105. #| KLL Options
  106. set ( kll_backend --backend kiibohd )
  107. set ( kll_template --templates ${PROJECT_SOURCE_DIR}/kll/templates/kiibohdKeymap.h ${PROJECT_SOURCE_DIR}/kll/templates/kiibohdDefs.h )
  108. set ( kll_outputname generatedKeymap.h kll_defs.h )
  109. set ( kll_output --outputs ${kll_outputname} )
  110. #| KLL Cmd
  111. set ( kll_cmd ${PROJECT_SOURCE_DIR}/kll/kll.py ${BaseMap_Args} ${DefaultMap_Args} ${PartialMap_Args} ${kll_backend} ${kll_template} ${kll_output} )
  112. add_custom_command ( OUTPUT ${kll_outputname}
  113. COMMAND ${kll_cmd}
  114. DEPENDS ${KLL_DEPENDS}
  115. COMMENT "Generating KLL Layout"
  116. )
  117. #| KLL Regen Convenience Target
  118. add_custom_target ( kll_regen
  119. COMMAND ${kll_cmd}
  120. COMMENT "Re-generating KLL Layout"
  121. )
  122. #| Append generated file to required sources so it becomes a dependency in the main build
  123. set ( SRCS ${SRCS} ${kll_outputname} )
  124. endif () # PartialMap