2014-09-14 22:51:36 +00:00
|
|
|
###| CMAKE Kiibohd Controller Source Configurator |###
|
|
|
|
#
|
2015-03-02 09:58:53 +00:00
|
|
|
# Written by Jacob Alexander in 2011-2015 for the Kiibohd Controller
|
2014-09-14 22:51:36 +00:00
|
|
|
#
|
|
|
|
# Released into the Public Domain
|
|
|
|
#
|
|
|
|
###
|
|
|
|
|
|
|
|
|
2014-09-15 02:27:22 +00:00
|
|
|
###
|
2014-09-15 03:07:40 +00:00
|
|
|
# Disable -Wl,-search_paths_first for OSX (not supported by avr-gcc or arm-none-eabi-gcc)
|
2014-09-15 02:27:22 +00:00
|
|
|
#
|
|
|
|
|
2014-09-15 03:07:40 +00:00
|
|
|
if ( APPLE )
|
2014-09-15 02:27:22 +00:00
|
|
|
string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_C_LINK_FLAGS ${CMAKE_C_LINK_FLAGS} )
|
|
|
|
string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} )
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
|
2014-09-14 22:51:36 +00:00
|
|
|
|
|
|
|
###
|
|
|
|
# Build Targets
|
|
|
|
#
|
|
|
|
|
|
|
|
#| Create the .ELF file
|
|
|
|
set( TARGET_ELF ${TARGET}.elf )
|
2016-01-03 18:21:10 +00:00
|
|
|
add_executable( ${TARGET_ELF} ${SRCS} generatedKeymap.h kll_defs.h )
|
2014-09-14 22:51:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
#| .ELF Properties
|
|
|
|
set_target_properties( ${TARGET_ELF} PROPERTIES
|
|
|
|
LINK_FLAGS ${LINKER_FLAGS}
|
|
|
|
SUFFIX "" # XXX Force Windows to keep the .exe off
|
|
|
|
)
|
|
|
|
|
2015-01-01 03:42:16 +00:00
|
|
|
#| llvm-clang does not have an objcopy equivalent
|
|
|
|
if ( "${COMPILER}" MATCHES "clang" )
|
|
|
|
if ( "${COMPILER_FAMILY}" MATCHES "arm" )
|
|
|
|
set ( OBJ_COPY arm-none-eabi-objcopy )
|
|
|
|
elseif ( "${COMPILER_FAMILY}" MATCHES "arm" )
|
|
|
|
set ( OBJ_COPY avr-objcopy )
|
|
|
|
endif ()
|
|
|
|
else ()
|
|
|
|
set ( OBJ_COPY ${CMAKE_OBJCOPY} )
|
|
|
|
endif ()
|
|
|
|
|
2014-09-14 22:51:36 +00:00
|
|
|
|
|
|
|
#| Convert the .ELF into a .bin to load onto the McHCK
|
2015-03-02 09:58:53 +00:00
|
|
|
#| Then sign using dfu-suffix (requries dfu-util)
|
2015-01-01 03:42:16 +00:00
|
|
|
if ( DEFINED DFU )
|
2015-03-02 09:58:53 +00:00
|
|
|
# dfu-suffix is required to sign the dfu binary
|
|
|
|
find_package ( DFUSuffix )
|
|
|
|
|
2014-09-14 22:51:36 +00:00
|
|
|
set( TARGET_BIN ${TARGET}.dfu.bin )
|
2015-03-02 09:58:53 +00:00
|
|
|
if ( DFU_SUFFIX_FOUND )
|
|
|
|
add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
|
|
|
|
COMMAND ${OBJ_COPY} ${BIN_FLAGS} ${TARGET_ELF} ${TARGET_BIN}
|
|
|
|
COMMAND ${DFU_SUFFIX_EXECUTABLE} --add ${TARGET_BIN} --vid ${BOOT_VENDOR_ID} --pid ${BOOT_PRODUCT_ID} 1> /dev/null
|
|
|
|
COMMENT "Create and sign dfu bin file: ${TARGET_BIN}"
|
|
|
|
)
|
|
|
|
else ()
|
|
|
|
message ( WARNING "DFU Binary has not been signed, requires dfu-suffix..." )
|
|
|
|
add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
|
|
|
|
COMMAND ${OBJ_COPY} ${BIN_FLAGS} ${TARGET_ELF} ${TARGET_BIN}
|
|
|
|
COMMENT "Creating dfu binary file: ${TARGET_BIN}"
|
|
|
|
)
|
|
|
|
endif ()
|
2015-01-01 03:42:16 +00:00
|
|
|
endif ()
|
2014-09-14 22:51:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
#| 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
|
2015-01-01 03:42:16 +00:00
|
|
|
COMMAND ${OBJ_COPY} ${HEX_FLAGS} ${TARGET_ELF} ${TARGET_HEX}
|
2014-09-14 22:51:36 +00:00
|
|
|
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}"
|
|
|
|
)
|
|
|
|
|
2014-09-14 23:22:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
# Setup Loader Script and Program
|
|
|
|
#
|
|
|
|
|
|
|
|
#| First check for DFU based controllers
|
|
|
|
if( DEFINED DFU )
|
|
|
|
configure_file( LoadFile/load.dfu load NEWLINE_STYLE UNIX )
|
|
|
|
|
|
|
|
#| Next check for Teensy based
|
|
|
|
elseif ( DEFINED TEENSY )
|
|
|
|
# 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.teensy load NEWLINE_STYLE UNIX )
|
|
|
|
# Default
|
|
|
|
else()
|
|
|
|
configure_file( LoadFile/load.teensy load NEWLINE_STYLE UNIX )
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2016-03-04 08:23:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
# Compiler Command Generation
|
|
|
|
#
|
|
|
|
|
|
|
|
#| Generate list of compiler commands for clang-tidy usage
|
|
|
|
set( CMAKE_EXPORT_COMPILE_COMMANDS ON )
|
|
|
|
|
|
|
|
#| Make sure symlink exists (for convenience)
|
|
|
|
if ( UNIX )
|
|
|
|
# Make sure symlink is created immediately
|
|
|
|
execute_process ( COMMAND ln -sfn ${CMAKE_BINARY_DIR}/compile_commands.json ${CMAKE_SOURCE_DIR}/. )
|
|
|
|
|
|
|
|
# Also update before each build
|
|
|
|
add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
|
|
|
|
COMMAND ln -sfn ${CMAKE_BINARY_DIR}/compile_commands.json ${CMAKE_SOURCE_DIR}/.
|
|
|
|
)
|
|
|
|
endif ()
|
|
|
|
|