[CMake] add dependencies to clean target ?

Brad King brad.king at kitware.com
Mon Oct 9 20:17:46 EDT 2006


frederic heem wrote:
> It seems that it's not possible to add dependencies to implicit target such as 
> clean and package_source. The user defined target FsmCompilerClean must be 
> called whenever the target clean is used.
[snip]
> # fails here
> ADD_DEPENDENCIES(clean FsmCompilerClean)

The "clean" target is not a first class target available to
CMakeLists.txt code.  It is a property of the Makefile generators.  On
Visual Studio there is an implicit clean target provided by the native
build tool without help from CMake.  There is no way to attach
dependencies to this target AFAIK (even manually through the IDE),
though I have not investigated this thoroughly.

Several users have asked for custom clean target support.  We do plan to
make targets like install and clean first class eventually but it is not
yet implemented.

You can try adding your own "fsm_clean" target that executes a CMake
script and then runs the makefile's clean target:

IF("${CMAKE_GENERATOR}" MATCHES "Make")
  ADD_CUSTOM_TARGET(fsm_clean
    COMMAND ${CMAKE_MAKE_PROGRAM} clean
    WORKING_DIRECTORY ${CMAKE_CURRENT_DIR}
    )
  ADD_DEPENDENCIES(fsm_clean FsmCompilerClean)
ENDIF("${CMAKE_GENERATOR}" MATCHES "Make")

-Brad


More information about the CMake mailing list