Search code examples
cmakesymlinkpackagingdebcpack

How can I package a symlink with cpack?


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?


Solution

  • 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 ...).