# Creating an RPM sets RUNPATH to build directory

**URL:** https://discourse.cmake.org/t/creating-an-rpm-sets-runpath-to-build-directory/11543
**Category:** Usage
**Tags:** cpack:rpm
**Created:** [August 29, 2024, 7:08am UTC](https://discourse.cmake.org/t/creating-an-rpm-sets-runpath-to-build-directory/11543 "2024-08-29T07:08:04Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![JanWielemaker](https://discourse.cmake.org/user_avatar/discourse.cmake.org/janwielemaker/32/438_2.png) [@JanWielemaker](https://discourse.cmake.org/u/JanWielemaker)
#### Post date: [August 29, 2024, 7:08am UTC](https://discourse.cmake.org/t/creating-an-rpm-sets-runpath-to-build-directory/11543/1 "2024-08-29T07:08:04Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [August 30, 2024, 5:25am UTC](https://discourse.cmake.org/t/creating-an-rpm-sets-runpath-to-build-directory/11543/2 "2024-08-30T05:25:48Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![JanWielemaker](https://discourse.cmake.org/user_avatar/discourse.cmake.org/janwielemaker/32/438_2.png) [@JanWielemaker](https://discourse.cmake.org/u/JanWielemaker)
#### Post date: [August 30, 2024, 7:53am UTC](https://discourse.cmake.org/t/creating-an-rpm-sets-runpath-to-build-directory/11543/3 "2024-08-30T07:53:34Z")

</div>

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

```
