-1

Every time I get a different source directory, and I have a fixed build directory. Every time I will run cmake /path/to/project and run ninja. It will report an error : Make Error: The source "/path1/to/project/CMakeLists.txt" does not match the source "/path2/to/project/CMakeLists.txt" used to generate cache. Re-run cmake with a different source directory.

So what I did was manually change the options related to the path of project in the CMakeCache.txt. The result is that it will compile the project from scratch every time instead of incrementally compiling, So is there any feasible way to achieve incremental compilation or in this case it is impossible to achieve incremental compilation ?

Ðаn
  • 10,934
  • 11
  • 59
  • 95
  • Why are you running cmake multiple times? – sweenish Aug 18 '21 at 11:17
  • @sweenish Because the path of project is changed. So I should rerun cmake /new_path/to/project, isn't it ? And every time the project is update (the source files have some update) – dounaiKing Aug 18 '21 at 11:42
  • 2
    If you are constantly changing the path, you shouldn't be surprised that you get errors. Cmake tells you what to do in that case: delete everything it created and run it from scratch. You do **not** run it again if all you did was update a source file. You run ninja again. – sweenish Aug 18 '21 at 11:46
  • Why are you constantly moving the source directory? Is `ccache` not an option? – Alex Reinking Aug 18 '21 at 15:59
  • @AlexReinking yes I have tried `ccache`, but it doesn't work. Moving the source directory because – dounaiKing Aug 19 '21 at 02:20
  • @sweenish Even if they are in different paths, I just run ninja again ? I mean I updated some source files in another project path, in this case, I think I must run cmake first ? – dounaiKing Aug 19 '21 at 02:22
  • @AlexReinking sry, I forgot it. Beacause it runs in the git CI, every some time it will create a new temporary directory... – dounaiKing Aug 19 '21 at 03:23

1 Answers1

0

Mount the source directory always to a same constant absolute location. On Linux, you could use mount namespaces, for example use proot.

proot -b /path/to/project:/work -w /work cmake -B builddir -S .
proot -b /path/to/project:/work -w /work cmake --build builddir
KamilCuk
  • 120,984
  • 8
  • 59
  • 111