From c1d95c5525baba7c95730abf08d2b54e7a9603a8 Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Sat, 13 Apr 2019 15:40:02 -0500 Subject: [PATCH 1/7] Preliminary Arch Linux support --- cmake/Arduino-Toolchain.cmake | 6 ++- cmake/Platform/Other/ArduinoSDKSeeker.cmake | 40 +++++++++++++++++++ .../Platform/System/PlatformInitializer.cmake | 2 +- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/cmake/Arduino-Toolchain.cmake b/cmake/Arduino-Toolchain.cmake index 066974b..ced8e46 100644 --- a/cmake/Arduino-Toolchain.cmake +++ b/cmake/Arduino-Toolchain.cmake @@ -37,9 +37,11 @@ endfunction() function(_setup_sdk_internal_paths) - set(ARDUINO_SDK_BIN_PATH "${ARDUINO_SDK_PATH}/hardware/tools/avr/bin" CACHE PATH + find_arduino_sdk_bin(arduino_bin_path) + set(ARDUINO_SDK_BIN_PATH "${arduino_bin_path}" CACHE PATH "Path to Arduino SDK's binaries folder") - set(ARDUINO_SDK_ROOT_PATH "${ARDUINO_SDK_PATH}/hardware/tools/avr" CACHE PATH + find_arduino_sdk_root(arduino_root_path) + set(ARDUINO_SDK_ROOT_PATH "${arduino_root_path}" CACHE PATH "Path to Arduino SDK's sys-root folder") set(ARDUINO_SDK_LIBRARIES_PATH "${ARDUINO_SDK_PATH}/libraries" CACHE PATH "Path to SDK's libraries directory") diff --git a/cmake/Platform/Other/ArduinoSDKSeeker.cmake b/cmake/Platform/Other/ArduinoSDKSeeker.cmake index 18e915a..2ad11b5 100644 --- a/cmake/Platform/Other/ArduinoSDKSeeker.cmake +++ b/cmake/Platform/Other/ArduinoSDKSeeker.cmake @@ -40,3 +40,43 @@ function(find_arduino_sdk _return_var) endfunction() +function(find_arduino_sdk_bin _return_var) + + if (DEFINED ENV{ARDUINO_SDK_BIN_PATH}) + string(REPLACE "\\" "/" unix_style_sdk_bin_path $ENV{ARDUINO_SDK_BIN_PATH}) + set(${_return_var} "${unix_style_sdk_bin_path}" PARENT_SCOPE) + elseif (IS_DIRECTORY "${ARDUINO_SDK_PATH}/hardware/tools/avr/bin") + set(${_return_var} "${ARDUINO_SDK_PATH}/hardware/tools/avr/bin" PARENT_SCOPE) + else () + # Some systems like the Arch Linux arduino package install binaries to /usr/bin + find_program(avr_gcc_location avr-gcc) + if (avr_gcc_location) + get_filename_component(avr_gcc_parent ${avr_gcc_location} DIRECTORY) + set(${_return_var} "${avr_gcc_parent}" PARENT_SCOPE) + else () + string(CONCAT error_message + "Couldn't find Arduino bin path - Is it in a non-standard location?" "\n" + "If so, please set the ARDUINO_SDK_BIN_PATH CMake-Variable") + message(FATAL_ERROR ${error_message}) + endif () + endif () + +endfunction() + +function(find_arduino_sdk_root _return_var) + + if (DEFINED ENV{ARDUINO_SDK_ROOT_PATH}) + string(REPLACE "\\" "/" unix_style_sdk_root_path $ENV{ARDUINO_SDK_ROOT_PATH}) + set(${_return_var} "${unix_style_sdk_root_path}" PARENT_SCOPE) + elseif (EXISTS "${ARDUINO_SDK_PATH}/hardware/tools/avr/etc/avrdude.conf") + set(${_return_var} "${ARDUINO_SDK_PATH}/hardware/tools/avr" PARENT_SCOPE) + elseif (EXISTS "/etc/avrdude.conf") + set(${_return_var} "/" PARENT_SCOPE) + else () + string(CONCAT error_message + "Couldn't find Arduino root path - Is it in a non-standard location?" "\n" + "If so, please set the ARDUINO_SDK_ROOT_PATH CMake-Variable") + message(FATAL_ERROR ${error_message}) + endif () + +endfunction() diff --git a/cmake/Platform/System/PlatformInitializer.cmake b/cmake/Platform/System/PlatformInitializer.cmake index 19ba5db..1079ab0 100644 --- a/cmake/Platform/System/PlatformInitializer.cmake +++ b/cmake/Platform/System/PlatformInitializer.cmake @@ -37,7 +37,7 @@ function(initialize_arduino_platform) if (NOT DEFINED ARDUINO_CMAKE_PLATFORM_NAME OR NOT DEFINED ARDUINO_CMAKE_PLATFORM_PATH) if (USE_DEFAULT_PLATFORM_IF_NONE_EXISTING) - if (CMAKE_HOST_ARCHLINUX AND ${USE_ARCHLINUX_BUILTIN_SUPPORT}) + if (IS_DIRECTORY "${ARDUINO_SDK_PATH}/hardware/archlinux-arduino") set(ARDUINO_CMAKE_PLATFORM_NAME "archlinux-arduino" CACHE STRING "") else () set(ARDUINO_CMAKE_PLATFORM_NAME "arduino" CACHE STRING "") From e024115381e634d43b1ec82471357dbff68dcdb7 Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Sat, 13 Apr 2019 21:31:21 -0500 Subject: [PATCH 2/7] Fix sketchbook finder for newer linux versions of Arduino IDE --- cmake/Platform/System/SketchbookFinder.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmake/Platform/System/SketchbookFinder.cmake b/cmake/Platform/System/SketchbookFinder.cmake index b4db28a..98ac655 100644 --- a/cmake/Platform/System/SketchbookFinder.cmake +++ b/cmake/Platform/System/SketchbookFinder.cmake @@ -12,7 +12,11 @@ function(_get_user_preferences_file_path _return_var) if (${CMAKE_HOST_APPLE}) # Mac OS X set(dir_path "$ENV{HOME}/Library/Processing/${preferences_file_name}") else () # Linux - set(dir_path "$ENV{HOME}/.processing/${preferences_file_name}") + if (EXISTS "$ENV{HOME}/.arduino15/${preferences_file_name}") + set(dir_path "$ENV{HOME}/.arduino15/${preferences_file_name}") + else () + set(dir_path "$ENV{HOME}/.processing/${preferences_file_name}") + endif () endif () else () # Windows string(REPLACE "\\" "/" home_path $ENV{HOMEPATH}) From bfd4103259f2ca9008a9a1a7989d28ca7b2ab575 Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Sat, 13 Apr 2019 21:32:32 -0500 Subject: [PATCH 3/7] Fix example finding for distros that don't bundle base arduino libraries --- cmake/Platform/Targets/ArduinoExampleTarget.cmake | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmake/Platform/Targets/ArduinoExampleTarget.cmake b/cmake/Platform/Targets/ArduinoExampleTarget.cmake index 57f49b2..c20fb7a 100644 --- a/cmake/Platform/Targets/ArduinoExampleTarget.cmake +++ b/cmake/Platform/Targets/ArduinoExampleTarget.cmake @@ -42,7 +42,15 @@ function(add_arduino_library_example _target_name _library_target_name _library_ message(SEND_ERROR "Library target doesn't exist - It must be created first!") endif () - find_arduino_library_example_sources("${ARDUINO_SDK_LIBRARIES_PATH}/${arduino_compliant_library_name}" + find_file(library_path + NAMES ${arduino_compliant_library_name} + PATHS ${ARDUINO_CMAKE_PLATFORM_LIBRARIES_PATH} ${ARDUINO_SDK_LIBRARIES_PATH} + ${ARDUINO_CMAKE_SKETCHBOOK_PATH} ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR} + PATH_SUFFIXES libraries dependencies + NO_DEFAULT_PATH + NO_CMAKE_FIND_ROOT_PATH) + + find_arduino_library_example_sources("${library_path}" ${arduino_compliant_example_name} example_sketches ${ARGN}) add_arduino_executable(${_target_name}) From 229c00ab4492824aa91eb9d9ed82f1b01bc957d7 Mon Sep 17 00:00:00 2001 From: tellowkrinkle Date: Sat, 13 Apr 2019 21:38:17 -0500 Subject: [PATCH 4/7] Add documentation to new functions --- cmake/Platform/Other/ArduinoSDKSeeker.cmake | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cmake/Platform/Other/ArduinoSDKSeeker.cmake b/cmake/Platform/Other/ArduinoSDKSeeker.cmake index 2ad11b5..ae17c1f 100644 --- a/cmake/Platform/Other/ArduinoSDKSeeker.cmake +++ b/cmake/Platform/Other/ArduinoSDKSeeker.cmake @@ -40,6 +40,14 @@ function(find_arduino_sdk _return_var) endfunction() +#=============================================================================# +# Attempts to find the Arduino SDK's bin folder in the host system, searching at known locations. +# Most installs will have it at SDK/hardware/tools/avr/bin but if nothing is there, it will +# attempt to find a folder in PATH containing avr-gcc, hoping that everything else will be there too +# This is because a bunch of linux distros' package managers install the binaries into /usr/bin +# _return_var - Name of variable in parent-scope holding the return value. +# Returns - Path to the folder containing Arduino compiler binaries +#=============================================================================# function(find_arduino_sdk_bin _return_var) if (DEFINED ENV{ARDUINO_SDK_BIN_PATH}) @@ -63,6 +71,14 @@ function(find_arduino_sdk_bin _return_var) endfunction() +#=============================================================================# +# Attempts to find the Arduino SDK's root folder in the host system, searching at known locations. +# Most installs will have it at SDK/hardware/tools/avr/ but if nothing is there, it will +# attempt to find a folder containing etc/avrdude.conf, since a bunch of linux distros +# put this into /etc rather than a subdirectory of the arduino SDK +# _return_var - Name of variable in parent-scope holding the return value. +# Returns - Path to the directory containing etc/avrdude.conf +#=============================================================================# function(find_arduino_sdk_root _return_var) if (DEFINED ENV{ARDUINO_SDK_ROOT_PATH}) From e459a6853d3d809b91dbb7c03b9cd33d9de9a9b8 Mon Sep 17 00:00:00 2001 From: tellowkrinkle Date: Sat, 13 Apr 2019 21:45:13 -0500 Subject: [PATCH 5/7] Fix sketchbook finding for newer versions of macOS IDE --- cmake/Platform/System/SketchbookFinder.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmake/Platform/System/SketchbookFinder.cmake b/cmake/Platform/System/SketchbookFinder.cmake index 98ac655..cc3c781 100644 --- a/cmake/Platform/System/SketchbookFinder.cmake +++ b/cmake/Platform/System/SketchbookFinder.cmake @@ -10,7 +10,11 @@ function(_get_user_preferences_file_path _return_var) if (${CMAKE_HOST_UNIX}) if (${CMAKE_HOST_APPLE}) # Mac OS X - set(dir_path "$ENV{HOME}/Library/Processing/${preferences_file_name}") + if (EXISTS "$ENV{HOME}/Library/Arduino15/${preferences_file_name}") + set(dir_path "$ENV{HOME}/Library/Arduino15/${preferences_file_name}") + else () + set(dir_path "$ENV{HOME}/Library/Processing/${preferences_file_name}") + endif () else () # Linux if (EXISTS "$ENV{HOME}/.arduino15/${preferences_file_name}") set(dir_path "$ENV{HOME}/.arduino15/${preferences_file_name}") From d35d0543c3e977f8b6414041b74854f2d9a7e036 Mon Sep 17 00:00:00 2001 From: tellowkrinkle Date: Fri, 19 Apr 2019 19:41:30 -0500 Subject: [PATCH 6/7] Fedora support --- cmake/Platform/Other/ArduinoSDKSeeker.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Platform/Other/ArduinoSDKSeeker.cmake b/cmake/Platform/Other/ArduinoSDKSeeker.cmake index ae17c1f..c0e82b3 100644 --- a/cmake/Platform/Other/ArduinoSDKSeeker.cmake +++ b/cmake/Platform/Other/ArduinoSDKSeeker.cmake @@ -86,7 +86,7 @@ function(find_arduino_sdk_root _return_var) set(${_return_var} "${unix_style_sdk_root_path}" PARENT_SCOPE) elseif (EXISTS "${ARDUINO_SDK_PATH}/hardware/tools/avr/etc/avrdude.conf") set(${_return_var} "${ARDUINO_SDK_PATH}/hardware/tools/avr" PARENT_SCOPE) - elseif (EXISTS "/etc/avrdude.conf") + elseif (EXISTS "/etc/avrdude.conf" OR EXISTS "/etc/avrdude/avrdude.conf") set(${_return_var} "/" PARENT_SCOPE) else () string(CONCAT error_message From 649e8f2c7378b0c5e8e58078cfb511c8659f2980 Mon Sep 17 00:00:00 2001 From: tellowkrinkle Date: Mon, 22 Apr 2019 02:04:27 -0500 Subject: [PATCH 7/7] Use `MATCHES "NOTFOUND"` for variable checks --- cmake/Platform/Other/ArduinoSDKSeeker.cmake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmake/Platform/Other/ArduinoSDKSeeker.cmake b/cmake/Platform/Other/ArduinoSDKSeeker.cmake index c0e82b3..be65f7a 100644 --- a/cmake/Platform/Other/ArduinoSDKSeeker.cmake +++ b/cmake/Platform/Other/ArduinoSDKSeeker.cmake @@ -58,14 +58,14 @@ function(find_arduino_sdk_bin _return_var) else () # Some systems like the Arch Linux arduino package install binaries to /usr/bin find_program(avr_gcc_location avr-gcc) - if (avr_gcc_location) - get_filename_component(avr_gcc_parent ${avr_gcc_location} DIRECTORY) - set(${_return_var} "${avr_gcc_parent}" PARENT_SCOPE) - else () + if ("${avr_gcc_location}" MATCHES "NOTFOUND") string(CONCAT error_message "Couldn't find Arduino bin path - Is it in a non-standard location?" "\n" "If so, please set the ARDUINO_SDK_BIN_PATH CMake-Variable") message(FATAL_ERROR ${error_message}) + else () + get_filename_component(avr_gcc_parent ${avr_gcc_location} DIRECTORY) + set(${_return_var} "${avr_gcc_parent}" PARENT_SCOPE) endif () endif ()