]> git.donarmstrong.com Git - kiibohd-controller.git/blobdiff - Lib/CMake/kll.cmake
Adding preliminary MDErgo keymap
[kiibohd-controller.git] / Lib / CMake / kll.cmake
index 2e53ddd815bd7077a205c07d55eadac12148f586..f41b92a1b93550fa3e50bba0ae47736507f04d24 100644 (file)
@@ -1,6 +1,6 @@
 ###| CMAKE Kiibohd Controller KLL Configurator |###
 #
-# Written by Jacob Alexander in 2014 for the Kiibohd Controller
+# Written by Jacob Alexander in 2014-2015 for the Kiibohd Controller
 #
 # Released into the Public Domain
 #
@@ -19,9 +19,9 @@ if ( "${MacroModule}" STREQUAL "PartialMap" )
 # KLL Installation (Make sure repo has been cloned)
 #
 
-message ( STATUS "Checking for latest kll version:" )
-
 if ( NOT EXISTS "${PROJECT_SOURCE_DIR}/kll/kll.py" )
+       message ( STATUS "Downloading latest kll version:" )
+
        # Make sure git is available
        find_package ( Git REQUIRED )
 
@@ -29,7 +29,9 @@ if ( NOT EXISTS "${PROJECT_SOURCE_DIR}/kll/kll.py" )
        execute_process ( COMMAND ${GIT_EXECUTABLE} clone https://github.com/kiibohd/kll.git
                WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
        )
-else () # Otherwise attempt to update the repo
+elseif ( REFRESH_KLL ) # Otherwise attempt to update the repo
+       message ( STATUS "Checking for latest kll version:" )
+
        # Clone kll git repo
        execute_process ( COMMAND ${GIT_EXECUTABLE} pull --rebase
                WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/kll
@@ -44,25 +46,29 @@ endif () # kll/kll.py exists
 
 #| KLL_DEPENDS is used to build a dependency tree for kll.py, this way when files are changed, kll.py gets re-run
 
-#| Search for capabilities.kll in each module directory
-foreach ( DIR ${ScanModulePath} ${MacroModulePath} ${OutputModulePath} ${DebugModulePath} )
-       # capabilities.kll exists, add to BaseMap
-       set ( filename "${PROJECT_SOURCE_DIR}/${DIR}/capabilities.kll" )
-       if ( EXISTS ${filename} )
-               set ( BaseMap_Args ${BaseMap_Args} ${filename} )
-               set ( KLL_DEPENDS ${KLL_DEPENDS} ${filename} )
-       endif ()
+#| Add each of the detected capabilities.kll
+foreach ( filename ${ScanModule_KLL} ${MacroModule_KLL} ${OutputModule_KLL} ${DebugModule_KLL} )
+       set ( BaseMap_Args ${BaseMap_Args} ${filename} )
+       set ( KLL_DEPENDS ${KLL_DEPENDS} ${filename} )
 endforeach ()
 
 #| If set BaseMap cannot be found, use default map
 set ( pathname "${PROJECT_SOURCE_DIR}/${ScanModulePath}" )
-if ( NOT EXISTS ${pathname}/${BaseMap}.kll )
-       set ( BaseMap_Args ${BaseMap_Args} ${pathname}/defaultMap.kll )
-       set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/defaultMap.kll )
-else ()
-       set ( BaseMap_Args ${BaseMap_Args} ${pathname}/${BaseMap}.kll )
-       set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/${BaseMap}.kll )
-endif ()
+
+string ( REPLACE " " ";" MAP_LIST ${BaseMap} ) # Change spaces to semicolons
+foreach ( MAP ${MAP_LIST} )
+       # Only check the Scan Module for BaseMap .kll files, default to defaultMap.kll
+       message("THIS -> ${pathname} ${MAP}")
+       if ( NOT EXISTS ${pathname}/${MAP}.kll )
+               set ( BaseMap_Args ${BaseMap_Args} ${pathname}/defaultMap.kll )
+               set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/defaultMap.kll )
+       elseif ( EXISTS "${pathname}/${MAP}.kll" )
+               set ( BaseMap_Args ${BaseMap_Args} ${pathname}/${MAP}.kll )
+               set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/${MAP}.kll )
+       else ()
+               message ( FATAL " Could not find '${MAP}.kll' BaseMap in Scan module directory" )
+       endif ()
+endforeach ()
 
 #| Configure DefaultMap if specified
 if ( NOT "${DefaultMap}" STREQUAL "" )
