Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit d87dc5e

Browse files
committed
Added feature to automatically find Sketchbook location if option is enabled.
1 parent 3e032cb commit d87dc5e

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

cmake/Platform/System/BuildSystemInitializer.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ include(AvrToolsFinder)
22
include(VersionDetector)
33
include(PlatformInitializer)
44
include(LinuxDistDetector)
5+
include(SketchbookFinder)
56

67
function(find_required_platform_tools)
78

@@ -23,6 +24,9 @@ function(initialize_build_system)
2324
if (CMAKE_HOST_UNIX AND NOT CMAKE_HOST_APPLE) # Detect host's Linux distribution
2425
detect_host_linux_distribution()
2526
endif ()
27+
if (AUTO_SET_SKETCHBOOK_PATH)
28+
find_sketchbook_path()
29+
endif ()
2630

2731
initialize_arduino_platform()
2832

cmake/Platform/System/DefaultsManager.cmake

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,21 @@ endfunction()
3939
function(set_default_arduino_cmake_options)
4040

4141
option(USE_DEFAULT_PLATFORM_IF_NONE_EXISTING
42-
"Whether to use Arduino as default platform if none is supplied" ON)
42+
"Whether to use Arduino as default platform if none is supplied"
43+
ON)
4344
option(USE_CUSTOM_PLATFORM_HEADER
4445
"Whether to expect and use a custom-supplied platform header, \
45-
skipping the selection algorithm" OFF)
46+
skipping the selection algorithm"
47+
OFF)
4648
option(USE_ARCHLINUX_BUILTIN_SUPPORT
47-
"Whether to use Arduino CMake's built-in support for the archlinux distribution" ON)
49+
"Whether to use Arduino CMake's built-in support for the archlinux distribution"
50+
ON)
4851
option(CONVERT_SKETCHES_IF_CONVERTED_SOURCES_EXISTS
4952
"Whether to convert sketches to source files even if converted sources already exist"
5053
OFF)
54+
option(AUTO_SET_SKETCHBOOK_PATH
55+
"Whether Arduino IDE's Sketchbook Location should be automatically found"
56+
ON)
5157

5258
endfunction()
5359

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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

Comments
 (0)