2014-09-14 22:51:36 +00:00
|
|
|
###| CMAKE Kiibohd Controller KLL Configurator |###
|
|
|
|
#
|
2016-08-31 04:56:30 +00:00
|
|
|
# Written by Jacob Alexander in 2014-2016 for the Kiibohd Controller
|
2014-09-14 22:51:36 +00:00
|
|
|
#
|
|
|
|
# Released into the Public Domain
|
|
|
|
#
|
|
|
|
###
|
|
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
# Check if KLL compiler is needed
|
|
|
|
#
|
|
|
|
|
|
|
|
if ( "${MacroModule}" STREQUAL "PartialMap" )
|
|
|
|
|
|
|
|
|
2016-08-31 03:03:21 +00:00
|
|
|
###
|
|
|
|
# Python 3 is required for kll
|
2016-08-31 08:09:44 +00:00
|
|
|
# Check disabled for Win32 as it can't detect version correctly (we don't use Python directly through CMake anyways)
|
2016-08-31 03:03:21 +00:00
|
|
|
#
|
2016-08-31 08:09:44 +00:00
|
|
|
|
2016-10-11 05:31:53 +00:00
|
|
|
if ( NOT CMAKE_HOST_WIN32 )
|
2016-08-31 08:09:44 +00:00
|
|
|
# Required on systems where python is 2, not 3
|
|
|
|
set ( PYTHON_EXECUTABLE
|
|
|
|
python3
|
|
|
|
CACHE STRING "Python 3 Executable Path"
|
|
|
|
)
|
|
|
|
find_package ( PythonInterp 3 REQUIRED )
|
|
|
|
endif ()
|
2016-08-31 03:03:21 +00:00
|
|
|
|
2014-09-14 22:51:36 +00:00
|
|
|
|
|
|
|
###
|
|
|
|
# KLL Installation (Make sure repo has been cloned)
|
|
|
|
#
|
|
|
|
|
|
|
|
if ( NOT EXISTS "${PROJECT_SOURCE_DIR}/kll/kll.py" )
|
2015-02-09 20:14:45 +00:00
|
|
|
message ( STATUS "Downloading latest kll version:" )
|
|
|
|
|
2014-09-14 22:51:36 +00:00
|
|
|
# Make sure git is available
|
|
|
|
find_package ( Git REQUIRED )
|
|
|
|
|
|
|
|
# Clone kll git repo
|
|
|
|
execute_process ( COMMAND ${GIT_EXECUTABLE} clone https://github.com/kiibohd/kll.git
|
|
|
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
|
|
|
)
|
2015-02-09 20:14:45 +00:00
|
|
|
elseif ( REFRESH_KLL ) # Otherwise attempt to update the repo
|
|
|
|
message ( STATUS "Checking for latest kll version:" )
|
|
|
|
|
2014-09-14 23:03:10 +00:00
|
|
|
# Clone kll git repo
|
|
|
|
execute_process ( COMMAND ${GIT_EXECUTABLE} pull --rebase
|
|
|
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/kll
|
|
|
|
)
|
2014-09-14 22:51:36 +00:00
|
|
|
endif () # kll/kll.py exists
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
# Prepare KLL layout arguments
|
|
|
|
#
|
|
|
|
|
|
|
|
#| KLL_DEPENDS is used to build a dependency tree for kll.py, this way when files are changed, kll.py gets re-run
|
|
|
|
|
2015-03-01 06:13:17 +00:00
|
|
|
#| 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} )
|
2014-09-14 22:51:36 +00:00
|
|
|
endforeach ()
|
|
|
|
|
|
|
|
#| If set BaseMap cannot be found, use default map
|
|
|
|
set ( pathname "${PROJECT_SOURCE_DIR}/${ScanModulePath}" )
|
2015-08-06 07:36:37 +00:00
|
|
|
|
|
|
|
string ( REPLACE " " ";" MAP_LIST ${BaseMap} ) # Change spaces to semicolons
|
|
|
|
foreach ( MAP ${MAP_LIST} )
|
2016-07-06 16:00:57 +00:00
|
|
|
# Only check the Scan Module for BaseMap .kll files, default to scancode_map.kll or defaultMap.kll
|
2015-08-06 07:36:37 +00:00
|
|
|
if ( NOT EXISTS ${pathname}/${MAP}.kll )
|
2016-07-06 16:00:57 +00:00
|
|
|
if ( EXISTS ${pathname}/scancode_map.kll )
|
|
|
|
set ( BaseMap_Args ${BaseMap_Args} ${pathname}/scancode_map.kll )
|
|
|
|
set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/scancode_map.kll )
|
|
|
|
else ()
|
|
|
|
set ( BaseMap_Args ${BaseMap_Args} ${pathname}/defaultMap.kll )
|
|
|
|
set ( KLL_DEPENDS ${KLL_DEPENDS} ${pathname}/defaultMap.kll )
|
|
|
|
endif ()
|
2015-08-06 07:36:37 +00:00
|
|
|
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 ()
|
2014-09-14 22:51:36 +00:00
|
|
|
|
|
|
|
#| Configure DefaultMap if specified
|
|
|
|
if ( NOT "${DefaultMap}" STREQUAL "" )
|
|
|
|
set ( DefaultMap_Args -d )
|
|
|
|
|
|
|
|
string ( REPLACE " " ";" MAP_LIST ${DefaultMap} ) # Change spaces to semicolons
|
|
|
|
foreach ( MAP ${MAP_LIST} )
|
|
|
|
# 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 )
|
2015-05-07 10:17:58 +00:00
|
|
|
set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_BINARY_DIR}/${MAP}.kll )
|
2015-05-09 20:36:37 +00:00
|
|
|
elseif ( EXISTS "${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll" )
|
2014-09-14 22:51:36 +00:00
|
|
|
set ( DefaultMap_Args ${DefaultMap_Args} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll )
|
|
|
|
set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll )
|
2015-05-09 20:36:37 +00:00
|
|
|
else ()
|
2015-08-06 07:36:37 +00:00
|
|
|
message ( FATAL " Could not find '${MAP}.kll' DefaultMap" )
|
2014-09-14 22:51:36 +00:00
|
|
|
endif ()
|
|
|
|
endforeach ()
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
#| Configure PartialMaps if specified
|
|
|
|
if ( NOT "${PartialMaps}" STREQUAL "" )
|
|
|
|
# For each partial layer
|
|
|
|
foreach ( MAP ${PartialMaps} )
|
|
|
|
set ( PartialMap_Args ${PartialMap_Args} -p )
|
|
|
|
|
|
|
|
# Combine each layer
|
|
|
|
string ( REPLACE " " ";" MAP_LIST ${MAP} ) # Change spaces to semicolons
|
|
|
|
foreach ( MAP_PART ${MAP_LIST} )
|
|
|
|
# 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 )
|
2015-05-07 10:17:58 +00:00
|
|
|
set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_BINARY_DIR}/${MAP_PART}.kll )
|
2015-05-09 20:36:37 +00:00
|
|
|
elseif ( EXISTS "${PROJECT_SOURCE_DIR}/kll/layouts/${MAP_PART}.kll" )
|
2014-09-14 22:51:36 +00:00
|
|
|
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 )
|
2015-05-09 20:36:37 +00:00
|
|
|
else ()
|
2015-08-06 07:36:37 +00:00
|
|
|
message ( FATAL " Could not find '${MAP_PART}.kll' PartialMap" )
|
2014-09-14 22:51:36 +00:00
|
|
|
endif ()
|
|
|
|
endforeach ()
|
|
|
|
endforeach ()
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
|
2014-09-14 23:03:10 +00:00
|
|
|
#| Print list of layout sources used
|
|
|
|
message ( STATUS "Detected Layout Files:" )
|
|
|
|
foreach ( filename ${KLL_DEPENDS} )
|
|
|
|
message ( "${filename}" )
|
|
|
|
endforeach ()
|
|
|
|
|
|
|
|
|
2014-09-14 22:51:36 +00:00
|
|
|
|
|
|
|
###
|
|
|
|
# Run KLL Compiler
|
|
|
|
#
|
|
|
|
|
|
|
|
#| KLL Options
|
2015-02-22 07:21:59 +00:00
|
|
|
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} )
|
2014-09-14 22:51:36 +00:00
|
|
|
|
|
|
|
#| KLL Cmd
|
2015-02-22 07:21:59 +00:00
|
|
|
set ( kll_cmd ${PROJECT_SOURCE_DIR}/kll/kll.py ${BaseMap_Args} ${DefaultMap_Args} ${PartialMap_Args} ${kll_backend} ${kll_template} ${kll_output} )
|
2014-09-14 22:51:36 +00:00
|
|
|
add_custom_command ( OUTPUT ${kll_outputname}
|
|
|
|
COMMAND ${kll_cmd}
|
|
|
|
DEPENDS ${KLL_DEPENDS}
|
|
|
|
COMMENT "Generating KLL Layout"
|
|
|
|
)
|
|
|
|
|
2015-02-16 21:27:42 +00:00
|
|
|
#| KLL Regen Convenience Target
|
|
|
|
add_custom_target ( kll_regen
|
|
|
|
COMMAND ${kll_cmd}
|
|
|
|
COMMENT "Re-generating KLL Layout"
|
|
|
|
)
|
|
|
|
|
2014-09-14 22:51:36 +00:00
|
|
|
#| Append generated file to required sources so it becomes a dependency in the main build
|
|
|
|
set ( SRCS ${SRCS} ${kll_outputname} )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
endif () # PartialMap
|
|
|
|
|