17

I have some executables/libraries being placed into the system paths using CMake's "install" keyword. Is there a built-in mechanism to do something like a "distclean", where all installed files are removed?

Endless Google searches have repeatedly turned-up conversations where the responses always mention "rm -fr " if the question mentions "cmake" and "cleanup", without reading it more closely.

Dustin Oprea
  • 9,673
  • 13
  • 65
  • 105

2 Answers2

21

There should be file "install_manifest.txt" after executing "make install". The following command should work:

cat install_manifest.txt | sudo xargs rm
jupp0r
  • 4,502
  • 1
  • 27
  • 34
Ferry
  • 329
  • 2
  • 3
  • This does remove all files, but some directories might remain intact. – hetepeperfan Sep 04 '17 at 15:05
  • Actually, we should not delete any directory that was not created by the corresponding install, like `/usr/local/bin`, if it happened to be the only thing installed there. Maybe install_manifest.txt is not enough... – ateijelo Nov 27 '17 at 21:57
  • 2
    You can improve that idea by doing `(cat install_manifest.txt; echo) | sudo sh -c 'while read i ; do rm "$i" ; rmdir --ignore-fail-on-non-empty -p "${i%/*}" ; done'`. That'll take care of all directories as long as they're empty. – ateijelo Nov 27 '17 at 22:02
  • `sudo make uninstall` usually work as https://askubuntu.com/questions/944544/how-to-correctly-uninstall-and-remove-something-and-built-from-source-and-instal#comment1500500_944544 – BugKiller Aug 26 '18 at 13:34
  • Please be aware that this code won't work on windows because of `crlf/lf` pain. – puchu Jan 27 '21 at 13:37
3

You could ask the authors of the software to add an 'uninstall' target in CMake, see https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake

so that you can just call make uninstall.

ferdymercury
  • 698
  • 4
  • 15