Reputation: 4467
I need to find a way to link additional names to an installed executable, after installing it.
The below example is close, except for two problems. One, the linking is done after every target, not just the install. Two, the links are created in the build directory, not in the install directory (I can probably add the paths necessary to do that, but it would then error out if done before the install.)
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 simple, clean way to do what I want?
In case it's 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
Upvotes: 3
Views: 866
Reputation: 1143
What I have done in similar situations is use the custom command similar to what you have done, but add an additional install
command to install the links in the final bin directory alongside 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).
Upvotes: 4