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

Commit 1cc0681

Browse files
authored
Merge pull request #74 from arduino-cmake/feature/project-global-setup
Created a project-global work model
2 parents 5d06dec + 408450f commit 1cc0681

36 files changed

+252
-197
lines changed

cmake/Platform/Arduino.cmake

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
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)
7+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Project)
68
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Properties)
79
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Sketches)
810
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Sources)
@@ -11,13 +13,15 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Targets)
1113

1214
include(Utilities)
1315

14-
include(BoardManager)
16+
include(Boards)
17+
1518
include(RecipeParser)
1619
include(TargetFlagsManager)
1720
include(SourcesManager)
1821
include(SketchManager)
1922
include(DefaultsManager)
2023
include(ArchitectureSupportQuery)
24+
include(CMakeProperties)
2125

2226
include(Libraries)
2327

@@ -31,4 +35,6 @@ include(ArduinoLibraryTarget)
3135
include(PlatformLibraryTarget)
3236
include(ArduinoExampleTarget)
3337

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

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include(BoardManager)

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: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
# Sets compiler and linker flags on the given library target.
33
# Changes are kept even outside the scope of the function since they apply on a target.
44
# _library_target - Name of the library target.
5-
# _board_id - Board ID associated with the library. Some flags require it.
65
#=============================================================================#
7-
function(set_library_flags _library_target _board_id)
6+
function(set_library_flags _library_target)
87

98
parse_scope_argument(scope "${ARGN}"
109
DEFAULT_SCOPE PUBLIC)
1110

12-
set_compiler_target_flags(${_library_target} ${_board_id} ${scope})
11+
set_target_compile_flags(${_library_target} ${PROJECT_${ARDUINO_CMAKE_PROJECT_NAME}_BOARD} ${scope})
1312

1413
# Set linker flags
15-
set_linker_flags(${_library_target} ${_board_id})
14+
set_target_linker_flags(${_library_target} ${PROJECT_${ARDUINO_CMAKE_PROJECT_NAME}_BOARD})
1615

1716
endfunction()

cmake/Platform/Libraries/LibrarySourcesArchitectureResolver.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ function(resolve_library_architecture _library_sources _return_var)
4141
set(lib_props_file ${parsed_args_LIB_PROPS_FILE})
4242
else ()
4343

44-
# Warn user and assume library is arch-agnostic
45-
message(STATUS "Library's properties file can't be found under its' root directory.\n\t"
46-
"Assuming the library is architecture-agnostic (supports all architectures)")
4744
set(${_return_var} "${_library_sources}" PARENT_SCOPE)
4845
return()
4946

cmake/Platform/Other/TargetFlagsManager.cmake

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
#=============================================================================#
22
# Sets compiler flags on the given target using the given board ID, compiler language and scope.
33
# _target_name - Name of the target (Executable or Library) to set flags on.
4-
# _board_id - Target's bounded board ID.
54
# _language - Language for which flags are set (such as C/C++).
65
# _scope - Flags' scope relative to outer targets (targets using the given target).
6+
# _board_id - Board ID asociated with the target.
77
#=============================================================================#
88
function(_set_target_language_flags _target_name _board_id _language _scope)
99

10-
parse_compiler_recipe_flags(${_board_id} compiler_recipe_flags
11-
LANGUAGE "${_language}")
10+
parse_compiler_recipe_flags(${_board_id} compiler_recipe_flags LANGUAGE "${_language}")
1211

13-
target_compile_options(${_target_name} ${_scope}
14-
$<$<COMPILE_LANGUAGE:${_language}>:${compiler_recipe_flags}>)
12+
target_compile_options(${_target_name} ${_scope} $<$<COMPILE_LANGUAGE:${_language}>:${compiler_recipe_flags}>)
1513

1614
endfunction()
1715

