# Change directory of build

**URL:** https://discourse.cmake.org/t/change-directory-of-build/8671
**Category:** Usage
**Tags:** os:linux
**Created:** [August 3, 2023, 11:33am UTC](https://discourse.cmake.org/t/change-directory-of-build/8671 "2023-08-03T11:33:10Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Alex2671](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alex2671/32/2916_2.png) [@Alex2671](https://discourse.cmake.org/u/Alex2671)
#### Post date: [August 3, 2023, 11:33am UTC](https://discourse.cmake.org/t/change-directory-of-build/8671/1 "2023-08-03T11:33:10Z")

</div>

Greetings! i have a project located on one place with src, build , install folders. After building project(that consume a lot of time), i want to copy full folder structure in another place without rebilding again. However, after “make” command it builds anyway. How can i avoid such temper?

P.S. i typed locations through the …/ so in configuration should be releative paths

---

<div class="post-metadata">

### Author: ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)
#### Post date: [August 3, 2023, 12:27pm UTC](https://discourse.cmake.org/t/change-directory-of-build/8671/2 "2023-08-03T12:27:25Z")

</div>

You can’t. The build tree uses absolute paths everywhere. Once created in one location, it cannot be moved (without re-building the world 😉 )

---

<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: [August 3, 2023, 12:36pm UTC](https://discourse.cmake.org/t/change-directory-of-build/8671/3 "2023-08-03T12:36:14Z")

</div>

You should create an `install` of the project. That can be relocated if the rpaths (`$ORIGIN` or `@executable_path` and friends) and library ids (`@rpath/`) are set up properly. The code also needs to not use `CMAKE_INSTALL_PREFIX` or the like.

---

<div class="post-metadata">

### Author: ![Alex2671](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alex2671/32/2916_2.png) [@Alex2671](https://discourse.cmake.org/u/Alex2671)
#### Post date: [August 3, 2023, 12:39pm UTC](https://discourse.cmake.org/t/change-directory-of-build/8671/4 "2023-08-03T12:39:31Z")

</div>

Install from old path and then create or from new path?

How to not use CMAKE\_INSTALL\_PREFIX? It’s should be replaced with cmake --target?

---

<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: [August 3, 2023, 1:00pm UTC](https://discourse.cmake.org/t/change-directory-of-build/8671/5 "2023-08-03T13:00:59Z")

</div>

> [@Alex2671](#):
>
> Install from old path and then create or from new path?

If you make a relocatable install, you should be able to just move the entire tree under `CMAKE_INSTALL_PREFIX` and things keep working.

> [@Alex2671](#):
>
> How to not use CMAKE\_INSTALL\_PREFIX? It’s should be replaced with cmake --target?

I’m saying the C++ code (or whatever language) should not use `CMAKE_INSTALL_PREFIX`. So, don’t do things like `target_compile_definitions(tgt PRIVATE prefix=${CMAKE_INSTALL_PREFIX})`. This makes the code “aware” of where it expects to live which breaks relocatability. Instead, use platform-specific APIs like `dladdr` to detect where the code lives on the filesystem at runtime and compute relative paths based on that.

---

<div class="post-metadata">

### Author: ![Alex2671](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alex2671/32/2916_2.png) [@Alex2671](https://discourse.cmake.org/u/Alex2671)
#### Post date: [August 3, 2023, 1:32pm UTC](https://discourse.cmake.org/t/change-directory-of-build/8671/6 "2023-08-03T13:32:00Z")

</div>

Also i have additional solution: instead of “cp” i have used “cp -a” and it saved state of build
