1 ###| CMAKE Kiibohd Controller KLL Configurator |###
3 # Written by Jacob Alexander in 2014-2015 for the Kiibohd Controller
5 # Released into the Public Domain
11 # Check if KLL compiler is needed
14 if ( "${MacroModule}" STREQUAL "PartialMap" )
19 # KLL Installation (Make sure repo has been cloned)
22 if ( NOT EXISTS "${PROJECT_SOURCE_DIR}/kll/kll.py" )
23 message ( STATUS "Downloading latest kll version:" )
25 # Make sure git is available
26 find_package ( Git REQUIRED )
29 execute_process ( COMMAND ${GIT_EXECUTABLE} clone https://github.com/kiibohd/kll.git
30 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
32 elseif ( REFRESH_KLL ) # Otherwise attempt to update the repo
33 message ( STATUS "Checking for latest kll version:" )
36 execute_process ( COMMAND ${GIT_EXECUTABLE} pull --rebase
37 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/kll
39 endif () # kll/kll.py exists
44 # Prepare KLL layout arguments
47 #| KLL_DEPENDS is used to build a dependency tree for kll.py, this way when files are changed, kll.py gets re-run
49 #| Add each of the detected capabilities.kll
50 foreach ( filename ${ScanModule_KLL} ${MacroModule_KLL} ${OutputModule_KLL} ${DebugModule_KLL} )
51 set ( BaseMap_Args ${BaseMap_Args} ${filename} )
52 set ( KLL_DEPENDS ${KLL_DEPENDS} ${filename} )
55 #| If set BaseMap cannot be found, use default map
56 set ( pathname "${PROJECT_SOURCE_DIR}/${ScanModulePath}" )
58 string ( REPLACE " " ";" MAP_LIST ${BaseMap} ) # Change spaces to semicolons
59 foreach ( MAP ${MAP_LIST} )
60 # Only check the Scan Module for BaseMap .kll files, default to defaultMap.kll
61 if ( NOT EXISTS ${pathname}/${MAP}.kll )
62 set ( BaseMap_Args ${BaseMap_Args} ${pathname}/defaultMap.kll )
63 set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/defaultMap.kll )
64 elseif ( EXISTS "${pathname}/${MAP}.kll" )
65 set ( BaseMap_Args ${BaseMap_Args} ${pathname}/${MAP}.kll )
66 set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/${MAP}.kll )
68 message ( FATAL " Could not find '${MAP}.kll' BaseMap in Scan module directory" )
72 #| Configure DefaultMap if specified
73 if ( NOT "${DefaultMap}" STREQUAL "" )
74 set ( DefaultMap_Args -d )
76 string ( REPLACE " " ";" MAP_LIST ${DefaultMap} ) # Change spaces to semicolons
77 foreach ( MAP ${MAP_LIST} )
78 # Check if kll file is in build directory, otherwise default to layout directory
79 if ( EXISTS "${PROJECT_BINARY_DIR}/${MAP}.kll" )
80 set ( DefaultMap_Args ${DefaultMap_Args} ${MAP}.kll )
81 set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_BINARY_DIR}/${MAP}.kll )
82 elseif ( EXISTS "${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll" )
83 set ( DefaultMap_Args ${DefaultMap_Args} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll )
84 set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll )
86 message ( FATAL " Could not find '${MAP}.kll' DefaultMap" )
91 #| Configure PartialMaps if specified
92 if ( NOT "${PartialMaps}" STREQUAL "" )
93 # For each partial layer
94 foreach ( MAP ${PartialMaps} )
95 set ( PartialMap_Args ${PartialMap_Args} -p )
98 string ( REPLACE " " ";" MAP_LIST ${MAP} ) # Change spaces to semicolons
99 foreach ( MAP_PART ${MAP_LIST} )
100 # Check if kll file is in build directory, otherwise default to layout directory
101 if ( EXISTS "${PROJECT_BINARY_DIR}/${MAP_PART}.kll" )
102 set ( PartialMap_Args ${PartialMap_Args} ${MAP_PART}.kll )
103 set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_BINARY_DIR}/${MAP_PART}.kll )
104 elseif ( EXISTS "${PROJECT_SOURCE_DIR}/kll/layouts/${MAP_PART}.kll" )
105 set ( PartialMap_Args ${PartialMap_Args} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP_PART}.kll )
106 set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP_PART}.kll )
108 message ( FATAL " Could not find '${MAP_PART}.kll' PartialMap" )
115 #| Print list of layout sources used
116 message ( STATUS "Detected Layout Files:" )
117 foreach ( filename ${KLL_DEPENDS} )
118 message ( "${filename}" )
128 set ( kll_backend --backend kiibohd )
129 set ( kll_template --templates ${PROJECT_SOURCE_DIR}/kll/templates/kiibohdKeymap.h ${PROJECT_SOURCE_DIR}/kll/templates/kiibohdDefs.h )
130 set ( kll_outputname generatedKeymap.h kll_defs.h )
131 set ( kll_output --outputs ${kll_outputname} )
134 set ( kll_cmd ${PROJECT_SOURCE_DIR}/kll/kll.py ${BaseMap_Args} ${DefaultMap_Args} ${PartialMap_Args} ${kll_backend} ${kll_template} ${kll_output} )
135 add_custom_command ( OUTPUT ${kll_outputname}
137 DEPENDS ${KLL_DEPENDS}
138 COMMENT "Generating KLL Layout"
141 #| KLL Regen Convenience Target
142 add_custom_target ( kll_regen
144 COMMENT "Re-generating KLL Layout"
147 #| Append generated file to required sources so it becomes a dependency in the main build
148 set ( SRCS ${SRCS} ${kll_outputname} )
152 endif () # PartialMap