# CMAKE\_INSTALL\_PREFIX available inside \`install(CODE\`

**URL:** https://discourse.cmake.org/t/cmake-install-prefix-available-inside-install-code/8594
**Category:** Usage
**Tags:** os:linux, gen:makefiles, gen:ninja
**Created:** [July 25, 2023, 10:32am UTC](https://discourse.cmake.org/t/cmake-install-prefix-available-inside-install-code/8594 "2023-07-25T10:32:28Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![gabyx](https://discourse.cmake.org/user_avatar/discourse.cmake.org/gabyx/32/2107_2.png) [@gabyx](https://discourse.cmake.org/u/gabyx)
#### Post date: [July 25, 2023, 10:32am UTC](https://discourse.cmake.org/t/cmake-install-prefix-available-inside-install-code/8594/1 "2023-07-25T10:32:28Z")

</div>

Is there a way to access the final (potentially overrriden) `CMAKE_INSTALL_PREFIX` inside a  
code/script in `install(CODE ...)` or `install(SCRIPT script.cmake ...)`.

Because we have custom code which hardbakes the `install-prefix` at configure time, but when user do `cmake --install --prefix=blabla` the above `install(CODE ... )` will not notice this…

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [July 26, 2023, 4:36pm UTC](https://discourse.cmake.org/t/cmake-install-prefix-available-inside-install-code/8594/2 "2023-07-26T16:36:13Z")

</div>

`--prefix` just gets translated into `-DCMAKE_INSTALL_PREFIX=`, so `install(CODE "[[message(${CMAKE_INSTALL_PREFIX}]])"` should work. Scripts should just be able to work as-is too.
