As a developer, I want to reduce file clutter on my machines. For example, I often run make clean
when I temporarily put away a software project. This reduces noise in the project directory tree, and frees up disk space.
However, when run cmake --build . --target clean
, then cmake leaves behind a TON of junk files.
I can work around most of these junk files, by appending a rather extensive boilerplate list of the names in an ADDITIONAL_CLEAN_FILES
directory property:
set_property(
DIRECTORY .
APPEND PROPERTY
ADDITIONAL_CLEAN_FILES
"html;${EXECUTABLE_OUTPUT_PATH};debug;debug.log;Makefile;build.ninja;.ninja_deps;Testing;CTestTestfile.cmake;CMakeFiles;CMakeCache.txt;cmake_install.cmake;conanbuildinfo.cmake;conanbuildinfo.txt;conaninfo.txt;graph_info.json;conan.lock"
)
However, appending ;.ninja_log
in this string has no effect. cmake appears to forcibly regenerate this file after every task, including cmake --build . --target clean
. So there is that one annoying junk file leftover in all my cmake + ninja projects: .ninja_log
.
I also tried working around this by declaring a custom cmake cleanup task:
add_custom_target(clean-ninja-log COMMAND "${CMAKE_COMMAND}" -E rm -f .ninja_log)
With the same results.
Currently, my operational workaround is to wrap cmake in yet another build system:
https://github.com/mcandre/rez
And have the outer build system run some C++ standard library calls to remove this file.
Another similar workaround involves writing a custom clean.ninja
, clean.mk
, clean.sh
, or similar script. But these tend to limit portability, assuming either rm
or del
based commands. And it's annoying to have to use TWO scripting systems for basic things. I want a cmake task that works like make clean
, for full project cleaning.
But if at all possible, I would prefer a solution that works in 100% cmake. Maybe I can configure cmake to stop running ninja -t restat
after every single cmake task?