From a6288895dfb573a0ff5b07da86a5307fda0a55c6 Mon Sep 17 00:00:00 2001 From: Timor Gruber Date: Mon, 25 Feb 2019 23:07:29 +0200 Subject: [PATCH 1/3] Modified upload command to target Also renamed function `upload_arduino_target` to `set_target_upload_port`. --- cmake/Platform/Targets/UploadTarget.cmake | 12 ++++++------ examples/hello-world/CMakeLists.txt | 7 +++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/cmake/Platform/Targets/UploadTarget.cmake b/cmake/Platform/Targets/UploadTarget.cmake index 6b33dce..f81fa2e 100644 --- a/cmake/Platform/Targets/UploadTarget.cmake +++ b/cmake/Platform/Targets/UploadTarget.cmake @@ -3,7 +3,7 @@ # _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 "") message(FATAL_ERROR "Can't create upload target for an invalid target ${_target_name}") @@ -11,10 +11,10 @@ function(upload_arduino_target _target_name _port) 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() diff --git a/examples/hello-world/CMakeLists.txt b/examples/hello-world/CMakeLists.txt index 219a084..1d8e4a8 100644 --- a/examples/hello-world/CMakeLists.txt +++ b/examples/hello-world/CMakeLists.txt @@ -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 nano BOARD_CPU atmega328old) -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) From 2435807475b671e92e5ce9341c2bbd8f2c997f51 Mon Sep 17 00:00:00 2001 From: Timor Gruber Date: Mon, 25 Feb 2019 23:14:03 +0200 Subject: [PATCH 2/3] Enhanced checks for valid upload target --- cmake/Platform/Targets/UploadTarget.cmake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmake/Platform/Targets/UploadTarget.cmake b/cmake/Platform/Targets/UploadTarget.cmake index f81fa2e..63c50c8 100644 --- a/cmake/Platform/Targets/UploadTarget.cmake +++ b/cmake/Platform/Targets/UploadTarget.cmake @@ -5,8 +5,13 @@ #=============================================================================# 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) From def3e8406815fbc69e5654ba018c9ac5fc71c377 Mon Sep 17 00:00:00 2001 From: Timor Gruber Date: Tue, 26 Feb 2019 23:49:12 +0200 Subject: [PATCH 3/3] Modified board CPU that doesn't exist on older SDKs --- examples/hello-world/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/hello-world/CMakeLists.txt b/examples/hello-world/CMakeLists.txt index 1d8e4a8..27ee457 100644 --- a/examples/hello-world/CMakeLists.txt +++ b/examples/hello-world/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.8.2) project(Hello_World) -arduino_cmake_project(Hello_World BOARD_NAME nano BOARD_CPU atmega328old) +arduino_cmake_project(Hello_World BOARD_NAME uno) add_arduino_executable(Hello_World helloWorld.cpp)