CMake: How to bind (ln) additional names after installation?

I need to find a way to associate additional names with an installed executable after installing it.

Below is an example except for two problems. First, the binding is done after each target, not just for the set. Secondly, the links are created in the build directory, not the install directory (maybe I can add the paths needed for this, but then it will fail if done before installation.)

cmake_minimum_required(VERSION 2.8.4)
add_executable(gr gr.c)
install(TARGETS gr DESTINATION bin)
add_custom_command(
  TARGET gr
  POST_BUILD
  COMMAND ln;-f;gr;grm
  COMMAND ln;-f;gr;grs
  COMMAND ln;-f;gr;grh
)

      

What's a simple, clean way to do what I want?

If it is not clear, the Makefile equivalent is:

gr:  gr.c
    cc -o gr gr.c

install:
    install gr ${BINDIR}
    ln -f ${BINDIR}/gr ${BINDIR}/grm
    ln -f ${BINDIR}/gr ${BINDIR}/grs
    ln -f ${BINDIR}/gr ${BINDIR}/grh

      

+3


source to share


1 answer


What I did in situations like this is use a custom command similar to what you did, but add an extra command install

to set links in the final bin directory next to the target. So after your add_custom_command

:

install(
  FILES
    ${CMAKE_CURRENT_BINARY_DIR}/grm
    ${CMAKE_CURRENT_BINARY_DIR}/grs
    ${CMAKE_CURRENT_BINARY_DIR}/grh
  DESTINATION bin
)

      



Of course, this will probably only do what you expect if you change your links to symbolic links (ln -s).

+4


source







All Articles