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

Commit 73cd076

Browse files
committed
Further refactored towards a project-global board_id
It omits the need to pass it as an argument to functions or to set it as a target property.
1 parent 55dfe2b commit 73cd076

File tree

28 files changed

+114
-161
lines changed

28 files changed

+114
-161
lines changed

cmake/Platform/Arduino.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Utilities)
44
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Hardware/Boards)
55
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/System)
66
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Other)
7+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Project)
78
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Properties)
89
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Sketches)
910
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Sources)
@@ -34,4 +35,6 @@ include(ArduinoLibraryTarget)
3435
include(PlatformLibraryTarget)
3536
include(ArduinoExampleTarget)
3637

38+
include(Project)
39+
3740
initialize_build_system()

cmake/Platform/Hardware/Boards/BoardConfigurator.cmake

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
include(BoardManager)
2-
include(BoardConfigurator)

cmake/Platform/Libraries/LibrariesFinder.cmake

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ endmacro()
1111
# using the current platform architecture.
1212
# _target_name - Name of the library target to be created. Usually library's real name.
1313
# _library_name - Name of the Arduino library to find.
14-
# _board_id - Board ID associated with the linked Core Lib.
1514
# [3RD_PARTY] - Whether library should be treated as a 3rd Party library.
1615
# [HEADER_ONLY] - Whether library should be treated as header-only library.
1716
# [QUIET] - Whether function should "fail" safely without warnings/errors
1817
# in case of an actual error.
1918
#=============================================================================#
20-
function(find_arduino_library _target_name _library_name _board_id)
19+
function(find_arduino_library _target_name _library_name)
2120

2221
set(argument_options "3RD_PARTY" "HEADER_ONLY" "QUIET")
2322
cmake_parse_arguments(parsed_args "${argument_options}" "" "" ${ARGN})
@@ -53,7 +52,7 @@ function(find_arduino_library _target_name _library_name _board_id)
5352
else ()
5453

5554
if (parsed_args_HEADER_ONLY)
56-
add_arduino_header_only_library(${_target_name} ${_board_id} ${library_headers})
55+
add_arduino_header_only_library(${_target_name} ${library_headers})
5756

5857
else ()
5958

@@ -74,7 +73,7 @@ function(find_arduino_library _target_name _library_name _board_id)
7473

7574
set(sources ${library_headers} ${library_sources})
7675

77-
add_arduino_library(${_target_name} ${_board_id} ${sources})
76+
add_arduino_library(${_target_name} ${sources})
7877

7978
endif ()
8079

cmake/Platform/Libraries/LibraryFlagsManager.cmake

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ function(set_library_flags _library_target)
1111
# Infer target's type and act differently if it's an interface-library
1212
get_target_property(target_type ${_library_target} TYPE)
1313

14-
if ("${target_type}" STREQUAL "INTERFACE_LIBRARY")
15-
get_target_property(board_id ${_library_target} INTERFACE_BOARD_ID)
16-
else ()
17-
get_target_property(board_id ${_library_target} BOARD_ID)
18-
endif ()
19-
2014
set_target_compile_flags(${_library_target} ${scope})
2115

2216
# Set linker flags

cmake/Platform/Other/TargetFlagsManager.cmake

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,9 @@ function(_set_target_language_flags _target_name _language _scope)
99
# Infer target's type and act differently if it's an interface-library
1010
get_target_property(target_type ${_target_name} TYPE)
1111

12-
if ("${target_type}" STREQUAL "INTERFACE_LIBRARY")
13-
get_target_property(board_id ${_target_name} INTERFACE_BOARD_ID)
14-
else ()
15-
get_target_property(board_id ${_target_name} BOARD_ID)
16-
endif ()
17-
18-
parse_compiler_recipe_flags(${board_id} compiler_recipe_flags
19-
LANGUAGE "${_language}")
12+
parse_compiler_recipe_flags(${ARDUINO_CMAKE_PROJECT_BOARD} compiler_recipe_flags LANGUAGE "${_language}")
2013

