CMakeLists.txt 9.8 KB

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