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

Commit 96dd17d

Browse files
committed
Added ability to configure boards on project-level
Moved board-related modules under the `Hardware/Boards` directory.
1 parent 76b3a84 commit 96dd17d

File tree

4 files changed

+59
-4
lines changed

4 files changed

+59
-4
lines changed

cmake/Platform/Arduino.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
cmake_minimum_required(VERSION 3.8)
1+
cmake_minimum_required(VERSION 3.8.2)
22

33
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Utilities)
4+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Hardware/Boards)
45
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/System)
56
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Other)
67
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Properties)
@@ -11,7 +12,8 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Targets)
1112

1213
include(Utilities)
1314

14-
include(BoardManager)
15+
include(Boards)
16+
1517
include(RecipeParser)
1618
include(TargetFlagsManager)
1719
include(SourcesManager)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
include(CoreLibTarget)
2+
3+
#========================================================================================================#
4+
# Internal function that actually configures project for use with a given hardware board.
5+
# Currently it only creates a Core-Library target based on the given board, which will be linked
6+
# to every Arduino-target created afterwards.
7+
# _board_id - Complete ID of the board which will be used throughout the project.
8+
#========================================================================================================#
9+
function(_configure_arduino_board _board_id)
10+
11+
add_arduino_core_lib(${_board_id})
12+
13+
endfunction()
14+
15+
#========================================================================================================#
16+
# Configures CMake framework for use with the given Arduino hardware board.
17+
# Note that it doesn't do anything that's actually related to hardware, this is simply configuration!
18+
# This functio should be called at least once in each project, so targets created later could use the board.
19+
# _board_name - Name of the board, e.g. nano, uno, etc...
20+
# [] - Explicit board CPU if there are multiple versions of the board (such as atmega328p).
21+
# This is an argument variable which has no name and can be passed as the last argument when required.
22+
#========================================================================================================#
23+
function(configure_arduino_board _board_name _board_cpu)
24+
25+
get_board_id(board_id ${_board_name} ${_board_cpu})
26+
27+
_configure_arduino_board(${board_id})
28+
29+
endfunction()

cmake/Platform/Other/BoardManager.cmake renamed to cmake/Platform/Hardware/Boards/BoardManager.cmake

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,43 @@
1212
function(get_board_id _return_var _board_name)
1313

1414
set(extra_args ${ARGN})
15+
1516
list(LENGTH extra_args num_of_extra_args)
17+
1618
if (${num_of_extra_args} GREATER 0)
1719
list(GET extra_args 0 _board_cpu)
1820
endif ()
1921

2022
list(FIND ARDUINO_CMAKE_BOARDS ${_board_name} board_name_index)
23+
2124
if (${board_name_index} LESS 0) # Negative value = not found in list
22-
message(FATAL_ERROR "Unknown given board name, not defined in 'boards.txt'. Check your\
23-
spelling.")
25+
message(FATAL_ERROR "Given board not defined in 'boards.txt' - Check your spelling.")
26+
2427
else () # Board is valid and has been found
28+
2529
if (DEFINED ${_board_name}_cpu_list) # Board cpu is to be expected
30+
2631
if (NOT _board_cpu)
2732
message(FATAL_ERROR "Expected board CPU to be provided for the ${_board_name} board")
33+
2834
else ()
35+
2936
list(FIND ${_board_name}_cpu_list ${_board_cpu} board_cpu_index)
37+
3038
if (${board_cpu_index} LESS 0)
3139
message(FATAL_ERROR "Unknown given board cpu")
3240
endif ()
41+
3342
set(board_id "${_board_name}.${_board_cpu}")
43+
3444
set(${_return_var} "${board_id}" PARENT_SCOPE)
45+
3546
endif ()
47+
3648
else () # Board without explicit CPU
3749
set(${_return_var} ${_board_name} PARENT_SCOPE)
3850
endif ()
51+
3952
endif ()
4053

4154
endfunction()
@@ -58,19 +71,24 @@ function(get_board_property _board_id _property _return_var)
5871

5972
# Get the length of the board to determine whether board CPU is to be expected
6073
list(LENGTH board_id num_of_board_elements)
74+
6175
list(GET board_id 0 board_name) # Get the board name which is mandatory
6276

6377
if (DEFINED ${board_name}_${property})
6478
set(retrieved_property ${${board_name}_${property}})
6579
elseif (${num_of_board_elements} EQUAL 1) # Only board name is supplied
6680
message(WARNING "Property ${_property} couldn't be found on board ${_board_id}")
81+
6782
else ()
83+
6884
list(GET board_id 1 board_cpu)
85+
6986
if (NOT DEFINED ${board_name}_menu_cpu_${board_cpu}_${property})
7087
message(WARNING "Property ${_property} couldn't be found on board ${_board_id}")
7188
else ()
7289
set(retrieved_property ${${board_name}_menu_cpu_${board_cpu}_${property}})
7390
endif ()
91+
7492
endif ()
7593

7694
set(${_return_var} ${retrieved_property} PARENT_SCOPE)
@@ -100,13 +118,17 @@ function(try_get_board_property _board_id _property _return_var)
100118
set(${_return_var} ${${board_name}_${property}} PARENT_SCOPE)
101119
elseif (${num_of_board_elements} EQUAL 1) # Only board name is supplied
102120
return()
121+
103122
else ()
123+
104124
list(GET board_id 1 board_cpu)
125+
105126
if (NOT DEFINED ${board_name}_menu_cpu_${board_cpu}_${property})
106127
return()
107128
else ()
108129
set(${_return_var} ${${board_name}_menu_cpu_${board_cpu}_${property}} PARENT_SCOPE)
109130
endif ()
131+
110132
endif ()
111133

112134
endfunction()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include(BoardManager)
2+
include(BoardConfigurator)

0 commit comments

Comments
 (0)