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..be65f7a 100644 --- a/cmake/Platform/Other/ArduinoSDKSeeker.cmake +++ b/cmake/Platform/Other/ArduinoSDKSeeker.cmake @@ -40,3 +40,59 @@ 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}) + 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}" 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 () + +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}) + 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" OR EXISTS "/etc/avrdude/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 "") diff --git a/cmake/Platform/System/SketchbookFinder.cmake b/cmake/Platform/System/SketchbookFinder.cmake index b4db28a..cc3c781 100644 --- a/cmake/Platform/System/SketchbookFinder.cmake +++ b/cmake/Platform/System/SketchbookFinder.cmake @@ -10,9 +10,17 @@ 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 - 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}) 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})