]> git.donarmstrong.com Git - kiibohd-controller.git/blob - Lib/CMake/kll.cmake
Adding preliminary MDErgo keymap
[kiibohd-controller.git] / Lib / CMake / kll.cmake
1 ###| CMAKE Kiibohd Controller KLL Configurator |###
2 #
3 # Written by Jacob Alexander in 2014-2015 for the Kiibohd Controller
4 #
5 # Released into the Public Domain
6 #
7 ###
8
9
10 ###
11 # Check if KLL compiler is needed
12 #
13
14 if ( "${MacroModule}" STREQUAL "PartialMap" )
15
16
17
18 ###
19 # KLL Installation (Make sure repo has been cloned)
20 #
21
22 if ( NOT EXISTS "${PROJECT_SOURCE_DIR}/kll/kll.py" )
23         message ( STATUS "Downloading latest kll version:" )
24
25         # Make sure git is available
26         find_package ( Git REQUIRED )
27
28         # Clone kll git repo
29         execute_process ( COMMAND ${GIT_EXECUTABLE} clone https://github.com/kiibohd/kll.git
30                 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
31         )
32 elseif ( REFRESH_KLL ) # Otherwise attempt to update the repo
33         message ( STATUS "Checking for latest kll version:" )
34
35         # Clone kll git repo
36         execute_process ( COMMAND ${GIT_EXECUTABLE} pull --rebase
37                 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/kll
38         )
39 endif () # kll/kll.py exists
40
41
42
43 ###
44 # Prepare KLL layout arguments
45 #
46
47 #| KLL_DEPENDS is used to build a dependency tree for kll.py, this way when files are changed, kll.py gets re-run
48
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} )
53 endforeach ()
54
55 #| If set BaseMap cannot be found, use default map
56 set ( pathname "${PROJECT_SOURCE_DIR}/${ScanModulePath}" )
57
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         message("THIS -> ${pathname} ${MAP}")
62         if ( NOT EXISTS ${pathname}/${MAP}.kll )
63                 set ( BaseMap_Args ${BaseMap_Args} ${pathname}/defaultMap.kll )
64                 set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/defaultMap.kll )
65         elseif ( EXISTS "${pathname}/${MAP}.kll" )
66                 set ( BaseMap_Args ${BaseMap_Args} ${pathname}/${MAP}.kll )
67                 set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/${MAP}.kll )
68         else ()
69                 message ( FATAL " Could not find '${MAP}.kll' BaseMap in Scan module directory" )
70         endif ()
71 endforeach ()
72
73 #| Configure DefaultMap if specified
74 if ( NOT "${DefaultMap}" STREQUAL "" )
75         set ( DefaultMap_Args -d )
76
77         string ( REPLACE " " ";" MAP_LIST ${DefaultMap} ) # Change spaces to semicolons
78         foreach ( MAP ${MAP_LIST} )
79                 # Check if kll file is in build directory, otherwise default to layout directory
80                 if ( EXISTS "${PROJECT_BINARY_DIR}/${MAP}.kll" )
81                         set ( DefaultMap_Args ${DefaultMap_Args} ${MAP}.kll )
82                         set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_BINARY_DIR}/${MAP}.kll )
83                 elseif ( EXISTS "${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll" )
84                         set ( DefaultMap_Args ${DefaultMap_Args} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll )
85                         set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll )
86                 else ()
87                         message ( FATAL " Could not find '${MAP}.kll' DefaultMap" )
88                 endif ()
89         endforeach ()
90 endif ()
91
92 #| Configure PartialMaps if specified
93 if ( NOT "${PartialMaps}" STREQUAL "" )
94         # For each partial layer
95         foreach ( MAP ${PartialMaps} )
96                 set ( PartialMap_Args ${PartialMap_Args} -p )
97
98                 # Combine each layer
99                 string ( REPLACE " " ";" MAP_LIST ${MAP} ) # Change spaces to semicolons
100                 foreach ( MAP_PART ${MAP_LIST} )
101                         # Check if kll file is in build directory, otherwise default to layout directory
102                         if ( EXISTS "${PROJECT_BINARY_DIR}/${MAP_PART}.kll" )
103                                 set ( PartialMap_Args ${PartialMap_Args} ${MAP_PART}.kll )
104                                 set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_BINARY_DIR}/${MAP_PART}.kll )
105                         elseif ( EXISTS "${PROJECT_SOURCE_DIR}/kll/layouts/${MAP_PART}.kll" )
106                                 set ( PartialMap_Args ${PartialMap_Args} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP_PART}.kll )
107                                 set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP_PART}.kll )
108                         else ()
109                                 message ( FATAL " Could not find '${MAP_PART}.kll' PartialMap" )
110                         endif ()
111                 endforeach ()
112         endforeach ()
113 endif ()
114
115
116 #| Print list of layout sources used
117 message ( STATUS "Detected Layout Files:" )
118 foreach ( filename ${KLL_DEPENDS} )
119         message ( "${filename}" )
120 endforeach ()
121
122
123
124 ###
125 # Run KLL Compiler
126 #
127
128 #| KLL Options
129 set ( kll_backend   --backend kiibohd )
130 set ( kll_template  --templates ${PROJECT_SOURCE_DIR}/kll/templates/kiibohdKeymap.h ${PROJECT_SOURCE_DIR}/kll/templates/kiibohdDefs.h )
131 set ( kll_outputname generatedKeymap.h kll_defs.h )
132 set ( kll_output    --outputs ${kll_outputname} )
133
134 #| KLL Cmd
135 set ( kll_cmd ${PROJECT_SOURCE_DIR}/kll/kll.py ${BaseMap_Args} ${DefaultMap_Args} ${PartialMap_Args} ${kll_backend} ${kll_template} ${kll_output} )
136 add_custom_command ( OUTPUT ${kll_outputname}
137         COMMAND ${kll_cmd}
138         DEPENDS ${KLL_DEPENDS}
139         COMMENT "Generating KLL Layout"
140 )
141
142 #| KLL Regen Convenience Target
143 add_custom_target ( kll_regen
144         COMMAND ${kll_cmd}
145         COMMENT "Re-generating KLL Layout"
146 )
147
148 #| Append generated file to required sources so it becomes a dependency in the main build
149 set ( SRCS ${SRCS} ${kll_outputname} )
150
151
152
153 endif () # PartialMap
154