Search code examples
cmakecopysymlink

CMake command copy for symlink


I have following command:

add_custom_command(
    TARGET Packaging POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy 
        source_file
        target_file )

Sometimes the source_file is a symlink. However, when it is copied, the referenced file is copied not the symlink.

How can I tell CMake command to copy the symlink as it is without de-referencing it?


Solution

  • It seems that there is no direct solution in CMake till now https://gitlab.kitware.com/cmake/cmake/issues/14609

    A work around is to call a shell script that does the trick.