Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit b93aef6

Browse files
Merge pull request #76 from arduino-cmake/feature/upload-api
Refactored upload API
2 parents 7c99deb + def3e84 commit b93aef6

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

‎cmake/Platform/Targets/UploadTarget.cmake‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@
33
# _target_name - Name of the target (Executable) to upload.
44
# _port - Serial port on the host system used to upload/flash the connected Arduino board.
55
#=============================================================================#
6-
function(upload_arduino_target _target_name _port)
6+
function(set_target_upload_port _target_name _port)
77

8-
if ("${_target_name}"STREQUAL"")
8+
if (NOTTARGET${_target_name})
99
message(FATAL_ERROR "Can't create upload target for an invalid target ${_target_name}")
10+
else ()
11+
get_target_property(target_type ${_target_name} TYPE)
12+
if (NOT ${target_type} STREQUAL "EXECUTABLE") # Target is not executable
13+
message(SEND_ERROR "Upload target ${_target_name} must be an executable target")
14+
endif ()
1015
endif ()
1116

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

14-
add_custom_command(TARGET${_target_name} POST_BUILD
15-
COMMAND ${ARDUINO_CMAKE_AVRDUDE_PROGRAM}
16-
ARGS ${upload_args}
17-
COMMENT"Uploading ${_target_name} target"
18-
DEPENDS ${_target_name})
19+
add_custom_target(${_target_name}_flash
20+
COMMAND ${ARDUINO_CMAKE_AVRDUDE_PROGRAM}${upload_args}
21+
COMMENT"Uploading ${_target_name} target")
22+
23+
add_dependencies(${_target_name}_flash ${_target_name})
1924

2025
endfunction()

‎examples/hello-world/CMakeLists.txt‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
cmake_minimum_required(VERSION 3.8.2)
22

33
project(Hello_World)
4-
#get_board_id(board_id nano atmega328)
54

6-
arduino_cmake_project(Hello_World BOARD_NAME nano BOARD_CPU atmega328)
5+
arduino_cmake_project(Hello_World BOARD_NAME uno)
76

8-
add_arduino_executable(Hello_World ${board_id}helloWorld.cpp)
7+
add_arduino_executable(Hello_World helloWorld.cpp)
98

10-
#upload_arduino_target(Hello_World "${board_id}" COM3)
9+
set_target_upload_port(Hello_World COM3)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /