]> git.donarmstrong.com Git - kiibohd-controller.git/blob - Lib/CMake/kll.cmake
Adding CMake build support for the KLL compiler
[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 endif () # kll/kll.py exists
31
32
33
34 ###
35 # Prepare KLL layout arguments
36 #
37
38 #| KLL_DEPENDS is used to build a dependency tree for kll.py, this way when files are changed, kll.py gets re-run
39
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} )
47         endif ()
48 endforeach ()
49
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 )
55 else ()
56         set ( BaseMap_Args ${BaseMap_Args} ${pathname}/${BaseMap}.kll )
57         set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/${BaseMap}.kll )
58 endif ()
59
60 #| Configure DefaultMap if specified
61 if ( NOT "${DefaultMap}" STREQUAL "" )
62         set ( DefaultMap_Args -d )
63
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 )
70                 else ()
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 )
73                 endif ()
74         endforeach ()
75 endif ()
76
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 )
82
83                 # Combine each layer
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 )
90                         else ()
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 )
93                         endif ()
94                 endforeach ()
95         endforeach ()
96 endif ()
97
98
99
100 ###
101 # Run KLL Compiler
102 #
103
104 #| KLL Options
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} )
109
110 #| KLL Cmd
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}
113         COMMAND ${kll_cmd}
114         DEPENDS ${KLL_DEPENDS}
115         COMMENT "Generating KLL Layout"
116 )
117
118 #| Append generated file to required sources so it becomes a dependency in the main build
119 set ( SRCS ${SRCS} ${kll_outputname} )
120
121
122
123 endif () # PartialMap
124