CMake: How to force reconfiguration.

c c-plus-plus cmake

In a TIL from yesterday, I mentioned that when I’m changing around the CMakeLists.txt file, my go-to troubleshooting strategy is to delete everything in the build directory so that the next configure is from scratch.

I asked this question on interwebs – is there a more automated way to force a reconfigure? I have project files for the IDE in my build directories, so I don’t want to wipe the whole thing out.

Option 1: --fresh for CMake versions 3.24 onwards

CMake has this functionality to reconfigure in new versions with the --fresh flag. Usage:

cmake ../src --fresh

Docs, cmake.

Option 2: remove select elements in the build directory

You can set up an alias to get rid of the CMakeFiles directory and CMakeCache.txt file.

alias clean_cmake='rm -rf CMakeFiles/ CMakeCache.txt'

© Amy Tabb 2018 - 2023. All rights reserved. The contents of this site reflect my personal perspectives and not those of any other entity.