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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. # Make sure git is available
  17. find_package ( Git REQUIRED )
  18. # Clone kll git repo
  19. execute_process ( COMMAND ${GIT_EXECUTABLE} clone https://github.com/kiibohd/kll.git
  20. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  21. )
  22. endif () # kll/kll.py exists
  23. ###
  24. # Prepare KLL layout arguments
  25. #
  26. #| KLL_DEPENDS is used to build a dependency tree for kll.py, this way when files are changed, kll.py gets re-run
  27. #| Search for capabilities.kll in each module directory
  28. foreach ( DIR ${ScanModulePath} ${MacroModulePath} ${OutputModulePath} ${DebugModulePath} )
  29. # capabilities.kll exists, add to BaseMap
  30. set ( filename "${PROJECT_SOURCE_DIR}/${DIR}/capabilities.kll" )
  31. if ( EXISTS ${filename} )
  32. set ( BaseMap_Args ${BaseMap_Args} ${filename} )
  33. set ( KLL_DEPENDS ${KLL_DEPENDS} ${filename} )
  34. endif ()
  35. endforeach ()
  36. #| If set BaseMap cannot be found, use default map
  37. set ( pathname "${PROJECT_SOURCE_DIR}/${ScanModulePath}" )
  38. if ( NOT EXISTS "${filename}/${BaseMap}.kll" )
  39. set ( BaseMap_Args ${BaseMap_Args} ${pathname}/defaultMap.kll )
  40. set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/defaultMap.kll )
  41. else ()
  42. set ( BaseMap_Args ${BaseMap_Args} ${pathname}/${BaseMap}.kll )
  43. set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/${BaseMap}.kll )
  44. endif ()
  45. #| Configure DefaultMap if specified
  46. if ( NOT "${DefaultMap}" STREQUAL "" )
  47. set ( DefaultMap_Args -d )
  48. string ( REPLACE " " ";" MAP_LIST ${DefaultMap} ) # Change spaces to semicolons
  49. foreach ( MAP ${MAP_LIST} )
  50. # Check if kll file is in build directory, otherwise default to layout directory
  51. if ( EXISTS "${PROJECT_BINARY_DIR}/${MAP}.kll" )
  52. set ( DefaultMap_Args ${DefaultMap_Args} ${MAP}.kll )
  53. set ( KLL_DEPENDS ${KLL_DEPENDS} ${MAP}.kll )
  54. else ()
  55. set ( DefaultMap_Args ${DefaultMap_Args} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll )
  56. set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll )
  57. endif ()
  58. endforeach ()
  59. endif ()
  60. #| Configure PartialMaps if specified
  61. if ( NOT "${PartialMaps}" STREQUAL "" )
  62. # For each partial layer
  63. foreach ( MAP ${PartialMaps} )
  64. set ( PartialMap_Args ${PartialMap_Args} -p )
  65. # Combine each layer
  66. string ( REPLACE " " ";" MAP_LIST ${MAP} ) # Change spaces to semicolons
  67. foreach ( MAP_PART ${MAP_LIST} )
  68. # Check if kll file is in build directory, otherwise default to layout directory
  69. if ( EXISTS "${PROJECT_BINARY_DIR}/${MAP_PART}.kll" )
  70. set ( PartialMap_Args ${PartialMap_Args} ${MAP_PART}.kll )
  71. set ( KLL_DEPENDS ${KLL_DEPENDS} ${MAP_PART}.kll )
  72. else ()
  73. set ( PartialMap_Args ${PartialMap_Args} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP_PART}.kll )
  74. set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP_PART}.kll )
  75. endif ()
  76. endforeach ()
  77. endforeach ()
  78. endif ()
  79. ###
  80. # Run KLL Compiler
  81. #
  82. #| KLL Options
  83. set ( kll_backend -b kiibohd )
  84. set ( kll_template -t ${PROJECT_SOURCE_DIR}/kll/templates/kiibohdKeymap.h )
  85. set ( kll_outputname generatedKeymap.h )
  86. set ( kll_output -o ${kll_outputname} )
  87. #| KLL Cmd
  88. set ( kll_cmd ${PROJECT_SOURCE_DIR}/kll/kll.py ${BaseMap_Args} ${DefaultMap_Args} ${PartialMap_Args} ${kll_backend} ${kll_template} ${kll_output} )
  89. add_custom_command ( OUTPUT ${kll_outputname}
  90. COMMAND ${kll_cmd}
  91. DEPENDS ${KLL_DEPENDS}
  92. COMMENT "Generating KLL Layout"
  93. )
  94. #| Append generated file to required sources so it becomes a dependency in the main build
  95. set ( SRCS ${SRCS} ${kll_outputname} )
  96. endif () # PartialMap