为cmake添加make install自定义命令
source link: https://note.qidong.name/2021/11/cmake-uninstall/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
为cmake添加make install自定义命令
2021-11-04 19:58:00 +08 字数:364 标签: Linux
CMake生成的Makefile里,竟然是没有uninstall
的。
尽管在大部分场合都没问题,但有时候还是比较麻烦。
make uninstall ¶
一般的解决方案是,执行以下命令:
xargs rm < install_manifest.txt
当然,这需要先执行make install
,以生成install_manifest.txt
文件。
如果这个文件丢了,只能再安装一次,然后再卸载。
当然,可以通过添加自定义命令,来复刻这个configure时代的常见功能。
# make uninstall
add_custom_target("uninstall" COMMENT "Uninstall installed files")
add_custom_command(
TARGET "uninstall"
POST_BUILD
COMMENT "Uninstall files with install_manifest.txt"
COMMAND xargs rm -vf < install_manifest.txt || echo Nothing in
install_manifest.txt to be uninstalled!
)
执行效果 ¶
根据一个Demo项目cmake-cpack-demo,演示uninstall
的执行效果。
$ git clone https://github.com/yanqd0/cmake-cpack-demo.git
...
$ cmake . && make
...
$ sudo make install
[ 50%] Built target greet
[100%] Built target hello
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/lib/libgreet.so
-- Installing: /usr/local/bin/hello
-- Set runtime path of "/usr/local/bin/hello" to ""
-- Installing: /usr/local/include/greet.h
$ sudo make uninstall
Uninstall files with install_manifest.txt
removed '/usr/local/lib/libgreet.so'
removed '/usr/local/bin/hello'
removed '/usr/local/include/greet.h'
Built target uninstall
参考 ¶
其实都是孤写的。
本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可,详见本站版权声明。
本站没有任何支持评论功能的计划。 如果你对本站的设计、内容、观点有什么意见,欢迎来信指正。
作者:匿蟒 邮箱:[email protected] 备案:闽ICP备15022549号
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK