diff --git a/cmake/Platform/Arduino.cmake b/cmake/Platform/Arduino.cmake index abe748b..5980fc1 100644 --- a/cmake/Platform/Arduino.cmake +++ b/cmake/Platform/Arduino.cmake @@ -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) @@ -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) @@ -31,4 +35,6 @@ include(ArduinoLibraryTarget) include(PlatformLibraryTarget) include(ArduinoExampleTarget) +include(Project) + initialize_build_system() diff --git a/cmake/Platform/Other/BoardManager.cmake b/cmake/Platform/Hardware/Boards/BoardManager.cmake similarity index 97% rename from cmake/Platform/Other/BoardManager.cmake rename to cmake/Platform/Hardware/Boards/BoardManager.cmake index f9ecec0..d923842 100644 --- a/cmake/Platform/Other/BoardManager.cmake +++ b/cmake/Platform/Hardware/Boards/BoardManager.cmake @@ -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() @@ -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) @@ -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() diff --git a/cmake/Platform/Hardware/Boards/Boards.cmake b/cmake/Platform/Hardware/Boards/Boards.cmake new file mode 100644 index 0000000..773a826 --- /dev/null +++ b/cmake/Platform/Hardware/Boards/Boards.cmake @@ -0,0 +1 @@ +include(BoardManager) diff --git a/cmake/Platform/Libraries/LibrariesFinder.cmake b/cmake/Platform/Libraries/LibrariesFinder.cmake index 4fa1df0..70e0a8c 100644 --- a/cmake/Platform/Libraries/LibrariesFinder.cmake +++ b/cmake/Platform/Libraries/LibrariesFinder.cmake @@ -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}) @@ -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 () @@ -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 () diff --git a/cmake/Platform/Libraries/LibraryFlagsManager.cmake b/cmake/Platform/Libraries/LibraryFlagsManager.cmake index 13a8c2a..36be98b 100644 --- a/cmake/Platform/Libraries/LibraryFlagsManager.cmake +++ b/cmake/Platform/Libraries/LibraryFlagsManager.cmake @@ -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() diff --git a/cmake/Platform/Libraries/LibrarySourcesArchitectureResolver.cmake b/cmake/Platform/Libraries/LibrarySourcesArchitectureResolver.cmake index 137882f..e01afde 100644 --- a/cmake/Platform/Libraries/LibrarySourcesArchitectureResolver.cmake +++ b/cmake/Platform/Libraries/LibrarySourcesArchitectureResolver.cmake @@ -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() diff --git a/cmake/Platform/Other/TargetFlagsManager.cmake b/cmake/Platform/Other/TargetFlagsManager.cmake index 0941bee..9b8fed7 100644 --- a/cmake/Platform/Other/TargetFlagsManager.cmake +++ b/cmake/Platform/Other/TargetFlagsManager.cmake @@ -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} - $<$:${compiler_recipe_flags}>) + target_compile_options(${_target_name} ${_scope} $<$:${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}" @@ -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}") @@ -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 @@ -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}") diff --git a/cmake/Platform/Project/BoardSetup.cmake b/cmake/Platform/Project/BoardSetup.cmake new file mode 100644 index 0000000..2994540 --- /dev/null +++ b/cmake/Platform/Project/BoardSetup.cmake @@ -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() diff --git a/cmake/Platform/Project/CoreLibSetup.cmake b/cmake/Platform/Project/CoreLibSetup.cmake new file mode 100644 index 0000000..efa1bf0 --- /dev/null +++ b/cmake/Platform/Project/CoreLibSetup.cmake @@ -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() diff --git a/cmake/Platform/Project/Project.cmake b/cmake/Platform/Project/Project.cmake new file mode 100644 index 0000000..5e1cbe3 --- /dev/null +++ b/cmake/Platform/Project/Project.cmake @@ -0,0 +1,3 @@ +include(BoardSetup) +include(CoreLibSetup) +include(ProjectSetup) diff --git a/cmake/Platform/Project/ProjectSetup.cmake b/cmake/Platform/Project/ProjectSetup.cmake new file mode 100644 index 0000000..732a688 --- /dev/null +++ b/cmake/Platform/Project/ProjectSetup.cmake @@ -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() diff --git a/cmake/Platform/Properties/CMakeProperties.cmake b/cmake/Platform/Properties/CMakeProperties.cmake new file mode 100644 index 0000000..9da2372 --- /dev/null +++ b/cmake/Platform/Properties/CMakeProperties.cmake @@ -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() diff --git a/cmake/Platform/Sketches/SketchHeadersManager.cmake b/cmake/Platform/Sketches/SketchHeadersManager.cmake index 3fc4303..e98025a 100644 --- a/cmake/Platform/Sketches/SketchHeadersManager.cmake +++ b/cmake/Platform/Sketches/SketchHeadersManager.cmake @@ -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) @@ -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 @@ -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 () diff --git a/cmake/Platform/Sketches/SketchManager.cmake b/cmake/Platform/Sketches/SketchManager.cmake index 4673821..c92e7bf 100644 --- a/cmake/Platform/Sketches/SketchManager.cmake +++ b/cmake/Platform/Sketches/SketchManager.cmake @@ -24,10 +24,9 @@ endfunction() # Each sketch is converted to a valid '.cpp' source file under the project's source directory. # The function also finds and links any libraries the sketch uses to the 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(add_sketch_to_target _target_name _board_id _sketch_file) +function(add_sketch_to_target _target_name _sketch_file) _get_converted_source_desired_path(${_sketch_file} sketch_converted_source_path) @@ -35,7 +34,7 @@ function(add_sketch_to_target _target_name _board_id _sketch_file) if (CONVERT_SKETCHES_IF_CONVERTED_SOURCES_EXISTS OR NOT EXISTS ${sketch_converted_source_path}) - resolve_sketch_headers(${_target_name} ${_board_id} ${_sketch_file}) + resolve_sketch_headers(${_target_name} ${_sketch_file}) convert_sketch_to_source(${_sketch_file} ${sketch_converted_source_path}) @@ -48,15 +47,14 @@ endfunction() #=============================================================================# # Adds a list of sketch files as converted sources to the given 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). # [Sketches] - List of paths to sketch files to add to the target. #=============================================================================# -function(target_sketches _target_name _board_id) +function(target_sketches _target_name) parse_sources_arguments(parsed_sketches "" "" "" "${ARGN}") foreach (sketch_file ${parsed_sketches}) - add_sketch_to_target(${_target_name} ${_board_id} ${sketch_file}) + add_sketch_to_target(${_target_name} ${sketch_file}) endforeach () endfunction() diff --git a/cmake/Platform/System/BuildSystemInitializer.cmake b/cmake/Platform/System/BuildSystemInitializer.cmake index c7fb507..9dce221 100644 --- a/cmake/Platform/System/BuildSystemInitializer.cmake +++ b/cmake/Platform/System/BuildSystemInitializer.cmake @@ -18,12 +18,18 @@ endfunction() #=============================================================================# function(initialize_build_system) + define_custom_properties() + set_arduino_cmake_defaults() + find_required_platform_tools() + detect_sdk_version() + if (CMAKE_HOST_UNIX AND NOT CMAKE_HOST_APPLE) # Detect host's Linux distribution detect_host_linux_distribution() endif () + if (AUTO_SET_SKETCHBOOK_PATH) find_sketchbook_path() endif () diff --git a/cmake/Platform/Targets/ArduinoCMakeLibraryTarget.cmake b/cmake/Platform/Targets/ArduinoCMakeLibraryTarget.cmake index 129eece..9bb0b04 100644 --- a/cmake/Platform/Targets/ArduinoCMakeLibraryTarget.cmake +++ b/cmake/Platform/Targets/ArduinoCMakeLibraryTarget.cmake @@ -3,12 +3,11 @@ # One can also specify an architecture for the library, which will result in a special parsing # of the sources, ommiting non-compliant sources. # _target_name - Name of the library target to be created. Usually library's real name. -# _board_id - Board ID associated with the linked Core Lib. # _sources - Source and header files to create library target from. # [ARCH] - Optional library architecture (Such as 'avr', 'nrf52', etc.). # [INTERFACE] - Whether the library should be created as an interface library (header-only). #=============================================================================# -function(_add_arduino_cmake_library _target_name _board_id _sources) +function(_add_arduino_cmake_library _target_name _sources) cmake_parse_arguments(parsed_args "INTERFACE" "" "" ${ARGN}) @@ -16,19 +15,19 @@ function(_add_arduino_cmake_library _target_name _board_id _sources) add_library(${_target_name} INTERFACE) set(scope INTERFACE) - + else () - - add_library(${_target_name} STATIC "${_sources}") + + add_library(${_target_name} STATIC "${_sources}") set(scope PUBLIC) - + endif () # Treat headers' parent directories as include directories of the target get_headers_parent_directories("${_sources}" include_dirs) target_include_directories(${_target_name} ${scope} ${include_dirs}) - set_library_flags(${_target_name} ${_board_id} ${scope}) + set_library_flags(${_target_name} ${scope}) set_target_architecture_definition(${_target_name} ${scope} ${ARDUINO_CMAKE_PLATFORM_ARCHITECTURE}) @@ -41,8 +40,7 @@ endfunction() # _target_name - Name of the target to link against. # _library_name - Name of the library target to link. # [PRIVATE|PUBLIC|INTERFACE] - Optional link scope for the internally linked Core-Lib. -# [BOARD_CORE_TARGET] - Optional target name of the Core Lib to use. -# Use when the target is a library. +# [BOARD_CORE_TARGET] - Optional target name of the Core Lib to use. Use when the target is a library. #=============================================================================# function(_link_arduino_cmake_library _target_name _library_name) @@ -57,7 +55,7 @@ function(_link_arduino_cmake_library _target_name _library_name) if (parsed_args_BOARD_CORE_TARGET) set(core_target ${parsed_args_BOARD_CORE_TARGET}) else () - set(core_target ${${_target_name}_CORE_LIB_TARGET}) + set(core_target ${${PROJECT_${ARDUINO_CMAKE_PROJECT_NAME}_BOARD}_CORELIB_TARGET}) endif () get_target_property(core_lib_includes ${core_target} INCLUDE_DIRECTORIES) diff --git a/cmake/Platform/Targets/ArduinoExampleTarget.cmake b/cmake/Platform/Targets/ArduinoExampleTarget.cmake index a9805f8..57f49b2 100644 --- a/cmake/Platform/Targets/ArduinoExampleTarget.cmake +++ b/cmake/Platform/Targets/ArduinoExampleTarget.cmake @@ -2,20 +2,22 @@ # Adds/Creates an Arduino-Example executable target with the given name, # using the given board ID and example's sources. # _target_name - Name of the target (Executable) to create. -# _board_id - ID of the board to bind to the target (Each target can have a single board). # _example_name - Name of the example to use, such as 'Blink'. # [CATEGORY cat] - Optional argument representing the category of the Example to use. # e.g The 'Blink' example is under the '01.Basics' category. # Generally, all this does is improving search performance by narrowing. #=============================================================================# -function(add_arduino_example _target_name _board_id _example_name) +function(add_arduino_example _target_name _example_name) convert_string_to_pascal_case(${_example_name} arduino_compliant_example_name) + find_arduino_example_sources("${ARDUINO_SDK_EXAMPLES_PATH}" ${arduino_compliant_example_name} example_sketches ${ARGN}) + # First create the target (Without sources), then add sketches as converted sources - add_arduino_executable(${_target_name} ${_board_id}) - target_sketches(${_target_name} ${_board_id} "${example_sketches}") + add_arduino_executable(${_target_name}) + + target_sketches(${_target_name} "${example_sketches}") endfunction() @@ -23,7 +25,6 @@ endfunction() # Adds/Creates an Arduino-Library-Example executable target with the given name, # using the given board ID and library example's sources. # _target_name - Name of the target (Executable) to create. -# _board_id - ID of the board to bind to the target (Each target can have a single board). # _library_target_name - Name of an already-existing library target. # This means the library should first be found by the user. # _library_name - Name of the library the example belongs to, such as 'Servo'. @@ -32,8 +33,7 @@ endfunction() # e.g The 'Blink' example is under the '01.Basics' category. # Generally, all this does is improving search performance by narrowing. #=============================================================================# -function(add_arduino_library_example _target_name _board_id - _library_target_name _library_name _example_name) +function(add_arduino_library_example _target_name _library_target_name _library_name _example_name) convert_string_to_pascal_case(${_example_name} arduino_compliant_example_name) convert_string_to_pascal_case(${_library_name} arduino_compliant_library_name) @@ -44,8 +44,11 @@ function(add_arduino_library_example _target_name _board_id find_arduino_library_example_sources("${ARDUINO_SDK_LIBRARIES_PATH}/${arduino_compliant_library_name}" ${arduino_compliant_example_name} example_sketches ${ARGN}) - add_arduino_executable(${_target_name} ${_board_id}) - target_sketches(${_target_name} ${_board_id} "${example_sketches}") - link_arduino_library(${_target_name} ${_library_target_name} ${_board_id}) + + add_arduino_executable(${_target_name}) + + target_sketches(${_target_name} "${example_sketches}") + + link_arduino_library(${_target_name} ${_library_target_name}) endfunction() \ No newline at end of file diff --git a/cmake/Platform/Targets/ArduinoLibraryTarget.cmake b/cmake/Platform/Targets/ArduinoLibraryTarget.cmake index 084ed75..be472cd 100644 --- a/cmake/Platform/Targets/ArduinoLibraryTarget.cmake +++ b/cmake/Platform/Targets/ArduinoLibraryTarget.cmake @@ -2,11 +2,10 @@ # Creates a library target for the given name and sources. # As it's an Arduino library, it also finds and links all dependent platform libraries (if any). # _target_name - Name of the library target to be created. Usually library's real name. -# _board_id - Board ID associated with the linked Core Lib. # [Sources] - List of source files (Could also be headers for code-inspection in some IDEs) # to create the executable from, similar to CMake's built-in add_executable. #=============================================================================# -function(add_arduino_library _target_name _board_id) +function(add_arduino_library _target_name) parse_sources_arguments(parsed_sources "" "" "" "${ARGN}") @@ -15,7 +14,6 @@ function(add_arduino_library _target_name _board_id) get_sources_root_directory("${parsed_sources}" library_root_dir) get_library_properties_file(${library_root_dir} library_properties_file) - if (library_properties_file) # Properties file has been found resolve_library_architecture("${parsed_sources}" arch_resolved_sources LIB_PROPS_FILE ${library_properties_file}) @@ -23,18 +21,16 @@ function(add_arduino_library _target_name _board_id) resolve_library_architecture("${parsed_sources}" arch_resolved_sources) endif () - _add_arduino_cmake_library(${_target_name} ${_board_id} "${arch_resolved_sources}") + _add_arduino_cmake_library(${_target_name} "${arch_resolved_sources}") else() # No sources have been provided at this stage, simply create a library target - - _add_arduino_cmake_library(${_target_name} ${_board_id} "") - + _add_arduino_cmake_library(${_target_name} "") endif() find_dependent_platform_libraries("${arch_resolved_sources}" lib_platform_libs) foreach (platform_lib ${lib_platform_libs}) - link_platform_library(${_target_name} ${platform_lib} ${_board_id}) + link_platform_library(${_target_name} ${platform_lib}) endforeach () endfunction() @@ -42,13 +38,12 @@ endfunction() #=============================================================================# # Creates a header-only library target for the given name and sources. # _target_name - Name of the "executable" target. -# _board_id - Board ID associated with the linked Core Lib. #=============================================================================# -function(add_arduino_header_only_library _target_name _board_id) +function(add_arduino_header_only_library _target_name) parse_sources_arguments(parsed_headers "" "" "" "${ARGN}") - _add_arduino_cmake_library(${_target_name} ${_board_id} "${parsed_headers}" INTERFACE) + _add_arduino_cmake_library(${_target_name} "${parsed_headers}" INTERFACE) endfunction() @@ -57,23 +52,19 @@ endfunction() # it adds core lib's include directories to the libraries include directories. # _target_name - Name of the "executable" target. # _library_target_name - Name of the library target. -# _board_id - Board ID associated with the linked Core Lib. # [HEADER_ONLY] - Whether library is a header-only library, i.e has no source files #=============================================================================# -function(link_arduino_library _target_name _library_target_name _board_id) +function(link_arduino_library _target_name _library_target_name) cmake_parse_arguments(parsed_args "HEADER_ONLY" "" "" ${ARGN}) - get_core_lib_target_name(${_board_id} core_lib_target) - if (NOT TARGET ${_target_name}) message(FATAL_ERROR "Target doesn't exist - It must be created first!") elseif (NOT TARGET ${_library_target_name}) message(FATAL_ERROR "Library target doesn't exist - It must be created first!") - elseif (NOT TARGET ${core_lib_target}) - message(FATAL_ERROR "Core Library target doesn't exist. This is bad and should be reported") endif () + # Infer scope if (parsed_args_HEADER_ONLY) set(scope INTERFACE) else () @@ -82,6 +73,6 @@ function(link_arduino_library _target_name _library_target_name _board_id) _link_arduino_cmake_library(${_target_name} ${_library_target_name} ${scope} - BOARD_CORE_TARGET ${core_lib_target}) + BOARD_CORE_TARGET ${${PROJECT_${ARDUINO_CMAKE_PROJECT_NAME}_BOARD}_CORELIB_TARGET}) endfunction() diff --git a/cmake/Platform/Targets/CoreLibTarget.cmake b/cmake/Platform/Targets/CoreLibTarget.cmake index 83f6e9d..8951d91 100644 --- a/cmake/Platform/Targets/CoreLibTarget.cmake +++ b/cmake/Platform/Targets/CoreLibTarget.cmake @@ -5,6 +5,7 @@ function(_is_board_core_valid _board_core _board_id) list(FIND ARDUINO_CMAKE_PLATFORM_CORES "${board_core}" index) + if (${index} LESS 0) message(FATAL_ERROR "Unknown board core \"${board_core}\" for the ${_board_id} board") endif () @@ -18,6 +19,7 @@ endfunction() function(_is_board_variant_valid _board_variant _board_id) list(FIND ARDUINO_CMAKE_PLATFORM_VARIANTS "${board_variant}" index) + if (${index} LESS 0) message(FATAL_ERROR "Unknown board variant \"${board_variant}\" for the ${_board_id} board") endif () @@ -60,65 +62,47 @@ endfunction() # Sets compiler and linker flags on the given Core-Lib target. # Changes are kept even outside the scope of the function since they apply on a target. # _core_target_name - Name of the Core-Lib target. -# _board_id - Board ID associated with the library. Some flags require it. +# _board_id - Board ID asociated with the target. #=============================================================================# function(_set_core_lib_flags _core_target_name _board_id) - set_compiler_target_flags(${_core_target_name} ${_board_id} PUBLIC) - - # Set linker flags - set_linker_flags(${_core_target_name} ${_board_id}) + set_target_compile_flags(${_core_target_name} ${_board_id} PUBLIC) + set_target_linker_flags(${_core_target_name} ${_board_id}) endfunction() #=============================================================================# # Adds/Creates a static library target for Arduino's core library (Core-Lib), -# required by every standard Arduino Application/Executable. -# The library is then linked against the given executable target -# (Which also means is has to be created first). -# _target_name - Name of the Application/Executable target created earlier. +# required by every arduino target. # _board_id - Board to create the core library for. # Note that each board has a unique version of the library. +# _return_var - Name of variable in parent-scope holding the return value. +# Returns - Generated Core-lib's target name. #=============================================================================# -function(add_arduino_core_lib _target_name _board_id) - - get_core_lib_target_name(${_board_id} core_lib_target) - - if (TARGET ${core_lib_target}) # Core-lib target already created for the given board - if (TARGET ${_target_name}) # Executable/Firmware target also exists - target_link_libraries(${_target_name} PUBLIC ${core_lib_target}) - endif () - else () # Core-Lib target needs to be created - _get_board_core(${_board_id} board_core) # Get board's core - _get_board_variant(${_board_id} board_variant) # Get board's variant - - # Find sources in core directory and add the library target - find_source_files("${ARDUINO_CMAKE_CORE_${board_core}_PATH}" core_sources) - - if (${CMAKE_HOST_UNIX}) +function(add_arduino_core_lib _board_id _return_var) - if (CMAKE_HOST_UBUNTU OR CMAKE_HOST_DEBIAN) + generate_core_lib_target_name(${_board_id} core_lib_target) - list(FILTER core_sources EXCLUDE REGEX "[Mm]ain\\.c.*") + _get_board_core(${_board_id} board_core) # Get board's core + _get_board_variant(${_board_id} board_variant) # Get board's variant - endif () + # Find sources in core directory and add the library target + find_source_files("${ARDUINO_CMAKE_CORE_${board_core}_PATH}" core_sources) + if (CMAKE_HOST_UNIX) + if (CMAKE_HOST_UBUNTU OR CMAKE_HOST_DEBIAN) + list(FILTER core_sources EXCLUDE REGEX "[Mm]ain\\.c.*") endif () + endif () - add_library(${core_lib_target} STATIC "${core_sources}") + add_library(${core_lib_target} STATIC "${core_sources}") - # Include platform's core and variant directories - target_include_directories(${core_lib_target} PUBLIC - "${ARDUINO_CMAKE_CORE_${board_core}_PATH}") - target_include_directories(${core_lib_target} PUBLIC - "${ARDUINO_CMAKE_VARIANT_${board_variant}_PATH}") + # Include platform's core and variant directories + target_include_directories(${core_lib_target} PUBLIC "${ARDUINO_CMAKE_CORE_${board_core}_PATH}") + target_include_directories(${core_lib_target} PUBLIC "${ARDUINO_CMAKE_VARIANT_${board_variant}_PATH}") - _set_core_lib_flags(${core_lib_target} ${_board_id}) + _set_core_lib_flags(${core_lib_target} ${_board_id}) - # Link Core-Lib to executable target - if (TARGET ${_target_name}) - target_link_libraries(${_target_name} PUBLIC "${core_lib_target}") - endif () - endif () + set(${_return_var} ${core_lib_target} PARENT_SCOPE) endfunction() diff --git a/cmake/Platform/Targets/ExecutableTarget.cmake b/cmake/Platform/Targets/ExecutableTarget.cmake index 12542f2..95b3c9e 100644 --- a/cmake/Platform/Targets/ExecutableTarget.cmake +++ b/cmake/Platform/Targets/ExecutableTarget.cmake @@ -2,19 +2,19 @@ # Adds/Creates an Arduino-Executable target with the given name, # using the given board ID and source files. # _target_name - Name of the target (Executable) to create. -# _board_id - ID of the board to bind to the target (Each target can have a single board). # [Sources] - List of source files (Could also be headers for code-inspection in some IDEs) # to create the executable from, similar to CMake's built-in add_executable. #=============================================================================# -function(add_arduino_executable _target_name _board_id) +function(add_arduino_executable _target_name) list(APPEND sources "${ARGN}") # Treat all remaining arguments as sources add_executable(${_target_name} "${sources}") - # Always add board's core lib - add_arduino_core_lib(${_target_name} "${_board_id}") + + target_link_libraries(${_target_name} PRIVATE ${${PROJECT_${ARDUINO_CMAKE_PROJECT_NAME}_BOARD}_CORELIB_TARGET}) + # Add compiler and linker flags - set_executable_target_flags(${_target_name} "${_board_id}") + set_executable_target_flags(${_target_name}) set(target_path "${CMAKE_CURRENT_BINARY_DIR}/${_target_name}") @@ -37,9 +37,9 @@ function(add_arduino_executable _target_name _board_id) VERBATIM) # Required for avr-size - get_board_property("${_board_id}" build.mcu board_mcu) - set(avr_size_script - "${ARDUINO_CMAKE_TOOLCHAIN_DIR}/Platform/Other/FirmwareSizeCalculator.cmake") + get_board_property(${PROJECT_${ARDUINO_CMAKE_PROJECT_NAME}_BOARD} build.mcu board_mcu) + + set(avr_size_script "${ARDUINO_CMAKE_TOOLCHAIN_DIR}/Platform/Other/FirmwareSizeCalculator.cmake") add_custom_command(TARGET ${_target_name} POST_BUILD COMMAND ${CMAKE_COMMAND} diff --git a/cmake/Platform/Targets/PlatformLibraryTarget.cmake b/cmake/Platform/Targets/PlatformLibraryTarget.cmake index e5a9fd4..c0b9049 100644 --- a/cmake/Platform/Targets/PlatformLibraryTarget.cmake +++ b/cmake/Platform/Targets/PlatformLibraryTarget.cmake @@ -25,26 +25,24 @@ endfunction() #=============================================================================# # Creates a platform library target with the given name. # _library_name - Name of the library target to create, usually the platform library name. -# _board_id - Board ID associated with the linked Core Lib. #=============================================================================# -function(_add_platform_library _library_name _board_id) +function(_add_platform_library _library_name) find_library_header_files("${ARDUINO_CMAKE_PLATFORM_LIBRARIES_PATH}/${_library_name}/src" lib_headers) find_library_source_files("${ARDUINO_CMAKE_PLATFORM_LIBRARIES_PATH}/${_library_name}/src" lib_source_files) set(lib_sources ${lib_headers} ${lib_source_files}) - _add_arduino_cmake_library(${_library_name} ${_board_id} "${lib_sources}") + _add_arduino_cmake_library(${_library_name} "${lib_sources}") endfunction() #=============================================================================# # Links the given platform library target to the given target. # _target_name - Name of the target to link against. -# _library_name - Name of the library target to create, usually the platform library name. -# _board_id - Board ID associated with the linked Core Lib. +# _library_name - Platform library's name. #=============================================================================# -function(link_platform_library _target_name _library_name _board_id) +function(link_platform_library _target_name _platform_library_name) if (NOT TARGET ${_target_name}) message(FATAL_ERROR "Target ${_target_name} doesn't exist - It must be created first!") @@ -53,17 +51,16 @@ function(link_platform_library _target_name _library_name _board_id) parse_scope_argument(scope "${ARGN}" DEFAULT_SCOPE PUBLIC) - if (NOT TARGET ${_library_name}) + if (NOT TARGET ${_platform_library_name}) - _add_platform_library(${_library_name} ${_board_id}) + _add_platform_library(${_platform_library_name}) - get_core_lib_target_name(${_board_id} core_lib_target) - _link_arduino_cmake_library(${_target_name} ${_library_name} + _link_arduino_cmake_library(${_target_name} ${_platform_library_name} ${scope} - BOARD_CORE_TARGET ${core_lib_target}) + BOARD_CORE_TARGET ${${PROJECT_${ARDUINO_CMAKE_PROJECT_NAME}_BOARD}_CORELIB_TARGET}) else () - target_link_libraries(${_target_name} ${scope} ${_library_name}) + target_link_libraries(${_target_name} ${scope} ${_platform_library_name}) endif () endfunction() diff --git a/cmake/Platform/Targets/UploadTarget.cmake b/cmake/Platform/Targets/UploadTarget.cmake index aeee595..6b33dce 100644 --- a/cmake/Platform/Targets/UploadTarget.cmake +++ b/cmake/Platform/Targets/UploadTarget.cmake @@ -1,16 +1,15 @@ #=============================================================================# # Uploads the given target to te connected Arduino board using the given board ID and port. # _target_name - Name of the target (Executable) to upload. -# _board_id - Target's bounded board ID. # _port - Serial port on the host system used to upload/flash the connected Arduino board. #=============================================================================# -function(upload_arduino_target _target_name _board_id _port) +function(upload_arduino_target _target_name _port) if ("${_target_name}" STREQUAL "") message(FATAL_ERROR "Can't create upload target for an invalid target ${_target_name}") endif () - set_upload_target_flags("${_target_name}" "${_board_id}" "${_port}" upload_args) + set_upload_target_flags(${_target_name} ${_port} upload_args) add_custom_command(TARGET ${_target_name} POST_BUILD COMMAND ${ARDUINO_CMAKE_AVRDUDE_PROGRAM} @@ -18,4 +17,4 @@ function(upload_arduino_target _target_name _board_id _port) COMMENT "Uploading ${_target_name} target" DEPENDS ${_target_name}) -endfunction() \ No newline at end of file +endfunction() diff --git a/cmake/Platform/Utilities/CMakeArgumentsUtils.cmake b/cmake/Platform/Utilities/CMakeArgumentsUtils.cmake index 7dc9f40..a94a62b 100644 --- a/cmake/Platform/Utilities/CMakeArgumentsUtils.cmake +++ b/cmake/Platform/Utilities/CMakeArgumentsUtils.cmake @@ -21,6 +21,8 @@ function(_consume_reserved_arguments _args _reserved_options _reserved_single_va decrement_integer(args_length 1) # We'll peform index iteration - It's always length-1 + # ToDo: Handle empty given sources + foreach (index RANGE ${args_length}) list(GET _args ${index} arg) diff --git a/cmake/Platform/Utilities/LibraryUtils.cmake b/cmake/Platform/Utilities/LibraryUtils.cmake index ce3b912..b9f22dc 100644 --- a/cmake/Platform/Utilities/LibraryUtils.cmake +++ b/cmake/Platform/Utilities/LibraryUtils.cmake @@ -19,7 +19,8 @@ function(get_library_properties_file _library_root_directory _return_var) set(lib_props_file ${absolute_lib_root_dir}/${ARDUINO_CMAKE_LIBRARY_PROPERTIES_FILE_NAME}) if (NOT EXISTS ${lib_props_file}) - message(STATUS "Library's properties file doesn't exist under the given root directory.\n\t" + message(STATUS "Library's properties file doesn't exist under the given root directory, " + "assuming it's architecture-agnostic (supports all architectures)\n\t" "Root directory: ${absolute_lib_root_dir}") return() endif () diff --git a/cmake/Platform/Utilities/StringUtils.cmake b/cmake/Platform/Utilities/StringUtils.cmake index 3efa362..c4b599f 100644 --- a/cmake/Platform/Utilities/StringUtils.cmake +++ b/cmake/Platform/Utilities/StringUtils.cmake @@ -59,13 +59,13 @@ endfunction() # _return_var - Name of variable in parent-scope holding the return value. # Returns - Name of the core library target for the given board. #=============================================================================# -function(get_core_lib_target_name _board_id _return_var) +function(generate_core_lib_target_name _board_id _return_var) string(REPLACE "." "_" board_id "${_board_id}") - set(core_lib_target_name "${board_id}_core_lib") + string(TOLOWER "${board_id}" board_id) - string(TOLOWER "${core_lib_target_name}" core_lib_target_name) + set(core_lib_target_name "${board_id}_Core_Lib") set(${_return_var} ${core_lib_target_name} PARENT_SCOPE) diff --git a/examples/3rd-party-library/CMakeLists.txt b/examples/3rd-party-library/CMakeLists.txt index b10778c..0e4d67f 100644 --- a/examples/3rd-party-library/CMakeLists.txt +++ b/examples/3rd-party-library/CMakeLists.txt @@ -1,31 +1,32 @@ cmake_minimum_required(VERSION 3.8.2) project(3rd_Party_Arduino_Library) -get_board_id(board_id nano atmega328) + +arduino_cmake_project(3rd_Party_Arduino_Library BOARD_NAME nano BOARD_CPU atmega328) # First, declare and create our executable - It'll use 4 sources -add_arduino_executable(3rd_Party_Arduino_Library ${board_id} 3rd_party.cpp +add_arduino_executable(3rd_Party_Arduino_Library 3rd_party.cpp NeoPixelTest.cpp GFXTest.cpp LiquidCrystalTest.cpp) target_include_directories(3rd_Party_Arduino_Library PRIVATE include) # Add the "NeoPixel" library manually using the library addition API -add_arduino_library(adafruit_NeoPixel ${board_id} libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp) +add_arduino_library(adafruit_NeoPixel libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp) target_include_directories(adafruit_NeoPixel PUBLIC libraries/Adafruit_NeoPixel) # Find the "GFX" library - It's located under the 'libraries' sub-dir, which is a valid search path -find_arduino_library(adafruit_GFX Adafruit-GFX-Library ${board_id} 3RD_PARTY) +find_arduino_library(adafruit_GFX Adafruit-GFX-Library 3RD_PARTY) # We can also explicitly add additional directories to the target, # as only root dir and 'src' and 'utility' sub-dirs are added by default target_source_directories(adafruit_GFX DIRS libraries/Adafruit-GFX-Library/Fonts) # We can even automatically find a library that doesn't have a properties file! -find_arduino_library(sky_writer Skywriter ${board_id} 3RD_PARTY) +find_arduino_library(sky_writer Skywriter 3RD_PARTY) # Libraries that have an inner-dependency on a platform library are also suported! -find_arduino_library(liquid_Crystal LiquidCrystal_I2C ${board_id} 3RD_PARTY) +find_arduino_library(liquid_Crystal LiquidCrystal_I2C 3RD_PARTY) # Link all libraries to our previously created target -link_arduino_library(3rd_Party_Arduino_Library adafruit_NeoPixel ${board_id}) -link_arduino_library(3rd_Party_Arduino_Library adafruit_GFX ${board_id}) -link_arduino_library(3rd_Party_Arduino_Library sky_writer ${board_id}) -link_arduino_library(3rd_Party_Arduino_Library liquid_Crystal ${board_id}) +link_arduino_library(3rd_Party_Arduino_Library adafruit_NeoPixel) +link_arduino_library(3rd_Party_Arduino_Library adafruit_GFX) +link_arduino_library(3rd_Party_Arduino_Library sky_writer) +link_arduino_library(3rd_Party_Arduino_Library liquid_Crystal) diff --git a/examples/arduino-library/CMakeLists.txt b/examples/arduino-library/CMakeLists.txt index 5af7320..911dbbe 100644 --- a/examples/arduino-library/CMakeLists.txt +++ b/examples/arduino-library/CMakeLists.txt @@ -1,21 +1,22 @@ cmake_minimum_required(VERSION 3.8.2) project(Arduino_Library) -get_board_id(board_id nano atmega328) -add_arduino_executable(Arduino_Library ${board_id} test.cpp) +arduino_cmake_project(Arduino_Library BOARD_NAME nano BOARD_CPU atmega328) + +add_arduino_executable(Arduino_Library test.cpp) # Find and link the Stepper library -find_arduino_library(stepper_lib stePpEr ${board_id}) # Library name is case-insensitive to the user -link_arduino_library(Arduino_Library stepper_lib ${board_id}) +find_arduino_library(stepper_lib stePpEr) # Library name is case-insensitive to the user +link_arduino_library(Arduino_Library stepper_lib) # Find and link the Servo library - Custom implementation for many architectures, # 'avr' is used by default -find_arduino_library(servo_lib Servo ${board_id}) -link_arduino_library(Arduino_Library servo_lib ${board_id}) +find_arduino_library(servo_lib Servo) +link_arduino_library(Arduino_Library servo_lib) # Find and link the Ethernet library - Depends on the SPI avr-platform library -find_arduino_library(ethernet_lib Ethernet ${board_id}) -link_arduino_library(Arduino_Library ethernet_lib ${board_id}) +find_arduino_library(ethernet_lib Ethernet) +link_arduino_library(Arduino_Library ethernet_lib) -#upload_arduino_target(Arduino_Library "${board_id}" COM3) +#upload_arduino_target(Arduino_Library "" COM3) diff --git a/examples/blink-example/CMakeLists.txt b/examples/blink-example/CMakeLists.txt index 998897d..f806616 100644 --- a/examples/blink-example/CMakeLists.txt +++ b/examples/blink-example/CMakeLists.txt @@ -2,6 +2,6 @@ cmake_minimum_required(VERSION 3.8.2) project(Blink_Example) -get_board_id(board_id nano atmega328) +arduino_cmake_project(Blink_Example BOARD_NAME nano BOARD_CPU atmega328) -add_arduino_example(Blink_Example ${board_id} Blink) +add_arduino_example(Blink_Example Blink) diff --git a/examples/header-only-library/CMakeLists.txt b/examples/header-only-library/CMakeLists.txt index c4f8d2d..5d8a34a 100644 --- a/examples/header-only-library/CMakeLists.txt +++ b/examples/header-only-library/CMakeLists.txt @@ -1,13 +1,14 @@ cmake_minimum_required(VERSION 3.8.2) project(Header_Only_Lib) -get_board_id(board_id nano atmega328) -add_arduino_executable(Header_Only_Lib ${board_id} headerOnlyTest.cpp) +arduino_cmake_project(Header_Only_Lib BOARD_NAME nano BOARD_CPU atmega328) + +add_arduino_executable(Header_Only_Lib headerOnlyTest.cpp) # Find the library by 'tricking' the framework to use current directory as the Sketchbook path, # allowing us to use the 'find' API set(ARDUINO_CMAKE_SKETCHBOOK_PATH "${CMAKE_CURRENT_LIST_DIR}") -find_arduino_library(headerTest test-lib ${board_id} 3RD_PARTY HEADER_ONLY) +find_arduino_library(headerTest test-lib 3RD_PARTY HEADER_ONLY) -link_arduino_library(Header_Only_Lib headerTest ${board_id} HEADER_ONLY) +link_arduino_library(Header_Only_Lib headerTest HEADER_ONLY) diff --git a/examples/hello-world/CMakeLists.txt b/examples/hello-world/CMakeLists.txt index deb7c4b..219a084 100644 --- a/examples/hello-world/CMakeLists.txt +++ b/examples/hello-world/CMakeLists.txt @@ -1,7 +1,9 @@ cmake_minimum_required(VERSION 3.8.2) project(Hello_World) -get_board_id(board_id nano atmega328) +#get_board_id(board_id nano atmega328) + +arduino_cmake_project(Hello_World BOARD_NAME nano BOARD_CPU atmega328) add_arduino_executable(Hello_World ${board_id} helloWorld.cpp) diff --git a/examples/misc/CMakeLists.txt b/examples/misc/CMakeLists.txt index 7094aa9..07dd26c 100644 --- a/examples/misc/CMakeLists.txt +++ b/examples/misc/CMakeLists.txt @@ -1,5 +1,3 @@ cmake_minimum_required(VERSION 3.8.2) -project(NONE) - add_subdirectory(libraries) diff --git a/examples/misc/libraries/CMakeLists.txt b/examples/misc/libraries/CMakeLists.txt index 31e79e6..1285af1 100644 --- a/examples/misc/libraries/CMakeLists.txt +++ b/examples/misc/libraries/CMakeLists.txt @@ -1,5 +1,3 @@ cmake_minimum_required(VERSION 3.8.2) -project(NONE) - add_subdirectory(late-sources-library) diff --git a/examples/misc/libraries/late-sources-library/CMakeLists.txt b/examples/misc/libraries/late-sources-library/CMakeLists.txt index a3df1c8..14b009c 100644 --- a/examples/misc/libraries/late-sources-library/CMakeLists.txt +++ b/examples/misc/libraries/late-sources-library/CMakeLists.txt @@ -2,15 +2,15 @@ cmake_minimum_required(VERSION 3.8.2) project(Late_Source_Library) -get_board_id(board_id nano atmega328) +arduino_cmake_project(Late_Source_Library BOARD_NAME nano BOARD_CPU atmega328) # Explictly/Manually add a library without any sources at this stage -add_arduino_library(adafruit_NeoPixel_Late ${board_id}) +add_arduino_library(adafruit_NeoPixel_Late) -add_arduino_executable(Late_Source_Library ${board_id} late-sources-lib.cpp) +add_arduino_executable(Late_Source_Library late-sources-lib.cpp) # Complete required sources for the library that was manaully created earlier target_sources(adafruit_NeoPixel_Late PUBLIC ${CMAKE_CURRENT_LIST_DIR}/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp) target_include_directories(adafruit_NeoPixel_Late PUBLIC Adafruit_NeoPixel) -link_arduino_library(Late_Source_Library adafruit_NeoPixel_Late ${board_id}) +link_arduino_library(Late_Source_Library adafruit_NeoPixel_Late) diff --git a/examples/platform-library/CMakeLists.txt b/examples/platform-library/CMakeLists.txt index c6fe6ef..2c9e395 100644 --- a/examples/platform-library/CMakeLists.txt +++ b/examples/platform-library/CMakeLists.txt @@ -1,9 +1,10 @@ cmake_minimum_required(VERSION 3.8.2) project(Platform_Library) -get_board_id(board_id nano atmega328) -add_arduino_executable(Platform_Library ${board_id} platformLibrary.cpp) +arduino_cmake_project(Platform_Library BOARD_NAME nano BOARD_CPU atmega328) -link_platform_library(Platform_Library Wire ${board_id}) -link_platform_library(Platform_Library SPI ${board_id}) +add_arduino_executable(Platform_Library platformLibrary.cpp) + +link_platform_library(Platform_Library Wire) +link_platform_library(Platform_Library SPI) diff --git a/examples/servo-knob-example/CMakeLists.txt b/examples/servo-knob-example/CMakeLists.txt index 014a29d..ee5c0c1 100644 --- a/examples/servo-knob-example/CMakeLists.txt +++ b/examples/servo-knob-example/CMakeLists.txt @@ -2,8 +2,7 @@ cmake_minimum_required(VERSION 3.8.2) project(Knob_Example) -get_board_id(board_id nano atmega328) - -find_arduino_library(servo_example_lib Servo ${board_id}) -add_arduino_library_example(Knob_Example ${board_id} servo_example_lib Servo Knob) +arduino_cmake_project(Knob_Example BOARD_NAME nano BOARD_CPU atmega328) +find_arduino_library(servo_example_lib Servo) +add_arduino_library_example(Knob_Example servo_example_lib Servo Knob) diff --git a/examples/sketch/CMakeLists.txt b/examples/sketch/CMakeLists.txt index 796458f..3ca58a5 100644 --- a/examples/sketch/CMakeLists.txt +++ b/examples/sketch/CMakeLists.txt @@ -1,7 +1,8 @@ cmake_minimum_required(VERSION 3.8.2) project(Sketch) -get_board_id(board_id nano atmega328) -add_arduino_executable(Sketch ${board_id}) -target_sketches(Sketch ${board_id} sketch1.ino sketch2.pde) +arduino_cmake_project(Sketch BOARD_NAME nano BOARD_CPU atmega328) + +add_arduino_executable(Sketch) +target_sketches(Sketch sketch1.ino sketch2.pde)