Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cmake/Platform/Arduino.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.8.2)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Utilities)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Hardware/Boards)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/System)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Other)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Project)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Properties)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Sketches)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Sources)
Expand All @@ -11,13 +13,15 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Targets)

include(Utilities)

include(BoardManager)
include(Boards)

include(RecipeParser)
include(TargetFlagsManager)
include(SourcesManager)
include(SketchManager)
include(DefaultsManager)
include(ArchitectureSupportQuery)
include(CMakeProperties)

include(Libraries)

Expand All @@ -31,4 +35,6 @@ include(ArduinoLibraryTarget)
include(PlatformLibraryTarget)
include(ArduinoExampleTarget)

include(Project)

initialize_build_system()
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,43 @@
function(get_board_id _return_var _board_name)

set(extra_args ${ARGN})

list(LENGTH extra_args num_of_extra_args)

if (${num_of_extra_args} GREATER 0)
list(GET extra_args 0 _board_cpu)
endif ()

list(FIND ARDUINO_CMAKE_BOARDS ${_board_name} board_name_index)

if (${board_name_index} LESS 0) # Negative value = not found in list
message(FATAL_ERROR "Unknown given board name, not defined in 'boards.txt'. Check your\
spelling.")
message(FATAL_ERROR "Given board not defined in 'boards.txt' - Check your spelling.")

else () # Board is valid and has been found

if (DEFINED ${_board_name}_cpu_list) # Board cpu is to be expected

if (NOT _board_cpu)
message(FATAL_ERROR "Expected board CPU to be provided for the ${_board_name} board")

else ()

list(FIND ${_board_name}_cpu_list ${_board_cpu} board_cpu_index)

if (${board_cpu_index} LESS 0)
message(FATAL_ERROR "Unknown given board cpu")
endif ()

set(board_id "${_board_name}.${_board_cpu}")

set(${_return_var} "${board_id}" PARENT_SCOPE)

endif ()

else () # Board without explicit CPU
set(${_return_var} ${_board_name} PARENT_SCOPE)
endif ()

endif ()

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

# Get the length of the board to determine whether board CPU is to be expected
list(LENGTH board_id num_of_board_elements)

list(GET board_id 0 board_name) # Get the board name which is mandatory

if (DEFINED ${board_name}_${property})
set(retrieved_property ${${board_name}_${property}})
elseif (${num_of_board_elements} EQUAL 1) # Only board name is supplied
message(WARNING "Property ${_property} couldn't be found on board ${_board_id}")

else ()

list(GET board_id 1 board_cpu)

if (NOT DEFINED ${board_name}_menu_cpu_${board_cpu}_${property})
message(WARNING "Property ${_property} couldn't be found on board ${_board_id}")
else ()
set(retrieved_property ${${board_name}_menu_cpu_${board_cpu}_${property}})
endif ()

endif ()

set(${_return_var} ${retrieved_property} PARENT_SCOPE)
Expand Down Expand Up @@ -100,13 +118,17 @@ function(try_get_board_property _board_id _property _return_var)
set(${_return_var} ${${board_name}_${property}} PARENT_SCOPE)
elseif (${num_of_board_elements} EQUAL 1) # Only board name is supplied
return()

else ()

list(GET board_id 1 board_cpu)

if (NOT DEFINED ${board_name}_menu_cpu_${board_cpu}_${property})
return()
else ()
set(${_return_var} ${${board_name}_menu_cpu_${board_cpu}_${property}} PARENT_SCOPE)
endif ()

endif ()

endfunction()
1 change: 1 addition & 0 deletions cmake/Platform/Hardware/Boards/Boards.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include(BoardManager)
7 changes: 3 additions & 4 deletions cmake/Platform/Libraries/LibrariesFinder.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ endmacro()
# using the current platform architecture.
# _target_name - Name of the library target to be created. Usually library's real name.
# _library_name - Name of the Arduino library to find.
# _board_id - Board ID associated with the linked Core Lib.
# [3RD_PARTY] - Whether library should be treated as a 3rd Party library.
# [HEADER_ONLY] - Whether library should be treated as header-only library.
# [QUIET] - Whether function should "fail" safely without warnings/errors
# in case of an actual error.
#=============================================================================#
function(find_arduino_library _target_name _library_name _board_id)
function(find_arduino_library _target_name _library_name)

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

