Browse Source

Reorganizing CMake build system.

- Only one file to edit now
- Compiler architecture automatically detected based off of chip target
simple
Jacob Alexander 10 years ago
parent
commit
38266ca2cc
6 changed files with 220 additions and 232 deletions
  1. 53
    114
      CMakeLists.txt
  2. 0
    4
      Lib/CMake/arm.cmake
  3. 2
    4
      Lib/CMake/avr.cmake
  4. 42
    0
      Lib/CMake/initialize.cmake
  5. 107
    42
      Lib/CMake/modules.cmake
  6. 16
    68
      README

+ 53
- 114
CMakeLists.txt View File

@@ -7,163 +7,102 @@
#
###

#| Windows / Cygwin Compatibility options
set( CMAKE_LEGACY_CYGWIN_WIN32 0 )
set( CMAKE_USE_RELATIVE_PATHS 1 )



###
# Compiler Family
# Chip Selection
#

#| Specify the compiler family to use
#| Currently only supports AVR and ARM
#| "avr" # Teensy 1.0
#| "avr" # Teensy 2.0
#| "avr" # Teensy++ 1.0
#| "avr" # Teensy++ 2.0
#| "arm" # Teensy 3.0
#| "arm" # Teensy 3.1
#set( COMPILER_FAMILY "arm" )
set( COMPILER_FAMILY "avr" )

message( STATUS "Compiler Family:" )
message( "${COMPILER_FAMILY}" )



#| Load the compiler family specific configurations
include( ${COMPILER_FAMILY}.cmake )

#| Binutils not set by CMake
set( CMAKE_SIZE "${_CMAKE_TOOLCHAIN_PREFIX}size" )
#| You _MUST_ set this to match the microcontroller you are trying to compile for
#| You _MUST_ clean the build directory if you change this value
#|
set( CHIP
# "at90usb162" # Teensy 1.0 (avr)
# "atmega32u4" # Teensy 2.0 (avr)
# "at90usb646" # Teensy++ 1.0 (avr)
"at90usb1286" # Teensy++ 2.0 (avr)
# "mk20dx128" # Teensy 3.0 (arm)
# "mk20dx256" # Teensy 3.1 (arm)
)



###
# Project Description
# Compiler Intialization
#

#| Project
project( kiibohd_controller )

#| Target Name (output name)
set( TARGET kiibohd )

#| General Settings
cmake_minimum_required( VERSION 2.8 )
include( Lib/CMake/initialize.cmake )



###
# Source Defines
# Project Modules
#

#| Sources (see setup.h for configuring in/away code blocks or other complete modules)
#| XXX Not set here in this project, see setup.cmake
#set( SRCS ./main.c )

#| Instead, include the module source selector
include( setup.cmake )
set( SRCS
main.c
${COMPILER_SRCS}
${SCAN_SRCS}
${MACRO_SRCS}
${OUTPUT_SRCS}
${DEBUG_SRCS}
)

#| Directories to include by default
include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )
#| Note: This is the only section you probably want to modify
#| Each module is defined by it's own folder (e.g. Scan/Matrix represents the "Matrix" module)
#| All of the modules must be specified, as they generate the sources list of files to compile
#| Any modifications to this file will cause a complete rebuild of the project

#| Please look at the {Scan,Macro,USB,Debug}/module.txt for information on the modules and how to create new ones

##| Deals with acquiring the keypress information and turning it into a key index
set( ScanModule "DPH" )

###
# Module Compatibility Check
#

#| Check for whether the set modules are compatible with the specified compiler family
ModuleCompatibility( ${ScanModulePath} ${ScanModuleCompatibility} )
ModuleCompatibility( ${MacroModulePath} ${MacroModuleCompatibility} )
ModuleCompatibility( ${OutputModulePath} ${OutputModuleCompatibility} )
ModuleCompatibility( ${DebugModulePath} ${DebugModuleCompatibility} )
##| Provides the mapping functions for DefaultMap and handles any macro processing before sending to the OutputModule
set( MacroModule "PartialMap" )

##| Sends the current list of usb key codes through USB HID
set( OutputModule "pjrcUSB" )

