1 ###| CMAKE Kiibohd Controller KLL Configurator |###
3 # Written by Jacob Alexander in 2014 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 #| Search for capabilities.kll in each module directory
50 foreach ( DIR ${ScanModulePath} ${MacroModulePath} ${OutputModulePath} ${DebugModulePath} )
51 # capabilities.kll exists, add to BaseMap
52 set ( filename "${PROJECT_SOURCE_DIR}/${DIR}/capabilities.kll" )
53 if ( EXISTS ${filename} )
54 set ( BaseMap_Args ${BaseMap_Args} ${filename} )
55 set ( KLL_DEPENDS ${KLL_DEPENDS} ${filename} )
59 #| If set BaseMap cannot be found, use default map
60 set ( pathname "${PROJECT_SOURCE_DIR}/${ScanModulePath}" )
61 if ( NOT EXISTS ${pathname}/${BaseMap}.kll )
62 set ( BaseMap_Args ${BaseMap_Args} ${pathname}/defaultMap.kll )
63 set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/defaultMap.kll )
65 set ( BaseMap_Args ${BaseMap_Args} ${pathname}/${BaseMap}.kll )
66 set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/${BaseMap}.kll )
69 #| Configure DefaultMap if specified
70 if ( NOT "${DefaultMap}" STREQUAL "" )
71 set ( DefaultMap_Args -d )
73 string ( REPLACE " " ";" MAP_LIST ${DefaultMap} ) # Change spaces to semicolons
74 foreach ( MAP ${MAP_LIST} )
75 # Check if kll file is in build directory, otherwise default to layout directory
76 if ( EXISTS "${PROJECT_BINARY_DIR}/${MAP}.kll" )
77 set ( DefaultMap_Args ${DefaultMap_Args} ${MAP}.kll )
78 set ( KLL_DEPENDS ${KLL_DEPENDS} ${MAP}.kll )
80 set ( DefaultMap_Args ${DefaultMap_Args} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll )
81 set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll )
86 #| Configure PartialMaps if specified
87 if ( NOT "${PartialMaps}" STREQUAL "" )
88 # For each partial layer
89 foreach ( MAP ${PartialMaps} )
90 set ( PartialMap_Args ${PartialMap_Args} -p )
93 string ( REPLACE " " ";" MAP_LIST ${MAP} ) # Change spaces to semicolons
94 foreach ( MAP_PART ${MAP_LIST} )
95 # Check if kll file is in build directory, otherwise default to layout directory
96 if ( EXISTS "${PROJECT_BINARY_DIR}/${MAP_PART}.kll" )
97 set ( PartialMap_Args ${PartialMap_Args} ${MAP_PART}.kll )
98 set ( KLL_DEPENDS ${KLL_DEPENDS} ${MAP_PART}.kll )
100 set ( PartialMap_Args ${PartialMap_Args} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP_PART}.kll )
101 set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP_PART}.kll )
108 #| Print list of layout sources used
109 message ( STATUS "Detected Layout Files:" )
110 foreach ( filename ${KLL_DEPENDS} )
111 message ( "${filename}" )
121 set ( kll_backend -b kiibohd )
122 set ( kll_template -t ${PROJECT_SOURCE_DIR}/kll/templates/kiibohdKeymap.h )
123 set ( kll_outputname generatedKeymap.h )
124 set ( kll_output -o ${kll_outputname} )
125 set ( kll_define_output --defines-output kll_defs.h )
126 set ( kll_define_template --defines-template ${PROJECT_SOURCE_DIR}/kll/templates/kiibohdDefs.h )
129 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} )
130 add_custom_command ( OUTPUT ${kll_outputname}
132 DEPENDS ${KLL_DEPENDS}
133 COMMENT "Generating KLL Layout"
136 #| Append generated file to required sources so it becomes a dependency in the main build
137 set ( SRCS ${SRCS} ${kll_outputname} )
141 endif () # PartialMap