|
| 1 | +#=============================================================================# |
| 2 | +# Gets the path of the user's Arduino IDE preferences file, usually located in a hidden directory |
| 3 | +# under the home directory. |
| 4 | +# _return_var - Name of variable in parent-scope holding the return value. |
| 5 | +# Returns - Filtered list of architectures. |
| 6 | +#=============================================================================# |
| 7 | +function(_get_user_preferences_file_path _return_var) |
| 8 | + |
| 9 | + set(preferences_file_name preferences.txt) |
| 10 | + |
| 11 | + if (${CMAKE_HOST_UNIX}) |
| 12 | + if (${CMAKE_HOST_APPLE}) # Mac OS X |
| 13 | + set(dir_path "$ENV{HOME}/Library/Processing/${preferences_file_name}") |
| 14 | + else () # Linux |
| 15 | + set(dir_path "$ENV{HOME}/.processing/${preferences_file_name}") |
| 16 | + endif () |
| 17 | + else () # Windows |
| 18 | + string(REPLACE "\\" "/" home_path $ENV{HOMEPATH}) |
| 19 | + string(REPLACE "\\" "/" home_drive $ENV{HOMEDRIVE}) |
| 20 | + string(CONCAT home_path ${home_drive} ${home_path}) |
| 21 | + set(dir_path "${home_path}/AppData/Local/arduino15/${preferences_file_name}") |
| 22 | + endif () |
| 23 | + |
| 24 | + set(${_return_var} ${dir_path} PARENT_SCOPE) |
| 25 | + |
| 26 | +endfunction() |
| 27 | + |
| 28 | +#=============================================================================# |
| 29 | +# Finds the location of Arduino IDE's Sketchbook directory, where all libraries and sketches |
| 30 | +# are downloaded to. |
| 31 | +#=============================================================================# |
| 32 | +function(find_sketchbook_path) |
| 33 | + |
| 34 | + _get_user_preferences_file_path(arduino_ide_preferences_file) |
| 35 | + if (NOT EXISTS "${arduino_ide_preferences_file}") |
| 36 | + string(CONCAT error_message |
| 37 | + "Arduino IDE preferences file couldn't be found at " |
| 38 | + "${arduino_ide_preferences_file}.\n" |
| 39 | + "ARDUINO_CMAKE_SKETCHBOOK_PATH should be manually set to the real Sketchbook path") |
| 40 | + message(WARNING ${error_message}) |
| 41 | + return() |
| 42 | + endif () |
| 43 | + |
| 44 | + file(STRINGS "${arduino_ide_preferences_file}" arduino_ide_preferences) |
| 45 | + list(FILTER arduino_ide_preferences INCLUDE REGEX "sketchbook") |
| 46 | + _get_property_value(${arduino_ide_preferences} sketchbook_path) |
| 47 | + |
| 48 | + set(ARDUINO_CMAKE_SKETCHBOOK_PATH "${sketchbook_path}" CACHE PATH |
| 49 | + "Arduino IDE's Sketchbook Path") |
| 50 | + |
| 51 | +endfunction() |
0 commit comments