cmake自定义命令复制和重命名 [英] cmake custom command to copy and rename

查看:31
本文介绍了cmake自定义命令复制和重命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个生成 .so 库的现有 cmake 文件.我想修改它,这样它就会复制 .so 命名的其他东西.这大概是我所拥有的:

I have an existing cmake file that generates a .so library. I want to modify it so that it will then make a copy of the .so named something else. This is roughly what I have:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8.7)
PROJECT(test1)

SET(TEST_SOURCES f1.c)
ADD_LIBRARY(test SHARED ${TEST_SOURCES})
ADD_CUSTOM_COMMAND(
    OUTPUT custom1
    COMMAND cp libtest.so custom1
    DEPENDS libtest.so)

我意识到有比硬编码库名称更好的方法,我只是在尝试弄清楚如何让它工作的同时这样做.我缺少什么会导致我的复制/重命名自定义命令运行?注意:这不是安装时的事情.谢谢

I realise there are better ways than hardcoding the library name, I'm just doing this while I try and figure out how to make it work at all. What's the thing I'm missing that will cause my copy/rename custom command to run? Note: this is not an install-time thing. Thanks

推荐答案

add_custom_target(CopyAndRename
    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/test.so ${CMAKE_BINARY_DIR}/SomeThingElse.so
)

add_custom_target 引入了一个名为 CopyAndRename 的新目标.你可以运行它:

add_custom_target introduces a new target named CopyAndRename. You can run it with:

make CopyAndRename

这篇关于cmake自定义命令复制和重命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