# \[BUG\] postrm run when install

**URL:** https://discourse.cmake.org/t/bug-postrm-run-when-install/6434
**Category:** Code
**Tags:** os:linux
**Created:** [September 8, 2022, 3:11am UTC](https://discourse.cmake.org/t/bug-postrm-run-when-install/6434 "2022-09-08T03:11:13Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![alice](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alice/32/1615_2.png) [@alice](https://discourse.cmake.org/u/alice)
#### Post date: [September 8, 2022, 3:11am UTC](https://discourse.cmake.org/t/bug-postrm-run-when-install/6434/1 "2022-09-08T03:11:13Z")

</div>

I want to let postrm run when uninstalling.  
But it run on installing, so my folder test be remove.

```auto
set(DEBIAN_PRERM prerm.in)
    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/deb/linux/${DEBIAN_PRERM}
                ${CMAKE_CURRENT_BINARY_DIR}/prerm @ONLY)
    set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_BINARY_DIR}/prerm;")

```

prerm

```auto
#!/bin/bash

set -e
ROOT=/opt/test/
BIN_DIR="${ROOT}"

# Remove entire folder 
rm -rf "${BIN_DIR}"

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [September 8, 2022, 2:34pm UTC](https://discourse.cmake.org/t/bug-postrm-run-when-install/6434/2 "2022-09-08T14:34:01Z")

</div>

You can use `install(CODE)` to inject CMake code into the install scripts.

---

<div class="post-metadata">

### Author: ![alice](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alice/32/1615_2.png) [@alice](https://discourse.cmake.org/u/alice)
#### Post date: [September 8, 2022, 3:56pm UTC](https://discourse.cmake.org/t/bug-postrm-run-when-install/6434/3 "2022-09-08T15:56:51Z")

</div>

Thanks for your reply.  
Do you have the sample code?

And I want to delete my project folder when uninstalling (\*.deb)

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [September 8, 2022, 4:27pm UTC](https://discourse.cmake.org/t/bug-postrm-run-when-install/6434/4 "2022-09-08T16:27:32Z")

</div>

```cmake
install(CODE "
cmake_code_you_want_to_call()
multiple_commands_work()
")

```

---

<div class="post-metadata">

### Author: ![alice](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alice/32/1615_2.png) [@alice](https://discourse.cmake.org/u/alice)
#### Post date: [September 9, 2022, 2:32am UTC](https://discourse.cmake.org/t/bug-postrm-run-when-install/6434/5 "2022-09-09T02:32:54Z")

</div>

How can I trigger it when uninstalling.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [September 9, 2022, 5:32pm UTC](https://discourse.cmake.org/t/bug-postrm-run-when-install/6434/6 "2022-09-09T17:32:16Z")

</div>

CMake has no built-in uninstall support.

---

<div class="post-metadata">

### Author: ![alice](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alice/32/1615_2.png) [@alice](https://discourse.cmake.org/u/alice)
#### Post date: [September 10, 2022, 4:47pm UTC](https://discourse.cmake.org/t/bug-postrm-run-when-install/6434/7 "2022-09-10T16:47:44Z")

</div>

YOU mean CPACK\_DEBIAN\_PACKAGE\_CONTROL\_EXTRA ( prerm postrm )doesnt work when uninstalling.

All of them (prerm postrm preinst postinst ) just work on install.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [September 11, 2022, 9:18pm UTC](https://discourse.cmake.org/t/bug-postrm-run-when-install/6434/8 "2022-09-11T21:18:01Z")

</div>

Oh, this is for Debian CPack stuff? @kyle.edwards might know.
