Skip to content

Commit

Permalink
🔨 Fix cmake build on Linux (#27605)
Browse files Browse the repository at this point in the history
  • Loading branch information
classicrocker883 authored Jan 11, 2025
1 parent a7d7961 commit 8d7ecad
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions buildroot/share/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.10)
#====================================================================#
# Usage under Linux: #
# #
# From Marlin/buildroot/share/cmake folder: #
# From the project folder: #
# cd buildroot/share/cmake #
# mkdir -p build && cd build #
# cmake .. #
# make #
# #
# Usage under Windows: #
# #
# From Marlin/buildroot/share/cmake folder: #
# From the project folder: #
# cd buildroot/share/cmake #
# mkdir build && cd build #
# cmake -G"Unix Makefiles" .. #
# make #
Expand Down Expand Up @@ -82,10 +84,21 @@ 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(REGEX REPLACE "cmake_minimum_required\\(VERSION[^\n]*\n" "cmake_minimum_required(VERSION 3.5)\n" NEW_FILE_CONTENTS "${ORIGINAL_FILE_CONTENTS}")
string(REGEX REPLACE "cmake_minimum_required\\(VERSION[^\n]*\n" "cmake_minimum_required(VERSION 3.10)\n" NEW_FILE_CONTENTS "${ORIGINAL_FILE_CONTENTS}")
file(WRITE "${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/Platform/Arduino.cmake" "${NEW_FILE_CONTENTS}")

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/modules)
# Fix "CMake Error... avr-gcc / avr-g++ is not a full path..."
if(UNIX)
set(ORIGINAL_FILE_CONTENTS "")
set(NEW_FILE_CONTENTS "")
file(READ "${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/toolchain/ArduinoToolchain.cmake" ORIGINAL_FILE_CONTENTS)
string(REPLACE "set(CMAKE_C_COMPILER avr-gcc)\nset(CMAKE_CXX_COMPILER avr-g++)"
"set(CMAKE_C_COMPILER /usr/bin/gcc)\nset(CMAKE_CXX_COMPILER /usr/bin/gcc)"
NEW_FILE_CONTENTS "${ORIGINAL_FILE_CONTENTS}")
file(WRITE "${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/toolchain/ArduinoToolchain.cmake" "${NEW_FILE_CONTENTS}")
endif(UNIX)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/modules)

#====================================================================#
# Custom path to Arduino SDK can be set here #
Expand Down Expand Up @@ -116,6 +129,7 @@ set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/marlin-cmake/toolchain/Arduin
# Go to the file in your CMake directory #
# #
# For Windows: cmake\Modules\Platform\WindowsPaths.cmake #
# For macOS: cmake/Modules/Platform/UnixPaths.cmake #
# For Linux: cmake/Modules/Platform/UnixPaths.cmake #
# #
# Comment out "_cmake_record_install_prefix()" #
Expand Down

0 comments on commit 8d7ecad

Please sign in to comment.