1816
#=============================================================================#
1917
# Sets compiler flags on the given target, according also to the given board ID.
20-
# _target_name - Name of the target (Executable or Library) to set flags on.
21-
# _board_id - Target's bounded board ID.
18+
# _target_name - Name of the target (Executable or Library) to set flags on
19+
# _board_id - Board ID asociated with the target..
2220
#=============================================================================#
23-
function(set_compiler_target_flags _target_name _board_id)
21+
function(set_target_compile_flags _target_name _board_id)
2422

2523
cmake_parse_arguments(parsed_args "" "LANGUAGE" "" ${ARGN})
2624
parse_scope_argument(scope "${ARGN}"
@@ -47,11 +45,11 @@ endfunction()
4745
#=============================================================================#
4846
# Sets linker flags on the given target, according also to the given board ID.
4947
# _target_name - Name of the target (Executable or Library) to set flags on.
50-
# _board_id - Target's bounded board ID.
48+
# _board_id - Board ID asociated with the target.
5149
#=============================================================================#
52-
function(set_linker_flags _target_name _board_id)
50+
function(set_target_linker_flags _target_name _board_id)
5351

54-
parse_linker_recpie_pattern("${_board_id}" linker_recipe_flags)
52+
parse_linker_recpie_pattern(${_board_id} linker_recipe_flags)
5553

5654
string(REPLACE ";" " " cmake_compliant_linker_flags "${linker_recipe_flags}")
5755

@@ -63,12 +61,11 @@ endfunction()
6361
# Sets compiler and linker flags on the given Executable target,
6462
# according also to the given board ID.
6563
# _target_name - Name of the target (Executable) to set flags on.
66-
# _board_id - Target's bounded board ID.
6764
#=============================================================================#
68-
function(set_executable_target_flags _target_name _board_id)
65+
function(set_executable_target_flags _target_name)
6966

70-
set_compiler_target_flags(${_target_name} "${_board_id}")
71-
set_linker_flags(${_target_name} "${_board_id}")
67+
set_target_compile_flags(${_target_name} ${PROJECT_${ARDUINO_CMAKE_PROJECT_NAME}_BOARD})
68+
set_target_linker_flags(${_target_name} ${PROJECT_${ARDUINO_CMAKE_PROJECT_NAME}_BOARD})
7269

7370
target_link_libraries(${_target_name} PUBLIC m) # Add math library
7471

@@ -80,14 +77,11 @@ endfunction()
8077
#=============================================================================#
8178
# Sets upload/flash flags on the given target, according also to the given board ID.
8279
# _target_name - Name of the target (Executable) to set flags on.
83-
# _board_id - Target's bounded board ID.
8480
#=============================================================================#
85-
function(set_upload_target_flags _target_name _board_id _upload_port _return_var)
86-
87-
set(upload_flags "")
81+
function(set_upload_target_flags _target_name _upload_port _return_var)
8882

8983
# Parse and append recipe flags
90-
parse_upload_recipe_pattern("${_board_id}" "${_upload_port}" upload_recipe_flags)
84+
parse_upload_recipe_pattern(${PROJECT_${ARDUINO_CMAKE_PROJECT_NAME}_BOARD} "${_upload_port}" upload_recipe_flags)
9185
list(APPEND upload_flags "${upload_recipe_flags}")
9286

9387
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 _project_name)
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(PROJECT_${_project_name}_BOARD ${board_id} CACHE STRING "Project-Global board ID")
12+
13+
endif ()
14+
15+
endfunction()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function(setup_project_core_lib _project_name)
2+
3+
# Guard against redefiniton of the Core Lib target
4+
if (NOT TARGET ${${PROJECT_${_project_name}_BOARD}_CORELIB_TARGET})
5+
6+
add_arduino_core_lib(${PROJECT_${_project_name}_BOARD} target_name)
7+
8+
# Define a global way to access Core Lib's target name
9+
set(${PROJECT_${_project_name}_BOARD}_CORELIB_TARGET ${target_name}
10+
CACHE STRING "Project-Global CoreLib target name")
11+
12+
endif ()
13+
14+
endfunction()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include(BoardSetup)
2+
include(CoreLibSetup)
3+
include(ProjectSetup)

0 commit comments

Comments
 (0)