定义不同目录中自定义命令之间的依赖关系

发布于 2024-11-04 14:50:46 字数 906 浏览 2 评论 0原文

我有一个项目,其中一个自定义命令的输出用作另一个命令的输入,但在不同的目录中。例如:

目录 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

莳間冲淡了誓言ζ 2024-11-11 14:50:46

您可以尝试在 test/CMakLists.txt 中添加

add_custom_target(test DEPENDS test.yy)

添加

add_dependencies(test libfoo)

,然后在顶级 CMakeLists.txt

免责声明:我没有测试过它,而且我是 CMake 初学者。告诉我们是否有效!

You could try in test/CMakLists.txt to add

add_custom_target(test DEPENDS test.yy)

and then to add

add_dependencies(test libfoo)

in your top-level CMakeLists.txt.

Disclaimer: I didn't test it and I'm a CMake beginner. Tell us if it works!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文