CMake Uninstall
CMake does not provide a built-in uninstall command, but you can implement an uninstall process manually using the install_manifest.txt file generated during installation. Below are the steps to add and execute an uninstall target in your CMake project.
1. Create an uninstall Script
-
Create a file named cmake_uninstall.cmake.in in your project directory with the following content:
2. Add Uninstall Target to CMakeLists.txt
-
Modify your CMakeLists.txt file to include the uninstall target:
3. Execute the Uninstall Command
-
After building and installing your project, you can run the following command to uninstall:
This will remove all files listed in the install_manifest.txt.
Best Practices
-
Always verify that the install_manifest.txt exists before running the uninstall process.
-
For UNIX systems, you can also directly use:
to remove installed files.
By following these steps, you can safely implement and execute an uninstall process for your CMake-based projects.
浙公网安备 33010602011771号