##| Debugging source to use, each module has it's own set of defines that it sets
set( DebugModule "full" )

###
# CMake Module Checking
#
find_package( Git REQUIRED )


###
# Build Targets
# Keymap Configuration (XXX - Not worky yet, currently ignored)
#

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


#| .ELF Properties
set_target_properties( ${TARGET_ELF} PROPERTIES
LINK_FLAGS ${LINKER_FLAGS}
SUFFIX "" # XXX Force Windows to keep the .exe off
)
##| If there are multiple DefaultMaps, it is defined here. If, the specified DefaultMap is not found, defaultMap.h is used.
set( DefaultMap "kishsaver" )

##| PartialMap combined keymap layering. The first keymap has the "least" precedence.
set( CombinedMap colemak capslock2ctrl )

#| Convert the .ELF into a .HEX to load onto the Teensy
set( TARGET_HEX ${TARGET}.hex )
add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} ${HEX_FLAGS} ${TARGET_ELF} ${TARGET_HEX}
COMMENT "Creating load file for Flash: ${TARGET_HEX}"
)
##| ParitalMaps available on top of the CombinedMap. If there are input conflicts, the last PartialMap takes precedence.
set( PartialMaps hhkbnav kbdctrl )

##| MacroSets define extra capabilities that are not provided by the Scan or Output modules. Last MacroSet takes precedence.
set( MacroSets retype )

#| 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}"
###
# Source Defines (in addition to the selected Modules)
#
set( MAIN_SRCS
main.c
)



###
# Size Information
# Project Description
#

#| After Changes Size Information
#| TODO Do lookup on Flash and RAM sizes and do % used
add_custom_target( SizeAfter ALL
COMMAND ${CMAKE_SIZE} --target=${FORMAT} ${TARGET_HEX} ${TARGET_ELF}
DEPENDS ${TARGET_ELF}
COMMENT "Size after generation\n\tFlash Usage: data (hex)\n\t RAM Usage: data (elf)"
)
#| Project
project( kiibohd_controller )

#| Target Name (output name)
set( TARGET kiibohd )

#| General Settings
cmake_minimum_required( VERSION 2.8 )

###
# Setup Loader Script and Program
#


#| Provides the user with the correct teensy-loader-cli command for the built .HEX file
#| Windows
if( CMAKE_SYSTEM_NAME MATCHES "Windows" )
configure_file( LoadFile/winload load NEWLINE_STYLE UNIX )
#| Default
else()
configure_file( LoadFile/load load NEWLINE_STYLE UNIX )
endif()
###
# Module Initialization / Compilation / Targets
#
include( Lib/CMake/modules.cmake )


arm.cmake → Lib/CMake/arm.cmake View File

@@ -24,13 +24,9 @@ set( _CMAKE_TOOLCHAIN_PREFIX arm-none-eabi- )
#

#| Chip Name (Linker)
#| You _MUST_ set this to match the board you are using
#| type "make clean" after changing this, so all files will be rebuilt
#|
#| "mk20dx128" # Teensy 3.0
#| "mk20dx256" # Teensy 3.1
#set( CHIP "mk20dx128" )
set( CHIP "mk20dx256" )

message( STATUS "Chip Selected:" )
message( "${CHIP}" )

avr.cmake → Lib/CMake/avr.cmake View File

@@ -24,15 +24,13 @@ set( _CMAKE_TOOLCHAIN_PREFIX avr- )
#

#| MCU Name
#| You _MUST_ set this to match the board you are using
#| type "make clean" after changing this, so all files will be rebuilt
#|
#| "at90usb162" # Teensy 1.0
#| "atmega32u4" # Teensy 2.0
#| "at90usb646" # Teensy++ 1.0
#| "at90usb1286" # Teensy++ 2.0
#set( MCU "atmega32u4" )
set( MCU "at90usb1286" )
set( MCU "${CHIP}" )

message( STATUS "MCU Selected:" )
message( "${MCU}" )

+ 42
- 0
Lib/CMake/initialize.cmake View File

@@ -0,0 +1,42 @@
###| CMAKE Kiibohd Controller Initialization |###
#
# Written by Jacob Alexander in 2011-2014 for the Kiibohd Controller
#
# Released into the Public Domain
#
###


