Skip to content

Commit

Permalink
Adding CMake build support for the KLL compiler
Browse files Browse the repository at this point in the history
- Automatically downloads the kll compiler if not found
- Added capability files to each of the module that currently have them
- Split modules.cmake so kll.cmake could influence build targets (also needs info from modules.cmake)
- Updated .gitignore for kll compiler directory
- Added documentation on how to manipulate layouts using CMakeLists.txt
- Cleanup of old layout files
  • Loading branch information
haata committed Sep 14, 2014
1 parent cb37c82 commit e0a2a48
Show file tree
Hide file tree
Showing 11 changed files with 357 additions and 563 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ CMakeFiles
CMakeCache.txt
cmake_install.cmake

# External Repos #
##################
kll

41 changes: 32 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,41 @@ set( DebugModule "full" )


###
# Keymap Configuration (XXX - Not worky yet, currently ignored)
# Keymap Configuration (do not include the .kll extension)
#

##| If there are multiple DefaultMaps, it is defined here. If, the specified DefaultMap is not found, defaultMap.h is used.
set( DefaultMap "kishsaver" )
#| Do not include the .kll extension
#| * BaseMap maps the native keyboard scan codes to USB Codes so the layout is compatible with all other layouts
#| * DefaultMap allows the default keymap to be modified from the BaseMap
#| * PartialMaps is a set of dynamically set layers (there is no limit, but too many may use up too much RAM...)
#| BaseMap generally does not need to be changed from "defaultMap"
#|
#| Syntax:
#| myMap
#| * defines a single .kll layout file, double-quotes are needed to distinguish between layers
#| "myMap specialLayer"
#| * defines myMap to be the main layout, then replace specialLayers on top of it
#|
#| - Only for PartialMaps -
#| "myMap specialLayer" "myMap colemak" dvorak
#| * As before, but also generates a second layer at index 2 and third at index 3
#|
#| NOTE: Remember to add key(s) to enable each Partial Layer
#| NOTE2: Layers are always based up the BaseMap (which should be an ANSI-like mapping)
#| NOTE3: Compiler looks in kll/layouts and the build directory for layout files (precedence on build directory)

##| PartialMap combined keymap layering. The first keymap has the "least" precedence.
set( CombinedMap colemak capslock2ctrl )
##| Set the base keyboard .kll map, defaults to "defaultMap" if not found
##| Looks in Scan/<Module Name> for the available BaseMaps
##| TODO Support layering in basemap
set( BaseMap "defaultMap" )

##| ParitalMaps available on top of the CombinedMap. If there are input conflicts, the last PartialMap takes precedence.
set( PartialMaps hhkbnav kbdctrl )
##| Layer additonal .kll maps on the BaseMap, layers are in order from 1st to nth
##| Can be set to ""
set( DefaultMap "colemak stdFuncMap" )

##| MacroSets define extra capabilities that are not provided by the Scan or Output modules. Last MacroSet takes precedence.
set( MacroSets retype )
##| ParitalMaps available on top of the BaseMap. See above for syntax on specifying multiple layers vs. layering
##| Can be set to ""
set( PartialMaps "hhkbpro2" )



Expand Down Expand Up @@ -107,4 +128,6 @@ cmake_minimum_required( VERSION 2.8 )
# Module Initialization / Compilation / Targets
#
include( Lib/CMake/modules.cmake )
include( Lib/CMake/kll.cmake ) # Generate kll layouts if necessary
include( Lib/CMake/build.cmake )

81 changes: 81 additions & 0 deletions Lib/CMake/build.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
###| CMAKE Kiibohd Controller Source Configurator |###
#
# Written by Jacob Alexander in 2011-2014 for the Kiibohd Controller
#
# Released into the Public Domain
#
###



###
# Build Targets
#

#| Create the .ELF file
set( TARGET_ELF ${TARGET}.elf )
add_executable( ${TARGET_ELF} ${SRCS} generatedKeymap.h )


