Marlin/buildroot/share/cmake/CMakeLists.txt

183 lines
9.8 KiB
CMake
Raw Normal View History

cmake_minimum_required(VERSION 3.5)
2016-11-18 04:07:47 +00:00
#====================================================================#
# Usage under Linux: #
# #
# From Marlin/buildroot/share/cmake folder: #
# mkdir -p build && cd build #
# cmake .. #
# make #
# #
# Usage under Windows: #
# #
2017-01-15 05:39:26 +00:00
# From Marlin/buildroot/share/cmake folder: #
2016-11-18 04:07:47 +00:00
# mkdir build && cd build #
# cmake -G"Unix Makefiles" .. #
# make #
#====================================================================#
2017-04-20 22:43:19 +00:00
2016-11-18 04:07:47 +00:00
#====================================================================#
# Download marlin-cmake scriptfiles if not already installed #
# and add the path to the module path #
#====================================================================#
2017-01-15 05:39:26 +00:00
set(SCRIPT_BRANCH 1.0.2) #Set to wanted marlin-cmake release tag or branch
2016-11-18 04:07:47 +00:00
2017-01-15 05:39:26 +00:00
if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake)
2023-06-18 04:19:28 +00:00
file(DOWNLOAD https://github.com/tohara/marlin-cmake/archive/${SCRIPT_BRANCH}.tar.gz
${CMAKE_CURRENT_LIST_DIR}/marlin-cmake-src.tar.gz SHOW_PROGRESS)
2017-04-20 22:43:19 +00:00
2023-06-18 04:19:28 +00:00
execute_process(COMMAND ${CMAKE_COMMAND} -E tar -xvf ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake-src.tar.gz WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
2017-04-20 22:43:19 +00:00
2023-06-18 04:19:28 +00:00
file(RENAME ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake-${SCRIPT_BRANCH} ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake)
file(REMOVE ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake-src.tar.gz)
2017-04-20 22:43:19 +00:00
2023-06-18 04:19:28 +00:00
endif()
if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/modules/Arduino_SDK.cmake)
file(DOWNLOAD https://raw.githubusercontent.com/tohara/marlin-cmake/master/modules/Arduino_SDK.cmake
${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/modules/Arduino_SDK.cmake SHOW_PROGRESS)
endif()
if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/modules/marlin_cmake_functions.cmake)
file(DOWNLOAD https://raw.githubusercontent.com/tohara/marlin-cmake/master/modules/marlin_cmake_functions.cmake
${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/modules/marlin_cmake_functions.cmake SHOW_PROGRESS)
endif()
2017-04-20 22:43:19 +00:00
2023-06-18 04:19:28 +00:00
if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/Platform/Arduino.cmake)
file(DOWNLOAD https://raw.githubusercontent.com/tohara/marlin-cmake/master/Platform/Arduino.cmake
${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/Platform/Arduino.cmake SHOW_PROGRESS)
2017-01-15 05:39:26 +00:00
endif()
2016-11-18 04:07:47 +00:00
2023-06-18 04:19:28 +00:00
if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/settings/marlin_boards.txt)
file(DOWNLOAD https://raw.githubusercontent.com/tohara/marlin-cmake/master/settings/marlin_boards.txt
${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/settings/marlin_boards.txt SHOW_PROGRESS)
2016-11-18 04:07:47 +00:00
endif()
2023-06-18 04:19:28 +00:00
if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/toolchain/ArduinoToolchain.cmake)
file(DOWNLOAD https://raw.githubusercontent.com/tohara/marlin-cmake/master/toolchain/ArduinoToolchain.cmake
${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/toolchain/ArduinoToolchain.cmake SHOW_PROGRESS)
endif()
if(WIN32)
if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/resources/make.exe)
file(DOWNLOAD https://raw.githubusercontent.com/tohara/marlin-cmake/master/resources/make.exe
${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/resources/make.exe SHOW_PROGRESS)
endif()
endif(WIN32)
if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/arduino-1.8.19)
file(DOWNLOAD https://downloads.arduino.cc/arduino-1.8.19-windows.zip
${CMAKE_CURRENT_LIST_DIR}/arduino-1.8.19-windows.zip SHOW_PROGRESS)
execute_process(COMMAND ${CMAKE_COMMAND} -E tar -xvzf ${CMAKE_CURRENT_LIST_DIR}/arduino-1.8.19-windows.zip WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
file(REMOVE ${CMAKE_CURRENT_LIST_DIR}/arduino-1.8.19-windows.zip)
endif()
# Print CMake version
message("-- Running CMake version: " ${CMAKE_VERSION})
# Replace the CMake Ver. in the Arduino.cmake
file(READ "${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/Platform/Arduino.cmake" ORIGINAL_FILE_CONTENTS)
string(REPLACE "cmake_minimum_required(VERSION 2.8.5)" "cmake_minimum_required(VERSION 3.5)" NEW_FILE_CONTENTS "${ORIGINAL_FILE_CONTENTS}")
2023-06-18 04:19:28 +00:00
file(WRITE "${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/Platform/Arduino.cmake" "${NEW_FILE_CONTENTS}")
2017-01-15 05:39:26 +00:00
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/modules)
2016-11-18 04:07:47 +00:00
#====================================================================#
# Custom path to Arduino SDK can be set here. #
# It can also be set from command line. eg.: #
# cmake .. -DARDUINO_SDK_PATH="/path/to/arduino-1.x.x" #
#====================================================================#
2023-06-18 04:19:28 +00:00
set(ARDUINO_SDK_PATH ${CMAKE_CURRENT_LIST_DIR}/arduino-1.8.19)
#set(ARDUINO_SDK_PATH /Applications/Arduino.app/Contents/Java)
#set(ARDUINO_SDK_PATH $HOME/ArduinoAddons/Arduino_1.6.x)
2016-11-18 04:07:47 +00:00
#====================================================================#
# Set included cmake files #
#====================================================================#
include(Arduino_SDK) # Find the intallpath of Arduino SDK
include(marlin_cmake_functions)
#====================================================================#
# Set toolchain file for arduino #
#====================================================================#
2017-01-15 05:39:26 +00:00
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/toolchain/ArduinoToolchain.cmake) # Arduino Toolchain
2016-11-18 04:07:47 +00:00
#====================================================================#
# Setup Project #
# #
# If you receive this error: #
# 'Unknown CMake command "_cmake_record_install_prefix".' #
# #
# Go to the file in your CMake directory. #
# #
# For Windows: cmake\Modules\Platform\WindowsPaths.cmake #
# For Linux: cmake/Modules/Platform/UnixPaths.cmake #
# #
# Comment out "_cmake_record_install_prefix()" #
# - OR - #
# Add "include(CMakeSystemSpecificInformation)" above the line. #
# #
2016-11-18 04:07:47 +00:00
#====================================================================#
project(Marlin C CXX)
#====================================================================#
# Register non standard hardware #
#====================================================================#
#register_hardware_platform(/home/tom/test/Sanguino)
#====================================================================#
# Print any info #
# print_board_list() #
# print_programmer_list() #
# print_board_settings(mega) #
#====================================================================#
print_board_list()
print_programmer_list()
#====================================================================#
# Get motherboard settings from Configuration.h #
# setup_motherboard(TARGET Marlin_src_folder) #
# Returns ${TARGET}_BOARD and ${TARGET}_CPU #
# #
# To set it manually: #
# set(${PROJECT_NAME}_BOARD mega) #
# set(${PROJECT_NAME}_CPU atmega2560) #
#====================================================================#
setup_motherboard(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/../../../Marlin)
#====================================================================#
# Setup all source files #
2017-09-06 11:28:32 +00:00
# Include Marlin.ino to compile libs not included in *.cpp files #
2016-11-18 04:07:47 +00:00
#====================================================================#
file(GLOB_RECURSE SOURCES "../../../Marlin/*.cpp")
set(${PROJECT_NAME}_SRCS "${SOURCES};../../../Marlin/Marlin.ino")
2016-11-18 04:07:47 +00:00
#====================================================================#
# Define the port for uploading code to the Arduino #
# Can be set from commandline with: #
# cmake .. -DUPLOAD_PORT=/dev/ttyACM0 #
#====================================================================#
if(UPLOAD_PORT)
2023-06-18 04:19:28 +00:00
set(${PROJECT_NAME}_PORT ${UPLOAD_PORT})
2016-11-18 04:07:47 +00:00
else()
2023-06-18 04:19:28 +00:00
set(${PROJECT_NAME}_PORT /dev/ttyACM0)
2016-11-18 04:07:47 +00:00
endif()
#====================================================================#
# Register arduino libraries not included in SDK #
#====================================================================#
#link_directories(/home/tom/test/ArduinoAddons) #U8glib
#set(${PROJECT_NAME}_ARDLIBS U8glib)
#set(U8glib_RECURSE True)
#====================================================================#
# Command to generate code arduino firmware (.hex file) #
#====================================================================#
generate_arduino_firmware(${PROJECT_NAME})