21-
target_compile_options(${_target_name} ${_scope}
22-
$<$<COMPILE_LANGUAGE:${_language}>:${compiler_recipe_flags}>)
14+
target_compile_options(${_target_name} ${_scope} $<$<COMPILE_LANGUAGE:${_language}>:${compiler_recipe_flags}>)
2315

2416
endfunction()
2517

@@ -60,13 +52,7 @@ function(set_target_linker_flags _target_name)
6052
# Infer target's type and act differently if it's an interface-library
6153
get_target_property(target_type ${_target_name} TYPE)
6254

63-
if ("${target_type}" STREQUAL "INTERFACE_LIBRARY")
64-
get_target_property(board_id ${_target_name} INTERFACE_BOARD_ID)
65-
else ()
66-
get_target_property(board_id ${_target_name} BOARD_ID)
67-
endif ()
68-
69-
parse_linker_recpie_pattern(${board_id} linker_recipe_flags)
55+
parse_linker_recpie_pattern(${ARDUINO_CMAKE_PROJECT_BOARD} linker_recipe_flags)
7056

7157
string(REPLACE ";" " " cmake_compliant_linker_flags "${linker_recipe_flags}")
7258

@@ -97,10 +83,8 @@ endfunction()
9783
#=============================================================================#
9884
function(set_upload_target_flags _target_name _upload_port _return_var)
9985

100-
get_target_property(board_id ${_target_name} BOARD_ID)
101-
10286
# Parse and append recipe flags
103-
parse_upload_recipe_pattern(${board_id} "${_upload_port}" upload_recipe_flags)
87+
parse_upload_recipe_pattern(${ARDUINO_CMAKE_PROJECT_BOARD} "${_upload_port}" upload_recipe_flags)
10488
list(APPEND upload_flags "${upload_recipe_flags}")
10589

10690
set(target_binary_base_path "${CMAKE_CURRENT_BINARY_DIR}/${_target_name}")
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function(setup_project_board)
2+
3+
cmake_parse_arguments(parsed_args "" "BOARD_NAME;BOARD_CPU" "" ${ARGV})
4+
5+
if (NOT parsed_args_BOARD_NAME)
6+
message(FATAL_ERROR "Expected board name in setup function")
7+
else ()
8+
9+
get_board_id(board_id ${parsed_args_BOARD_NAME} ${parsed_args_BOARD_CPU})
10+
11+
set(ARDUINO_CMAKE_PROJECT_BOARD ${board_id} CACHE STRING "Project-Wide board ID")
12+
13+
endif ()
14+
15+
endfunction()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include(BoardSetup)
2+
include(Setup)

cmake/Platform/Project/Setup.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function(arduino_cmake_project _project_name)
2+
3+
project(${_project_name})
4+
5+
set(ARDUINO_CMAKE_PROJECT_NAME ${_project_name} CACHE STRING "Current project name")
6+
7+
setup_project_board(${ARGN})
8+
9+
endfunction()

cmake/Platform/Sketches/SketchHeadersManager.cmake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ function(resolve_sketch_headers _target_name _sketch_file)
88

99
get_source_file_included_headers("${_sketch_file}" sketch_headers)
1010

11-
get_target_property(board_id ${_target_name} BOARD_ID)
12-
1311
foreach (header ${sketch_headers})
1412

1513
# Header name without extension (such as '.h') can represent an Arduino/Platform library
@@ -27,7 +25,7 @@ function(resolve_sketch_headers _target_name _sketch_file)
2725
else ()
2826

2927
# Pass the '3RD_PARTY' option to avoid name-conversion
30-
find_arduino_library(${header_we}_sketch_lib ${header_we} ${board_id} 3RD_PARTY QUIET)
28+
find_arduino_library(${header_we}_sketch_lib ${header_we} 3RD_PARTY QUIET)
3129

3230
# If library isn't found, display a status since it might be a user library
3331
if (NOT TARGET ${header_we}_sketch_lib OR

0 commit comments

Comments
 (0)