# cmake how to use scp command to transport bin file to another linux board

**URL:** https://discourse.cmake.org/t/cmake-how-to-use-scp-command-to-transport-bin-file-to-another-linux-board/4690
**Category:** Usage
**Tags:** os:linux
**Created:** [December 17, 2021, 3:54am UTC](https://discourse.cmake.org/t/cmake-how-to-use-scp-command-to-transport-bin-file-to-another-linux-board/4690 "2021-12-17T03:54:53Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![lichunfei](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@lichunfei](https://discourse.cmake.org/u/lichunfei)
#### Post date: [December 17, 2021, 3:54am UTC](https://discourse.cmake.org/t/cmake-how-to-use-scp-command-to-transport-bin-file-to-another-linux-board/4690/1 "2021-12-17T03:54:53Z")

</div>

how to use cmake file generated makefile scp conmand?

makefile like this  
upload:  
scp $(TARGET) [orangepi@192.168.8.105](mailto:orangepi@192.168.8.105):/home/orangepi/sgai

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 17, 2021, 1:21pm UTC](https://discourse.cmake.org/t/cmake-how-to-use-scp-command-to-transport-bin-file-to-another-linux-board/4690/2 "2021-12-17T13:21:27Z")

</div>

It seems you want to send the output of some target to another machine?

```cmake
add_custom_command(
  DEPENDS "${target}"
  OUTPUT "${output}"
  COMMAND scp "$<TARGET_FILE:${target}>" "${destination}"
  COMMAND "${CMAKE_COMMAND}" -E touch "${output}")
add_custom_target("send-${target}" DEPENDS "${output}")

```

---

<div class="post-metadata">

### Author: ![lichunfei](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@lichunfei](https://discourse.cmake.org/u/lichunfei)
#### Post date: [December 17, 2021, 3:11pm UTC](https://discourse.cmake.org/t/cmake-how-to-use-scp-command-to-transport-bin-file-to-another-linux-board/4690/3 "2021-12-17T15:11:56Z")

</div>

cmake:write like this blow

set(target sgai.txt)  
set(output /home/orangepi/sgai)  
set(destination [orangepi@192.168.8.105](mailto:orangepi@192.168.8.105))  
add\_custom\_command(  
DEPENDS “${target}”  
OUTPUT “${output}”  
COMMAND scp “$\<TARGET\_FILE:${target}\>” “${destination}”  
COMMAND “${CMAKE\_COMMAND}” -E touch “${output}”)  
add\_custom\_target(“send-${target}” DEPENDS “${output}”)

equals blow???  
makefile:

upload:  
scp sgai.txt [orangepi@192.168.8.105](mailto:orangepi@192.168.8.105):/home/orangepi/sgai

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 17, 2021, 3:38pm UTC](https://discourse.cmake.org/t/cmake-how-to-use-scp-command-to-transport-bin-file-to-another-linux-board/4690/4 "2021-12-17T15:38:02Z")

</div>

`output` should be some unique file that indicates “this upload was performed”. `destination` should be `orangepi@ipaddress:/path/on/remote`.

---

<div class="post-metadata">

### Author: ![lichunfei](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@lichunfei](https://discourse.cmake.org/u/lichunfei)
#### Post date: [December 17, 2021, 3:51pm UTC](https://discourse.cmake.org/t/cmake-how-to-use-scp-command-to-transport-bin-file-to-another-linux-board/4690/5 "2021-12-17T15:51:46Z")

</div>

upload:  
scp sgai.txt [orangepi@192.168.8.105](mailto:orangepi@192.168.8.105):/home/orangepi/sgai

I want to use command"make upload" to achieve “scp sgai.txt [orangepi@192.168.8.105](mailto:orangepi@192.168.8.105):/home/orangepi/sgai”，how should I encode my cmakefile?thanks!!!

---

<div class="post-metadata">

### Author: ![lichunfei](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@lichunfei](https://discourse.cmake.org/u/lichunfei)
#### Post date: [December 17, 2021, 4:08pm UTC](https://discourse.cmake.org/t/cmake-how-to-use-scp-command-to-transport-bin-file-to-another-linux-board/4690/6 "2021-12-17T16:08:16Z")

</div>

set(target sgai)  
set(destination [orangepi@192.168.8.105](mailto:orangepi@192.168.8.105):/home/orangepi/sgai)  
message(STATUS “destination: ${destination}”)  
add\_custom\_target(upload  
POST\_BUILD  
COMMAND scp “$\<TARGET\_FILE:${target}\>” “${destination}”

generated:

#=============================================================================

# Target rules for targets named upload

# Build rule for target.

upload: cmake\_check\_build\_system  
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 upload  
.PHONY : upload

# fast build rule for target.

upload/fast:  
$(MAKE) $(MAKESILENT) -f CMakeFiles/upload.dir/build.make CMakeFiles/upload.dir/build  
.PHONY : upload/fast

#============================================================================

is this right?

---

<div class="post-metadata">

### Author: ![lichunfei](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@lichunfei](https://discourse.cmake.org/u/lichunfei)
#### Post date: [December 17, 2021, 4:20pm UTC](https://discourse.cmake.org/t/cmake-how-to-use-scp-command-to-transport-bin-file-to-another-linux-board/4690/7 "2021-12-17T16:20:59Z")

</div>

set(target upload)  
set(output sgai)  
set(destination [orangepi@192.168.8.105](mailto:orangepi@192.168.8.105):/home/orangepi/sgai)

add\_custom\_command(  
DEPENDS “${target}”  
OUTPUT “${output}”  
COMMAND scp “$\<TARGET\_FILE:${target}\>” “${destination}”  
COMMAND “${CMAKE\_COMMAND}” -E touch “${output}”)  
add\_custom\_target("${target}" DEPENDS “${output}”)

is this right?

---

<div class="post-metadata">

### Author: ![lichunfei](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@lichunfei](https://discourse.cmake.org/u/lichunfei)
#### Post date: [December 18, 2021, 6:32am UTC](https://discourse.cmake.org/t/cmake-how-to-use-scp-command-to-transport-bin-file-to-another-linux-board/4690/8 "2021-12-18T06:32:30Z")

</div>

hello,  
COMMAND SCP “$\<TARGET\_FILE:${target}\>” “${destination}”  
cmake version 3.18.0 version assist SCP command?

---

<div class="post-metadata">

### Author: ![lichunfei](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@lichunfei](https://discourse.cmake.org/u/lichunfei)
#### Post date: [December 18, 2021, 2:40pm UTC](https://discourse.cmake.org/t/cmake-how-to-use-scp-command-to-transport-bin-file-to-another-linux-board/4690/9 "2021-12-18T14:40:20Z")

</div>

add\_custom\_target(upload  
DEPENDS

```
  COMMAND scp /home/dji/SGAI_3399/sgai-main/build/log.c
  orangepi@192.168.8.105:/home/orangepi/log.c
  COMMAND ${CMAKE_COMMAND} -E echo "send finish"

```

)

hello,dose cmake add\_custom\_target COMMAND sopport SCP cmd transport file?

---

<div class="post-metadata">

### Author: ![lichunfei](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@lichunfei](https://discourse.cmake.org/u/lichunfei)
#### Post date: [December 20, 2021, 1:33am UTC](https://discourse.cmake.org/t/cmake-how-to-use-scp-command-to-transport-bin-file-to-another-linux-board/4690/10 "2021-12-20T01:33:32Z")

</div>

add\_custom\_target(upload  
DEPENDS  
COMMAND scp ${PROJECT\_NAME} ${destination}  
COMMAND ${CMAKE\_COMMAND} -E echo “transport finish”  
)

have solveld，thanks！
