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

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