# No way retrieve the value of the --prefix argument at install-time?

**URL:** <https://discourse.cmake.org/t/no-way-retrieve-the-value-of-the-prefix-argument-at-install-time/12974>\
**Category:** Code\
**Created:** [November 15, 2024, 5:37pm UTC](https://discourse.cmake.org/t/no-way-retrieve-the-value-of-the-prefix-argument-at-install-time/12974 "2024-11-15T17:37:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcm](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/58f4c7/32.png) [@jcm](https://discourse.cmake.org/u/jcm)\
**Post date:** [November 15, 2024, 5:37pm UTC](https://discourse.cmake.org/t/no-way-retrieve-the-value-of-the-prefix-argument-at-install-time/12974/1 "2024-11-15T17:37:27Z")

</div>

I have a project that, if a `CMAKE_INSTALL_PREFIX` is provided at configure/generation-time, provides that prefix to the project code to help out with certain search paths and file storage logic.

I wanted to provide a warning to the developer if they configured by passing a prefix, but then they try to call `cmake --install . --prefix <prefix>` with a different prefix than they configured with.

I assumed that I could do this with something like the following:

```auto
if(NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  set(CONFIGURE_PREFIX ${CMAKE_INSTALL_PREFIX})
endif()
install(CODE "
  if(NOT \"${CMAKE_INSTALL_PREFIX}\" STREQUAL \"${CONFIGURE_PREFIX}\")
    message(AUTHOR_WARNING \" Install prefix differs from configured install prefix! \")
  endif()
")

```

But the value of `CMAKE_INSTALL_PREFIX` is still the same as `CONFIGURE_PREFIX` regardless of the argument passed with `--prefix`.

This might be a bit of an edge case, because who would pass an install prefix different than the one they configured with, but isn’t it a bit odd that we can’t access the contents of a provided `--prefix` argument at install time?

---

<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:** [November 15, 2024, 9:09pm UTC](https://discourse.cmake.org/t/no-way-retrieve-the-value-of-the-prefix-argument-at-install-time/12974/2 "2024-11-15T21:09:02Z")

</div>

> [@jcm](#):
>
> This might be a bit of an edge case, because who would pass an install prefix different than the one they configured with

This is actually an extremely common case! CPack does this when it produces packages, for example. It uses an install step with a prefix override to install to a temporary staging area, then it creates the final package from that staging area’s contents.

I would recommend rethinking your approach. The `CMAKE_INSTALL_PREFIX` set at configure time should be thought of as just setting the default install location. The user is free to install to anywhere they want, and you should expect that many will override the default.
