4

I've seen many linux applications packaged with their binaries in some path like /opt/mypkg/myexecutable and a symlink to it in /usr/bin. I've seen these symlinks in the packaged files.

I want to do the same while packaging my software with cpack, creating deb and rpm packages with CPackDEB and CPackRPM.

  • Is it possible to create a symlink to an arbitrary, possibly non existent path?

  • Could I then use INSTALL(FILES "mysymlink" DESTINATION /usr/bin/myapp COMPONENT MyComponent)? (Would there be problems with symlinks being followed when the destination actually exists?)

  • Could I change the link destination with something like CONFIGURE_FILE()

Or am I just missing a cpack directive that does the job correctly?

unR
  • 1,298
  • 14
  • 21

1 Answers1

4

Have a look at the following example:

cmake_minimum_required(VERSION 3.0)
project(myls NONE)

execute_process(COMMAND ln -s /opt/myapp/superls myls)

install(FILES ${CMAKE_BINARY_DIR}/myls DESTINATION /usr/bin/myapp COMPONENT MyComponent)

SET(CPACK_PACKAGE_CONTACT dmarquant)
include(CPack)

You can simply create a symlink to a non existing location and as you have written install it with install(FILES ...).

David Marquant
  • 2,039
  • 14
  • 12
  • 1
    This works well for installation, but while packaging, this causes to add the folder/target too for which I want to add the symlink. Any alternative you can suggest? – Avinal Aug 06 '21 at 09:04