if (parsed_args_HEADER_ONLY)
add_arduino_header_only_library(${_target_name} ${_board_id} ${library_headers})
add_arduino_header_only_library(${_target_name} ${library_headers})

else ()

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

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

add_arduino_library(${_target_name} ${_board_id} ${sources})
add_arduino_library(${_target_name} ${sources})

endif ()

Expand Down
7 changes: 3 additions & 4 deletions cmake/Platform/Libraries/LibraryFlagsManager.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
# Sets compiler and linker flags on the given library target.
# Changes are kept even outside the scope of the function since they apply on a target.
# _library_target - Name of the library target.
# _board_id - Board ID associated with the library. Some flags require it.
#=============================================================================#
function(set_library_flags _library_target _board_id)
function(set_library_flags _library_target)

parse_scope_argument(scope "${ARGN}"
DEFAULT_SCOPE PUBLIC)

set_compiler_target_flags(${_library_target} ${_board_id} ${scope})
set_target_compile_flags(${_library_target} ${PROJECT_${ARDUINO_CMAKE_PROJECT_NAME}_BOARD} ${scope})

# Set linker flags
set_linker_flags(${_library_target} ${_board_id})
set_target_linker_flags(${_library_target} ${PROJECT_${ARDUINO_CMAKE_PROJECT_NAME}_BOARD})

endfunction()
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ function(resolve_library_architecture _library_sources _return_var)
set(lib_props_file ${parsed_args_LIB_PROPS_FILE})
else ()

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

Expand Down
34 changes: 14 additions & 20 deletions cmake/Platform/Other/TargetFlagsManager.cmake
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
#=============================================================================#
# Sets compiler flags on the given target using the given board ID, compiler language and scope.
# _target_name - Name of the target (Executable or Library) to set flags on.
# _board_id - Target's bounded board ID.
# _language - Language for which flags are set (such as C/C++).
# _scope - Flags' scope relative to outer targets (targets using the given target).
# _board_id - Board ID asociated with the target.
#=============================================================================#
function(_set_target_language_flags _target_name _board_id _language _scope)

parse_compiler_recipe_flags(${_board_id} compiler_recipe_flags
LANGUAGE "${_language}")
parse_compiler_recipe_flags(${_board_id} compiler_recipe_flags LANGUAGE "${_language}")

target_compile_options(${_target_name} ${_scope}
$<$<COMPILE_LANGUAGE:${_language}>:${compiler_recipe_flags}>)
target_compile_options(${_target_name} ${_scope} $<$<COMPILE_LANGUAGE:${_language}>:${compiler_recipe_flags}>)

endfunction()

#=============================================================================#
# Sets compiler flags on the given target, according also to the given board ID.
# _target_name - Name of the target (Executable or Library) to set flags on.
# _board_id - Target's bounded board ID.
# _target_name - Name of the target (Executable or Library) to set flags on
# _board_id - Board ID asociated with the target..
#=============================================================================#
function(set_compiler_target_flags _target_name _board_id)
function(set_target_compile_flags _target_name _board_id)

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

parse_linker_recpie_pattern("${_board_id}" linker_recipe_flags)
parse_linker_recpie_pattern(${_board_id} linker_recipe_flags)

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

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

set_compiler_target_flags(${_target_name} "${_board_id}")
set_linker_flags(${_target_name} "${_board_id}")
set_target_compile_flags(${_target_name} ${PROJECT_${ARDUINO_CMAKE_PROJECT_NAME}_BOARD})
set_target_linker_flags(${_target_name} ${PROJECT_${ARDUINO_CMAKE_PROJECT_NAME}_BOARD})

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

Expand All @@ -80,14 +77,11 @@ endfunction()
#=============================================================================#
# Sets upload/flash flags on the given target, according also to the given board ID.
# _target_name - Name of the target (Executable) to set flags on.
# _board_id - Target's bounded board ID.
#=============================================================================#
function(set_upload_target_flags _target_name _board_id _upload_port _return_var)

set(upload_flags "")
function(set_upload_target_flags _target_name _upload_port _return_var)

# Parse and append recipe flags
parse_upload_recipe_pattern("${_board_id}" "${_upload_port}" upload_recipe_flags)
parse_upload_recipe_pattern(${PROJECT_${ARDUINO_CMAKE_PROJECT_NAME}_BOARD} "${_upload_port}" upload_recipe_flags)
list(APPEND upload_flags "${upload_recipe_flags}")

