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