# How do I use the --prefix argument in cmake --install?

**URL:** https://discourse.cmake.org/t/how-do-i-use-the-prefix-argument-in-cmake-install/4671
**Category:** Usage
**Created:** [December 15, 2021, 1:06pm UTC](https://discourse.cmake.org/t/how-do-i-use-the-prefix-argument-in-cmake-install/4671 "2021-12-15T13:06:59Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![MrZoraman](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mrzoraman/32/2033_2.png) [@MrZoraman](https://discourse.cmake.org/u/MrZoraman)
#### Post date: [December 15, 2021, 1:06pm UTC](https://discourse.cmake.org/t/how-do-i-use-the-prefix-argument-in-cmake-install/4671/1 "2021-12-15T13:06:59Z")

</div>

My command is `cmake --install . --prefix somewhereelse`. I’m trying to get cmake to install a project in a custom directory instead of my program files folder. No matter what, though, it always puts it in my program files folder. It seems to be entirely ignoring my prefix argument.

Output for the above command is:

```auto
-- Install configuration: "Release"
-- Up-to-date: C:/Program Files (x86)/zlib/lib/zlib.lib
-- Up-to-date: C:/Program Files (x86)/zlib/bin/zlib.dll
-- Up-to-date: C:/Program Files (x86)/zlib/lib/zlibstatic.lib
-- Up-to-date: C:/Program Files (x86)/zlib/include/zconf.h
-- Up-to-date: C:/Program Files (x86)/zlib/include/zlib.h
-- Up-to-date: C:/Program Files (x86)/zlib/share/man/man3/zlib.3
-- Up-to-date: C:/Program Files (x86)/zlib/share/pkgconfig/zlib.pc

```

---

<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: [December 15, 2021, 1:23pm UTC](https://discourse.cmake.org/t/how-do-i-use-the-prefix-argument-in-cmake-install/4671/2 "2021-12-15T13:23:30Z")

</div>

What do the `install()` commands look like for these files in the original project?

---

<div class="post-metadata">

### Author: ![MrZoraman](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mrzoraman/32/2033_2.png) [@MrZoraman](https://discourse.cmake.org/u/MrZoraman)
#### Post date: [December 15, 2021, 1:26pm UTC](https://discourse.cmake.org/t/how-do-i-use-the-prefix-argument-in-cmake-install/4671/3 "2021-12-15T13:26:31Z")

</div>

> <https://github.com/madler/zlib/blob/master/CMakeLists.txt>

It looks like I have to set a variable at cmake _build_ time?

---

<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: [December 15, 2021, 1:29pm UTC](https://discourse.cmake.org/t/how-do-i-use-the-prefix-argument-in-cmake-install/4671/4 "2021-12-15T13:29:53Z")

</div>

This:

```cmake
set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
# …
    install(TARGETS zlib zlibstatic
        RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
        ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
        LIBRARY DESTINATION "${INSTALL_LIB_DIR}" )

```

means that the prefix is baked in at configure time. Instead, the `INSTALL_BIN_DIR` should be relative and let the install script add `${CMAKE_INSTALL_PREFIX}` as needed. Right now, the install path is seen as absolute and therefore not eligible for replacement at install time.

---

<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: [December 15, 2021, 1:41pm UTC](https://discourse.cmake.org/t/how-do-i-use-the-prefix-argument-in-cmake-install/4671/5 "2021-12-15T13:41:33Z")

</div>

Incidentally, it is also bad because those values are only the _defaults_. This process:

```auto
$ cmake -DCMAKE_INSTALL_PREFIX=oops ../src # initial configure
$ cmake -DCMAKE_INSTALL_PREFIX=what_i_meant ../src

```

leaves the install still looking at `oops` because the `INSTALL_BIN_DIR` was initialized with `oops/bin` and won’t be updated with the new prefix selection. There’s been a

---

<div class="post-metadata">

### Author: ![MrZoraman](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mrzoraman/32/2033_2.png) [@MrZoraman](https://discourse.cmake.org/u/MrZoraman)
#### Post date: [December 15, 2021, 5:42pm UTC](https://discourse.cmake.org/t/how-do-i-use-the-prefix-argument-in-cmake-install/4671/6 "2021-12-15T17:42:02Z")

</div>

There’s been a what? Are you ok? Did the zlib authors get to you before you could finish your statement? 😰

---

<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: [December 15, 2021, 5:46pm UTC](https://discourse.cmake.org/t/how-do-i-use-the-prefix-argument-in-cmake-install/4671/7 "2021-12-15T17:46:57Z")

</div>

Ah, sorry. My wireless flaked out and it seemed like everything had been there, but I guess not.

Basically, I could fix my upstream PR that already tries to fix some of this, but given the lack of activity…that’s probably not a useful investment of time.
