The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →cmake clean is not a standalone CMake command. To clean a configured build tree without building afterward, run cmake --build <build-directory> --target clean. This invokes the generated buildsystem’s clean target, removing built object files and other build outputs—not the source tree or the entire build directory.
Is cmake clean available?
No. There is no separate cmake clean subcommand. Running this commonly suggested form is incorrect:
cmake clean
CMake uses a two-stage model:
- CMake configures the source tree and generates a native buildsystem in a binary or build directory.
- The generated buildsystem performs actions such as compiling, linking, installing, and cleaning.
Because clean is a build target, the portable CMake wrapper is cmake --build followed by the build directory and --target clean. The current CMake documentation lists version 4.4.2.
The correct clean-only command
cmake --build <build-directory> --target clean
For example:
cmake -S . -B build
cmake --build build --target clean
The first command configures the project and generates its buildsystem. The second asks that generated buildsystem to run its clean target.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitches#1 Best Overall
If you use separate build directories, specify the directory containing CMakeCache.txt and the generated files. For example:
cmake --build out/linux-debug --target clean
A clean operation removes built object files and other generated build output. It is not the same as deleting out/linux-debug, and it does not reset every configuration choice stored in CMakeCache.txt.
Clean before building
CMake also supports --clean-first:
cmake --build <build-directory> --clean-first
For example:
cmake --build build --clean-first
This runs the clean target and then performs the normal build. It is therefore not a clean-only command. Use the options this way:
| Goal | Command |
|---|---|
| Clean only | cmake --build build --target clean |
| Clean, then build | cmake --build build --clean-first |
| Build without cleaning first | cmake --build build |
Cleaning a Debug or Release build
Multi-configuration generators, such as Visual Studio and Xcode, can contain several configurations in one build directory. Select the configuration when cleaning:
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →cmake --build build --config Debug --target clean
For a Release build:
cmake --build build --config Release --target clean
The --config option selects the configuration for multi-configuration tools. Single-configuration generators generally select the configuration during configuration, commonly with a cache option such as -DCMAKE_BUILD_TYPE=Debug.
Using the native build tool
You can also call the generated tool directly, although the CMake wrapper is usually easier to use in scripts that should work across generators.
Rank #2
Makefiles
With a Makefile generator, the generated buildsystem exposes a clean target. From the build directory, this is typically:
Recommended Free Tools
make clean
CMake generates a clean target for each directory in Makefile builds, which can be useful in a nested build tree. The exact behavior and available targets are properties of the generated Makefiles, not a separate cmake clean command.
Ninja
Ninja has its own cleanup tool mode:
ninja -C build -t clean
That is Ninja-specific syntax. If you want CMake to select the underlying build tool for you, use:
cmake --build build --target clean
Ninja also supports more granular cleanup options through its own -t clean interface. Those options are useful when you need Ninja-specific control, but they are not portable CMake options.
Clean versus deleting the build directory
A normal clean removes generated build outputs. Deleting the build directory removes considerably more, including the generated buildsystem and configuration state.
| Operation | Typical effect | Use it when |
|---|---|---|
cmake --build build --target clean |
Removes compiled objects and other build outputs | You want a fresh compilation while keeping the existing configuration |
cmake --build build --clean-first |
Cleans and then builds | You want to force a full rebuild immediately |
Delete build/, then configure again |
Removes the cache, generated files, and build outputs | The cache or generated build tree is stale or corrupted |
Deleting and regenerating the build directory is also required when changing generators. For example, do not reuse a build directory first configured for Ninja with a Visual Studio generator. Generator selection cannot be changed after the first CMake invocation in that existing build directory.
A clean is usually the safer first step for a compilation problem. Recreate the build directory only when you intentionally want to discard configuration state, change the generator, or recover from a broken cache.
Rank #3
Cleaning from CMake GUI
cmake-gui is used to choose source and build directories, configure the project, and generate the buildsystem. It does not provide a build-output Clean command equivalent to the generated build target.
Use a terminal for the cleanup:
cmake --build build --target clean
Alternatively, run the native generated tool, such as make clean or Ninja’s cleanup mode, from the build tree.
Cleaning a CMake project in CLion
CLion provides a Clean build action for CMake projects. It cleans by building the CMake clean target from the current CMake profile.
Its Rebuild Project action is different: CLion runs Clean for all CMake profiles and then runs Build Project.
The label does not mean the same underlying command for every project type in CLion:
- CMake projects build the CMake
cleantarget. - Makefile projects call
make clean. - Meson projects use
meson compile --clean. - Custom run/debug configurations use their configured Clean tool.
For a CMake project, the terminal equivalent remains:
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallcmake --build <profile-build-directory> --target clean
Cleaning and resetting a CMake project in Visual Studio
Visual Studio’s CMake integration can build the generated project, but a normal build is separate from deleting the CMake cache or build tree.
Rank #4
To reset the cache, Microsoft documents commands labelled Delete Cache and Reconfigure and, in some documented workflow/version sections, Clean Cache. These commands are available from the CMake project’s Project menu or from the CMakeLists.txt context menu in Solution Explorer. They delete the build-root folder and reconfigure from a clean cache.
That is more destructive than running the CMake clean target. Use it when you want to discard configuration and generated build-tree state, not merely compiled output.
To build all CMake targets in Visual Studio, use Build > Build All. In Solution Explorer, you can switch to CMake Targets View using Select View, choosing CMake Targets View, and pressing Enter. Alternatively, right-click a file or folder and choose Switch to CMake Targets View. Then right-click a target and choose Build.
Free tools Windows power users keep installed
One-click scans. No signup required.
If you manually changed CMakeCache.txt, remember that cache cleanup removes those changes. Put persistent settings in CMake configuration, a preset, or the appropriate Visual Studio project settings instead. Visual Studio supports CMakePresets.json from version 16.10 onward and recommends it for current configurations; older workflows may use CMakeSettings.json.
Practical cleanup workflow
- Identify the active build directory. It is the directory passed to
cmake -B, or the directory containing the relevantCMakeCache.txt. - Run a clean-only operation:
cmake --build build --target clean. - Build again:
cmake --build build. - If the problem remains, remove and regenerate the build directory, then configure again:
rm -rf build, followed bycmake -S . -B buildandcmake --build build.
On Windows PowerShell, the destructive step can be written as:
Remove-Item -Recurse -Force build
Then configure and build again with cmake -S . -B build and cmake --build build. Only delete a directory you know is a generated build directory. A source tree can contain files that are not recreated by CMake.
FAQ
What is the exact CMake clean command?
Use cmake --build <build-directory> --target clean, such as cmake --build build --target clean.
Does cmake clean work?
No. clean is a target in the generated buildsystem, not a standalone CMake subcommand.
Does --clean-first only clean the project?
No. It cleans first and then performs the normal build. Use --target clean when you want cleanup without a subsequent build.
How do I clean a Release build with Visual Studio or another multi-configuration generator?
Specify the configuration: cmake --build build --config Release --target clean.
Will CMake clean delete my source files?
The generated clean target removes object files and other build outputs. It is not documented as deleting the source tree or the entire build directory.
How do I perform a complete CMake reset?
Delete the build directory and configure again with cmake -S . -B build. This removes the cache and generated buildsystem, so it is more destructive than a normal clean.
Can I clean from cmake-gui?
cmake-gui configures and generates the buildsystem but does not provide a build-output Clean command. Run cmake --build ... --target clean or the native build tool instead.
The Bottom Line
There is no standalone cmake clean. For a clean-only operation, run cmake --build build --target clean. Use --clean-first when you want CMake to clean and then build. Delete and regenerate the build directory only when you need to discard the cache, repair a stale build tree, or change generators.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.