#| .ELF Properties
set_target_properties( ${TARGET_ELF} PROPERTIES
LINK_FLAGS ${LINKER_FLAGS}
SUFFIX "" # XXX Force Windows to keep the .exe off
)


#| Convert the .ELF into a .bin to load onto the McHCK
if( DEFINED DFU )
set( TARGET_BIN ${TARGET}.dfu.bin )
add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} ${BIN_FLAGS} ${TARGET_ELF} ${TARGET_BIN}
COMMENT "Creating dfu binary file: ${TARGET_BIN}"
)
endif()


#| Convert the .ELF into a .HEX to load onto the Teensy
if ( DEFINED TEENSY )
set( TARGET_HEX ${TARGET}.teensy.hex )
add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} ${HEX_FLAGS} ${TARGET_ELF} ${TARGET_HEX}
COMMENT "Creating iHex file to load: ${TARGET_HEX}"
)
endif()


#| Generate the Extended .LSS
set( TARGET_LSS ${TARGET}.lss )
add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
COMMAND ${CMAKE_OBJDUMP} ${LSS_FLAGS} ${TARGET_ELF} > ${TARGET_LSS}
COMMENT "Creating Extended Listing: ${TARGET_LSS}"
)


#| Generate the Symbol Table .SYM
set( TARGET_SYM ${TARGET}.sym )
add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
COMMAND ${CMAKE_NM} -n ${TARGET_ELF} > ${TARGET_SYM}
COMMENT "Creating Symbol Table: ${TARGET_SYM}"
)


#| Compiler Selection Record
add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
COMMAND ${CMAKE_SOURCE_DIR}/Lib/CMake/writer compiler ${COMPILER_FAMILY}
)



###
# Size Information
#

#| After Changes Size Information
add_custom_target( SizeAfter ALL
COMMAND ${CMAKE_SOURCE_DIR}/Lib/CMake/sizeCalculator ${CMAKE_SIZE} ram ${TARGET_ELF} ${SIZE_RAM} " SRAM"
COMMAND ${CMAKE_SOURCE_DIR}/Lib/CMake/sizeCalculator ${CMAKE_SIZE} flash ${TARGET_ELF} ${SIZE_FLASH} "Flash"
DEPENDS ${TARGET_ELF}
COMMENT "Chip usage for ${CHIP}"
)

124 changes: 124 additions & 0 deletions Lib/CMake/kll.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
###| CMAKE Kiibohd Controller KLL Configurator |###
#
# Written by Jacob Alexander in 2014 for the Kiibohd Controller
#
# Released into the Public Domain
#
###


###
# Check if KLL compiler is needed
#

if ( "${MacroModule}" STREQUAL "PartialMap" )



###
# KLL Installation (Make sure repo has been cloned)
#

if ( NOT EXISTS "${PROJECT_SOURCE_DIR}/kll/kll.py" )
# 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}
)
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

#| 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 ()
endforeach ()

#| If set BaseMap cannot be found, use default map
set ( pathname "${PROJECT_SOURCE_DIR}/${ScanModulePath}" )
if ( NOT EXISTS "${filename}/${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 ()

#| 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 )
set ( KLL_DEPENDS ${KLL_DEPENDS} ${MAP}.kll )
else ()
set ( DefaultMap_Args ${DefaultMap_Args} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll )
set ( KLL_DEPENDS ${KLL_DEPENDS} ${PROJECT_SOURCE_DIR}/kll/layouts/${MAP}.kll )
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 )
set ( KLL_DEPENDS ${KLL_DEPENDS} ${MAP_PART}.kll )
else ()
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 )
endif ()
endforeach ()
endforeach ()
endif ()



###
# Run KLL Compiler
#

#| 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} )

#| KLL Cmd
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"
)

#| Append generated file to required sources so it becomes a dependency in the main build
set ( SRCS ${SRCS} ${kll_outputname} )



endif () # PartialMap

Loading

0 comments on commit e0a2a48

Please sign in to comment.