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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. ###| CMAKE Kiibohd Controller KLL Configurator |###
  2. #
  3. # Written by Jacob Alexander in 2014-2016 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. # Python 3 is required for kll
  14. #
  15. set ( PYTHON_EXECUTABLE python3 ) # Required on systems where python is 2, not 3
  16. find_package ( PythonInterp 3 REQUIRED )
  17. ###
  18. # KLL Installation (Make sure repo has been cloned)
  19. #
  20. if ( NOT EXISTS "${PROJECT_SOURCE_DIR}/kll/kll.py" )
  21. message ( STATUS "Downloading latest kll version:" )
  22. # Make sure git is available
  23. find_package ( Git REQUIRED )
  24. # Clone kll git repo
  25. execute_process ( COMMAND ${GIT_EXECUTABLE} clone https://github.com/kiibohd/kll.git
  26. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  27. )
  28. elseif ( REFRESH_KLL ) # Otherwise attempt to update the repo
  29. message ( STATUS "Checking for latest kll version:" )
  30. # Clone kll git repo
  31. execute_process ( COMMAND ${GIT_EXECUTABLE} pull --rebase
  32. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/kll
  33. )
  34. endif () # kll/kll.py exists
  35. ###
  36. # Prepare KLL layout arguments
  37. #
  38. #| KLL_DEPENDS is used to build a dependency tree for kll.py, this way when files are changed, kll.py gets re-run
  39. #| Add each of the detected capabilities.kll
  40. foreach ( filename ${ScanModule_KLL} ${MacroModule_KLL} ${OutputModule_KLL} ${DebugModule_KLL} )
  41. set ( BaseMap_Args ${BaseMap_Args} ${filename} )
  42. set ( KLL_DEPENDS ${KLL_DEPENDS} ${filename} )
  43. endforeach ()
  44. #| If set BaseMap cannot be found, use default map
  45. set ( pathname "${PROJECT_SOURCE_DIR}/${ScanModulePath}" )
  46. string ( REPLACE " " ";" MAP_LIST ${BaseMap} ) # Change spaces to semicolons
  47. foreach ( MAP ${MAP_LIST} )
  48. # Only check the Scan Module for BaseMap .kll files, default to scancode_map.kll or defaultMap.kll
  49. if ( NOT EXISTS ${pathname}/${MAP}.kll )
  50. if ( EXISTS ${pathname}/scancode_map.kll )
  51. set ( BaseMap_Args ${BaseMap_Args} ${pathname}/scancode_map.kll )
  52. set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/scancode_map.kll )
  53. else ()
  54. set ( BaseMap_Args ${BaseMap_Args} ${pathname}/defaultMap.kll )
  55. set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/defaultMap.kll )
  56. endif ()
  57. elseif ( EXISTS "${pathname}/${MAP}.kll" )
  58. set ( BaseMap_Args ${BaseMap_Args} ${pathname}/${MAP}.kll )
  59. set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/${MAP}.kll )
  60. else ()
  61. message ( FATAL " Could not find '${MAP}.kll' BaseMap in Scan module directory" )
  62. endif ()
  63. endforeach ()
  64. #| Configure DefaultMap if specified
  65. if ( NOT "${DefaultMap}" STREQUAL "" )
  66. set ( DefaultMap_Args -d )
  67. string ( REPLACE " " ";" MAP_LIST ${DefaultMap} ) # Change spaces to semicolons
  68. foreach ( MAP ${MAP_LIST} )
  69. # Check if kll file is in build directory, otherwise default to layout directory
  70. if ( EXISTS "${PROJECT_BINARY_DIR}/${MAP}.kll" )
  71. set ( DefaultMap_Args ${DefaultMap_Args} ${MAP}.kll )
  72. set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_BINARY_DIR}/${MAP}.kll )
  73. elseif ( EXISTS "${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll" )
  74. set ( DefaultMap_Args ${DefaultMap_Args} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll )
  75. set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll )
  76. else ()
  77. message ( FATAL " Could not find '${MAP}.kll' DefaultMap" )
  78. endif ()
  79. endforeach ()
  80. endif ()
  81. #| Configure PartialMaps if specified
  82. if ( NOT "${PartialMaps}" STREQUAL "" )
  83. # For each partial layer
  84. foreach ( MAP ${PartialMaps} )
  85. set ( PartialMap_Args ${PartialMap_Args} -p )
  86. # Combine each layer
  87. string ( REPLACE " " ";" MAP_LIST ${MAP} ) # Change spaces to semicolons
  88. foreach ( MAP_PART ${MAP_LIST} )
  89. # Check if kll file is in build directory, otherwise default to layout directory
  90. if ( EXISTS "${PROJECT_BINARY_DIR}/${MAP_PART}.kll" )
  91. set ( PartialMap_Args ${PartialMap_Args} ${MAP_PART}.kll )
  92. set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_BINARY_DIR}/${MAP_PART}.kll )
  93. elseif ( EXISTS "${PROJECT_SOURCE_DIR}/kll/layouts/${MAP_PART}.kll" )
  94. set ( PartialMap_Args ${PartialMap_Args} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP_PART}.kll )
  95. set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP_PART}.kll )
  96. else ()
  97. message ( FATAL " Could not find '${MAP_PART}.kll' PartialMap" )
  98. endif ()
  99. endforeach ()
  100. endforeach ()
  101. endif ()
  102. #| Print list of layout sources used
  103. message ( STATUS "Detected Layout Files:" )
  104. foreach ( filename ${KLL_DEPENDS} )
  105. message ( "${filename}" )
  106. endforeach ()
  107. ###
  108. # Run KLL Compiler
  109. #
  110. #| KLL Options
  111. set ( kll_backend --backend kiibohd )
  112. set ( kll_template --templates ${PROJECT_SOURCE_DIR}/kll/templates/kiibohdKeymap.h ${PROJECT_SOURCE_DIR}/kll/templates/kiibohdDefs.h )
  113. set ( kll_outputname generatedKeymap.h kll_defs.h )
  114. set ( kll_output --outputs ${kll_outputname} )
  115. #| KLL Cmd
  116. set ( kll_cmd ${PROJECT_SOURCE_DIR}/kll/kll.py ${BaseMap_Args} ${DefaultMap_Args} ${PartialMap_Args} ${kll_backend} ${kll_template} ${kll_output} )
  117. add_custom_command ( OUTPUT ${kll_outputname}
  118. COMMAND ${kll_cmd}
  119. DEPENDS ${KLL_DEPENDS}
  120. COMMENT "Generating KLL Layout"
  121. )
  122. #| KLL Regen Convenience Target
  123. add_custom_target ( kll_regen
  124. COMMAND ${kll_cmd}
  125. COMMENT "Re-generating KLL Layout"
  126. )
  127. #| Append generated file to required sources so it becomes a dependency in the main build
  128. set ( SRCS ${SRCS} ${kll_outputname} )
  129. endif () # PartialMap