cmake add_custom_target保存目录 [英] cmake add_custom_target preserve directory

查看:123
本文介绍了cmake add_custom_target保存目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下CMakeFiles.txt中的以下行:

Imagine the following lines in a CMakeFiles.txt:

add_custom_target( target
          cd bin
          COMMAND echo "test" > README
)

设为目标无法按预期工作,因为它不会修改文件 bin / README 而是文件 ./ README 。我发现,为了使CMake修改 bin / README ,我必须编写

make target will not work as expected, as it will not modify the file bin/README but rather the file ./README. I found out that, in order to make CMake modify bin/README, I have to write

COMMAND cd bin&&回声测试 README

这很耗时,并且多次使用时会炸毁CMakeLists。我想要的行为与Shell脚本的行为非常相似。我该如何实现?

which is time consuming and blows the CMakeLists up when used multiple times. I want a behavior that is much like the behaviour of shell scripts. How can I achieve this?

推荐答案

使用 WORKING_DIRECTORY 指令:

add_custom_target( target
      COMMAND echo "test" > README
      WORKING_DIRECTORY bin
)

编辑:相反的COMMAND和WORKING_DIRECTORY订单

EDIT: Reversed COMMAND and WORKING_DIRECTORY order

这篇关于cmake add_custom_target保存目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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