[CMake] Deleting a directory

Brad King brad.king at kitware.com
Wed Aug 30 16:05:12 EDT 2006


Brandon J. Van Every wrote:
> Yann Renard wrote:
>> Cheers list,
>>
>> when using cmake for building my libraries, I add additional commands
>> in order to copy all the corresponding header tree to a target
>> directory. On clean stage, I would like to remove this tree so removed
>> the .h files one by one using ADDITIONAL_MAKE_CLEAN_FILES. This
>> empties the tree but after that, it would be nice to remove the tree
>> itself. How could I remove those directories ? cmake -E seems not to
>> be able to remove directories.
> 
> FILE(REMOVE_RECURSE [directory]...)
> is what you want?  Can't remember if I've used it.  Also, I note that
> the docs list the command, but don't say what it does, although it's
> fairly obvious.

This will remove a directory but there is no way to get it to run during
a "make clean" right now.  The INSTALL(CODE) and INSTALL(SCRIPT)
commands allow code to be inserted for execution during installation but
there is no equivalent for cleaning.

The clean target in the Makefile generators is meant to get the build
rules to run again from scratch, not to make things look nice on disk.
The Visual Studio generators do not even support cleaning directly: the
IDE provides its own clean rules based on the generated project files.
This is why we suggest using out-of-source builds so that the source
tree is never touched and the build tree can just be wiped clean by
removing the directory.

-Brad


More information about the CMake mailing list