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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. ##| TODO List |##
  10. # - Add avr-gcc as requirement
  11. # - Add avr-objcopy as a requirement
  12. # - Generate .lst files
  13. # - Extend .lst to .lss
  14. # - Autoloader to Teensy
  15. # - specify on commandline which atmel mcu
  16. #| Set the Compilers
  17. include( CMakeForceCompiler )
  18. set( CMAKE_SYSTEM_NAME Generic )
  19. cmake_force_c_compiler ( avr-gcc AVRCCompiler )
  20. cmake_force_cxx_compiler( avr-g++ AVRCxxCompiler )
  21. #| Project
  22. project( kiibohd_controller )
  23. #| General Settings
  24. cmake_minimum_required( VERSION 2.8 )
  25. #| Sources
  26. set( SRCS
  27. ./main.c
  28. ./print.c
  29. ./usb_keyboard_debug.c
  30. ./scan_loop.c
  31. )
  32. #| Target Name
  33. set( TARGET kiibohd )
  34. #| Compiler flag to set the C Standard level.
  35. #| c89 = "ANSI" C
  36. #| gnu89 = c89 plus GCC extensions
  37. #| c99 = ISO C99 standard (not yet fully implemented)
  38. #| gnu99 = c99 plus GCC extensions
  39. set( CSTANDARD "-std=gnu99" )
  40. #| Warning Options
  41. #| -Wall...: warning level
  42. set( WARN "-Wall -Wstrict-prototypes" )
  43. #| Tuning Options
  44. #| -f...: tuning, see GCC manual and avr-libc documentation
  45. set( TUNING "-funsigned-char -funsigned-bitfields -ffunction-sections -fpack-struct -fshort-enums" )
  46. #| Optimization level, can be [0, 1, 2, 3, s].
  47. #| 0 = turn off optimization. s = optimize for size.
  48. #| (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
  49. set( OPT "s" )
  50. #| Output Format
  51. #| srec, ihex, binary
  52. set( FORMAT "ihex" )
  53. #| MCU Name
  54. #| You MUST set this to match the board you are using
  55. #| type "make clean" after changing this, so all files will be rebuilt
  56. #|
  57. #| "at90usb162" # Teensy 1.0
  58. #| "atmega32u4" # Teensy 2.0
  59. #| "at90usb646" # Teensy++ 1.0
  60. #| "at90usb1286" # Teensy++ 2.0
  61. set( MCU "at90usb1286" )
  62. #| Processor frequency.
  63. #| Normally the first thing your program should do is set the clock prescaler,
  64. #| so your program will run at the correct speed. You should also set this
  65. #| variable to same clock speed. The _delay_ms() macro uses this, and many
  66. #| examples use this variable to calculate timings. Do not add a "UL" here.
  67. set( F_CPU "16000000" )
  68. set( CDEFS "-DF_CPU=${F_CPU}" )
  69. #| Dependency Files
  70. #| Compiler flags to generate dependency files.
  71. set( GENDEPFLAGS "-MMD -MP" )
  72. #| Listing file
  73. set( TARGET_LST ${TARGET}.lst )
  74. #| Compiler Flags
  75. add_definitions( "-mmcu=${MCU} -DF_CPU=${F_CPU} -O${OPT} ${TUNING} ${WARN} -Wa,-adhlns ${CSTANDARD} ${GENDEPFLAGS}" )
  76. #| Linker Flags
  77. set( LINKER_FLAGS "-mmcu=${MCU} -Wl,-Map=${TARGET}.map,--cref -Wl,--relax -Wl,--gc-sections" )
  78. #| Hex Flags (XXX, CMake seems to have issues if you quote the arguments for the custom commands...)
  79. set( HEX_FLAGS -O ${FORMAT} -R .eeprom -R .fuse -R .lock -R .signature )
  80. #| Eep Flags
  81. set( EEP_FLAGS -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ${FORMAT} )
  82. #| Lss Flags
  83. set( LSS_FLAGS -h -S -z )
  84. #| Create the .ELF file
  85. set( TARGET_ELF ${TARGET}.elf )
  86. add_executable( ${TARGET_ELF} ${SRCS} )
  87. #| .ELF Properties
  88. set_target_properties( ${TARGET_ELF} PROPERTIES
  89. LINK_FLAGS ${LINKER_FLAGS}
  90. )
  91. #| Convert the .ELF into a .HEX to load onto the Teensy
  92. set( TARGET_HEX ${TARGET}.hex )
  93. add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
  94. COMMAND avr-objcopy ${HEX_FLAGS} ${TARGET_ELF} ${TARGET_HEX}
  95. COMMENT "Creating load file for Flash: ${TARGET_HEX}"
  96. )
  97. #| Convert the .ELF into a .EEP
  98. set( TARGET_EEP ${TARGET}.eep )
  99. add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
  100. COMMAND avr-objcopy ${EEP_FLAGS} ${TARGET_ELF} ${TARGET_EEP}
  101. COMMENT "Creating load file for EEPROM: ${TARGET_EEP}"
  102. )
  103. #| Generate the Extended .LSS TODO Incomplete
  104. set( TARGET_LSS ${TARGET}.lss )
  105. add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
  106. COMMAND avr-objcopy ${LSS_FLAGS} ${TARGET_ELF} > ${TARGET_LSS}
  107. COMMENT "Creating Extended Listing: ${TARGET_LSS}"
  108. )
  109. #| Generate the Symbol Table .SYM
  110. set( TARGET_SYM ${TARGET}.sym )
  111. add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
  112. COMMAND avr-nm -n ${TARGET_ELF} > ${TARGET_SYM}
  113. COMMENT "Creating Symbol Table: ${TARGET_SYM}"
  114. )
  115. #| Before Changes Size Information (and make sure it is run before ${TARGET_ELF} is generated) TODO Only call if the files exist
  116. #add_dependencies( ${TARGET_ELF} SizeBefore )
  117. #add_custom_target( SizeBefore ALL avr-size --target=${FORMAT} ${TARGET_HEX} ${TARGET_ELF}
  118. # COMMENT "Size before generation:"
  119. #)
  120. #| After Changes Size Information
  121. add_custom_target( SizeAfter ALL avr-size --target=${FORMAT} ${TARGET_HEX} ${TARGET_ELF}
  122. DEPENDS ${TARGET_ELF}
  123. COMMENT "Size after generation:"
  124. )