set(target_binary_base_path "${CMAKE_CURRENT_BINARY_DIR}/${_target_name}")
Expand Down
15 changes: 15 additions & 0 deletions cmake/Platform/Project/BoardSetup.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function(setup_project_board _project_name)

cmake_parse_arguments(parsed_args "" "BOARD_NAME;BOARD_CPU" "" ${ARGV})

if (NOT parsed_args_BOARD_NAME)
message(FATAL_ERROR "Expected board name in setup function")
else ()

get_board_id(board_id ${parsed_args_BOARD_NAME} ${parsed_args_BOARD_CPU})

set(PROJECT_${_project_name}_BOARD ${board_id} CACHE STRING "Project-Global board ID")

endif ()

endfunction()
14 changes: 14 additions & 0 deletions cmake/Platform/Project/CoreLibSetup.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function(setup_project_core_lib _project_name)

# Guard against redefiniton of the Core Lib target
if (NOT TARGET ${${PROJECT_${_project_name}_BOARD}_CORELIB_TARGET})

add_arduino_core_lib(${PROJECT_${_project_name}_BOARD} target_name)

# Define a global way to access Core Lib's target name
set(${PROJECT_${_project_name}_BOARD}_CORELIB_TARGET ${target_name}
CACHE STRING "Project-Global CoreLib target name")

endif ()

endfunction()
3 changes: 3 additions & 0 deletions cmake/Platform/Project/Project.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include(BoardSetup)
include(CoreLibSetup)
include(ProjectSetup)
14 changes: 14 additions & 0 deletions cmake/Platform/Project/ProjectSetup.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function(arduino_cmake_project _project_name)

# Store the project's name in parent scope as if it were defined by the CMakeLists.txt file
# that called this function. It helps ensure each "sub-project" can actually exists separately from the others,
# as is the case with the examples of the framework.
# This is done because CMake's `project()` function doesn't maintain scope properly,
# thus a custom one is needed.
set(ARDUINO_CMAKE_PROJECT_NAME ${_project_name} PARENT_SCOPE)

setup_project_board(${_project_name} ${ARGN})

setup_project_core_lib(${_project_name})

endfunction()
11 changes: 11 additions & 0 deletions cmake/Platform/Properties/CMakeProperties.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#=============================================================================#
# Defines custom properties used internally by the framework.
#=============================================================================#
function(define_custom_properties)

define_property(TARGET PROPERTY BOARD_ID
BRIEF_DOCS "ID of the associated hardware board"
FULL_DOCS
"Framework-Internal ID of the hardware Arduino board associated with the target")

endfunction()
9 changes: 4 additions & 5 deletions cmake/Platform/Sketches/SketchHeadersManager.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
# Resolves the header files included in a sketch by linking their appropriate library if necessary
# or by validating they're included by the sketch target.
# _target_name - Name of the target to add the sketch file to.
# _board_id - ID of the board to bind to the target (Each target can have a single board).
# _sketch_file - Path to a sketch file to add to the target.
#=============================================================================#
function(resolve_sketch_headers _target_name _board_id _sketch_file)
function(resolve_sketch_headers _target_name _sketch_file)

get_source_file_included_headers("${_sketch_file}" sketch_headers)

Expand All @@ -21,12 +20,12 @@ function(resolve_sketch_headers _target_name _board_id _sketch_file)

string(TOLOWER ${header_we} header_we_lower)

link_platform_library(${_target_name} ${header_we_lower} ${_board_id})
link_platform_library(${_target_name} ${header_we_lower})

else ()

# Pass the '3RD_PARTY' option to avoid name-conversion
find_arduino_library(${header_we}_sketch_lib ${header_we} ${_board_id} 3RD_PARTY QUIET)
find_arduino_library(${header_we}_sketch_lib ${header_we} 3RD_PARTY QUIET)

# If library isn't found, display a status since it might be a user library
if (NOT TARGET ${header_we}_sketch_lib OR
Expand All @@ -38,7 +37,7 @@ function(resolve_sketch_headers _target_name _board_id _sketch_file)
"you'd have to check this manually!")

else ()
link_arduino_library(${_target_name} ${header_we}_sketch_lib ${_board_id})
link_arduino_library(${_target_name} ${header_we}_sketch_lib)
endif ()

endif ()
Expand Down
Loading