11

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?

einpoklum
  • 118,144
  • 57
  • 340
  • 684

1 Answers1

12

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
    
einpoklum
  • 118,144
  • 57
  • 340
  • 684
Florian
  • 39,996
  • 9
  • 133
  • 149
  • Re *"the internally for each target generated"*: do you mean *"the internally generated for each target"*? And what does *"internally"* and *"generated"* refer to (one or more nouns missing)? - what is it that is internal and generated? – Peter Mortensen Sep 18 '18 at 19:29
  • 3
    Unfortunately this will also clean any targets which foo depends on. Is there a way to clean only foo ? – Sergio Martins Dec 15 '20 at 14:59