@@ -49,39 +49,81 @@ set(CMAKE_SYSTEM_NAME "Arduino")
4949set (ARDUINO_TOOLCHAIN_DIR "${CMAKE_CURRENT_LIST_DIR} " )
5050set (_ARDUINO_TOOLCHAIN_PARENT "${CMAKE_PARENT_LIST_FILE} " )
5151set (CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH} " "${CMAKE_CURRENT_LIST_DIR} " )
52- set (ARDUINO_TOOLCHAIN_VERSION "1.0 " )
52+ set (ARDUINO_TOOLCHAIN_VERSION "1.1 " )
5353
5454# Include modules
55+ include (Arduino/System /PackagePathIndex)
56+ include (Arduino/System /PackageIndex)
5557include (Arduino/System /BoardsIndex)
5658include (Arduino/System /BoardToolchain)
5759include (Arduino/System /BoardBuildTargets)
60+ include (Arduino/PackageManager/BoardsManager)
5861
5962#*****************************************************************************
60- # For improved speed, indexing of boards is done only once during a
61- # cmake invocation. However, this toolchain file is included multiple
62- # times in multiple contexts (system determination context, separate
63- # context for each try compile etc.). After indexing, the selected
64- # board's toolchain info is configured to a generated file that gets
65- # included in every other inclusion of this toolchain.
66- if (NOT _BOARD_INDEXING_COMPLETED )
63+ # For improved speed, indexing and setup of boards is done only once during a
64+ # cmake invocation. However, this toolchain file is included multiple times
65+ # in multiple contexts (system determination context, separate context for
66+ # each try compile etc.). After indexing, the selected board's toolchain
67+ # info is configured to a generated file that gets included in every other
68+ # inclusion of this toolchain.
69+ if (NOT _BOARD_SETUP_COMPLETED )
6770 get_property (_in_try_compile GLOBAL PROPERTY IN_TRY_COMPILE )
68- # IN_TRY_COMPILE check seems to be not enough. Check for parent
69- # script works, but may be undocumented!
70- get_filename_component (parent_script "${_ARDUINO_TOOLCHAIN_PARENT} " NAME_WE )
71+ # IN_TRY_COMPILE check seems to be not enough. Checking for parent
72+ # script works, but might be using undocumented feature?
73+ get_filename_component (parent_script "${_ARDUINO_TOOLCHAIN_PARENT} "
74+ NAME_WE )
7175 if (parent_script STREQUAL "CMakeSystem" )
7276 check_board_options_changed(_b_changed)
7377 if (NOT _b_changed)
74- set (_BOARD_INDEXING_COMPLETED TRUE )
78+ set (_BOARD_SETUP_COMPLETED TRUE )
7579 endif ()
80+ elseif (ARDUINO_SYSTEM_FILE)
81+ # If passing with pre-generated Arduino system code
82+ set (_BOARD_SETUP_COMPLETED TRUE )
83+ set (CMAKE_SYSTEM_CUSTOM_CODE
84+ "include(\" ${ARDUINO_SYSTEM_FILE} \" )"
85+ )
7686 endif ()
7787endif ()
7888
79- if (NOT _BOARD_INDEXING_COMPLETED)
80- SetupBoardToolchain()
89+ # Wrap it in a function so that the scope of variables are within
90+ # the function
91+ function (BoardSetupWorkflow)
92+
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()
98+
99+ # Select one of the boards as selected in BoardOptions.cmake or in
100+ # cmake-gui or other mechanisms. If none selected, this call will
101+ # generate options in CMake Cache and BoardOptions.cmake to allow
102+ # later selection of the board.
103+ SelectArduinoBoard(ard_boards)
104+ set (ARDUINO_BOARD_IDENTIFIER "${ARDUINO_BOARD_IDENTIFIER} "
105+ PARENT_SCOPE)
106+ list (LENGTH ARDUINO_BOARD_IDENTIFIER _num_board_ids)
107+
108+ # if a board is selected, setup a toolchain for the board
109+ # Else, Arduino-Determine.cmake will print an error message later
110+ # Arduino-Determine.cmake.
111+ if (_num_board_ids EQUAL 1)
112+ SetupBoardToolchain(ard_boards "${ARDUINO_BOARD_IDENTIFIER} "
113+ "${CMAKE_BINARY_DIR} " )
114+ endif ()
115+
116+ endfunction ()
117+
118+ if (NOT _BOARD_SETUP_COMPLETED)
119+
120+ BoardSetupWorkflow()
121+
81122 set (CMAKE_SYSTEM_CUSTOM_CODE
82123 "include(\" ${CMAKE_BINARY_DIR} /ArduinoSystem.cmake\" )"
83124 )
84- set (_BOARD_INDEXING_COMPLETED TRUE )
125+ set (_BOARD_SETUP_COMPLETED TRUE )
126+
85127endif ()
86128
87129# Search for programs in the build host directories
@@ -94,7 +136,9 @@ set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
94136file (WRITE "${CMAKE_CURRENT_BINARY_DIR} /build_opt.h" "" )
95137
96138# Do not try to link during the configure time, due to the dependency on the
97- # core, which we do not have a target yet.
98- set (CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
139+ # core for some platforms, which we do not have a target yet.
140+ if (NOT "${ARDUINO_TRY_STANDALONE_TOOLCHAIN} " )
141+ set (CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
142+ endif ()
99143
100144cmake_policy (POP)
0 commit comments