Change directory of build

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

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

1 Like

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.

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?

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

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.

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