#| Windows / Cygwin Compatibility options
set( CMAKE_LEGACY_CYGWIN_WIN32 0 )
set( CMAKE_USE_RELATIVE_PATHS 1 )



###
# Compiler Lookup
#

#| avr match
if ( "${CHIP}" MATCHES "^at90usb.*$" OR "${CHIP}" MATCHES "^atmega.*$" )
set( COMPILER_FAMILY "avr" )

#| arm match
elseif ( "${CHIP}" MATCHES "^mk20dx.*$" )
set( COMPILER_FAMILY "arm" )

#| Invalid CHIP
else ()
message( FATAL_ERROR "CHIP: ${CHIP} - Unknown chip, could not choose compiler..." )
endif ()

#| Results of Compiler Lookup
message( STATUS "Compiler Family:" )
message( "${COMPILER_FAMILY}" )

#| Load the compiler family specific configurations
include( Lib/CMake/${COMPILER_FAMILY}.cmake )

#| Binutils not set by CMake
set( CMAKE_SIZE "${_CMAKE_TOOLCHAIN_PREFIX}size" )


setup.cmake → Lib/CMake/modules.cmake View File

@@ -8,48 +8,6 @@



###
# Project Modules
#

#| Note: This is the only section you probably want to modify
#| Each module is defined by it's own folder (e.g. Scan/Matrix represents the "Matrix" module)
#| All of the modules must be specified, as they generate the sources list of files to compile
#| Any modifications to this file will cause a complete rebuild of the project

#| Please look at the {Scan,Macro,USB,Debug}/module.txt for information on the modules and how to create new ones

##| Deals with acquiring the keypress information and turning it into a key index
set( ScanModule "DPH" )

##| Provides the mapping functions for DefaultMap and handles any macro processing before sending to the OutputModule
set( MacroModule "PartialMap" )

##| Sends the current list of usb key codes through USB HID
set( OutputModule "pjrcUSB" )

##| Debugging source to use, each module has it's own set of defines that it sets
set( DebugModule "full" )



###
# Keymap Configuration
#

##| If there are multiple DefaultMaps, it is defined here. If, the specified DefaultMap is not found, defaultMap.h is used.
set( DefaultMap "kishsaver" )

##| PartialMap combined keymap layering. The first keymap has the "least" precedence.
set( CombinedMap colemak capslock2ctrl )

##| ParitalMaps available on top of the CombinedMap. If there are input conflicts, the last PartialMap takes precedence.
set( PartialMaps hhkbnav kbdctrl )

##| MacroSets define extra capabilities that are not provided by the Scan or Output modules. Last MacroSet takes precedence.
set( MacroSets retype )


###
# Module Overrides (Used in the buildall.bash script)
#
@@ -245,3 +203,110 @@ set( GitLastCommitDate "${Git_Modified_Status} ${Git_Branch_INFO} - ${Git_Date_I
#| Primarily for USB configuration
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/Lib/_buildvars.h buildvars.h )



###
# Source Defines
#
set( SRCS
${MAIN_SRCS}
${COMPILER_SRCS}
${SCAN_SRCS}
${MACRO_SRCS}
${OUTPUT_SRCS}
${DEBUG_SRCS}
)

#| Directories to include by default
include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )



###
# Module Compatibility Check
#

#| Check for whether the set modules are compatible with the specified compiler family
ModuleCompatibility( ${ScanModulePath} ${ScanModuleCompatibility} )
ModuleCompatibility( ${MacroModulePath} ${MacroModuleCompatibility} )
ModuleCompatibility( ${OutputModulePath} ${OutputModuleCompatibility} )
ModuleCompatibility( ${DebugModulePath} ${DebugModuleCompatibility} )



###
# CMake Module Checking
#
find_package( Git REQUIRED )


###
# Build Targets
#

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


#| .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 .HEX to load onto the Teensy
set( TARGET_HEX ${TARGET}.hex )
add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} ${HEX_FLAGS} ${TARGET_ELF} ${TARGET_HEX}
COMMENT "Creating load file for Flash: ${TARGET_HEX}"
)


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



