Symbolic links CMake

2020-02-12 01:20发布

I want to rename certain executables in CMakeLists.txt but also want symbolic links from the older names to new files for backward compatibility. How can this be accomplished on systems that support symbolic links?

Also what are the alternatives for system that does not support symbolic links?

Thanks

标签: cmake
3条回答
乱世女痞
2楼-- · 2020-02-12 02:03

You can create a custom target and use CMake to create symlinks

ADD_CUSTOM_TARGET(link_target ALL
                  COMMAND ${CMAKE_COMMAND} -E create_symlink ${target} ${link})

This will only work on systems that support symlinks, see guide.

Available on UNIX only:

create_symlink old new - create a symbolic link new -> old

查看更多
做个烂人
3楼-- · 2020-02-12 02:05

Another way to do it:

INSTALL(CODE "execute_process( \
    COMMAND ${CMAKE_COMMAND} -E create_symlink \
    ${target} \
    ${link}   \
    )"
)

This way the symlinking will be done during make install only.

查看更多
我欲成王,谁敢阻挡
4楼-- · 2020-02-12 02:10

Another method that is a bit more verbose and only runs on install:

macro(install_symlink filepath sympath)
    install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${filepath} ${sympath})")
    install(CODE "message(\"-- Created symlink: ${sympath} -> ${filepath}\")")
endmacro(install_symlink)

Use it like this (similar to ln -s):

install_symlink(filepath sympath)
查看更多
登录 后发表回答