CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. cmake_minimum_required(VERSION 3.10)
  2. #====================================================================#
  3. # Usage under Linux: #
  4. # #
  5. # From the project folder: #
  6. # cd buildroot/share/cmake #
  7. # mkdir -p build && cd build #
  8. # cmake .. #
  9. # make #
  10. # #
  11. # Usage under Windows: #
  12. # #
  13. # From the project folder: #
  14. # cd buildroot/share/cmake #
  15. # mkdir build && cd build #
  16. # cmake -G"Unix Makefiles" .. #
  17. # make #
  18. #====================================================================#
  19. #====================================================================#
  20. # Download marlin-cmake scriptfiles if not already installed #
  21. # and add the path to the module path #
  22. #====================================================================#
  23. set(SCRIPT_BRANCH 1.0.2) # Set to wanted marlin-cmake release tag or branch
  24. if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake)
  25. file(DOWNLOAD https://github.com/tohara/marlin-cmake/archive/${SCRIPT_BRANCH}.tar.gz
  26. ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake-src.tar.gz SHOW_PROGRESS)
  27. execute_process(COMMAND ${CMAKE_COMMAND} -E tar -xvf ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake-src.tar.gz WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
  28. file(RENAME ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake-${SCRIPT_BRANCH} ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake)
  29. file(REMOVE ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake-src.tar.gz)
  30. endif()
  31. if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/modules/Arduino_SDK.cmake)
  32. file(DOWNLOAD https://raw.githubusercontent.com/tohara/marlin-cmake/master/modules/Arduino_SDK.cmake
  33. ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/modules/Arduino_SDK.cmake SHOW_PROGRESS)
  34. endif()
  35. if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/modules/marlin_cmake_functions.cmake)
  36. file(DOWNLOAD https://raw.githubusercontent.com/tohara/marlin-cmake/master/modules/marlin_cmake_functions.cmake
  37. ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/modules/marlin_cmake_functions.cmake SHOW_PROGRESS)
  38. endif()
  39. if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/Platform/Arduino.cmake)
  40. file(DOWNLOAD https://raw.githubusercontent.com/tohara/marlin-cmake/master/Platform/Arduino.cmake
  41. ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/Platform/Arduino.cmake SHOW_PROGRESS)
  42. endif()
  43. if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/settings/marlin_boards.txt)
  44. file(DOWNLOAD https://raw.githubusercontent.com/tohara/marlin-cmake/master/settings/marlin_boards.txt
  45. ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/settings/marlin_boards.txt SHOW_PROGRESS)
  46. endif()
  47. if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/toolchain/ArduinoToolchain.cmake)
  48. file(DOWNLOAD https://raw.githubusercontent.com/tohara/marlin-cmake/master/toolchain/ArduinoToolchain.cmake
  49. ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/toolchain/ArduinoToolchain.cmake SHOW_PROGRESS)
  50. endif()
  51. if(WIN32)
  52. if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/resources/make.exe)
  53. file(DOWNLOAD https://raw.githubusercontent.com/tohara/marlin-cmake/master/resources/make.exe
  54. ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/resources/make.exe SHOW_PROGRESS)
  55. endif()
  56. endif(WIN32)
  57. if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/arduino-1.8.19)
  58. file(DOWNLOAD https://downloads.arduino.cc/arduino-1.8.19-windows.zip
  59. ${CMAKE_CURRENT_LIST_DIR}/arduino-1.8.19-windows.zip SHOW_PROGRESS)
  60. execute_process(COMMAND ${CMAKE_COMMAND} -E tar -xvzf ${CMAKE_CURRENT_LIST_DIR}/arduino-1.8.19-windows.zip WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
  61. file(REMOVE ${CMAKE_CURRENT_LIST_DIR}/arduino-1.8.19-windows.zip)
  62. endif()
  63. # Print CMake version
  64. message("-- Running CMake version: " ${CMAKE_VERSION})
  65. # Replace the CMake Ver. in the Arduino.cmake
  66. file(READ "${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/Platform/Arduino.cmake" ORIGINAL_FILE_CONTENTS)
  67. string(REGEX REPLACE "cmake_minimum_required\\(VERSION[^\n]*\n" "cmake_minimum_required(VERSION 3.10)\n" NEW_FILE_CONTENTS "${ORIGINAL_FILE_CONTENTS}")
  68. file(WRITE "${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/Platform/Arduino.cmake" "${NEW_FILE_CONTENTS}")
  69. # Fix "CMake Error... avr-gcc / avr-g++ is not a full path..."
  70. if(UNIX)
  71. set(ORIGINAL_FILE_CONTENTS "")
  72. set(NEW_FILE_CONTENTS "")
  73. file(READ "${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/toolchain/ArduinoToolchain.cmake" ORIGINAL_FILE_CONTENTS)
  74. string(REPLACE "set(CMAKE_C_COMPILER avr-gcc)\nset(CMAKE_CXX_COMPILER avr-g++)"
  75. "set(CMAKE_C_COMPILER /usr/bin/gcc)\nset(CMAKE_CXX_COMPILER /usr/bin/gcc)"
  76. NEW_FILE_CONTENTS "${ORIGINAL_FILE_CONTENTS}")
  77. file(WRITE "${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/toolchain/ArduinoToolchain.cmake" "${NEW_FILE_CONTENTS}")
  78. endif(UNIX)
  79. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/modules)
  80. #====================================================================#
  81. # Custom path to Arduino SDK can be set here #
  82. # It can also be set from command line. eg.: #
  83. # cmake .. -DARDUINO_SDK_PATH="/path/to/arduino-1.x.x" #
  84. #====================================================================#
  85. set(ARDUINO_SDK_PATH ${CMAKE_CURRENT_LIST_DIR}/arduino-1.8.19)
  86. #set(ARDUINO_SDK_PATH /Applications/Arduino.app/Contents/Java)
  87. #set(ARDUINO_SDK_PATH $HOME/ArduinoAddons/Arduino_1.6.x)
  88. #====================================================================#
  89. # Set included cmake files #
  90. #====================================================================#
  91. include(Arduino_SDK) # Find the intallpath of Arduino SDK
  92. include(marlin_cmake_functions)
  93. #====================================================================#
  94. # Set toolchain file for arduino #
  95. #====================================================================#
  96. set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/toolchain/ArduinoToolchain.cmake) # Arduino Toolchain
  97. #====================================================================#
  98. # Setup Project #
  99. # #
  100. # If you receive this error: #
  101. # 'Unknown CMake command "_cmake_record_install_prefix".' #
  102. # #
  103. # Go to the file in your CMake directory #
  104. # #
  105. # For Windows: cmake\Modules\Platform\WindowsPaths.cmake #
  106. # For macOS: cmake/Modules/Platform/UnixPaths.cmake #
  107. # For Linux: cmake/Modules/Platform/UnixPaths.cmake #
  108. # #
  109. # Comment out "_cmake_record_install_prefix()" #
  110. # - OR - #
  111. # Add "include(CMakeSystemSpecificInformation)" above the line #
  112. # #
  113. #====================================================================#
  114. project(Marlin C CXX)
  115. #====================================================================#
  116. # Register non standard hardware #
  117. #====================================================================#
  118. #register_hardware_platform(/home/tom/test/Sanguino)
  119. #====================================================================#
  120. # Print any info #
  121. # print_board_list() #
  122. # print_programmer_list() #
  123. # print_board_settings(mega) #
  124. #====================================================================#
  125. print_board_list()
  126. print_programmer_list()
  127. #====================================================================#
  128. # Get motherboard settings from Configuration.h #
  129. # setup_motherboard(TARGET Marlin_src_folder) #
  130. # Returns ${TARGET}_BOARD and ${TARGET}_CPU #
  131. # #
  132. # To set it manually: #
  133. # set(${PROJECT_NAME}_BOARD mega) #
  134. # set(${PROJECT_NAME}_CPU atmega2560) #
  135. #====================================================================#
  136. setup_motherboard(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/../../../Marlin)
  137. #====================================================================#
  138. # Setup all source files #
  139. # Include Marlin.ino to compile libs not included in *.cpp files #
  140. #====================================================================#
  141. file(GLOB_RECURSE SOURCES "../../../Marlin/*.cpp")
  142. set(${PROJECT_NAME}_SRCS "${SOURCES};../../../Marlin/Marlin.ino")
  143. #====================================================================#
  144. # Define the port for uploading code to the Arduino #
  145. # Can be set from commandline with: #
  146. # cmake .. -DUPLOAD_PORT=/dev/ttyACM0 #
  147. #====================================================================#
  148. if(UPLOAD_PORT)
  149. set(${PROJECT_NAME}_PORT ${UPLOAD_PORT})
  150. else()
  151. set(${PROJECT_NAME}_PORT /dev/ttyACM0)
  152. endif()
  153. #====================================================================#
  154. # Register arduino libraries not included in SDK #
  155. #====================================================================#
  156. #link_directories(/home/tom/test/ArduinoAddons) #U8glib
  157. #set(${PROJECT_NAME}_ARDLIBS U8glib)
  158. #set(U8glib_RECURSE True)
  159. #====================================================================#
  160. # Command to generate code arduino firmware (.hex file) #
  161. #====================================================================#
  162. generate_arduino_firmware(${PROJECT_NAME})