###
# Size Information
#

#| After Changes Size Information
#| TODO Do lookup on Flash and RAM sizes and do % used
add_custom_target( SizeAfter ALL
COMMAND ${CMAKE_SIZE} --target=${FORMAT} ${TARGET_HEX} ${TARGET_ELF}
DEPENDS ${TARGET_ELF}
COMMENT "Size after generation\n\tFlash Usage: data (hex)\n\t RAM Usage: data (elf)"
)



###
# Setup Loader Script and Program
#


#| Provides the user with the correct teensy-loader-cli command for the built .HEX file
#| Windows
if( CMAKE_SYSTEM_NAME MATCHES "Windows" )
configure_file( LoadFile/winload load NEWLINE_STYLE UNIX )
#| Default
else()
configure_file( LoadFile/load load NEWLINE_STYLE UNIX )
endif()



+ 16
- 68
README View File

@@ -80,85 +80,33 @@ Use the installer and make sure you add the binaries to your path within the ins



----------------------
Selecting Architecture
----------------------

This is where you choose which architecture you want to build for.
The options are:
- Teensy 1.0 (Not tested)
- Teensy 1.0++ (Not tested)
- Teensy 2.0
- Teensy 2.0++
- Teensy 3.0
- Teensy 3.1

Open up CMakeLists.txt in your favourite text editor.
You are looking for:

###
Compiler Family
#

#| Specify the compiler family to use
#| Currently only supports AVR and ARM
#| "avr" # Teensy 1.0
#| "avr" # Teensy 2.0
#| "avr" # Teensy++ 1.0
#| "avr" # Teensy++ 2.0
#| "arm" # Teensy 3.0
#| "arm" # Teensy 3.1

set( COMPILER_FAMILY "avr" )


Just change the COMPILER_FAMILY variable to whatever you are trying to build for.

NOTE: If you change this option, you will *may* to delete the build directory that is created in the Building sections below.



----------------------
Selecting Microcontroller
----------------------

Even if you selected the "avr" family of microcontroller architectures, you will still need to specify a target microcontroller (or once more ARM microcontrollers are supported).
This is where you select the chip you want to compile for.
The build system will automatically select the compiler needed to compile for your chip.

Open up avr.cmake (or arm.cmake) in your favourite text editor.
Open up CMakeLists.txt in your favourite text editor.
You are looking for:

###
# Atmel Defines and Linker Options
#

#| MCU Name
#| You _MUST_ set this to match the board you are using
#| type "make clean" after changing this, so all files will be rebuilt
#|
#| "at90usb162" # Teensy 1.0
#| "atmega32u4" # Teensy 2.0
#| "at90usb646" # Teensy++ 1.0
#| "at90usb1286" # Teensy++ 2.0

set( MCU "at90usb1286" )

*OR*

###
# ARM Defines and Linker Options
# Chip Selection
#

#| Chip Name (Linker)
#| You _MUST_ set this to match the board you are using
#| type "make clean" after changing this, so all files will be rebuilt
#| You _MUST_ set this to match the microcontroller you are trying to compile for
#| You _MUST_ clean the build directory if you change this value
#|
#| "mk20dx128" # Teensy 3.0
#| "mk20dx256" # Teensy 3.1
set( CHIP
# "at90usb162" # Teensy 1.0 (avr)
# "atmega32u4" # Teensy 2.0 (avr)
# "at90usb646" # Teensy++ 1.0 (avr)
"at90usb1286" # Teensy++ 2.0 (avr)
# "mk20dx128" # Teensy 3.0 (arm)
# "mk20dx256" # Teensy 3.1 (arm)
)

set( CHIP "mk20dx128" )


Just change the CHIP variable to the microcontroller you are trying to build for.
Just uncomment the chip you want, and comment out the old one.

NOTE: If you change this option, you will *need* to delete the build directory that is created in the Building sections below.

@@ -201,7 +149,7 @@ The Debug Module enables various things like the Teensy LED on errors, debug ter



Open up setup.cmake in your favourite text editor.
Open up CMakeLists.txt in your favourite text editor.
Look for:

###