Cleaning policy?

I am about to introduce CMake to our organisation. A question likely to come up is how to ‘clean’ a build directory. My understanding is that CMake doesn’t offer support for ‘clean’.

What is the recommendation? Should users simply delete all items in the build directory using:

rm -rf *

and then issue a fresh cmake command to recreate the cache etc?

A target clean is automatically generated by CMake (at least for Nina and Makefile generators) which can be used to clean-up build artifacts (not the CMake generated files).

CMake also generate dependencies over its own files (i.e. CMakeListrs.txt files), so editing any CMake file will relaunch CMake generation at the next build action.

And, if you want to change your configuration (impacting the cache), the easiest way is effectively to remove all the stuff under your build directory and relaunch a generation.

1 Like

@marc.chevrier Thanks for your answer.

There’s also ctest_empty_binary_directory if you’re building things from a CTest script to clean the directory.

1 Like