# CMAKE\_STAGING\_PREFIX vs. CMAKE\_INSTALL\_PREFIX

**URL:** https://discourse.cmake.org/t/cmake-staging-prefix-vs-cmake-install-prefix/6485
**Category:** Code
**Tags:** tool:cmake
**Created:** [September 14, 2022, 8:51am UTC](https://discourse.cmake.org/t/cmake-staging-prefix-vs-cmake-install-prefix/6485 "2022-09-14T08:51:59Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![bradlit](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/90ced4/32.png) [@bradlit](https://discourse.cmake.org/u/bradlit)
#### Post date: [September 14, 2022, 8:51am UTC](https://discourse.cmake.org/t/cmake-staging-prefix-vs-cmake-install-prefix/6485/1 "2022-09-14T08:51:59Z")

</div>

I’ve read the definitions in cmake-variables, but I’m still puzzled by the relationship between `CMAKE_STAGING_PREFIX` and `CMAKE_INSTALL_PREFIX`.

Some simple experiments seem to indicate that the perform the same function, and if STAGING is set, then it overrides INSTALL. [My test didn’t include any RPATH/RUNPATH entries, so the comment in the description of STAGING\_PREFIX in the manual about replacing it with INSTALL\_PREFIX didn’t come into play in my tests.]

The description also seems to say that STAGING is only used for cross-compiling, but it appears it overrides INSTALL for bin/lib/include even when CMAKE\_CROSSCOMPILING == FALSE.

Hence I’m a little confused.  
Should I never set both in the same CMAKE configuration?  
Is it expected that if STAGING is the empty string (as opposed to missing) it overrides INSTALL, basically removing the prefix.

---

<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: [September 15, 2022, 10:19pm UTC](https://discourse.cmake.org/t/cmake-staging-prefix-vs-cmake-install-prefix/6485/2 "2022-09-15T22:19:08Z")

</div>

The difference is subtle, but important. In general, you want to be setting `CMAKE_INSTALL_PREFIX` and it would make sense for the project to provide a value for that (but still overridable by the user if they wanted to). If you were producing a package and installing that package on a different machine, it is this path that would be used to create the package contents. This is also the path that affects the embedded RPATH on installed binaries.

The `CMAKE_STAGING_PREFIX` should not generally be set by the project, it is meant for the developer. In cross-compilation scenarios, the developer might mount the file system of the target machine on their host’s file system. They might want to install directly into that mounted file system. On the host, the path to the install base point might be `/mnt/raspi/opt/mything`, whereas on the target machine, that same path would be under `/opt/mything`. In this example, you would set `CMAKE_INSTALL_PREFIX` to `/opt/mything` and `CMAKE_STAGING_PREFIX` to `/mnt/raspi/opt/mything`.

I would have thought if `CMAKE_STAGING_PREFIX` was set but empty, it would be ignored, but I can’t confirm if that is the actual behavior. It might be that just having it set at all makes it override `CMAKE_INSTALL_PREFIX` when doing an install.
