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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. ###| CMAKE Kiibohd Controller |###
  2. #
  3. # Written by Jacob Alexander in 2011 for the Kiibohd Controller
  4. # Due to this file's usefulness:
  5. #
  6. # Released into the Public Domain
  7. #
  8. ###
  9. #| Set the Compilers (must be set first)
  10. include( CMakeForceCompiler )
  11. cmake_force_c_compiler ( avr-gcc AVRCCompiler )
  12. cmake_force_cxx_compiler( avr-g++ AVRCxxCompiler )
  13. #| Add Dependency Macro
  14. include( AddFileDependencies )
  15. ###
  16. # Project Description
  17. #
  18. #| Project
  19. project( kiibohd_controller )
  20. #| Target Name (output name)
  21. set( TARGET kiibohd )
  22. #| General Settings
  23. cmake_minimum_required( VERSION 2.8 )
  24. ###
  25. # Source Defines
  26. #
  27. #| Sources (see setup.h for configuring in/away code blocks or other complete modules)
  28. #| XXX Not set here in this project, see setup.cmake
  29. #set( SRCS ./main.c )
  30. #| Instead, include the module source selector
  31. include( setup.cmake )
  32. set( SRCS
  33. main.c
  34. ${SCAN_SRCS}
  35. ${MACRO_SRCS}
  36. ${USB_SRCS}
  37. ${DEBUG_SRCS}
  38. )
  39. ###
  40. # Atmel Defines and Linker Options
  41. #
  42. #| MCU Name
  43. #| You _MUST_ set this to match the board you are using
  44. #| type "make clean" after changing this, so all files will be rebuilt
  45. #|
  46. #| "at90usb162" # Teensy 1.0
  47. #| "atmega32u4" # Teensy 2.0
  48. #| "at90usb646" # Teensy++ 1.0
  49. #| "at90usb1286" # Teensy++ 2.0
  50. set( MCU "atmega32u4" )
  51. #| Compiler flag to set the C Standard level.
  52. #| c89 = "ANSI" C
  53. #| gnu89 = c89 plus GCC extensions
  54. #| c99 = ISO C99 standard (not yet fully implemented)
  55. #| gnu99 = c99 plus GCC extensions
  56. set( CSTANDARD "-std=gnu99" )
  57. #| Warning Options
  58. #| -Wall...: warning level
  59. set( WARN "-Wall -Wstrict-prototypes" )
  60. #| Tuning Options
  61. #| -f...: tuning, see GCC manual and avr-libc documentation
  62. set( TUNING "-funsigned-char -funsigned-bitfields -ffunction-sections -fpack-struct -fshort-enums" )
  63. #| Optimization level, can be [0, 1, 2, 3, s].
  64. #| 0 = turn off optimization. s = optimize for size.
  65. #| (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
  66. set( OPT "s" )
  67. #| Output Format
  68. #| srec, ihex, binary
  69. set( FORMAT "ihex" )
  70. #| Processor frequency.
  71. #| Normally the first thing your program should do is set the clock prescaler,
  72. #| so your program will run at the correct speed. You should also set this
  73. #| variable to same clock speed. The _delay_ms() macro uses this, and many
  74. #| examples use this variable to calculate timings. Do not add a "UL" here.
  75. set( F_CPU "16000000" )
  76. #| Dependency Files
  77. #| Compiler flags to generate dependency files.
  78. set( GENDEPFLAGS "-MMD -MP" )
  79. #| Listing file
  80. set( TARGET_LST ${TARGET}.lst )
  81. #| Compiler Flags
  82. add_definitions( "-mmcu=${MCU} -DF_CPU=${F_CPU} -O${OPT} ${TUNING} ${WARN} ${CSTANDARD} ${GENDEPFLAGS}" )
  83. #| Linker Flags
  84. set( LINKER_FLAGS "-mmcu=${MCU} -Wl,-Map=${TARGET}.map,--cref -Wl,--relax -Wl,--gc-sections" )
  85. #| Hex Flags (XXX, CMake seems to have issues if you quote the arguments for the custom commands...)
  86. set( HEX_FLAGS -O ${FORMAT} -R .eeprom -R .fuse -R .lock -R .signature )
  87. #| Eep Flags
  88. set( EEP_FLAGS -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ${FORMAT} )
  89. #| Lss Flags
  90. set( LSS_FLAGS -h -S -z )
  91. ###
  92. # Build Targets
  93. #
  94. #| Create the .ELF file
  95. set( TARGET_ELF ${TARGET}.elf )
  96. add_executable( ${TARGET_ELF} ${SRCS} )
  97. #| .ELF Properties
  98. set_target_properties( ${TARGET_ELF} PROPERTIES
  99. LINK_FLAGS ${LINKER_FLAGS}
  100. )
  101. #| Convert the .ELF into a .HEX to load onto the Teensy
  102. set( TARGET_HEX ${TARGET}.hex )
  103. add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
  104. COMMAND avr-objcopy ${HEX_FLAGS} ${TARGET_ELF} ${TARGET_HEX}
  105. COMMENT "Creating load file for Flash: ${TARGET_HEX}"
  106. )
  107. #| Convert the .ELF into a .EEP
  108. set( TARGET_EEP ${TARGET}.eep )
  109. add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
  110. COMMAND avr-objcopy ${EEP_FLAGS} ${TARGET_ELF} ${TARGET_EEP}
  111. COMMENT "Creating load file for EEPROM: ${TARGET_EEP}"
  112. )
  113. #| Generate the Extended .LSS
  114. set( TARGET_LSS ${TARGET}.lss )
  115. add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
  116. COMMAND avr-objdump ${LSS_FLAGS} ${TARGET_ELF} > ${TARGET_LSS}
  117. COMMENT "Creating Extended Listing: ${TARGET_LSS}"
  118. )
  119. #| Generate the Symbol Table .SYM
  120. set( TARGET_SYM ${TARGET}.sym )
  121. add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
  122. COMMAND avr-nm -n ${TARGET_ELF} > ${TARGET_SYM}
  123. COMMENT "Creating Symbol Table: ${TARGET_SYM}"
  124. )
  125. ###
  126. # Size Information
  127. #
  128. #| After Changes Size Information
  129. add_custom_target( SizeAfter ALL avr-size --target=${FORMAT} ${TARGET_HEX} ${TARGET_ELF}
  130. DEPENDS ${TARGET_ELF}
  131. COMMENT "Size after generation:"
  132. )
  133. ###
  134. # Setup Loader Script
  135. #
  136. #| Provides the user with the correct teensy-loader-cli command for the built .HEX file
  137. #| teensy-loader-cli must be in the user's path
  138. if( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
  139. configure_file( LoadFile/bash load )
  140. endif( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
  141. #| TODO Windows
  142. if( ${CMAKE_SYSTEM_NAME} MATCHES "Windows" )
  143. message( STATUS "Load Script is on my TODO List for Windows..." )
  144. endif( ${CMAKE_SYSTEM_NAME} MATCHES "Windows" )