I have a project that by default installs into a self-contained directory, where it also keeps its project specific .so files. Running in the build dir works fine, as well as installing it. However, if I use CPack to create an RPM, the RUNPATH of the executable is set to the .so file in the build tree rather than the target location.
Is this a bug? If not, how should I work around this?
When installing, CMake rewrites the RPATH details of the installed binaries. By default, it removes the RPATH. If you want to specify a different RPATH, you would use the INSTALL_RPATH
target property, or probably more likely, the CMAKE_INSTALL_RPATH
variable which is used to initialise that target property.
I’ve used “RPATH” in the above because that’s what CMake calls it throughout its API, but it applies equally to RUNPATH, which CMake handles internally.
Thanks. It was my mistake. The CMAKE_INSTALL_PREFIX
was not set to /usr
, where the RPM installs the software. Apparently it updates the RUNPATH if this matches, otherwise it just leaves it alone. So, this worked fine
cmake -DCMAKE_INSTALL_PREFIX=/usr -G Ninja ..
ninja
cpack