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.

CMakeLists.txt 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. ###| CMAKE Kiibohd Controller Bootloader |###
  2. #
  3. # Jacob Alexander 2011-2016
  4. # Due to this file's usefulness:
  5. #
  6. # Released into the Public Domain
  7. #
  8. # This bootloader is based upon the MCHCK dfu-usb bootloader.
  9. # DO NOT USE with Teensy based microcontrollers.
  10. #
  11. ###
  12. ###
  13. # Chip Selection
  14. #
  15. #| You _MUST_ set this to match the microcontroller you are trying to compile for
  16. #| You _MUST_ clean the build directory if you change this value
  17. #|
  18. set ( CHIP
  19. "mk20dx128vlf5" # McHCK mk20dx128vlf5
  20. # "mk20dx256vlh7" # Kiibohd-dfu mk20dx256vlh7
  21. CACHE STRING "Chip"
  22. )
  23. ###
  24. # Compiler Selection
  25. #
  26. #| *** EXPERIMENTAL ***
  27. #| Stick with gcc unless you know what you're doing
  28. #| Currently only arm is supported with clang
  29. set ( COMPILER
  30. "gcc" # arm-none-eabi-gcc / avr-gcc - Default
  31. # "clang" # arm-none-eabi
  32. CACHE STRING "Compiler Type"
  33. )
  34. ###
  35. # Bootloader Configuration
  36. #
  37. set ( BOOTLOADER 1 )
  38. ###
  39. # Compiler Intialization
  40. #
  41. set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/../Lib/CMake )
  42. include ( initialize )
  43. ##
  44. # Source Defines
  45. #
  46. set ( SRCS
  47. main.c
  48. dfu.c
  49. dfu.desc.c
  50. flash.c
  51. kinetis.c
  52. usb.c
  53. )
  54. # Only compile in if necessary
  55. if ( CHIP STREQUAL "mk20dx256vlh7" )
  56. set( SRCS ${SRCS}
  57. debug.c
  58. )
  59. endif ()
  60. message ( STATUS "Bootloader Source Files:" )
  61. message ( "${SRCS}" )
  62. #| Add Lib sources to main list
  63. foreach ( SRC_FILE ${COMPILER_SRCS} )
  64. set ( SRCS ${SRCS} ${CMAKE_SOURCE_DIR}/../${SRC_FILE} )
  65. endforeach ()
  66. ###
  67. # Directory Includes
  68. #
  69. include_directories (
  70. ${CMAKE_SOURCE_DIR}/../Lib
  71. ${CMAKE_SOURCE_DIR}
  72. )
  73. ###
  74. # Project Description
  75. #
  76. #| Project
  77. project ( kiibohd_bootloader C )
  78. #| Target Name (output name)
  79. set ( TARGET kiibohd_bootloader )
  80. #| General Settings
  81. cmake_minimum_required ( VERSION 2.8 )
  82. ###
  83. # Minimum Compiler Version Checks
  84. #
  85. # Due to optimization requirements, we have to impose a minimum GCC version on the bootloader
  86. set ( BOOTLOADER_MIN_GCC_VERSION "4.9" )
  87. if ( "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" )
  88. if ( CMAKE_C_COMPILER_VERSION VERSION_LESS "${BOOTLOADER_MIN_GCC_VERSION}" )
  89. message( FATAL_ERROR "arm-none-eabi-gcc ${BOOTLOADER_MIN_GCC_VERSION} or higher is required for bootloader" )
  90. endif ()
  91. endif ()
  92. ###
  93. # CMake Build Env
  94. #
  95. include ( buildinfo )
  96. ###
  97. # Generate Header Files
  98. #
  99. configure_file ( _buildvars.h buildvars.h )
  100. include_directories ( ${CMAKE_BINARY_DIR} )
  101. ###
  102. # ctag Generation
  103. #
  104. find_package ( Ctags ) # Optional
  105. if ( CTAGS_EXECUTABLE )
  106. # Generate the ctags
  107. execute_process( COMMAND ctags ${SRCS}
  108. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  109. )
  110. endif ()
  111. ###
  112. # Disable -Wl,-search_paths_first for OSX (not supported by arm-none-eabi-gcc)
  113. #
  114. if ( APPLE )
  115. string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_C_LINK_FLAGS ${CMAKE_C_LINK_FLAGS} )
  116. string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} )
  117. message ( AUTHOR_WARNING "Bootloader binary may not fit on device (must be less than 4096 bytes). Macports arm-none-eabi-gcc 4.7.3 doesn't seem to work properly with -flto. However, even disabling it doesn't shrink the binary enough... 4.9.1 is known to work on Arch Linux." )
  118. endif ()
  119. ###
  120. # Build Targets
  121. #
  122. #| Create the .ELF file
  123. set ( TARGET_ELF ${TARGET}.elf )
  124. add_executable ( ${TARGET_ELF} ${SRCS} )
  125. #| .ELF Properties
  126. set_target_properties ( ${TARGET_ELF} PROPERTIES
  127. LINK_FLAGS ${LINKER_FLAGS}
  128. SUFFIX "" # XXX Force Windows to keep the .exe off
  129. )
  130. #| Convert the .ELF into a .bin to load onto the McHCK
  131. set ( TARGET_BIN ${TARGET}.bin )
  132. add_custom_command ( TARGET ${TARGET_ELF} POST_BUILD
  133. COMMAND ${CMAKE_OBJCOPY} ${BIN_FLAGS} ${TARGET_ELF} ${TARGET_BIN}
  134. COMMENT "Creating binary file to load: ${TARGET_BIN}"
  135. )
  136. #| Generate the Extended .LSS
  137. set ( TARGET_LSS ${TARGET}.lss )
  138. add_custom_command ( TARGET ${TARGET_ELF} POST_BUILD
  139. COMMAND ${CMAKE_OBJDUMP} ${LSS_FLAGS} ${TARGET_ELF} > ${TARGET_LSS}
  140. COMMENT "Creating Extended Listing: ${TARGET_LSS}"
  141. )
  142. #| Generate the Symbol Table .SYM
  143. set ( TARGET_SYM ${TARGET}.sym )
  144. add_custom_command ( TARGET ${TARGET_ELF} POST_BUILD
  145. COMMAND ${CMAKE_NM} -n ${TARGET_ELF} > ${TARGET_SYM}
  146. COMMENT "Creating Symbol Table: ${TARGET_SYM}"
  147. )
  148. #| Compiler Selection Record
  149. add_custom_command ( TARGET ${TARGET_ELF} POST_BUILD
  150. COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/writer compiler ${COMPILER_FAMILY}
  151. )
  152. ###
  153. # Size Information
  154. #
  155. #| After Changes Size Information
  156. add_custom_target ( SizeAfter ALL
  157. COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/sizeCalculator ${CMAKE_SIZE} ram ${TARGET_ELF} ${SIZE_RAM} " SRAM"
  158. COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/sizeCalculator ${CMAKE_SIZE} flash ${TARGET_ELF} ${SIZE_FLASH} "Flash"
  159. DEPENDS ${TARGET_ELF}
  160. COMMENT "Chip usage for ${CHIP}"
  161. )