makefilebuildcmakeresource-cleanup

How can I get CMake to allow for "make clean"ing just one target?


I have a project using CMake to generate Makefiles, which then get built with (GNU) make.

In my project, the CMakeLists.txt defines two targets - but only one of them gets built when makeing after Makefile generation (e.g. using the EXCLUDE_FROM_DEFAULT_BUILD property).

I want to be able to cleanup (using make) the files used in the building of one of the targets, but not the files used to build the second target.

How can I do that?


Solution

  • I see two additional options:

    1. Using the internal cmake_clean.cmake scripts generated for for each target - which, unfortunately, are not directly accessible through make from the root path. For example, if you have a target named foo, you would write:

       cmake -P CMakeFiles/foo.dir/cmake_clean.cmake
      
    2. Using ninja instead of make generators where you could call

       ninja -t clean foo