[BUG] postrm run when install

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

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

#!/bin/bash

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

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

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

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

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

install(CODE "
cmake_code_you_want_to_call()
multiple_commands_work()
")

How can I trigger it when uninstalling.

CMake has no built-in uninstall support.

YOU mean CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ( prerm postrm )doesnt work when uninstalling.

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

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