@@ -73,10 +79,12 @@ if ( NOT "${DefaultMap}" STREQUAL "" )
                # Check if kll file is in build directory, otherwise default to layout directory
                if ( EXISTS "${PROJECT_BINARY_DIR}/${MAP}.kll" )
                        set ( DefaultMap_Args ${DefaultMap_Args} ${MAP}.kll )
-                       set ( KLL_DEPENDS ${KLL_DEPENDS} ${MAP}.kll )
-               else ()
+                       set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_BINARY_DIR}/${MAP}.kll )
+               elseif ( EXISTS "${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll" )
                        set ( DefaultMap_Args ${DefaultMap_Args} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll )
                        set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll )
+               else ()
+                       message ( FATAL " Could not find '${MAP}.kll' DefaultMap" )
                endif ()
        endforeach ()
 endif ()
@@ -93,10 +101,12 @@ if ( NOT "${PartialMaps}" STREQUAL "" )
                        # Check if kll file is in build directory, otherwise default to layout directory
                        if ( EXISTS "${PROJECT_BINARY_DIR}/${MAP_PART}.kll" )
                                set ( PartialMap_Args ${PartialMap_Args} ${MAP_PART}.kll )
-                               set ( KLL_DEPENDS ${KLL_DEPENDS} ${MAP_PART}.kll )
-                       else ()
+                               set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_BINARY_DIR}/${MAP_PART}.kll )
+                       elseif ( EXISTS "${PROJECT_SOURCE_DIR}/kll/layouts/${MAP_PART}.kll" )
                                set ( PartialMap_Args ${PartialMap_Args} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP_PART}.kll )
                                set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP_PART}.kll )
+                       else ()
+                               message ( FATAL " Could not find '${MAP_PART}.kll' PartialMap" )
                        endif ()
                endforeach ()
        endforeach ()
@@ -116,21 +126,25 @@ endforeach ()
 #
 
 #| KLL Options
-set ( kll_backend   -b kiibohd )
-set ( kll_template  -t ${PROJECT_SOURCE_DIR}/kll/templates/kiibohdKeymap.h )
-set ( kll_outputname generatedKeymap.h )
-set ( kll_output    -o ${kll_outputname} )
-set ( kll_define_output   --defines-output kll_defs.h )
-set ( kll_define_template --defines-template ${PROJECT_SOURCE_DIR}/kll/templates/kiibohdDefs.h )
+set ( kll_backend   --backend kiibohd )
+set ( kll_template  --templates ${PROJECT_SOURCE_DIR}/kll/templates/kiibohdKeymap.h ${PROJECT_SOURCE_DIR}/kll/templates/kiibohdDefs.h )
+set ( kll_outputname generatedKeymap.h kll_defs.h )
+set ( kll_output    --outputs ${kll_outputname} )
 
 #| KLL Cmd
-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} )
+set ( kll_cmd ${PROJECT_SOURCE_DIR}/kll/kll.py ${BaseMap_Args} ${DefaultMap_Args} ${PartialMap_Args} ${kll_backend} ${kll_template} ${kll_output} )
 add_custom_command ( OUTPUT ${kll_outputname}
        COMMAND ${kll_cmd}
        DEPENDS ${KLL_DEPENDS}
        COMMENT "Generating KLL Layout"
 )
 
+#| KLL Regen Convenience Target
+add_custom_target ( kll_regen
+       COMMAND ${kll_cmd}
+       COMMENT "Re-generating KLL Layout"
+)
+
 #| Append generated file to required sources so it becomes a dependency in the main build
 set ( SRCS ${SRCS} ${kll_outputname} )