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
19 changes: 12 additions & 7 deletions cmake/Platform/Targets/UploadTarget.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@
# _target_name - Name of the target (Executable) to upload.
# _port - Serial port on the host system used to upload/flash the connected Arduino board.
#=============================================================================#
function(upload_arduino_target _target_name _port)
function(set_target_upload_port _target_name _port)

if ("${_target_name}" STREQUAL "")
if (NOT TARGET ${_target_name})
message(FATAL_ERROR "Can't create upload target for an invalid target ${_target_name}")
else ()
get_target_property(target_type ${_target_name} TYPE)
if (NOT ${target_type} STREQUAL "EXECUTABLE") # Target is not executable
message(SEND_ERROR "Upload target ${_target_name} must be an executable target")
endif ()
endif ()

set_upload_target_flags(${_target_name} ${_port} upload_args)

add_custom_command(TARGET ${_target_name} POST_BUILD
COMMAND ${ARDUINO_CMAKE_AVRDUDE_PROGRAM}
ARGS ${upload_args}
COMMENT "Uploading ${_target_name} target"
DEPENDS ${_target_name})
add_custom_target(${_target_name}_flash
COMMAND ${ARDUINO_CMAKE_AVRDUDE_PROGRAM} ${upload_args}
COMMENT "Uploading ${_target_name} target")

add_dependencies(${_target_name}_flash ${_target_name})

endfunction()
7 changes: 3 additions & 4 deletions examples/hello-world/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
cmake_minimum_required(VERSION 3.8.2)

project(Hello_World)
#get_board_id(board_id nano atmega328)

arduino_cmake_project(Hello_World BOARD_NAME nano BOARD_CPU atmega328)
arduino_cmake_project(Hello_World BOARD_NAME uno)

add_arduino_executable(Hello_World ${board_id} helloWorld.cpp)
add_arduino_executable(Hello_World helloWorld.cpp)

#upload_arduino_target(Hello_World "${board_id}" COM3)
set_target_upload_port(Hello_World COM3)