当前位置: 首页 > news >正文

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:

if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
endif()

file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")

foreach(file ${files})
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
execute_process(COMMAND "@CMAKE_COMMAND@" -E remove "$ENV{DESTDIR}${file}")
else()
message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
endif()
endforeach()
 

2. Add Uninstall Target to CMakeLists.txt

  • Modify your CMakeLists.txt file to include the uninstall target:

if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY
)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
)
endif()
 

3. Execute the Uninstall Command

  • After building and installing your project, you can run the following command to uninstall:

sudo make 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:

xargs rm < install_manifest.txt
 

to remove installed files.

By following these steps, you can safely implement and execute an uninstall process for your CMake-based projects.

http://www.jsqmd.com/news/64278/

相关文章:

  • 实用指南:通过约束编程优化医疗智能系统的伦理风险降低(下)
  • 【Java 开发日记】大家来说一下 Mybatis 的缓存机制
  • Day12-20251206
  • 悬架设计计算工具:开启悬架设计学习与实践的钥匙
  • Solon AI 开发学习17 - generate - 使用复杂提示语
  • c++笔记
  • 别再发愁!对比多款后锁定这6个型号,挑选高中学习机,不花冤枉钱
  • [UVA1316 Supermarket]
  • 使用typora来写md文件时配置文件存放图片的路径
  • 靠谱厂房拆迁法律机构排行榜 2026:专业解析与高性价比解决方案
  • 滥用ESC10:通过注册表配置不当实现权限提升的ADCS攻击分析
  • [NOI2015 程序自动分析]
  • 【基础】Unity着色器网格和计算对象介绍
  • 【基础】Unity着色器网格和计算对象介绍
  • 基于大内容的保险数据管理与可视化分析平台
  • 深入解析:C++ 闭散式和开散式的模拟实现
  • 基于先验地图的无人机路径规划
  • 首单半价对话框的实现
  • Anchor宽高比
  • SAM3模型来了,手把手带你运行SAM3模型代码,SAM3模型初探!
  • 从可优化到可进化:企业智能化的本质、边界与治理
  • SGD优化器贯穿Faster R-CNN的全模型
  • 线段树学习笔记
  • Anchor尺寸
  • 西门子S7-1200与施耐德Altivar320通讯 工业自动化场景的总线协议转换方案
  • 短剧小程序 2025 核心痛点分析:内容、工艺与合规的三重困境
  • 「C++」vector的利用及接口模拟详解
  • 「Java EE开发指南」如何在MyEclipse中构建EJB 2 Session Bean?(一)
  • Android开发 Jetpack_Compose DatePickerBottomSheet 滚轮日历选择器对话框
  • 代码资源空间调整:当前代码与资源的总大小超过FLASH的大小,需要更大的FLASH