Skip to content

Commit e745a9b

Browse files
authored
Identify install path better in Linux (#30)
1 parent 3cd3a77 commit e745a9b

File tree

1 file changed

+53
-8
lines changed

1 file changed

+53
-8
lines changed

Arduino/System/PackagePathIndex.cmake

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ function(InitializeArduinoPackagePathList)
1919

2020
if (${CMAKE_HOST_APPLE})
2121

22-
set(install_search_paths "$ENV{HOME}/Applications" /Applications /Developer/Applications
23-
/sw /opt/local)
24-
set(install_path_suffixes Arduino.app/Contents/Java Arduino.app/Contents/Resources/Java)
22+
set(install_search_paths "$ENV{HOME}/Applications" /Applications
23+
/Developer/Applications /sw /opt/local)
24+
set(install_path_suffixes Arduino.app/Contents/Java
25+
Arduino.app/Contents/Resources/Java)
2526

2627
file(GLOB package_search_paths "$ENV{HOME}/Library/Arduino15")
2728
set(package_path_suffixes "")
@@ -31,10 +32,40 @@ function(InitializeArduinoPackagePathList)
3132

3233
elseif (${CMAKE_HOST_UNIX}) # Probably Linux or some unix-like
3334

34-
file(GLOB install_search_paths /usr/share/arduino* /opt/local/arduino* /opt/arduino*
35-
/usr/local/share/arduino* "$ENV{HOME}/opt/arduino*")
35+
set(install_search_paths)
3636
set(install_path_suffixes "")
3737

38+
# Resolve from arduino executable path
39+
execute_process(COMMAND which arduino OUTPUT_VARIABLE _bin_path
40+
ERROR_VARIABLE _ignore RESULT_VARIABLE _cmd_result)
41+
if (_cmd_result STREQUAL 0)
42+
string(STRIP "${_bin_path}" _bin_path)
43+
execute_process(COMMAND readlink -f "${_bin_path}"
44+
OUTPUT_VARIABLE _link_path RESULT_VARIABLE _cmd_result)
45+
if (_cmd_result STREQUAL 0)
46+
string(STRIP "${_link_path}" _bin_path)
47+
endif()
48+
get_filename_component(_install_path "${_bin_path}" DIRECTORY)
49+
list(APPEND install_search_paths "${_install_path}")
50+
else() # Resolve from application shortcut
51+
set(_app_path "$ENV{HOME}/.local/share/applications")
52+
if (EXISTS "${_app_path}/arduino-arduinoide.desktop")
53+
file(STRINGS "${_app_path}/arduino-arduinoide.desktop"
54+
_exec_prop REGEX "^Exec=")
55+
if ("${_exec_prop}" MATCHES "^Exec=\"?(.*)\"?")
56+
get_filename_component(_install_path "${CMAKE_MATCH_1}"
57+
DIRECTORY)
58+
list(APPEND install_search_paths "${_install_path}")
59+
endif()
60+
endif()
61+
endif()
62+
63+
# Other usual locations
64+
file(GLOB other_search_paths "$ENV{HOME}/.local/share/arduino*"
65+
/usr/share/arduino* /usr/local/share/arduino* /opt/local/arduino*
66+
/opt/arduino* "$ENV{HOME}/opt/arduino*")
67+
list(APPEND install_search_paths "${other_search_paths}")
68+
3869
file(GLOB package_search_paths "$ENV{HOME}/.arduino15")
3970
set(package_path_suffixes "")
4071

@@ -44,18 +75,23 @@ function(InitializeArduinoPackagePathList)
4475
elseif (${CMAKE_HOST_WIN32})
4576

4677
set(Prog86Path "ProgramFiles(x86)")
47-
set(install_search_paths "$ENV{${Prog86Path}}/Arduino" "$ENV{ProgramFiles}/Arduino")
78+
set(install_search_paths "$ENV{${Prog86Path}}/Arduino"
79+
"$ENV{ProgramFiles}/Arduino")
4880
set(install_path_suffixes "")
4981

5082
file(GLOB package_search_paths "$ENV{LOCALAPPDATA}/Arduino15")
5183
set(package_path_suffixes "")
5284

85+
set(_reg_software "HKEY_LOCAL_MACHINE\\SOFTWARE")
86+
set(_reg_win "${_reg_software}\\Microsoft\\Windows\\CurrentVersion")
87+
set(_reg_explorer "${_reg_win}\\Explorer")
5388
file(GLOB sketchbook_search_paths "$ENV{LOCALAPPDATA}/Arduino15"
54-
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders;Personal]/ArduinoData")
89+
"[${_reg_explorer}\\User Shell Folders;Personal]/ArduinoData")
5590
set(sketchbook_path_suffixes "")
5691
else()
5792

58-
message(FATAL_ERROR "Host system ${CMAKE_HOST_SYSTEM} is not supported!!!")
93+
message(FATAL_ERROR
94+
"Host system ${CMAKE_HOST_SYSTEM} is not supported!!!")
5995

6096
endif()
6197

@@ -71,6 +107,15 @@ function(InitializeArduinoPackagePathList)
71107
message(FATAL_ERROR "Arduino IDE installation is not found!!!\n"
72108
"Use -DARDUINO_INSTALL_PATH=<path> to manually specify the path\n"
73109
)
110+
elseif(ARDUINO_INSTALL_PATH AND NOT "${ARDUINO_ENABLE_PACKAGE_MANAGER}"
111+
AND "${ARDUINO_BOARD_MANAGER_URL}" STREQUAL "")
112+
message("${ARDUINO_INSTALL_PATH}")
113+
file(READ "${ARDUINO_INSTALL_PATH}/lib/version.txt" _version)
114+
string(REGEX MATCH "[0-9]+\\.[0-9]" _ard_version "${_version}")
115+
if (_version AND "${_ard_version}" VERSION_LESS "1.5")
116+
message(WARNING "${ARDUINO_INSTALL_PATH} may be unsupported version "
117+
"${_version}. Please install newer version!")
118+
endif()
74119
endif()
75120
# message("ARDUINO_INSTALL_PATH:${ARDUINO_INSTALL_PATH}")
76121

0 commit comments

Comments
 (0)