定义不同目录中自定义命令之间的依赖关系
我有一个项目,其中一个自定义命令的输出用作另一个命令的输入,但在不同的目录中。例如:
目录 lib/CMakeLists.txt
包含:
add_custom_command(
OUTPUT libfoo.xx
COMMAND <command to build libfoo.xx>
)
add_custom_target(libfoo DEPENDS libfoo.xx)
目录 test/CMakeLists.txt
包含:
add_custom_command(OUTPUT test.yy
COMMAND <command to build test.yy>
DEPENDS "${PROJECT_BINARY_DIR}/lib/libfoo.xx"
)
所以我需要确保 libfoo 在 test.yy 之前构建。文档说 add_custom_command() 的 DEPENDS 子句只能具有文件级依赖项。让我们尝试一下,看看会发生什么:
No rule to make target 'lib/libfoo.xx', needed by 'test/test.yy'. Stop.
另一方面,如果我尝试通过说 DEPENDS libfoo
创建目标级依赖项,那么错误将更改为:
No rule to make target 'libfoo', needed by 'test/test.yy'. Stop.
So it isn't not file-level or target级依赖项将在这里起作用。有没有办法让一个自定义命令的输出成为不同目录中另一个自定义命令的输入?
I have a project in which the output of one custom command is used as the input to another, but in a different directory. So for example:
Directory lib/CMakeLists.txt
contains:
add_custom_command(
OUTPUT libfoo.xx
COMMAND <command to build libfoo.xx>
)
add_custom_target(libfoo DEPENDS libfoo.xx)
Directory test/CMakeLists.txt
contains:
add_custom_command(OUTPUT test.yy
COMMAND <command to build test.yy>
DEPENDS "${PROJECT_BINARY_DIR}/lib/libfoo.xx"
)
So I need to make sure that libfoo is build before test.yy. The docs say that the DEPENDS clause of add_custom_command() can only have file-level dependencies. Let's try that and see what happens:
No rule to make target 'lib/libfoo.xx', needed by 'test/test.yy'. Stop.
If on the other hand, I attempt to create a target-level dependency by saying DEPENDS libfoo
, then the error changes to:
No rule to make target 'libfoo', needed by 'test/test.yy'. Stop.
So it seems neither file-level or target-level dependencies will work here. Is there any way to have the output from one custom command be the input to another custom command, in a different directory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试在
test/CMakLists.txt
中添加添加
,然后在顶级
CMakeLists.txt
中。 免责声明:我没有测试过它,而且我是 CMake 初学者。告诉我们是否有效!
You could try in
test/CMakLists.txt
to addand then to add
in your top-level
CMakeLists.txt
.Disclaimer: I didn't test it and I'm a CMake beginner. Tell us if it works!