@@ -86,159 +86,20 @@ if (NOT _BOARD_SETUP_COMPLETED)
8686 endif ()
8787endif ()
8888
89- # Wrap it in a function so that the scope of variables are within
90- # the function
91- function (IndexBoardsAndSetupBoard )
89+ # Wrap it in a function so that the scope of variables are within
90+ # the function
91+ function (BoardSetupWorkflow )
9292
93- # Find ARDUINO_INSTALL_PATH, ARDUINO_PACKAGE_PATH and
94- # ARDUNIO_SKETCHBOOK_PATH
95- InitializeArduinoPackagePathList()
96-
97- # Download and index the packages, and install the platforms from the
98- # given board manager URL list if any
99- set (_json_file "" )
100- set (_install_url "" )
101- set (_ref_url_list)
102- if (NOT "${ARDUINO_BOARD_MANAGER_URL} " STREQUAL "" )
103-
104- set (ARDUINO_BOARD_MANAGER_URL "${ARDUINO_BOARD_MANAGER_URL} "
105- CACHE STRING "Arduino Board Manager URL" FORCE)
106-
107- # Split comma seperated list of URLs
108- string (REPLACE "," ";" _url_list
109- "${ARDUINO_BOARD_MANAGER_URL} " )
110-
111- # First one in the list should contain the required board
112- list (GET _url_list 0 _install_url)
113- set (_ref_url_list "${_url_list} " )
114- list (REMOVE_AT _ref_url_list 0)
115-
116- # Download the package of the install URL
117- if (NOT EXISTS "${_install_url} " )
118- BoardManager_DownloadPackage(${_install_url}
119- JSON_FILES_LIST _json_file REQUIRED)
120- else ()
121- set (_json_file "${_install_url} " )
122- endif ()
123- IndexArduinoPackages(${_json_file} )
124-
125- set (ARDUINO_ENABLE_PACKAGE_MANAGER TRUE )
126-
127- else ()
128-
129- IndexArduinoPackages()
130-
131- endif ()
132-
133- if (NOT "${ARDUINO_BOARD_MANAGER_REF_URL} " STREQUAL "" )
134- set (ARDUINO_BOARD_MANAGER_REF_URL "${ARDUINO_BOARD_MANAGER_REF_URL} "
135- CACHE STRING
136- "Arduino Board Manager URL only for reference platforms/tools"
137- FORCE)
138- endif ()
139-
140- list (APPEND _ref_url_list ${ARDUINO_BOARD_MANAGER_REF_URL} )
141- # Download all other reference only URLs
142- if (NOT "${_ref_url_list} " STREQUAL "" )
143- BoardManager_DownloadPackage(${_ref_url_list}
144- JSON_FILES_LIST _ref_json_files)
145- if (_ref_json_files)
146- IndexArduinoPackages(${_ref_json_files} )
147- endif ()
148- endif ()
149-
150- if (DEFINED ARDUINO_NO_INSTALLED_REFERENCES)
151- set (ARDUINO_NO_INSTALLED_REFERENCES
152- "${ARDUINO_NO_INSTALLED_REFERENCES} " CACHE STRING
153- "Set this option to ignore any installed platforms as references"
154- FORCE)
155- endif ()
156-
157- # Index all the pre-installed packages
158- if (NOT "${ARDUINO_BOARD_MANAGER_URL} " STREQUAL "" AND
159- NOT "${ARDUINO_NO_INSTALLED_REFERENCES} " )
160-
161- IndexArduinoPackages()
162-
163- endif ()
164-
165- # Find the necessary platforms
166- set (_needed_pl_list)
167- set (_report_error TRUE )
168- packages_find_platforms(pl_list JSON_FILES ${_json_file}
169- INSTALL_PREFERRED)
170- if (NOT "${ARDUINO_PLATFORM} " STREQUAL "" )
171-
172- # Find the platforms that can be installed from the board given
173- platforms_find_platform_in_list("${pl_list} " "${ARDUINO_PLATFORM} "
174- _needed_pl_list)
175-
176- elseif (NOT "${ARDUINO_BOARD} " STREQUAL "" )
177-
178- # Find the platforms that can be installed from the board given
179- boards_find_platform_in_list("${pl_list} " "${ARDUINO_BOARD} "
180- _needed_pl_list)
181-
182- elseif (NOT "${ARDUINO_BOARD_MANAGER_URL} " STREQUAL "" )
183-
184- # install all the platforms in the board manager URL, if board
185- # or platform is not specified explicitly
186- set (_needed_pl_list "${pl_list} " )
187-
188- else ()
189-
190- # In case of no mention of board or platform or board manager URL,
191- # Package management is used only for installing reference tools
192- # and platforms. So no need to report error.
193- set (_report_error FALSE )
194- endif ()
195-
196- if (NOT _needed_pl_list AND _report_error)
197- #message("Available platforms: ${pl_list}")
198- #message(WARNING
199- # "Not sure which Arduino platform is needed! Provide the correct "
200- # "board manager URL of the board using the option "
201- # "-DARDUINO_BOARD_MANAGER_URL=<URL>.")
202- endif ()
203-
204- # Filter out those that are not installed
205- set (_install_pl_list "" )
206- foreach (_needed_pl IN LISTS _needed_pl_list)
207- packages_get_platform_property("${_needed_pl} " "/installed"
208- _b_installed)
209- if (NOT _b_installed)
210- list (APPEND _install_pl_list "${_needed_pl} " )
211- endif ()
212- endforeach ()
213-
214- # Install the necessary platforms. TODO Unnecessary installation for
215- # boards that are already installed
216- if (_install_pl_list)
217- if (ARDUINO_ENABLE_PACKAGE_MANAGER)
218- foreach (pl_id IN LISTS _install_pl_list)
219- BoardManager_InstallPlatform("${pl_id} " RESULT_VARIABLE
220- _result)
221- if (NOT _result EQUAL 0)
222- message (WARNING "Installing platform '${pl_id} ' failed!!! "
223- "Corresponding boards won't be available for tests." )
224- endif ()
225- endforeach ()
226- else ()
227- #string(REPLACE ";" ", " _install_pl_list "${_install_pl_list}")
228- #message(WARNING
229- # "Need to install the Arduino boards ${_install_pl_list}. "
230- # "Try with the option -DARDUINO_ENABLE_PACKAGE_MANAGER=TRUE, "
231- # "for local installation in the build directory.")
232- endif ()
233- endif ()
234-
235- # Index all the installed platforms and boards
236- IndexArduinoBoards("ard_boards" JSON_FILES ${_json_file} )
93+ # Call the common workflow for setting up the platform, which includes
94+ # installing the necessary platform (if package management is enabled),
95+ # and indexing the boards based on the platform. The platform to be
96+ # setup is identified using the board options which we already loaded.
97+ PlatformSetupWorkflow()
23798
23899 # Select one of the boards as selected in BoardOptions.cmake or in
239100 # cmake-gui or other mechanisms. If none selected, this call will
240101 # generate options in CMake Cache and BoardOptions.cmake to allow
241- # later selection of the board
102+ # later selection of the board.
242103 SelectArduinoBoard(ard_boards)
243104 set (ARDUINO_BOARD_IDENTIFIER "${ARDUINO_BOARD_IDENTIFIER} "
244105 PARENT_SCOPE)
@@ -256,7 +117,8 @@ endfunction()
256117
257118if (NOT _BOARD_SETUP_COMPLETED)
258119
259- IndexBoardsAndSetupBoard()
120+ BoardSetupWorkflow()
121+
260122 set (CMAKE_SYSTEM_CUSTOM_CODE
261123 "include(\" ${CMAKE_BINARY_DIR} /ArduinoSystem.cmake\" )"
262124 )
0 commit comments