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 # Make sure git is available
24 find_package ( Git REQUIRED )
27 execute_process ( COMMAND ${GIT_EXECUTABLE} clone https://github.com/kiibohd/kll.git
28 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
30 endif () # kll/kll.py exists
35 # Prepare KLL layout arguments
38 #| KLL_DEPENDS is used to build a dependency tree for kll.py, this way when files are changed, kll.py gets re-run
40 #| Search for capabilities.kll in each module directory
41 foreach ( DIR ${ScanModulePath} ${MacroModulePath} ${OutputModulePath} ${DebugModulePath} )
42 # capabilities.kll exists, add to BaseMap
43 set ( filename "${PROJECT_SOURCE_DIR}/${DIR}/capabilities.kll" )
44 if ( EXISTS ${filename} )
45 set ( BaseMap_Args ${BaseMap_Args} ${filename} )
46 set ( KLL_DEPENDS ${KLL_DEPENDS} ${filename} )
50 #| If set BaseMap cannot be found, use default map
51 set ( pathname "${PROJECT_SOURCE_DIR}/${ScanModulePath}" )
52 if ( NOT EXISTS "${filename}/${BaseMap}.kll" )
53 set ( BaseMap_Args ${BaseMap_Args} ${pathname}/defaultMap.kll )
54 set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/defaultMap.kll )
56 set ( BaseMap_Args ${BaseMap_Args} ${pathname}/${BaseMap}.kll )
57 set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/${BaseMap}.kll )
60 #| Configure DefaultMap if specified
61 if ( NOT "${DefaultMap}" STREQUAL "" )
62 set ( DefaultMap_Args -d )
64 string ( REPLACE " " ";" MAP_LIST ${DefaultMap} ) # Change spaces to semicolons
65 foreach ( MAP ${MAP_LIST} )
66 # Check if kll file is in build directory, otherwise default to layout directory
67 if ( EXISTS "${PROJECT_BINARY_DIR}/${MAP}.kll" )
68 set ( DefaultMap_Args ${DefaultMap_Args} ${MAP}.kll )
69 set ( KLL_DEPENDS ${KLL_DEPENDS} ${MAP}.kll )
71 set ( DefaultMap_Args ${DefaultMap_Args} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll )
72 set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll )
77 #| Configure PartialMaps if specified
78 if ( NOT "${PartialMaps}" STREQUAL "" )
79 # For each partial layer
80 foreach ( MAP ${PartialMaps} )
81 set ( PartialMap_Args ${PartialMap_Args} -p )
84 string ( REPLACE " " ";" MAP_LIST ${MAP} ) # Change spaces to semicolons
85 foreach ( MAP_PART ${MAP_LIST} )
86 # Check if kll file is in build directory, otherwise default to layout directory
87 if ( EXISTS "${PROJECT_BINARY_DIR}/${MAP_PART}.kll" )
88 set ( PartialMap_Args ${PartialMap_Args} ${MAP_PART}.kll )
89 set ( KLL_DEPENDS ${KLL_DEPENDS} ${MAP_PART}.kll )
91 set ( PartialMap_Args ${PartialMap_Args} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP_PART}.kll )
92 set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP_PART}.kll )
105 set ( kll_backend -b kiibohd )
106 set ( kll_template -t ${PROJECT_SOURCE_DIR}/kll/templates/kiibohdKeymap.h )
107 set ( kll_outputname generatedKeymap.h )
108 set ( kll_output -o ${kll_outputname} )
111 set ( kll_cmd ${PROJECT_SOURCE_DIR}/kll/kll.py ${BaseMap_Args} ${DefaultMap_Args} ${PartialMap_Args} ${kll_backend} ${kll_template} ${kll_output} )
112 add_custom_command ( OUTPUT ${kll_outputname}
114 DEPENDS ${KLL_DEPENDS}
115 COMMENT "Generating KLL Layout"
118 #| Append generated file to required sources so it becomes a dependency in the main build
119 set ( SRCS ${SRCS} ${kll_outputname} )
123 endif () # PartialMap