Skip to content
This repository has been archived by the owner on Apr 26, 2023. It is now read-only.

mcandre/cclean

Repository files navigation

cclean: a cmake sanitizer

SUMMARY

cclean cleans up cmake's messiest build artifacts.

This is mainly useful for in-source builds. In fact, cmake recommends out of source builds. For cmake projects that use out of source builds, you can simply run cmake -E rm -rf <build directory>. Or, you can script more complex cleanup tasks with the cmake -P scripts.

EXAMPLE

$ cd example

$ cmake .
$ cmake --build . --target hello
$ tree
.
├── CMakeCache.txt
├── CMakeFiles
...
├── CMakeLists.txt
├── Makefile
├── bin
│   └── hello
├── cmake_install.cmake
└── hello.c

$ cclean
$ tree
.
├── CMakeLists.txt
└── hello.c

See cclean -h for more options.

ABOUT

cclean assists cmake with removing common internal artifacts. This is helpful for freeing up disk space.

cmake often enters a corrupt state, requiring manual intervention. cclean automates the process of resetting cmake back to a clean state.

cclean is particularly helpful for cross-platform workflows. For example, when building the same host directory once in WSL, and then again in PowerShell.

NOTABLE FEATURES

  • cclean runs independently of cmake, enabling it to remove sticky cmake artifacts like .ninja_log
  • cclean removes custom -B build directories
  • cclean wraps the cmake global clean target
  • cclean removes cached conan packages

Like cmake, cclean encourages portable build steps. This enables cmake projects to build more reliably on difference machines.

WARNING

Configure the cmake global clean target (esp. ADDITIONAL_CLEAN_FILES) carefully, in order to avoid accidents.

Windows support

Windows users may enjoy cclean with either WSL or host-naive COMSPEC Windows environments (Command Prompt and PowerShell).

However, cmake fails to process ADDITIONAL_CLEAN_FILES when using the MSVC toolchain directly with cmake.

Fortunately, LLVM for Windows provides operational workarounds.

  1. Install the Clang, such as with the LLVM Chocolatey package.
  2. Install the GNU make and/or ninja Chocolatey packages.
  3. Manually clear your cmake project of any existing cmake MSVC artifacts.
  4. Update any compiler-specific sections of your CMakeLists.txt build configuration, to target clang / clang++, rather than MSVC.
  5. Initialize your cmake project with either the make generator or the Ninja generator:
  • cmake -G "Unix Makefiles" <build directory>
  • cmake -G Ninja <build directory>

Both of these cmake generator implementations will generally respect the cmake variable ADDITIONAL_CLEAN_FILES. Except when the variable contains an entry for the .ninja_log file, which fortunately cclean knows to automatically remove.

Further research

We are interested to hear reports of how cmake and cclean behave when using clang-cl or other generators.

CRATE

https://crates.io/crates/cclean

API DOCUMENTATION

https://docs.rs/cclean/latest/cclean/

INSTALL FROM SOURCE

$ cargo install --force --path .

RUNTIME REQUIREMENTS

CONTRIBUTING

For more details on developing cclean itself, see DEVELOPMENT.md.

LICENSE

FreeBSD

SEE ALSO

  • git, a distributed version control system
  • gitignore.io, community maintained gitignore templates
  • make, the classic, plain build system
  • ninja, the fast, plain build system
  • unmake, a linter for manually written makefiles