Kiibohd Controller
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

build.cmake 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. ###| CMAKE Kiibohd Controller Source Configurator |###
  2. #
  3. # Written by Jacob Alexander in 2011-2014 for the Kiibohd Controller
  4. #
  5. # Released into the Public Domain
  6. #
  7. ###
  8. ###
  9. # Disable -Wl,-search_paths_first for AVR on OSX (not supported by avr-gcc)
  10. #
  11. if ( "${CPU}" STREQUAL "megaAVR" AND APPLE )
  12. string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_C_LINK_FLAGS ${CMAKE_C_LINK_FLAGS} )
  13. string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} )
  14. endif ()
  15. ###
  16. # Build Targets
  17. #
  18. #| Create the .ELF file
  19. set( TARGET_ELF ${TARGET}.elf )
  20. add_executable( ${TARGET_ELF} ${SRCS} generatedKeymap.h )
  21. #| .ELF Properties
  22. set_target_properties( ${TARGET_ELF} PROPERTIES
  23. LINK_FLAGS ${LINKER_FLAGS}
  24. SUFFIX "" # XXX Force Windows to keep the .exe off
  25. )
  26. #| Convert the .ELF into a .bin to load onto the McHCK
  27. if( DEFINED DFU )
  28. set( TARGET_BIN ${TARGET}.dfu.bin )
  29. add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
  30. COMMAND ${CMAKE_OBJCOPY} ${BIN_FLAGS} ${TARGET_ELF} ${TARGET_BIN}
  31. COMMENT "Creating dfu binary file: ${TARGET_BIN}"
  32. )
  33. endif()
  34. #| Convert the .ELF into a .HEX to load onto the Teensy
  35. if ( DEFINED TEENSY )
  36. set( TARGET_HEX ${TARGET}.teensy.hex )
  37. add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
  38. COMMAND ${CMAKE_OBJCOPY} ${HEX_FLAGS} ${TARGET_ELF} ${TARGET_HEX}
  39. COMMENT "Creating iHex file to load: ${TARGET_HEX}"
  40. )
  41. endif()
  42. #| Generate the Extended .LSS
  43. set( TARGET_LSS ${TARGET}.lss )
  44. add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
  45. COMMAND ${CMAKE_OBJDUMP} ${LSS_FLAGS} ${TARGET_ELF} > ${TARGET_LSS}
  46. COMMENT "Creating Extended Listing: ${TARGET_LSS}"
  47. )
  48. #| Generate the Symbol Table .SYM
  49. set( TARGET_SYM ${TARGET}.sym )
  50. add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
  51. COMMAND ${CMAKE_NM} -n ${TARGET_ELF} > ${TARGET_SYM}
  52. COMMENT "Creating Symbol Table: ${TARGET_SYM}"
  53. )
  54. #| Compiler Selection Record
  55. add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
  56. COMMAND ${CMAKE_SOURCE_DIR}/Lib/CMake/writer compiler ${COMPILER_FAMILY}
  57. )
  58. ###
  59. # Size Information
  60. #
  61. #| After Changes Size Information
  62. add_custom_target( SizeAfter ALL
  63. COMMAND ${CMAKE_SOURCE_DIR}/Lib/CMake/sizeCalculator ${CMAKE_SIZE} ram ${TARGET_ELF} ${SIZE_RAM} " SRAM"
  64. COMMAND ${CMAKE_SOURCE_DIR}/Lib/CMake/sizeCalculator ${CMAKE_SIZE} flash ${TARGET_ELF} ${SIZE_FLASH} "Flash"
  65. DEPENDS ${TARGET_ELF}
  66. COMMENT "Chip usage for ${CHIP}"
  67. )
  68. ###
  69. # Setup Loader Script and Program
  70. #
  71. #| First check for DFU based controllers
  72. if( DEFINED DFU )
  73. configure_file( LoadFile/load.dfu load NEWLINE_STYLE UNIX )
  74. #| Next check for Teensy based
  75. elseif ( DEFINED TEENSY )
  76. # Provides the user with the correct teensy-loader-cli command for the built .HEX file
  77. # Windows
  78. if( CMAKE_SYSTEM_NAME MATCHES "Windows" )
  79. configure_file( LoadFile/winload.teensy load NEWLINE_STYLE UNIX )
  80. # Default
  81. else()
  82. configure_file( LoadFile/load.teensy load NEWLINE_STYLE UNIX )
  83. endif()
  84. endif()