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

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