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