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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. ###| CMAKE Kiibohd Controller Bootloader |###
  2. #
  3. # Jacob Alexander 2011-2014
  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. )
  22. ###
  23. # Compiler Selection
  24. #
  25. #| *** EXPERIMENTAL ***
  26. #| Stick with gcc unless you know what you're doing
  27. #| Currently only arm is supported with clang
  28. set( COMPILER
  29. "gcc" # arm-none-eabi-gcc / avr-gcc - Default
  30. # "clang" # arm-none-eabi
  31. CACHE STRING "Compiler Type" )
  32. ###
  33. # Bootloader Configuration
  34. #
  35. set ( BOOTLOADER 1 )
  36. ###
  37. # Compiler Intialization
  38. #
  39. set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/../Lib/CMake )
  40. include( initialize )
  41. ##
  42. # Source Defines
  43. #
  44. set( SRCS
  45. main.c
  46. dfu.c
  47. dfu.desc.c
  48. flash.c
  49. kinetis.c
  50. usb.c
  51. )
  52. message( STATUS "Bootloader Source Files:" )
  53. message( "${SRCS}" )
  54. #| Add Lib sources to main list
  55. foreach( SRC_FILE ${COMPILER_SRCS} )
  56. set( SRCS ${SRCS} ${CMAKE_SOURCE_DIR}/../${SRC_FILE} )
  57. endforeach()
  58. ###
  59. # Directory Includes
  60. #
  61. include_directories( ${CMAKE_SOURCE_DIR}/../Lib )
  62. ###
  63. # Project Description
  64. #
  65. #| Project
  66. project( kiibohd_bootloader )
  67. #| Target Name (output name)
  68. set( TARGET kiibohd_bootloader )
  69. #| General Settings
  70. cmake_minimum_required( VERSION 2.8 )
  71. ###
  72. # Generate Header Files
  73. #
  74. configure_file( _buildvars.h buildvars.h )
  75. include_directories( ${CMAKE_BINARY_DIR} )
  76. ###
  77. # CMake Module Checking
  78. #
  79. find_package( Git REQUIRED )
  80. find_package( Ctags ) # Optional
  81. ###
  82. # ctag Generation
  83. #
  84. if( CTAGS_EXECUTABLE )
  85. # Generate the ctags
  86. execute_process( COMMAND ctags ${SRCS}
  87. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  88. )
  89. endif()
  90. ###
  91. # Disable -Wl,-search_paths_first for OSX (not supported by arm-none-eabi-gcc)
  92. #
  93. if ( APPLE )
  94. string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_C_LINK_FLAGS ${CMAKE_C_LINK_FLAGS} )
  95. string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} )
  96. 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." )
  97. endif ()
  98. ###
  99. # Build Targets
  100. #
  101. #| Create the .ELF file
  102. set( TARGET_ELF ${TARGET}.elf )
  103. add_executable( ${TARGET_ELF} ${SRCS} )
  104. #| .ELF Properties
  105. set_target_properties( ${TARGET_ELF} PROPERTIES
  106. LINK_FLAGS ${LINKER_FLAGS}
  107. SUFFIX "" # XXX Force Windows to keep the .exe off
  108. )
  109. #| Convert the .ELF into a .bin to load onto the McHCK
  110. set( TARGET_BIN ${TARGET}.bin )
  111. add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
  112. COMMAND ${CMAKE_OBJCOPY} ${BIN_FLAGS} ${TARGET_ELF} ${TARGET_BIN}
  113. COMMENT "Creating binary file to load: ${TARGET_BIN}"
  114. )
  115. #| Generate the Extended .LSS
  116. set( TARGET_LSS ${TARGET}.lss )
  117. add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
  118. COMMAND ${CMAKE_OBJDUMP} ${LSS_FLAGS} ${TARGET_ELF} > ${TARGET_LSS}
  119. COMMENT "Creating Extended Listing: ${TARGET_LSS}"
  120. )
  121. #| Generate the Symbol Table .SYM
  122. set( TARGET_SYM ${TARGET}.sym )
  123. add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
  124. COMMAND ${CMAKE_NM} -n ${TARGET_ELF} > ${TARGET_SYM}
  125. COMMENT "Creating Symbol Table: ${TARGET_SYM}"
  126. )
  127. #| Compiler Selection Record
  128. add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
  129. COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/writer compiler ${COMPILER_FAMILY}
  130. )
  131. ###
  132. # Size Information
  133. #
  134. #| After Changes Size Information
  135. add_custom_target( SizeAfter ALL
  136. COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/sizeCalculator ${CMAKE_SIZE} ram ${TARGET_ELF} ${SIZE_RAM} " SRAM"
  137. COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/sizeCalculator ${CMAKE_SIZE} flash ${TARGET_ELF} ${SIZE_FLASH} "Flash"
  138. DEPENDS ${TARGET_ELF}
  139. COMMENT "Chip usage for ${CHIP}"
  140. )