2

I have seen that cmake does not have cmake clean from Looking for a 'cmake clean' command to clear up cmake output, When using cmake as to the following situation:

  1. source file change

  2. CMakeLists.txt change

  3. add new file or directory

  4. subdirectory(cmake) change

and do on.

We may need rebuild the project, lots of people will do rm -rf * in the build directory to clear the last build, and then cmake .. make to rebuild the project.This maybe very slow if the project is very big.And in some situation there is no need, just do make is enough.

So my question is when should we do rm -rf * in the build directory and then rebuild the project and when not ? Is there any best practice?

Jayhello
  • 5,931
  • 3
  • 49
  • 56

1 Answers1

3

When should we do rm -rf *?

Main usage

When something goes unexpectedly. This includes:

  • "I have library FOO installed, but CMake cannot find it",
  • "I have changed file BAR, but CMake doesn't rebuilt its dependencies",
  • and so on

Other usages

Technically, removing build directory usually helps in clearing the CMake cache. (So, the same effect can be achieved by rm CMakeCache.txt command). This is mainly needed for re-find things like libraries or header files. Examples:

  • "I have changed environment settings, so CMake needs to find another library"
  • "I have changed CMake variables before find_package call, so CMake needs to find another library"
Community
  • 1
  • 1
Tsyvarev
  • 60,011
  • 17
  • 110
  • 153