Cleaning the install directory

What’s the best way to ensure that the install directory is empty prior to building my project.

Ideally I’d like to put this in my top level CMake file, before I do the add_subirectory stuff

The actual command to empty the directory is easy:

COMMAND ${CMAKE_COMMAND} -E rm -rf ${CMAKE_INSTALL_PREFIX}/*

The tricky bit is how to get that issued at the correct stage.

Thanks
David

That is a really bad idea!

The default for CMAKE_INSTALL_PREFIX is /usr/local, and there is normally more than your project installed.

If you want a clean installation use cpack, it creates an archive with only your installation files.

That rather depends on what you have set CMAKE_INSTALL_PREFIX to

My builds install to a folder that is only there to hold the build output with all RPATHs adjusted to pick up the .so/.dylibs relative to the executables, and all related other files in an appropriate directory structure.

I then use that directory to create my installers.

So in my case it is not a really bad idea!

David