Tom Mekken
Tom Mekken

Reputation: 1039

How to execute cmake add_custom_command after target "install"

I have a Software which is installed under /opt/my_program/. Now I want to write a plugin for it. my_program consists of mutliple libraries and binaries, that every user of the system can use.

[user@pc:/opt/my_program]$ tree
├── bin
│   └── mp
└── lib
    ├── lib_foobar.so
    ├── mp_lib.so
    └── other_lib.so

The provided /opt/my_program/lib/mp_lib.so links against /opt/my_program/lib/lib_foobar.so. Now my plugin needs mp_lib.so to use another (ABI-compatible) version of lib_foobar.so which I deploy with my plugin. I dont want to modify the original lib, because not every other user of the system may need/have the new version.

My idea was the following:

This allows every other user, to use the regular my_program as is, and only the users that use my_plugin do have their own workspace with their own mp_lib_custom.so, and their own lib_foobar_new.so:

CMakeLists.txt

...
set(CUSTOM_WORKSPACE "workspace")
set(MY_PROGRAM_DIR "/opt/my_program")
install(FILES ${CMAKE_BINARY_DIR}/my_plugin.so DESTINATION ${CUSTOM_WORKSPACE})
install(FILES ${CMAKE_SOURCE_DIR}/my_config.txt DESTINATION ${CUSTOM_WORKSPACE})
install(FILES ${CMAKE_SOURCE_DIR}/lib_foobar_new.so DESTINATION ${CUSTOM_WORKSPACE})
install(FILES ${MY_PROGRAM_DIR}/lib/mp_lib.so DESTINATION ${CUSTOM_WORKSPACE})
...

output:

[user@pc:/tmp/workspace]$ tree
.
├── my_plugin.so
├── my_config.txt
├── lib_foobar_new.so
└── mp_lib_custom.so

Problem

Now I need to patch the mp_lib_custom.so's RPATH with a custom-command AFTER cmake install was called (because otherwhise the copy wouldn't exist yet).

I tried it with:

add_custom_command(TARGET install POST_BUILD
  COMMAND "chrpath" "<ARGUMENTS>"
  COMMAND "echo" "file-was-patched")

But somehow I seem to misunderstand something, or "install" is not a CMake-Target?!

Upvotes: 1

Views: 113

Answers (0)

Related Questions