当前位置: 首页 > 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.gsyq.cn/news/74831.html

相关文章:

  • Day12-20251206
  • [NOI2015 程序自动分析]
  • 【基础】Unity着色器网格和计算对象介绍
  • 首单半价对话框的实现
  • Anchor宽高比
  • SAM3模型来了,手把手带你运行SAM3模型代码,SAM3模型初探!
  • 从可优化到可进化:企业智能化的本质、边界与治理
  • 线段树学习笔记
  • 短剧小程序 2025 核心痛点分析:内容、工艺与合规的三重困境
  • 「Java EE开发指南」如何在MyEclipse中构建EJB 2 Session Bean?(一)
  • 文件摆渡系统哪个好:提升企业文件交换安全性的首选方案
  • 115.娇三“独处-再思考”
  • 2025最新发布!耐磨的轮胎推荐:五大高耐磨胎精选报告
  • 2025年权威发布!防爆胎更换推荐:权威防爆胎更换TOP指南
  • 路由注入
  • 实用指南:C++幻象:内存序、可见性与指令重排
  • 实验三
  • 实验五
  • 2025年12月新能源汽车轮胎推荐:最新电车胎精选指南
  • 2025年美国投行求职机构哪家高效不爆雷:助学员成本降60%offer量产
  • Go 语言(Golang):核心特性、生态优势与实战应用全解析
  • 详细介绍:《Windows 服务器 WinSCP 保姆级配置指南:从 0 到 1 实现 “无痛” 远程文件管理》
  • 每个人都在追寻远方,那远方的人是否也有自己的远方呢?
  • 2025年12月安全的轮胎推荐:专业安全胎权威指南
  • SUV车型轮胎推荐:权威SUV胎专业推荐
  • 家用轿车轮胎推荐:十大家轿胎深度榜单
  • “游戏无法启动”、“DLL文件丢失”或“缺少组件”怎么办
  • 2025年节油的轮胎推荐:权威省油胎最新榜单
  • 奔跑
  • Spring Boot:核心概念、核心特性与实战应用全解析