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 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 OSX (not supported by avr-gcc or arm-none-eabi-gcc)
  10. #
  11. if ( 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. #| llvm-clang does not have an objcopy equivalent
  27. if ( "${COMPILER}" MATCHES "clang" )
  28. if ( "${COMPILER_FAMILY}" MATCHES "arm" )
  29. set ( OBJ_COPY arm-none-eabi-objcopy )
  30. elseif ( "${COMPILER_FAMILY}" MATCHES "arm" )
  31. set ( OBJ_COPY avr-objcopy )
  32. endif ()
  33. else ()
  34. set ( OBJ_COPY ${CMAKE_OBJCOPY} )
  35. endif ()
  36. #| Convert the .ELF into a .bin to load onto the McHCK
  37. if ( DEFINED DFU )
  38. set( TARGET_BIN ${TARGET}.dfu.bin )
  39. add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
  40. COMMAND ${OBJ_COPY} ${BIN_FLAGS} ${TARGET_ELF} ${TARGET_BIN}
  41. COMMENT "Creating dfu binary file: ${TARGET_BIN}"
  42. )
  43. endif ()
  44. #| Convert the .ELF into a .HEX to load onto the Teensy
  45. if ( DEFINED TEENSY )
  46. set( TARGET_HEX ${TARGET}.teensy.hex )
  47. add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
  48. COMMAND ${OBJ_COPY} ${HEX_FLAGS} ${TARGET_ELF} ${TARGET_HEX}
  49. COMMENT "Creating iHex file to load: ${TARGET_HEX}"
  50. )
  51. endif()
  52. #| Generate the Extended .LSS
  53. set( TARGET_LSS ${TARGET}.lss )
  54. add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
  55. COMMAND ${CMAKE_OBJDUMP} ${LSS_FLAGS} ${TARGET_ELF} > ${TARGET_LSS}
  56. COMMENT "Creating Extended Listing: ${TARGET_LSS}"
  57. )
  58. #| Generate the Symbol Table .SYM
  59. set( TARGET_SYM ${TARGET}.sym )
  60. add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
  61. COMMAND ${CMAKE_NM} -n ${TARGET_ELF} > ${TARGET_SYM}
  62. COMMENT "Creating Symbol Table: ${TARGET_SYM}"
  63. )
  64. #| Compiler Selection Record
  65. add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
  66. COMMAND ${CMAKE_SOURCE_DIR}/Lib/CMake/writer compiler ${COMPILER_FAMILY}
  67. )
  68. ###
  69. # Size Information
  70. #
  71. #| After Changes Size Information
  72. add_custom_target( SizeAfter ALL
  73. COMMAND ${CMAKE_SOURCE_DIR}/Lib/CMake/sizeCalculator ${CMAKE_SIZE} ram ${TARGET_ELF} ${SIZE_RAM} " SRAM"
  74. COMMAND ${CMAKE_SOURCE_DIR}/Lib/CMake/sizeCalculator ${CMAKE_SIZE} flash ${TARGET_ELF} ${SIZE_FLASH} "Flash"
  75. DEPENDS ${TARGET_ELF}
  76. COMMENT "Chip usage for ${CHIP}"
  77. )
  78. ###
  79. # Setup Loader Script and Program
  80. #
  81. #| First check for DFU based controllers
  82. if( DEFINED DFU )
  83. configure_file( LoadFile/load.dfu load NEWLINE_STYLE UNIX )
  84. #| Next check for Teensy based
  85. elseif ( DEFINED TEENSY )
  86. # Provides the user with the correct teensy-loader-cli command for the built .HEX file
  87. # Windows
  88. if( CMAKE_SYSTEM_NAME MATCHES "Windows" )
  89. configure_file( LoadFile/winload.teensy load NEWLINE_STYLE UNIX )
  90. # Default
  91. else()
  92. configure_file( LoadFile/load.teensy load NEWLINE_STYLE UNIX )
  93. endif()
  94. endif()