10

With make install I can copy my binaries, configs etcetera to a target folder for execution.

Now I have the following situation: we have a virtual machine setup as a build host, and a different real Linux machine as a target platform.

I would like to have make install copy the files directly in a folder on my remote machine (via scp or similar). How can I achieve that?

Pro Backup
  • 729
  • 14
  • 34
Danoo
  • 111
  • 1
  • 5

5 Answers5

7

You often could do

 make install DESTDIR=/tmp/mydest/

then archive that destination directory

 tar czvf /tmp/mydest.tgz -C /tmp mydest

then copy that archive to the remote place

 scp /tmp/mydest.tgz remote:tmp/

at last, untar the archive at the remote and copy it at appropriate place

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • Actually I would like to prevent all these intermediate steps. I guess cmake uses a copy (cp) command to copy files. There MUST somehow be a way to tell cmake to use scp instead... – Danoo Jan 24 '12 at 07:08
  • Often the source comes with a file named "README". The contents of that file might give a clue. For example pcre-8.39 suggests to use `make dist` and/or `make distcheck` to make tarballs. – Pro Backup Oct 26 '16 at 18:02
  • @Basile Starynkevitch Why not untar directly at the appropriate place without the copy step? – Pro Backup Oct 26 '16 at 21:21
3

Using cmake 2.8.14, command "add_custom_command" into the CMakeLists.txt, can be also used :

add_custom_command(TARGET my_target POST_BUILD COMMAND scp $<TARGET_FILE:my_target> user@remote_host:dest_dir_path )

Advantage : only call when the target is rebuild.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
michel
  • 31
  • 1
  • " only call when the target is rebuild." So I use [--fresh option](https://cmake.org/cmake/help/latest/manual/cmake.1.html#cmdoption-cmake-fresh) This is my example with key (no login-password) add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND scp -i "/home/user/my_nonpublic_ssh_key" "/home/user/CppProjs/QThread-with-moveToThread_console/build-cross/QThread-with-moveToThread_console" remoteuser@"192.168.122.8:/home/remoteuser" ) – DungeonLords Jun 18 '23 at 12:12
2

make can operate with a specific prefix during installation:

  make prefix=$dest/usr install

A solution to your problem is to

  • mount the filesystem of the target machine on your build machine. This can be done via nfs (persistent) or via sshfs (easier),
  • set $dest to the mountpoint and run the command above
ypnos
  • 50,202
  • 14
  • 95
  • 141
  • 1
    prefix doesn't seem to do anything. DESTDIR works (as in the other answer.) However, mounting is the way to go to make it all work at once (and the server can be remote using an SSH mount for out of local network computers.) – Alexis Wilke Dec 29 '12 at 01:28
1

I am using this solution:

install (CODE "execute_process(COMMAND scp -r -i /home/user/.ssh/id_rsa ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/. user@remote:/path/to/copy/)")

Then I run command make install and it's works

I know that ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} not best variable for it but for me it's fine

0

With user a userprofile on the machine remote and a ssh key preperly configured :

  install(CODE "execute_process(COMMAND /usr/bin/rsync -avh ${INSTALL_DIR} user@remote:/home/user/)")

Copies the locally installed binaries on the remote only when make install is invoked.

Steven
  • 313
  • 3
  • 10